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