temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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