Mistake on this page?
Report an issue in GitHub or email us
CallChain.h
1 /* mbed Microcontroller Library
2  * Copyright (c) 2006-2013 ARM Limited
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_CALLCHAIN_H
18 #define MBED_CALLCHAIN_H
19 
20 #include "platform/Callback.h"
21 #include "platform/mbed_toolchain.h"
22 #include "platform/NonCopyable.h"
23 #include <string.h>
24 
25 namespace mbed {
26 
27 
28 typedef Callback<void()> *pFunctionPointer_t;
29 class CallChainLink;
30 
31 /** \addtogroup platform */
32 /** @{*/
33 /**
34  * \defgroup platform_CallChain CallChain class
35  * @{
36  */
37 
38 /** Group one or more functions in an instance of a CallChain, then call them in
39  * sequence using CallChain::call(). Used mostly by the interrupt chaining code,
40  * but can be used for other purposes.
41  *
42  * @deprecated Do not use this class. This class is not part of the public API of mbed-os and is being removed in the future.
43  * @note Synchronization level: Not protected
44  *
45  * Example:
46  * @code
47  * #include "mbed.h"
48  *
49  * CallChain chain;
50  *
51  * void first(void) {
52  * printf("'first' function.\n");
53  * }
54  *
55  * void second(void) {
56  * printf("'second' function.\n");
57  * }
58  *
59  * class Test {
60  * public:
61  * void f(void) {
62  * printf("A::f (class member).\n");
63  * }
64  * };
65  *
66  * int main() {
67  * Test test;
68  *
69  * chain.add(second);
70  * chain.add_front(first);
71  * chain.add(&test, &Test::f);
72  * chain.call();
73  * }
74  * @endcode
75  */
76 class CallChain : private NonCopyable<CallChain> {
77 public:
78  /** Create an empty chain
79  * @deprecated
80  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
81  *
82  * @param size (optional) Initial size of the chain
83  */
84  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
85  "public API of mbed-os and is being removed in the future.")
86  CallChain(int size = 4);
87 
88  /** Create an empty chain
89  * @deprecated
90  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
91  */
92  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
93  "public API of mbed-os and is being removed in the future.")
94  virtual ~CallChain();
95 
96  /** Add a function at the end of the chain
97  *
98  * @deprecated
99  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
100  *
101  * @param func A pointer to a void function
102  *
103  * @returns
104  * The function object created for 'func'
105  */
106  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
107  "public API of mbed-os and is being removed in the future.")
108  pFunctionPointer_t add(Callback<void()> func);
109 
110  /** Add a function at the end of the chain
111  *
112  * @param obj pointer to the object to call the member function on
113  * @param method pointer to the member function to be called
114  *
115  * @returns
116  * The function object created for 'obj' and 'method'
117  *
118  * @deprecated
119  * The add function does not support cv-qualifiers. Replaced by
120  * add(callback(obj, method)).
121  */
122  template<typename T, typename M>
123  MBED_DEPRECATED_SINCE("mbed-os-5.1",
124  "The add function does not support cv-qualifiers. Replaced by "
125  "add(callback(obj, method)).")
126  pFunctionPointer_t add(T *obj, M method)
127  {
128  return add(callback(obj, method));
129  }
130 
131  /** Add a function at the beginning of the chain
132  * @deprecated
133  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
134  *
135  *
136  * @param func A pointer to a void function
137  *
138  * @returns
139  * The function object created for 'func'
140  */
141  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
142  "public API of mbed-os and is being removed in the future.")
143  pFunctionPointer_t add_front(Callback<void()> func);
144 
145  /** Add a function at the beginning of the chain
146  *
147  * @param obj pointer to the object to call the member function on
148  * @param method pointer to the member function to be called
149  *
150  * @returns
151  * The function object created for the object and method pointers
152  *
153  * @deprecated
154  * The add_front function does not support cv-qualifiers. Replaced by
155  * add_front(callback(obj, method)).
156  */
157  template<typename T, typename M>
158  MBED_DEPRECATED_SINCE("mbed-os-5.1",
159  "The add_front function does not support cv-qualifiers. Replaced by "
160  "add_front(callback(obj, method)).")
161  pFunctionPointer_t add_front(T *obj, M method)
162  {
163  return add_front(callback(obj, method));
164  }
165 
166  /** Get the number of functions in the chain
167  * @deprecated
168  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
169  *
170  */
171  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
172  "public API of mbed-os and is being removed in the future.")
173  int size() const;
174 
175  /** Get a function object from the chain
176  * @deprecated
177  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
178  *
179  * @param i function object index
180  *
181  * @returns
182  * The function object at position 'i' in the chain
183  */
184  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
185  "public API of mbed-os and is being removed in the future.")
186  pFunctionPointer_t get(int i) const;
187 
188  /** Look for a function object in the call chain
189  * @deprecated
190  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
191  *
192  * @param f the function object to search
193  *
194  * @returns
195  * The index of the function object if found, -1 otherwise.
196  */
197  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
198  "public API of mbed-os and is being removed in the future.")
199  int find(pFunctionPointer_t f) const;
200 
201  /** Clear the call chain (remove all functions in the chain).
202  * @deprecated Do not use this function. This class is not part of the public API of mbed-os and is being removed in the future.
203  */
204  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
205  "public API of mbed-os and is being removed in the future.")
206  void clear();
207 
208  /** Remove a function object from the chain
209  * @deprecated
210  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
211  *
212  * @arg f the function object to remove
213  *
214  * @returns
215  * true if the function object was found and removed, false otherwise.
216  */
217  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
218  "public API of mbed-os and is being removed in the future.")
219  bool remove(pFunctionPointer_t f);
220 
221  /** Call all the functions in the chain in sequence
222  * @deprecated
223  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
224  *
225  */
226  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
227  "public API of mbed-os and is being removed in the future.")
228  void call();
229 
230  /**
231  * @deprecated
232  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
233  *
234  */
235  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
236  "public API of mbed-os and is being removed in the future.")
237  void operator()(void)
238  {
239  call();
240  }
241 
242  /**
243  * @deprecated
244  * Do not use this function, this class is not part of the public API of mbed-os and is being removed in the future.
245  *
246  */
247  MBED_DEPRECATED_SINCE("mbed-os-5.6", "This class is not part of the "
248  "public API of mbed-os and is being removed in the future.")
249  pFunctionPointer_t operator [](int i) const
250  {
251  return get(i);
252  }
253 
254 private:
255  CallChainLink *_chain;
256 };
257 
258 /**@}*/
259 
260 /**@}*/
261 
262 } // namespace mbed
263 
264 #endif
265 
pFunctionPointer_t add_front(Callback< void()> func)
Add a function at the beginning of the chain.
void clear()
Clear the call chain (remove all functions in the chain).
int size() const
Get the number of functions in the chain.
Prevents generation of copy constructor and copy assignment operator in derived classes.
Definition: NonCopyable.h:168
Callback< R()> callback(R(*func)()=0)
Create a callback class with type inferred from the arguments.
Definition: Callback.h:3848
CallChain(int size=4)
Create an empty chain.
int find(pFunctionPointer_t f) const
Look for a function object in the call chain.
pFunctionPointer_t add(Callback< void()> func)
Add a function at the end of the chain.
virtual ~CallChain()
Create an empty chain.
void call()
Call all the functions in the chain in sequence.
Callback class based on template specialization.
Definition: Callback.h:39
#define MBED_DEPRECATED_SINCE(D, M)
MBED_DEPRECATED("message string") Mark a function declaration as deprecated, if it used then a warnin...
Group one or more functions in an instance of a CallChain, then call them in sequence using CallChain...
Definition: CallChain.h:76
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.