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