mbed-os

Dependents:   cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more

Committer:
be_bryan
Date:
Mon Dec 11 17:54:04 2017 +0000
Revision:
0:b74591d5ab33
motor ++

Who changed what in which revision?

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