CallChain.h 8.8 KB

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