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