BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:47:08 2018 +0000
Revision:
1:9c5af431a1f1
sdf

Who changed what in which revision?

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