The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Anna Bridge
Date:
Fri Jun 22 15:38:59 2018 +0100
Revision:
169:a7c7b631e539
Parent:
165:d1b4690b3f8b
Child:
170:e95d10626187
mbed library. Release version 162

Who changed what in which revision?

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