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