The prosthetic control(MIT)

Committer:
ganlikun
Date:
Thu Jun 23 05:23:34 2022 +0000
Revision:
0:20e0c61e0684
01

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:20e0c61e0684 1 /* mbed Microcontroller Library
ganlikun 0:20e0c61e0684 2 * Copyright (c) 2006-2015 ARM Limited
ganlikun 0:20e0c61e0684 3 *
ganlikun 0:20e0c61e0684 4 * Licensed under the Apache License, Version 2.0 (the "License");
ganlikun 0:20e0c61e0684 5 * you may not use this file except in compliance with the License.
ganlikun 0:20e0c61e0684 6 * You may obtain a copy of the License at
ganlikun 0:20e0c61e0684 7 *
ganlikun 0:20e0c61e0684 8 * http://www.apache.org/licenses/LICENSE-2.0
ganlikun 0:20e0c61e0684 9 *
ganlikun 0:20e0c61e0684 10 * Unless required by applicable law or agreed to in writing, software
ganlikun 0:20e0c61e0684 11 * distributed under the License is distributed on an "AS IS" BASIS,
ganlikun 0:20e0c61e0684 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ganlikun 0:20e0c61e0684 13 * See the License for the specific language governing permissions and
ganlikun 0:20e0c61e0684 14 * limitations under the License.
ganlikun 0:20e0c61e0684 15 */
ganlikun 0:20e0c61e0684 16 #ifndef MBED_CALLBACK_H
ganlikun 0:20e0c61e0684 17 #define MBED_CALLBACK_H
ganlikun 0:20e0c61e0684 18
ganlikun 0:20e0c61e0684 19 #include <string.h>
ganlikun 0:20e0c61e0684 20 #include <stdint.h>
ganlikun 0:20e0c61e0684 21 #include <new>
ganlikun 0:20e0c61e0684 22 #include "platform/mbed_assert.h"
ganlikun 0:20e0c61e0684 23 #include "platform/mbed_toolchain.h"
ganlikun 0:20e0c61e0684 24
ganlikun 0:20e0c61e0684 25 namespace mbed {
ganlikun 0:20e0c61e0684 26 /** \addtogroup platform */
ganlikun 0:20e0c61e0684 27
ganlikun 0:20e0c61e0684 28
ganlikun 0:20e0c61e0684 29 /** Callback class based on template specialization
ganlikun 0:20e0c61e0684 30 *
ganlikun 0:20e0c61e0684 31 * @note Synchronization level: Not protected
ganlikun 0:20e0c61e0684 32 * @ingroup platform
ganlikun 0:20e0c61e0684 33 */
ganlikun 0:20e0c61e0684 34 template <typename F>
ganlikun 0:20e0c61e0684 35 class Callback;
ganlikun 0:20e0c61e0684 36
ganlikun 0:20e0c61e0684 37 // Internal sfinae declarations
ganlikun 0:20e0c61e0684 38 //
ganlikun 0:20e0c61e0684 39 // These are used to eliminate overloads based on type attributes
ganlikun 0:20e0c61e0684 40 // 1. Does a function object have a call operator
ganlikun 0:20e0c61e0684 41 // 2. Does a function object fit in the available storage
ganlikun 0:20e0c61e0684 42 //
ganlikun 0:20e0c61e0684 43 // These eliminations are handled cleanly by the compiler and avoid
ganlikun 0:20e0c61e0684 44 // massive and misleading error messages when confronted with an
ganlikun 0:20e0c61e0684 45 // invalid type (or worse, runtime failures)
ganlikun 0:20e0c61e0684 46 namespace detail {
ganlikun 0:20e0c61e0684 47 struct nil {};
ganlikun 0:20e0c61e0684 48
ganlikun 0:20e0c61e0684 49 template <bool B, typename R = nil>
ganlikun 0:20e0c61e0684 50 struct enable_if { typedef R type; };
ganlikun 0:20e0c61e0684 51
ganlikun 0:20e0c61e0684 52 template <typename R>
ganlikun 0:20e0c61e0684 53 struct enable_if<false, R> {};
ganlikun 0:20e0c61e0684 54
ganlikun 0:20e0c61e0684 55 template <typename M, M>
ganlikun 0:20e0c61e0684 56 struct is_type {
ganlikun 0:20e0c61e0684 57 static const bool value = true;
ganlikun 0:20e0c61e0684 58 };
ganlikun 0:20e0c61e0684 59 }
ganlikun 0:20e0c61e0684 60
ganlikun 0:20e0c61e0684 61 #define MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M) \
ganlikun 0:20e0c61e0684 62 typename detail::enable_if< \
ganlikun 0:20e0c61e0684 63 detail::is_type<M, &F::operator()>::value && \
ganlikun 0:20e0c61e0684 64 sizeof(F) <= sizeof(uintptr_t) \
ganlikun 0:20e0c61e0684 65 >::type = detail::nil()
ganlikun 0:20e0c61e0684 66
ganlikun 0:20e0c61e0684 67 /** Callback class based on template specialization
ganlikun 0:20e0c61e0684 68 *
ganlikun 0:20e0c61e0684 69 * @note Synchronization level: Not protected
ganlikun 0:20e0c61e0684 70 * @ingroup platform
ganlikun 0:20e0c61e0684 71 */
ganlikun 0:20e0c61e0684 72 template <typename R>
ganlikun 0:20e0c61e0684 73 class Callback<R()> {
ganlikun 0:20e0c61e0684 74 public:
ganlikun 0:20e0c61e0684 75 /** Create a Callback with a static function
ganlikun 0:20e0c61e0684 76 * @param func Static function to attach
ganlikun 0:20e0c61e0684 77 */
ganlikun 0:20e0c61e0684 78 Callback(R (*func)() = 0) {
ganlikun 0:20e0c61e0684 79 if (!func) {
ganlikun 0:20e0c61e0684 80 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 81 } else {
ganlikun 0:20e0c61e0684 82 generate(func);
ganlikun 0:20e0c61e0684 83 }
ganlikun 0:20e0c61e0684 84 }
ganlikun 0:20e0c61e0684 85
ganlikun 0:20e0c61e0684 86 /** Attach a Callback
ganlikun 0:20e0c61e0684 87 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 88 */
ganlikun 0:20e0c61e0684 89 Callback(const Callback<R()> &func) {
ganlikun 0:20e0c61e0684 90 if (func._ops) {
ganlikun 0:20e0c61e0684 91 func._ops->move(this, &func);
ganlikun 0:20e0c61e0684 92 }
ganlikun 0:20e0c61e0684 93 _ops = func._ops;
ganlikun 0:20e0c61e0684 94 }
ganlikun 0:20e0c61e0684 95
ganlikun 0:20e0c61e0684 96 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 97 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 98 * @param method Member function to attach
ganlikun 0:20e0c61e0684 99 */
ganlikun 0:20e0c61e0684 100 template<typename T, typename U>
ganlikun 0:20e0c61e0684 101 Callback(U *obj, R (T::*method)()) {
ganlikun 0:20e0c61e0684 102 generate(method_context<T, R (T::*)()>(obj, method));
ganlikun 0:20e0c61e0684 103 }
ganlikun 0:20e0c61e0684 104
ganlikun 0:20e0c61e0684 105 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 106 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 107 * @param method Member function to attach
ganlikun 0:20e0c61e0684 108 */
ganlikun 0:20e0c61e0684 109 template<typename T, typename U>
ganlikun 0:20e0c61e0684 110 Callback(const U *obj, R (T::*method)() const) {
ganlikun 0:20e0c61e0684 111 generate(method_context<const T, R (T::*)() const>(obj, method));
ganlikun 0:20e0c61e0684 112 }
ganlikun 0:20e0c61e0684 113
ganlikun 0:20e0c61e0684 114 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 115 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 116 * @param method Member function to attach
ganlikun 0:20e0c61e0684 117 */
ganlikun 0:20e0c61e0684 118 template<typename T, typename U>
ganlikun 0:20e0c61e0684 119 Callback(volatile U *obj, R (T::*method)() volatile) {
ganlikun 0:20e0c61e0684 120 generate(method_context<volatile T, R (T::*)() volatile>(obj, method));
ganlikun 0:20e0c61e0684 121 }
ganlikun 0:20e0c61e0684 122
ganlikun 0:20e0c61e0684 123 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 124 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 125 * @param method Member function to attach
ganlikun 0:20e0c61e0684 126 */
ganlikun 0:20e0c61e0684 127 template<typename T, typename U>
ganlikun 0:20e0c61e0684 128 Callback(const volatile U *obj, R (T::*method)() const volatile) {
ganlikun 0:20e0c61e0684 129 generate(method_context<const volatile T, R (T::*)() const volatile>(obj, method));
ganlikun 0:20e0c61e0684 130 }
ganlikun 0:20e0c61e0684 131
ganlikun 0:20e0c61e0684 132 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 133 * @param func Static function to attach
ganlikun 0:20e0c61e0684 134 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 135 */
ganlikun 0:20e0c61e0684 136 template<typename T, typename U>
ganlikun 0:20e0c61e0684 137 Callback(R (*func)(T*), U *arg) {
ganlikun 0:20e0c61e0684 138 generate(function_context<R (*)(T*), T>(func, arg));
ganlikun 0:20e0c61e0684 139 }
ganlikun 0:20e0c61e0684 140
ganlikun 0:20e0c61e0684 141 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 142 * @param func Static function to attach
ganlikun 0:20e0c61e0684 143 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 144 */
ganlikun 0:20e0c61e0684 145 template<typename T, typename U>
ganlikun 0:20e0c61e0684 146 Callback(R (*func)(const T*), const U *arg) {
ganlikun 0:20e0c61e0684 147 generate(function_context<R (*)(const T*), const T>(func, arg));
ganlikun 0:20e0c61e0684 148 }
ganlikun 0:20e0c61e0684 149
ganlikun 0:20e0c61e0684 150 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 151 * @param func Static function to attach
ganlikun 0:20e0c61e0684 152 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 153 */
ganlikun 0:20e0c61e0684 154 template<typename T, typename U>
ganlikun 0:20e0c61e0684 155 Callback(R (*func)(volatile T*), volatile U *arg) {
ganlikun 0:20e0c61e0684 156 generate(function_context<R (*)(volatile T*), volatile T>(func, arg));
ganlikun 0:20e0c61e0684 157 }
ganlikun 0:20e0c61e0684 158
ganlikun 0:20e0c61e0684 159 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 160 * @param func Static function to attach
ganlikun 0:20e0c61e0684 161 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 162 */
ganlikun 0:20e0c61e0684 163 template<typename T, typename U>
ganlikun 0:20e0c61e0684 164 Callback(R (*func)(const volatile T*), const volatile U *arg) {
ganlikun 0:20e0c61e0684 165 generate(function_context<R (*)(const volatile T*), const volatile T>(func, arg));
ganlikun 0:20e0c61e0684 166 }
ganlikun 0:20e0c61e0684 167
ganlikun 0:20e0c61e0684 168 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 169 * @param f Function object to attach
ganlikun 0:20e0c61e0684 170 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 171 */
ganlikun 0:20e0c61e0684 172 template <typename F>
ganlikun 0:20e0c61e0684 173 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)())) {
ganlikun 0:20e0c61e0684 174 generate(f);
ganlikun 0:20e0c61e0684 175 }
ganlikun 0:20e0c61e0684 176
ganlikun 0:20e0c61e0684 177 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 178 * @param f Function object to attach
ganlikun 0:20e0c61e0684 179 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 180 */
ganlikun 0:20e0c61e0684 181 template <typename F>
ganlikun 0:20e0c61e0684 182 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)() const)) {
ganlikun 0:20e0c61e0684 183 generate(f);
ganlikun 0:20e0c61e0684 184 }
ganlikun 0:20e0c61e0684 185
ganlikun 0:20e0c61e0684 186 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 187 * @param f Function object to attach
ganlikun 0:20e0c61e0684 188 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 189 */
ganlikun 0:20e0c61e0684 190 template <typename F>
ganlikun 0:20e0c61e0684 191 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)() volatile)) {
ganlikun 0:20e0c61e0684 192 generate(f);
ganlikun 0:20e0c61e0684 193 }
ganlikun 0:20e0c61e0684 194
ganlikun 0:20e0c61e0684 195 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 196 * @param f Function object to attach
ganlikun 0:20e0c61e0684 197 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 198 */
ganlikun 0:20e0c61e0684 199 template <typename F>
ganlikun 0:20e0c61e0684 200 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)() const volatile)) {
ganlikun 0:20e0c61e0684 201 generate(f);
ganlikun 0:20e0c61e0684 202 }
ganlikun 0:20e0c61e0684 203
ganlikun 0:20e0c61e0684 204 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 205 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 206 * @param func Static function to attach
ganlikun 0:20e0c61e0684 207 * @deprecated
ganlikun 0:20e0c61e0684 208 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 209 */
ganlikun 0:20e0c61e0684 210 template<typename T, typename U>
ganlikun 0:20e0c61e0684 211 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 212 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 213 Callback(U *obj, R (*func)(T*)) {
ganlikun 0:20e0c61e0684 214 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 215 }
ganlikun 0:20e0c61e0684 216
ganlikun 0:20e0c61e0684 217 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 218 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 219 * @param func Static function to attach
ganlikun 0:20e0c61e0684 220 * @deprecated
ganlikun 0:20e0c61e0684 221 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 222 */
ganlikun 0:20e0c61e0684 223 template<typename T, typename U>
ganlikun 0:20e0c61e0684 224 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 225 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 226 Callback(const U *obj, R (*func)(const T*)) {
ganlikun 0:20e0c61e0684 227 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 228 }
ganlikun 0:20e0c61e0684 229
ganlikun 0:20e0c61e0684 230 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 231 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 232 * @param func Static function to attach
ganlikun 0:20e0c61e0684 233 * @deprecated
ganlikun 0:20e0c61e0684 234 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 235 */
ganlikun 0:20e0c61e0684 236 template<typename T, typename U>
ganlikun 0:20e0c61e0684 237 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 238 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 239 Callback(volatile U *obj, R (*func)(volatile T*)) {
ganlikun 0:20e0c61e0684 240 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 241 }
ganlikun 0:20e0c61e0684 242
ganlikun 0:20e0c61e0684 243 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 244 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 245 * @param func Static function to attach
ganlikun 0:20e0c61e0684 246 * @deprecated
ganlikun 0:20e0c61e0684 247 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 248 */
ganlikun 0:20e0c61e0684 249 template<typename T, typename U>
ganlikun 0:20e0c61e0684 250 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 251 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 252 Callback(const volatile U *obj, R (*func)(const volatile T*)) {
ganlikun 0:20e0c61e0684 253 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 254 }
ganlikun 0:20e0c61e0684 255
ganlikun 0:20e0c61e0684 256 /** Destroy a callback
ganlikun 0:20e0c61e0684 257 */
ganlikun 0:20e0c61e0684 258 ~Callback() {
ganlikun 0:20e0c61e0684 259 if (_ops) {
ganlikun 0:20e0c61e0684 260 _ops->dtor(this);
ganlikun 0:20e0c61e0684 261 }
ganlikun 0:20e0c61e0684 262 }
ganlikun 0:20e0c61e0684 263
ganlikun 0:20e0c61e0684 264 /** Attach a static function
ganlikun 0:20e0c61e0684 265 * @param func Static function to attach
ganlikun 0:20e0c61e0684 266 * @deprecated
ganlikun 0:20e0c61e0684 267 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 268 */
ganlikun 0:20e0c61e0684 269 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 270 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 271 void attach(R (*func)()) {
ganlikun 0:20e0c61e0684 272 this->~Callback();
ganlikun 0:20e0c61e0684 273 new (this) Callback(func);
ganlikun 0:20e0c61e0684 274 }
ganlikun 0:20e0c61e0684 275
ganlikun 0:20e0c61e0684 276 /** Attach a Callback
ganlikun 0:20e0c61e0684 277 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 278 * @deprecated
ganlikun 0:20e0c61e0684 279 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 280 */
ganlikun 0:20e0c61e0684 281 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 282 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 283 void attach(const Callback<R()> &func) {
ganlikun 0:20e0c61e0684 284 this->~Callback();
ganlikun 0:20e0c61e0684 285 new (this) Callback(func);
ganlikun 0:20e0c61e0684 286 }
ganlikun 0:20e0c61e0684 287
ganlikun 0:20e0c61e0684 288 /** Attach a member function
ganlikun 0:20e0c61e0684 289 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 290 * @param method Member function to attach
ganlikun 0:20e0c61e0684 291 * @deprecated
ganlikun 0:20e0c61e0684 292 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 293 */
ganlikun 0:20e0c61e0684 294 template<typename T, typename U>
ganlikun 0:20e0c61e0684 295 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 296 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 297 void attach(U *obj, R (T::*method)()) {
ganlikun 0:20e0c61e0684 298 this->~Callback();
ganlikun 0:20e0c61e0684 299 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 300 }
ganlikun 0:20e0c61e0684 301
ganlikun 0:20e0c61e0684 302 /** Attach a member function
ganlikun 0:20e0c61e0684 303 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 304 * @param method Member function to attach
ganlikun 0:20e0c61e0684 305 * @deprecated
ganlikun 0:20e0c61e0684 306 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 307 */
ganlikun 0:20e0c61e0684 308 template<typename T, typename U>
ganlikun 0:20e0c61e0684 309 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 310 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 311 void attach(const U *obj, R (T::*method)() const) {
ganlikun 0:20e0c61e0684 312 this->~Callback();
ganlikun 0:20e0c61e0684 313 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 314 }
ganlikun 0:20e0c61e0684 315
ganlikun 0:20e0c61e0684 316 /** Attach a member function
ganlikun 0:20e0c61e0684 317 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 318 * @param method Member function to attach
ganlikun 0:20e0c61e0684 319 * @deprecated
ganlikun 0:20e0c61e0684 320 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 321 */
ganlikun 0:20e0c61e0684 322 template<typename T, typename U>
ganlikun 0:20e0c61e0684 323 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 324 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 325 void attach(volatile U *obj, R (T::*method)() volatile) {
ganlikun 0:20e0c61e0684 326 this->~Callback();
ganlikun 0:20e0c61e0684 327 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 328 }
ganlikun 0:20e0c61e0684 329
ganlikun 0:20e0c61e0684 330 /** Attach a member function
ganlikun 0:20e0c61e0684 331 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 332 * @param method Member function to attach
ganlikun 0:20e0c61e0684 333 * @deprecated
ganlikun 0:20e0c61e0684 334 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 335 */
ganlikun 0:20e0c61e0684 336 template<typename T, typename U>
ganlikun 0:20e0c61e0684 337 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 338 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 339 void attach(const volatile U *obj, R (T::*method)() const volatile) {
ganlikun 0:20e0c61e0684 340 this->~Callback();
ganlikun 0:20e0c61e0684 341 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 342 }
ganlikun 0:20e0c61e0684 343
ganlikun 0:20e0c61e0684 344 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 345 * @param func Static function to attach
ganlikun 0:20e0c61e0684 346 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 347 * @deprecated
ganlikun 0:20e0c61e0684 348 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 349 */
ganlikun 0:20e0c61e0684 350 template <typename T, typename U>
ganlikun 0:20e0c61e0684 351 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 352 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 353 void attach(R (*func)(T*), U *arg) {
ganlikun 0:20e0c61e0684 354 this->~Callback();
ganlikun 0:20e0c61e0684 355 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 356 }
ganlikun 0:20e0c61e0684 357
ganlikun 0:20e0c61e0684 358 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 359 * @param func Static function to attach
ganlikun 0:20e0c61e0684 360 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 361 * @deprecated
ganlikun 0:20e0c61e0684 362 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 363 */
ganlikun 0:20e0c61e0684 364 template <typename T, typename U>
ganlikun 0:20e0c61e0684 365 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 366 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 367 void attach(R (*func)(const T*), const U *arg) {
ganlikun 0:20e0c61e0684 368 this->~Callback();
ganlikun 0:20e0c61e0684 369 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 370 }
ganlikun 0:20e0c61e0684 371
ganlikun 0:20e0c61e0684 372 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 373 * @param func Static function to attach
ganlikun 0:20e0c61e0684 374 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 375 * @deprecated
ganlikun 0:20e0c61e0684 376 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 377 */
ganlikun 0:20e0c61e0684 378 template <typename T, typename U>
ganlikun 0:20e0c61e0684 379 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 380 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 381 void attach(R (*func)(volatile T*), volatile U *arg) {
ganlikun 0:20e0c61e0684 382 this->~Callback();
ganlikun 0:20e0c61e0684 383 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 384 }
ganlikun 0:20e0c61e0684 385
ganlikun 0:20e0c61e0684 386 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 387 * @param func Static function to attach
ganlikun 0:20e0c61e0684 388 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 389 * @deprecated
ganlikun 0:20e0c61e0684 390 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 391 */
ganlikun 0:20e0c61e0684 392 template <typename T, typename U>
ganlikun 0:20e0c61e0684 393 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 394 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 395 void attach(R (*func)(const volatile T*), const volatile U *arg) {
ganlikun 0:20e0c61e0684 396 this->~Callback();
ganlikun 0:20e0c61e0684 397 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 398 }
ganlikun 0:20e0c61e0684 399
ganlikun 0:20e0c61e0684 400 /** Attach a function object
ganlikun 0:20e0c61e0684 401 * @param f Function object to attach
ganlikun 0:20e0c61e0684 402 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 403 * @deprecated
ganlikun 0:20e0c61e0684 404 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 405 */
ganlikun 0:20e0c61e0684 406 template <typename F>
ganlikun 0:20e0c61e0684 407 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 408 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 409 void attach(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)())) {
ganlikun 0:20e0c61e0684 410 this->~Callback();
ganlikun 0:20e0c61e0684 411 new (this) Callback(f);
ganlikun 0:20e0c61e0684 412 }
ganlikun 0:20e0c61e0684 413
ganlikun 0:20e0c61e0684 414 /** Attach a function object
ganlikun 0:20e0c61e0684 415 * @param f Function object to attach
ganlikun 0:20e0c61e0684 416 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 417 * @deprecated
ganlikun 0:20e0c61e0684 418 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 419 */
ganlikun 0:20e0c61e0684 420 template <typename F>
ganlikun 0:20e0c61e0684 421 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 422 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 423 void attach(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)() const)) {
ganlikun 0:20e0c61e0684 424 this->~Callback();
ganlikun 0:20e0c61e0684 425 new (this) Callback(f);
ganlikun 0:20e0c61e0684 426 }
ganlikun 0:20e0c61e0684 427
ganlikun 0:20e0c61e0684 428 /** Attach a function object
ganlikun 0:20e0c61e0684 429 * @param f Function object to attach
ganlikun 0:20e0c61e0684 430 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 431 * @deprecated
ganlikun 0:20e0c61e0684 432 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 433 */
ganlikun 0:20e0c61e0684 434 template <typename F>
ganlikun 0:20e0c61e0684 435 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 436 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 437 void attach(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)() volatile)) {
ganlikun 0:20e0c61e0684 438 this->~Callback();
ganlikun 0:20e0c61e0684 439 new (this) Callback(f);
ganlikun 0:20e0c61e0684 440 }
ganlikun 0:20e0c61e0684 441
ganlikun 0:20e0c61e0684 442 /** Attach a function object
ganlikun 0:20e0c61e0684 443 * @param f Function object to attach
ganlikun 0:20e0c61e0684 444 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 445 * @deprecated
ganlikun 0:20e0c61e0684 446 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 447 */
ganlikun 0:20e0c61e0684 448 template <typename F>
ganlikun 0:20e0c61e0684 449 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 450 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 451 void attach(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)() const volatile)) {
ganlikun 0:20e0c61e0684 452 this->~Callback();
ganlikun 0:20e0c61e0684 453 new (this) Callback(f);
ganlikun 0:20e0c61e0684 454 }
ganlikun 0:20e0c61e0684 455
ganlikun 0:20e0c61e0684 456 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 457 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 458 * @param func Static function to attach
ganlikun 0:20e0c61e0684 459 * @deprecated
ganlikun 0:20e0c61e0684 460 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 461 */
ganlikun 0:20e0c61e0684 462 template <typename T, typename U>
ganlikun 0:20e0c61e0684 463 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 464 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 465 void attach(U *obj, R (*func)(T*)) {
ganlikun 0:20e0c61e0684 466 this->~Callback();
ganlikun 0:20e0c61e0684 467 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 468 }
ganlikun 0:20e0c61e0684 469
ganlikun 0:20e0c61e0684 470 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 471 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 472 * @param func Static function to attach
ganlikun 0:20e0c61e0684 473 * @deprecated
ganlikun 0:20e0c61e0684 474 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 475 */
ganlikun 0:20e0c61e0684 476 template <typename T, typename U>
ganlikun 0:20e0c61e0684 477 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 478 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 479 void attach(const U *obj, R (*func)(const T*)) {
ganlikun 0:20e0c61e0684 480 this->~Callback();
ganlikun 0:20e0c61e0684 481 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 482 }
ganlikun 0:20e0c61e0684 483
ganlikun 0:20e0c61e0684 484 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 485 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 486 * @param func Static function to attach
ganlikun 0:20e0c61e0684 487 * @deprecated
ganlikun 0:20e0c61e0684 488 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 489 */
ganlikun 0:20e0c61e0684 490 template <typename T, typename U>
ganlikun 0:20e0c61e0684 491 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 492 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 493 void attach(volatile U *obj, R (*func)(volatile T*)) {
ganlikun 0:20e0c61e0684 494 this->~Callback();
ganlikun 0:20e0c61e0684 495 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 496 }
ganlikun 0:20e0c61e0684 497
ganlikun 0:20e0c61e0684 498 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 499 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 500 * @param func Static function to attach
ganlikun 0:20e0c61e0684 501 * @deprecated
ganlikun 0:20e0c61e0684 502 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 503 */
ganlikun 0:20e0c61e0684 504 template <typename T, typename U>
ganlikun 0:20e0c61e0684 505 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 506 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 507 void attach(const volatile U *obj, R (*func)(const volatile T*)) {
ganlikun 0:20e0c61e0684 508 this->~Callback();
ganlikun 0:20e0c61e0684 509 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 510 }
ganlikun 0:20e0c61e0684 511
ganlikun 0:20e0c61e0684 512 /** Assign a callback
ganlikun 0:20e0c61e0684 513 */
ganlikun 0:20e0c61e0684 514 Callback &operator=(const Callback &that) {
ganlikun 0:20e0c61e0684 515 if (this != &that) {
ganlikun 0:20e0c61e0684 516 this->~Callback();
ganlikun 0:20e0c61e0684 517 new (this) Callback(that);
ganlikun 0:20e0c61e0684 518 }
ganlikun 0:20e0c61e0684 519
ganlikun 0:20e0c61e0684 520 return *this;
ganlikun 0:20e0c61e0684 521 }
ganlikun 0:20e0c61e0684 522
ganlikun 0:20e0c61e0684 523 /** Call the attached function
ganlikun 0:20e0c61e0684 524 */
ganlikun 0:20e0c61e0684 525 R call() const {
ganlikun 0:20e0c61e0684 526 MBED_ASSERT(_ops);
ganlikun 0:20e0c61e0684 527 return _ops->call(this);
ganlikun 0:20e0c61e0684 528 }
ganlikun 0:20e0c61e0684 529
ganlikun 0:20e0c61e0684 530 /** Call the attached function
ganlikun 0:20e0c61e0684 531 */
ganlikun 0:20e0c61e0684 532 R operator()() const {
ganlikun 0:20e0c61e0684 533 return call();
ganlikun 0:20e0c61e0684 534 }
ganlikun 0:20e0c61e0684 535
ganlikun 0:20e0c61e0684 536 /** Test if function has been attached
ganlikun 0:20e0c61e0684 537 */
ganlikun 0:20e0c61e0684 538 operator bool() const {
ganlikun 0:20e0c61e0684 539 return _ops;
ganlikun 0:20e0c61e0684 540 }
ganlikun 0:20e0c61e0684 541
ganlikun 0:20e0c61e0684 542 /** Test for equality
ganlikun 0:20e0c61e0684 543 */
ganlikun 0:20e0c61e0684 544 friend bool operator==(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 545 return memcmp(&l, &r, sizeof(Callback)) == 0;
ganlikun 0:20e0c61e0684 546 }
ganlikun 0:20e0c61e0684 547
ganlikun 0:20e0c61e0684 548 /** Test for inequality
ganlikun 0:20e0c61e0684 549 */
ganlikun 0:20e0c61e0684 550 friend bool operator!=(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 551 return !(l == r);
ganlikun 0:20e0c61e0684 552 }
ganlikun 0:20e0c61e0684 553
ganlikun 0:20e0c61e0684 554 /** Static thunk for passing as C-style function
ganlikun 0:20e0c61e0684 555 * @param func Callback to call passed as void pointer
ganlikun 0:20e0c61e0684 556 * @return the value as determined by func which is of
ganlikun 0:20e0c61e0684 557 * type and determined by the signiture of func
ganlikun 0:20e0c61e0684 558 */
ganlikun 0:20e0c61e0684 559 static R thunk(void *func) {
ganlikun 0:20e0c61e0684 560 return static_cast<Callback*>(func)->call();
ganlikun 0:20e0c61e0684 561 }
ganlikun 0:20e0c61e0684 562
ganlikun 0:20e0c61e0684 563 private:
ganlikun 0:20e0c61e0684 564 // Stored as pointer to function and pointer to optional object
ganlikun 0:20e0c61e0684 565 // Function pointer is stored as union of possible function types
ganlikun 0:20e0c61e0684 566 // to garuntee proper size and alignment
ganlikun 0:20e0c61e0684 567 struct _class;
ganlikun 0:20e0c61e0684 568 union {
ganlikun 0:20e0c61e0684 569 void (*_staticfunc)();
ganlikun 0:20e0c61e0684 570 void (*_boundfunc)(_class*);
ganlikun 0:20e0c61e0684 571 void (_class::*_methodfunc)();
ganlikun 0:20e0c61e0684 572 } _func;
ganlikun 0:20e0c61e0684 573 void *_obj;
ganlikun 0:20e0c61e0684 574
ganlikun 0:20e0c61e0684 575 // Dynamically dispatched operations
ganlikun 0:20e0c61e0684 576 const struct ops {
ganlikun 0:20e0c61e0684 577 R (*call)(const void*);
ganlikun 0:20e0c61e0684 578 void (*move)(void*, const void*);
ganlikun 0:20e0c61e0684 579 void (*dtor)(void*);
ganlikun 0:20e0c61e0684 580 } *_ops;
ganlikun 0:20e0c61e0684 581
ganlikun 0:20e0c61e0684 582 // Generate operations for function object
ganlikun 0:20e0c61e0684 583 template <typename F>
ganlikun 0:20e0c61e0684 584 void generate(const F &f) {
ganlikun 0:20e0c61e0684 585 static const ops ops = {
ganlikun 0:20e0c61e0684 586 &Callback::function_call<F>,
ganlikun 0:20e0c61e0684 587 &Callback::function_move<F>,
ganlikun 0:20e0c61e0684 588 &Callback::function_dtor<F>,
ganlikun 0:20e0c61e0684 589 };
ganlikun 0:20e0c61e0684 590
ganlikun 0:20e0c61e0684 591 MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
ganlikun 0:20e0c61e0684 592 "Type F must not exceed the size of the Callback class");
ganlikun 0:20e0c61e0684 593 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 594 new (this) F(f);
ganlikun 0:20e0c61e0684 595 _ops = &ops;
ganlikun 0:20e0c61e0684 596 }
ganlikun 0:20e0c61e0684 597
ganlikun 0:20e0c61e0684 598 // Function attributes
ganlikun 0:20e0c61e0684 599 template <typename F>
ganlikun 0:20e0c61e0684 600 static R function_call(const void *p) {
ganlikun 0:20e0c61e0684 601 return (*(F*)p)();
ganlikun 0:20e0c61e0684 602 }
ganlikun 0:20e0c61e0684 603
ganlikun 0:20e0c61e0684 604 template <typename F>
ganlikun 0:20e0c61e0684 605 static void function_move(void *d, const void *p) {
ganlikun 0:20e0c61e0684 606 new (d) F(*(F*)p);
ganlikun 0:20e0c61e0684 607 }
ganlikun 0:20e0c61e0684 608
ganlikun 0:20e0c61e0684 609 template <typename F>
ganlikun 0:20e0c61e0684 610 static void function_dtor(void *p) {
ganlikun 0:20e0c61e0684 611 ((F*)p)->~F();
ganlikun 0:20e0c61e0684 612 }
ganlikun 0:20e0c61e0684 613
ganlikun 0:20e0c61e0684 614 // Wrappers for functions with context
ganlikun 0:20e0c61e0684 615 template <typename O, typename M>
ganlikun 0:20e0c61e0684 616 struct method_context {
ganlikun 0:20e0c61e0684 617 M method;
ganlikun 0:20e0c61e0684 618 O *obj;
ganlikun 0:20e0c61e0684 619
ganlikun 0:20e0c61e0684 620 method_context(O *obj, M method)
ganlikun 0:20e0c61e0684 621 : method(method), obj(obj) {}
ganlikun 0:20e0c61e0684 622
ganlikun 0:20e0c61e0684 623 R operator()() const {
ganlikun 0:20e0c61e0684 624 return (obj->*method)();
ganlikun 0:20e0c61e0684 625 }
ganlikun 0:20e0c61e0684 626 };
ganlikun 0:20e0c61e0684 627
ganlikun 0:20e0c61e0684 628 template <typename F, typename A>
ganlikun 0:20e0c61e0684 629 struct function_context {
ganlikun 0:20e0c61e0684 630 F func;
ganlikun 0:20e0c61e0684 631 A *arg;
ganlikun 0:20e0c61e0684 632
ganlikun 0:20e0c61e0684 633 function_context(F func, A *arg)
ganlikun 0:20e0c61e0684 634 : func(func), arg(arg) {}
ganlikun 0:20e0c61e0684 635
ganlikun 0:20e0c61e0684 636 R operator()() const {
ganlikun 0:20e0c61e0684 637 return func(arg);
ganlikun 0:20e0c61e0684 638 }
ganlikun 0:20e0c61e0684 639 };
ganlikun 0:20e0c61e0684 640 };
ganlikun 0:20e0c61e0684 641
ganlikun 0:20e0c61e0684 642 /** Callback class based on template specialization
ganlikun 0:20e0c61e0684 643 *
ganlikun 0:20e0c61e0684 644 * @note Synchronization level: Not protected
ganlikun 0:20e0c61e0684 645 * @ingroup platform
ganlikun 0:20e0c61e0684 646 */
ganlikun 0:20e0c61e0684 647 template <typename R, typename A0>
ganlikun 0:20e0c61e0684 648 class Callback<R(A0)> {
ganlikun 0:20e0c61e0684 649 public:
ganlikun 0:20e0c61e0684 650 /** Create a Callback with a static function
ganlikun 0:20e0c61e0684 651 * @param func Static function to attach
ganlikun 0:20e0c61e0684 652 */
ganlikun 0:20e0c61e0684 653 Callback(R (*func)(A0) = 0) {
ganlikun 0:20e0c61e0684 654 if (!func) {
ganlikun 0:20e0c61e0684 655 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 656 } else {
ganlikun 0:20e0c61e0684 657 generate(func);
ganlikun 0:20e0c61e0684 658 }
ganlikun 0:20e0c61e0684 659 }
ganlikun 0:20e0c61e0684 660
ganlikun 0:20e0c61e0684 661 /** Attach a Callback
ganlikun 0:20e0c61e0684 662 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 663 */
ganlikun 0:20e0c61e0684 664 Callback(const Callback<R(A0)> &func) {
ganlikun 0:20e0c61e0684 665 if (func._ops) {
ganlikun 0:20e0c61e0684 666 func._ops->move(this, &func);
ganlikun 0:20e0c61e0684 667 }
ganlikun 0:20e0c61e0684 668 _ops = func._ops;
ganlikun 0:20e0c61e0684 669 }
ganlikun 0:20e0c61e0684 670
ganlikun 0:20e0c61e0684 671 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 672 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 673 * @param method Member function to attach
ganlikun 0:20e0c61e0684 674 */
ganlikun 0:20e0c61e0684 675 template<typename T, typename U>
ganlikun 0:20e0c61e0684 676 Callback(U *obj, R (T::*method)(A0)) {
ganlikun 0:20e0c61e0684 677 generate(method_context<T, R (T::*)(A0)>(obj, method));
ganlikun 0:20e0c61e0684 678 }
ganlikun 0:20e0c61e0684 679
ganlikun 0:20e0c61e0684 680 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 681 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 682 * @param method Member function to attach
ganlikun 0:20e0c61e0684 683 */
ganlikun 0:20e0c61e0684 684 template<typename T, typename U>
ganlikun 0:20e0c61e0684 685 Callback(const U *obj, R (T::*method)(A0) const) {
ganlikun 0:20e0c61e0684 686 generate(method_context<const T, R (T::*)(A0) const>(obj, method));
ganlikun 0:20e0c61e0684 687 }
ganlikun 0:20e0c61e0684 688
ganlikun 0:20e0c61e0684 689 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 690 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 691 * @param method Member function to attach
ganlikun 0:20e0c61e0684 692 */
ganlikun 0:20e0c61e0684 693 template<typename T, typename U>
ganlikun 0:20e0c61e0684 694 Callback(volatile U *obj, R (T::*method)(A0) volatile) {
ganlikun 0:20e0c61e0684 695 generate(method_context<volatile T, R (T::*)(A0) volatile>(obj, method));
ganlikun 0:20e0c61e0684 696 }
ganlikun 0:20e0c61e0684 697
ganlikun 0:20e0c61e0684 698 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 699 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 700 * @param method Member function to attach
ganlikun 0:20e0c61e0684 701 */
ganlikun 0:20e0c61e0684 702 template<typename T, typename U>
ganlikun 0:20e0c61e0684 703 Callback(const volatile U *obj, R (T::*method)(A0) const volatile) {
ganlikun 0:20e0c61e0684 704 generate(method_context<const volatile T, R (T::*)(A0) const volatile>(obj, method));
ganlikun 0:20e0c61e0684 705 }
ganlikun 0:20e0c61e0684 706
ganlikun 0:20e0c61e0684 707 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 708 * @param func Static function to attach
ganlikun 0:20e0c61e0684 709 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 710 */
ganlikun 0:20e0c61e0684 711 template<typename T, typename U>
ganlikun 0:20e0c61e0684 712 Callback(R (*func)(T*, A0), U *arg) {
ganlikun 0:20e0c61e0684 713 generate(function_context<R (*)(T*, A0), T>(func, arg));
ganlikun 0:20e0c61e0684 714 }
ganlikun 0:20e0c61e0684 715
ganlikun 0:20e0c61e0684 716 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 717 * @param func Static function to attach
ganlikun 0:20e0c61e0684 718 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 719 */
ganlikun 0:20e0c61e0684 720 template<typename T, typename U>
ganlikun 0:20e0c61e0684 721 Callback(R (*func)(const T*, A0), const U *arg) {
ganlikun 0:20e0c61e0684 722 generate(function_context<R (*)(const T*, A0), const T>(func, arg));
ganlikun 0:20e0c61e0684 723 }
ganlikun 0:20e0c61e0684 724
ganlikun 0:20e0c61e0684 725 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 726 * @param func Static function to attach
ganlikun 0:20e0c61e0684 727 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 728 */
ganlikun 0:20e0c61e0684 729 template<typename T, typename U>
ganlikun 0:20e0c61e0684 730 Callback(R (*func)(volatile T*, A0), volatile U *arg) {
ganlikun 0:20e0c61e0684 731 generate(function_context<R (*)(volatile T*, A0), volatile T>(func, arg));
ganlikun 0:20e0c61e0684 732 }
ganlikun 0:20e0c61e0684 733
ganlikun 0:20e0c61e0684 734 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 735 * @param func Static function to attach
ganlikun 0:20e0c61e0684 736 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 737 */
ganlikun 0:20e0c61e0684 738 template<typename T, typename U>
ganlikun 0:20e0c61e0684 739 Callback(R (*func)(const volatile T*, A0), const volatile U *arg) {
ganlikun 0:20e0c61e0684 740 generate(function_context<R (*)(const volatile T*, A0), const volatile T>(func, arg));
ganlikun 0:20e0c61e0684 741 }
ganlikun 0:20e0c61e0684 742
ganlikun 0:20e0c61e0684 743 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 744 * @param f Function object to attach
ganlikun 0:20e0c61e0684 745 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 746 */
ganlikun 0:20e0c61e0684 747 template <typename F>
ganlikun 0:20e0c61e0684 748 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0))) {
ganlikun 0:20e0c61e0684 749 generate(f);
ganlikun 0:20e0c61e0684 750 }
ganlikun 0:20e0c61e0684 751
ganlikun 0:20e0c61e0684 752 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 753 * @param f Function object to attach
ganlikun 0:20e0c61e0684 754 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 755 */
ganlikun 0:20e0c61e0684 756 template <typename F>
ganlikun 0:20e0c61e0684 757 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0) const)) {
ganlikun 0:20e0c61e0684 758 generate(f);
ganlikun 0:20e0c61e0684 759 }
ganlikun 0:20e0c61e0684 760
ganlikun 0:20e0c61e0684 761 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 762 * @param f Function object to attach
ganlikun 0:20e0c61e0684 763 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 764 */
ganlikun 0:20e0c61e0684 765 template <typename F>
ganlikun 0:20e0c61e0684 766 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0) volatile)) {
ganlikun 0:20e0c61e0684 767 generate(f);
ganlikun 0:20e0c61e0684 768 }
ganlikun 0:20e0c61e0684 769
ganlikun 0:20e0c61e0684 770 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 771 * @param f Function object to attach
ganlikun 0:20e0c61e0684 772 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 773 */
ganlikun 0:20e0c61e0684 774 template <typename F>
ganlikun 0:20e0c61e0684 775 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0) const volatile)) {
ganlikun 0:20e0c61e0684 776 generate(f);
ganlikun 0:20e0c61e0684 777 }
ganlikun 0:20e0c61e0684 778
ganlikun 0:20e0c61e0684 779 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 780 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 781 * @param func Static function to attach
ganlikun 0:20e0c61e0684 782 * @deprecated
ganlikun 0:20e0c61e0684 783 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 784 */
ganlikun 0:20e0c61e0684 785 template<typename T, typename U>
ganlikun 0:20e0c61e0684 786 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 787 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 788 Callback(U *obj, R (*func)(T*, A0)) {
ganlikun 0:20e0c61e0684 789 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 790 }
ganlikun 0:20e0c61e0684 791
ganlikun 0:20e0c61e0684 792 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 793 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 794 * @param func Static function to attach
ganlikun 0:20e0c61e0684 795 * @deprecated
ganlikun 0:20e0c61e0684 796 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 797 */
ganlikun 0:20e0c61e0684 798 template<typename T, typename U>
ganlikun 0:20e0c61e0684 799 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 800 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 801 Callback(const U *obj, R (*func)(const T*, A0)) {
ganlikun 0:20e0c61e0684 802 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 803 }
ganlikun 0:20e0c61e0684 804
ganlikun 0:20e0c61e0684 805 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 806 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 807 * @param func Static function to attach
ganlikun 0:20e0c61e0684 808 * @deprecated
ganlikun 0:20e0c61e0684 809 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 810 */
ganlikun 0:20e0c61e0684 811 template<typename T, typename U>
ganlikun 0:20e0c61e0684 812 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 813 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 814 Callback(volatile U *obj, R (*func)(volatile T*, A0)) {
ganlikun 0:20e0c61e0684 815 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 816 }
ganlikun 0:20e0c61e0684 817
ganlikun 0:20e0c61e0684 818 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 819 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 820 * @param func Static function to attach
ganlikun 0:20e0c61e0684 821 * @deprecated
ganlikun 0:20e0c61e0684 822 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 823 */
ganlikun 0:20e0c61e0684 824 template<typename T, typename U>
ganlikun 0:20e0c61e0684 825 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 826 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 827 Callback(const volatile U *obj, R (*func)(const volatile T*, A0)) {
ganlikun 0:20e0c61e0684 828 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 829 }
ganlikun 0:20e0c61e0684 830
ganlikun 0:20e0c61e0684 831 /** Destroy a callback
ganlikun 0:20e0c61e0684 832 */
ganlikun 0:20e0c61e0684 833 ~Callback() {
ganlikun 0:20e0c61e0684 834 if (_ops) {
ganlikun 0:20e0c61e0684 835 _ops->dtor(this);
ganlikun 0:20e0c61e0684 836 }
ganlikun 0:20e0c61e0684 837 }
ganlikun 0:20e0c61e0684 838
ganlikun 0:20e0c61e0684 839 /** Attach a static function
ganlikun 0:20e0c61e0684 840 * @param func Static function to attach
ganlikun 0:20e0c61e0684 841 * @deprecated
ganlikun 0:20e0c61e0684 842 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 843 */
ganlikun 0:20e0c61e0684 844 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 845 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 846 void attach(R (*func)(A0)) {
ganlikun 0:20e0c61e0684 847 this->~Callback();
ganlikun 0:20e0c61e0684 848 new (this) Callback(func);
ganlikun 0:20e0c61e0684 849 }
ganlikun 0:20e0c61e0684 850
ganlikun 0:20e0c61e0684 851 /** Attach a Callback
ganlikun 0:20e0c61e0684 852 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 853 * @deprecated
ganlikun 0:20e0c61e0684 854 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 855 */
ganlikun 0:20e0c61e0684 856 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 857 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 858 void attach(const Callback<R(A0)> &func) {
ganlikun 0:20e0c61e0684 859 this->~Callback();
ganlikun 0:20e0c61e0684 860 new (this) Callback(func);
ganlikun 0:20e0c61e0684 861 }
ganlikun 0:20e0c61e0684 862
ganlikun 0:20e0c61e0684 863 /** Attach a member function
ganlikun 0:20e0c61e0684 864 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 865 * @param method Member function to attach
ganlikun 0:20e0c61e0684 866 * @deprecated
ganlikun 0:20e0c61e0684 867 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 868 */
ganlikun 0:20e0c61e0684 869 template<typename T, typename U>
ganlikun 0:20e0c61e0684 870 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 871 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 872 void attach(U *obj, R (T::*method)(A0)) {
ganlikun 0:20e0c61e0684 873 this->~Callback();
ganlikun 0:20e0c61e0684 874 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 875 }
ganlikun 0:20e0c61e0684 876
ganlikun 0:20e0c61e0684 877 /** Attach a member function
ganlikun 0:20e0c61e0684 878 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 879 * @param method Member function to attach
ganlikun 0:20e0c61e0684 880 * @deprecated
ganlikun 0:20e0c61e0684 881 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 882 */
ganlikun 0:20e0c61e0684 883 template<typename T, typename U>
ganlikun 0:20e0c61e0684 884 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 885 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 886 void attach(const U *obj, R (T::*method)(A0) const) {
ganlikun 0:20e0c61e0684 887 this->~Callback();
ganlikun 0:20e0c61e0684 888 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 889 }
ganlikun 0:20e0c61e0684 890
ganlikun 0:20e0c61e0684 891 /** Attach a member function
ganlikun 0:20e0c61e0684 892 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 893 * @param method Member function to attach
ganlikun 0:20e0c61e0684 894 * @deprecated
ganlikun 0:20e0c61e0684 895 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 896 */
ganlikun 0:20e0c61e0684 897 template<typename T, typename U>
ganlikun 0:20e0c61e0684 898 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 899 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 900 void attach(volatile U *obj, R (T::*method)(A0) volatile) {
ganlikun 0:20e0c61e0684 901 this->~Callback();
ganlikun 0:20e0c61e0684 902 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 903 }
ganlikun 0:20e0c61e0684 904
ganlikun 0:20e0c61e0684 905 /** Attach a member function
ganlikun 0:20e0c61e0684 906 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 907 * @param method Member function to attach
ganlikun 0:20e0c61e0684 908 * @deprecated
ganlikun 0:20e0c61e0684 909 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 910 */
ganlikun 0:20e0c61e0684 911 template<typename T, typename U>
ganlikun 0:20e0c61e0684 912 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 913 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 914 void attach(const volatile U *obj, R (T::*method)(A0) const volatile) {
ganlikun 0:20e0c61e0684 915 this->~Callback();
ganlikun 0:20e0c61e0684 916 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 917 }
ganlikun 0:20e0c61e0684 918
ganlikun 0:20e0c61e0684 919 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 920 * @param func Static function to attach
ganlikun 0:20e0c61e0684 921 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 922 * @deprecated
ganlikun 0:20e0c61e0684 923 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 924 */
ganlikun 0:20e0c61e0684 925 template <typename T, typename U>
ganlikun 0:20e0c61e0684 926 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 927 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 928 void attach(R (*func)(T*, A0), U *arg) {
ganlikun 0:20e0c61e0684 929 this->~Callback();
ganlikun 0:20e0c61e0684 930 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 931 }
ganlikun 0:20e0c61e0684 932
ganlikun 0:20e0c61e0684 933 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 934 * @param func Static function to attach
ganlikun 0:20e0c61e0684 935 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 936 * @deprecated
ganlikun 0:20e0c61e0684 937 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 938 */
ganlikun 0:20e0c61e0684 939 template <typename T, typename U>
ganlikun 0:20e0c61e0684 940 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 941 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 942 void attach(R (*func)(const T*, A0), const U *arg) {
ganlikun 0:20e0c61e0684 943 this->~Callback();
ganlikun 0:20e0c61e0684 944 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 945 }
ganlikun 0:20e0c61e0684 946
ganlikun 0:20e0c61e0684 947 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 948 * @param func Static function to attach
ganlikun 0:20e0c61e0684 949 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 950 * @deprecated
ganlikun 0:20e0c61e0684 951 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 952 */
ganlikun 0:20e0c61e0684 953 template <typename T, typename U>
ganlikun 0:20e0c61e0684 954 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 955 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 956 void attach(R (*func)(volatile T*, A0), volatile U *arg) {
ganlikun 0:20e0c61e0684 957 this->~Callback();
ganlikun 0:20e0c61e0684 958 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 959 }
ganlikun 0:20e0c61e0684 960
ganlikun 0:20e0c61e0684 961 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 962 * @param func Static function to attach
ganlikun 0:20e0c61e0684 963 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 964 * @deprecated
ganlikun 0:20e0c61e0684 965 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 966 */
ganlikun 0:20e0c61e0684 967 template <typename T, typename U>
ganlikun 0:20e0c61e0684 968 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 969 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 970 void attach(R (*func)(const volatile T*, A0), const volatile U *arg) {
ganlikun 0:20e0c61e0684 971 this->~Callback();
ganlikun 0:20e0c61e0684 972 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 973 }
ganlikun 0:20e0c61e0684 974
ganlikun 0:20e0c61e0684 975 /** Attach a function object
ganlikun 0:20e0c61e0684 976 * @param f Function object to attach
ganlikun 0:20e0c61e0684 977 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 978 * @deprecated
ganlikun 0:20e0c61e0684 979 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 980 */
ganlikun 0:20e0c61e0684 981 template <typename F>
ganlikun 0:20e0c61e0684 982 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 983 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 984 void attach(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0))) {
ganlikun 0:20e0c61e0684 985 this->~Callback();
ganlikun 0:20e0c61e0684 986 new (this) Callback(f);
ganlikun 0:20e0c61e0684 987 }
ganlikun 0:20e0c61e0684 988
ganlikun 0:20e0c61e0684 989 /** Attach a function object
ganlikun 0:20e0c61e0684 990 * @param f Function object to attach
ganlikun 0:20e0c61e0684 991 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 992 * @deprecated
ganlikun 0:20e0c61e0684 993 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 994 */
ganlikun 0:20e0c61e0684 995 template <typename F>
ganlikun 0:20e0c61e0684 996 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 997 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 998 void attach(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0) const)) {
ganlikun 0:20e0c61e0684 999 this->~Callback();
ganlikun 0:20e0c61e0684 1000 new (this) Callback(f);
ganlikun 0:20e0c61e0684 1001 }
ganlikun 0:20e0c61e0684 1002
ganlikun 0:20e0c61e0684 1003 /** Attach a function object
ganlikun 0:20e0c61e0684 1004 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1005 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1006 * @deprecated
ganlikun 0:20e0c61e0684 1007 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1008 */
ganlikun 0:20e0c61e0684 1009 template <typename F>
ganlikun 0:20e0c61e0684 1010 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1011 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1012 void attach(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0) volatile)) {
ganlikun 0:20e0c61e0684 1013 this->~Callback();
ganlikun 0:20e0c61e0684 1014 new (this) Callback(f);
ganlikun 0:20e0c61e0684 1015 }
ganlikun 0:20e0c61e0684 1016
ganlikun 0:20e0c61e0684 1017 /** Attach a function object
ganlikun 0:20e0c61e0684 1018 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1019 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1020 * @deprecated
ganlikun 0:20e0c61e0684 1021 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1022 */
ganlikun 0:20e0c61e0684 1023 template <typename F>
ganlikun 0:20e0c61e0684 1024 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1025 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1026 void attach(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0) const volatile)) {
ganlikun 0:20e0c61e0684 1027 this->~Callback();
ganlikun 0:20e0c61e0684 1028 new (this) Callback(f);
ganlikun 0:20e0c61e0684 1029 }
ganlikun 0:20e0c61e0684 1030
ganlikun 0:20e0c61e0684 1031 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1032 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1033 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1034 * @deprecated
ganlikun 0:20e0c61e0684 1035 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 1036 */
ganlikun 0:20e0c61e0684 1037 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1038 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1039 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 1040 void attach(U *obj, R (*func)(T*, A0)) {
ganlikun 0:20e0c61e0684 1041 this->~Callback();
ganlikun 0:20e0c61e0684 1042 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1043 }
ganlikun 0:20e0c61e0684 1044
ganlikun 0:20e0c61e0684 1045 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1046 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1047 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1048 * @deprecated
ganlikun 0:20e0c61e0684 1049 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 1050 */
ganlikun 0:20e0c61e0684 1051 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1052 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1053 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 1054 void attach(const U *obj, R (*func)(const T*, A0)) {
ganlikun 0:20e0c61e0684 1055 this->~Callback();
ganlikun 0:20e0c61e0684 1056 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1057 }
ganlikun 0:20e0c61e0684 1058
ganlikun 0:20e0c61e0684 1059 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1060 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1061 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1062 * @deprecated
ganlikun 0:20e0c61e0684 1063 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 1064 */
ganlikun 0:20e0c61e0684 1065 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1066 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1067 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 1068 void attach(volatile U *obj, R (*func)(volatile T*, A0)) {
ganlikun 0:20e0c61e0684 1069 this->~Callback();
ganlikun 0:20e0c61e0684 1070 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1071 }
ganlikun 0:20e0c61e0684 1072
ganlikun 0:20e0c61e0684 1073 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1074 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1075 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1076 * @deprecated
ganlikun 0:20e0c61e0684 1077 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 1078 */
ganlikun 0:20e0c61e0684 1079 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1080 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1081 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 1082 void attach(const volatile U *obj, R (*func)(const volatile T*, A0)) {
ganlikun 0:20e0c61e0684 1083 this->~Callback();
ganlikun 0:20e0c61e0684 1084 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1085 }
ganlikun 0:20e0c61e0684 1086
ganlikun 0:20e0c61e0684 1087 /** Assign a callback
ganlikun 0:20e0c61e0684 1088 */
ganlikun 0:20e0c61e0684 1089 Callback &operator=(const Callback &that) {
ganlikun 0:20e0c61e0684 1090 if (this != &that) {
ganlikun 0:20e0c61e0684 1091 this->~Callback();
ganlikun 0:20e0c61e0684 1092 new (this) Callback(that);
ganlikun 0:20e0c61e0684 1093 }
ganlikun 0:20e0c61e0684 1094
ganlikun 0:20e0c61e0684 1095 return *this;
ganlikun 0:20e0c61e0684 1096 }
ganlikun 0:20e0c61e0684 1097
ganlikun 0:20e0c61e0684 1098 /** Call the attached function
ganlikun 0:20e0c61e0684 1099 */
ganlikun 0:20e0c61e0684 1100 R call(A0 a0) const {
ganlikun 0:20e0c61e0684 1101 MBED_ASSERT(_ops);
ganlikun 0:20e0c61e0684 1102 return _ops->call(this, a0);
ganlikun 0:20e0c61e0684 1103 }
ganlikun 0:20e0c61e0684 1104
ganlikun 0:20e0c61e0684 1105 /** Call the attached function
ganlikun 0:20e0c61e0684 1106 */
ganlikun 0:20e0c61e0684 1107 R operator()(A0 a0) const {
ganlikun 0:20e0c61e0684 1108 return call(a0);
ganlikun 0:20e0c61e0684 1109 }
ganlikun 0:20e0c61e0684 1110
ganlikun 0:20e0c61e0684 1111 /** Test if function has been attached
ganlikun 0:20e0c61e0684 1112 */
ganlikun 0:20e0c61e0684 1113 operator bool() const {
ganlikun 0:20e0c61e0684 1114 return _ops;
ganlikun 0:20e0c61e0684 1115 }
ganlikun 0:20e0c61e0684 1116
ganlikun 0:20e0c61e0684 1117 /** Test for equality
ganlikun 0:20e0c61e0684 1118 */
ganlikun 0:20e0c61e0684 1119 friend bool operator==(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 1120 return memcmp(&l, &r, sizeof(Callback)) == 0;
ganlikun 0:20e0c61e0684 1121 }
ganlikun 0:20e0c61e0684 1122
ganlikun 0:20e0c61e0684 1123 /** Test for inequality
ganlikun 0:20e0c61e0684 1124 */
ganlikun 0:20e0c61e0684 1125 friend bool operator!=(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 1126 return !(l == r);
ganlikun 0:20e0c61e0684 1127 }
ganlikun 0:20e0c61e0684 1128
ganlikun 0:20e0c61e0684 1129 /** Static thunk for passing as C-style function
ganlikun 0:20e0c61e0684 1130 * @param func Callback to call passed as void pointer
ganlikun 0:20e0c61e0684 1131 * @param a0 An argument to be called with function func
ganlikun 0:20e0c61e0684 1132 * @return the value as determined by func which is of
ganlikun 0:20e0c61e0684 1133 * type and determined by the signiture of func
ganlikun 0:20e0c61e0684 1134 */
ganlikun 0:20e0c61e0684 1135 static R thunk(void *func, A0 a0) {
ganlikun 0:20e0c61e0684 1136 return static_cast<Callback*>(func)->call(a0);
ganlikun 0:20e0c61e0684 1137 }
ganlikun 0:20e0c61e0684 1138
ganlikun 0:20e0c61e0684 1139 private:
ganlikun 0:20e0c61e0684 1140 // Stored as pointer to function and pointer to optional object
ganlikun 0:20e0c61e0684 1141 // Function pointer is stored as union of possible function types
ganlikun 0:20e0c61e0684 1142 // to garuntee proper size and alignment
ganlikun 0:20e0c61e0684 1143 struct _class;
ganlikun 0:20e0c61e0684 1144 union {
ganlikun 0:20e0c61e0684 1145 void (*_staticfunc)(A0);
ganlikun 0:20e0c61e0684 1146 void (*_boundfunc)(_class*, A0);
ganlikun 0:20e0c61e0684 1147 void (_class::*_methodfunc)(A0);
ganlikun 0:20e0c61e0684 1148 } _func;
ganlikun 0:20e0c61e0684 1149 void *_obj;
ganlikun 0:20e0c61e0684 1150
ganlikun 0:20e0c61e0684 1151 // Dynamically dispatched operations
ganlikun 0:20e0c61e0684 1152 const struct ops {
ganlikun 0:20e0c61e0684 1153 R (*call)(const void*, A0);
ganlikun 0:20e0c61e0684 1154 void (*move)(void*, const void*);
ganlikun 0:20e0c61e0684 1155 void (*dtor)(void*);
ganlikun 0:20e0c61e0684 1156 } *_ops;
ganlikun 0:20e0c61e0684 1157
ganlikun 0:20e0c61e0684 1158 // Generate operations for function object
ganlikun 0:20e0c61e0684 1159 template <typename F>
ganlikun 0:20e0c61e0684 1160 void generate(const F &f) {
ganlikun 0:20e0c61e0684 1161 static const ops ops = {
ganlikun 0:20e0c61e0684 1162 &Callback::function_call<F>,
ganlikun 0:20e0c61e0684 1163 &Callback::function_move<F>,
ganlikun 0:20e0c61e0684 1164 &Callback::function_dtor<F>,
ganlikun 0:20e0c61e0684 1165 };
ganlikun 0:20e0c61e0684 1166
ganlikun 0:20e0c61e0684 1167 MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
ganlikun 0:20e0c61e0684 1168 "Type F must not exceed the size of the Callback class");
ganlikun 0:20e0c61e0684 1169 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 1170 new (this) F(f);
ganlikun 0:20e0c61e0684 1171 _ops = &ops;
ganlikun 0:20e0c61e0684 1172 }
ganlikun 0:20e0c61e0684 1173
ganlikun 0:20e0c61e0684 1174 // Function attributes
ganlikun 0:20e0c61e0684 1175 template <typename F>
ganlikun 0:20e0c61e0684 1176 static R function_call(const void *p, A0 a0) {
ganlikun 0:20e0c61e0684 1177 return (*(F*)p)(a0);
ganlikun 0:20e0c61e0684 1178 }
ganlikun 0:20e0c61e0684 1179
ganlikun 0:20e0c61e0684 1180 template <typename F>
ganlikun 0:20e0c61e0684 1181 static void function_move(void *d, const void *p) {
ganlikun 0:20e0c61e0684 1182 new (d) F(*(F*)p);
ganlikun 0:20e0c61e0684 1183 }
ganlikun 0:20e0c61e0684 1184
ganlikun 0:20e0c61e0684 1185 template <typename F>
ganlikun 0:20e0c61e0684 1186 static void function_dtor(void *p) {
ganlikun 0:20e0c61e0684 1187 ((F*)p)->~F();
ganlikun 0:20e0c61e0684 1188 }
ganlikun 0:20e0c61e0684 1189
ganlikun 0:20e0c61e0684 1190 // Wrappers for functions with context
ganlikun 0:20e0c61e0684 1191 template <typename O, typename M>
ganlikun 0:20e0c61e0684 1192 struct method_context {
ganlikun 0:20e0c61e0684 1193 M method;
ganlikun 0:20e0c61e0684 1194 O *obj;
ganlikun 0:20e0c61e0684 1195
ganlikun 0:20e0c61e0684 1196 method_context(O *obj, M method)
ganlikun 0:20e0c61e0684 1197 : method(method), obj(obj) {}
ganlikun 0:20e0c61e0684 1198
ganlikun 0:20e0c61e0684 1199 R operator()(A0 a0) const {
ganlikun 0:20e0c61e0684 1200 return (obj->*method)(a0);
ganlikun 0:20e0c61e0684 1201 }
ganlikun 0:20e0c61e0684 1202 };
ganlikun 0:20e0c61e0684 1203
ganlikun 0:20e0c61e0684 1204 template <typename F, typename A>
ganlikun 0:20e0c61e0684 1205 struct function_context {
ganlikun 0:20e0c61e0684 1206 F func;
ganlikun 0:20e0c61e0684 1207 A *arg;
ganlikun 0:20e0c61e0684 1208
ganlikun 0:20e0c61e0684 1209 function_context(F func, A *arg)
ganlikun 0:20e0c61e0684 1210 : func(func), arg(arg) {}
ganlikun 0:20e0c61e0684 1211
ganlikun 0:20e0c61e0684 1212 R operator()(A0 a0) const {
ganlikun 0:20e0c61e0684 1213 return func(arg, a0);
ganlikun 0:20e0c61e0684 1214 }
ganlikun 0:20e0c61e0684 1215 };
ganlikun 0:20e0c61e0684 1216 };
ganlikun 0:20e0c61e0684 1217
ganlikun 0:20e0c61e0684 1218 /** Callback class based on template specialization
ganlikun 0:20e0c61e0684 1219 *
ganlikun 0:20e0c61e0684 1220 * @note Synchronization level: Not protected
ganlikun 0:20e0c61e0684 1221 * @ingroup platform
ganlikun 0:20e0c61e0684 1222 */
ganlikun 0:20e0c61e0684 1223 template <typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 1224 class Callback<R(A0, A1)> {
ganlikun 0:20e0c61e0684 1225 public:
ganlikun 0:20e0c61e0684 1226 /** Create a Callback with a static function
ganlikun 0:20e0c61e0684 1227 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1228 */
ganlikun 0:20e0c61e0684 1229 Callback(R (*func)(A0, A1) = 0) {
ganlikun 0:20e0c61e0684 1230 if (!func) {
ganlikun 0:20e0c61e0684 1231 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 1232 } else {
ganlikun 0:20e0c61e0684 1233 generate(func);
ganlikun 0:20e0c61e0684 1234 }
ganlikun 0:20e0c61e0684 1235 }
ganlikun 0:20e0c61e0684 1236
ganlikun 0:20e0c61e0684 1237 /** Attach a Callback
ganlikun 0:20e0c61e0684 1238 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 1239 */
ganlikun 0:20e0c61e0684 1240 Callback(const Callback<R(A0, A1)> &func) {
ganlikun 0:20e0c61e0684 1241 if (func._ops) {
ganlikun 0:20e0c61e0684 1242 func._ops->move(this, &func);
ganlikun 0:20e0c61e0684 1243 }
ganlikun 0:20e0c61e0684 1244 _ops = func._ops;
ganlikun 0:20e0c61e0684 1245 }
ganlikun 0:20e0c61e0684 1246
ganlikun 0:20e0c61e0684 1247 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 1248 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1249 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1250 */
ganlikun 0:20e0c61e0684 1251 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1252 Callback(U *obj, R (T::*method)(A0, A1)) {
ganlikun 0:20e0c61e0684 1253 generate(method_context<T, R (T::*)(A0, A1)>(obj, method));
ganlikun 0:20e0c61e0684 1254 }
ganlikun 0:20e0c61e0684 1255
ganlikun 0:20e0c61e0684 1256 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 1257 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1258 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1259 */
ganlikun 0:20e0c61e0684 1260 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1261 Callback(const U *obj, R (T::*method)(A0, A1) const) {
ganlikun 0:20e0c61e0684 1262 generate(method_context<const T, R (T::*)(A0, A1) const>(obj, method));
ganlikun 0:20e0c61e0684 1263 }
ganlikun 0:20e0c61e0684 1264
ganlikun 0:20e0c61e0684 1265 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 1266 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1267 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1268 */
ganlikun 0:20e0c61e0684 1269 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1270 Callback(volatile U *obj, R (T::*method)(A0, A1) volatile) {
ganlikun 0:20e0c61e0684 1271 generate(method_context<volatile T, R (T::*)(A0, A1) volatile>(obj, method));
ganlikun 0:20e0c61e0684 1272 }
ganlikun 0:20e0c61e0684 1273
ganlikun 0:20e0c61e0684 1274 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 1275 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1276 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1277 */
ganlikun 0:20e0c61e0684 1278 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1279 Callback(const volatile U *obj, R (T::*method)(A0, A1) const volatile) {
ganlikun 0:20e0c61e0684 1280 generate(method_context<const volatile T, R (T::*)(A0, A1) const volatile>(obj, method));
ganlikun 0:20e0c61e0684 1281 }
ganlikun 0:20e0c61e0684 1282
ganlikun 0:20e0c61e0684 1283 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1284 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1285 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1286 */
ganlikun 0:20e0c61e0684 1287 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1288 Callback(R (*func)(T*, A0, A1), U *arg) {
ganlikun 0:20e0c61e0684 1289 generate(function_context<R (*)(T*, A0, A1), T>(func, arg));
ganlikun 0:20e0c61e0684 1290 }
ganlikun 0:20e0c61e0684 1291
ganlikun 0:20e0c61e0684 1292 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1293 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1294 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1295 */
ganlikun 0:20e0c61e0684 1296 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1297 Callback(R (*func)(const T*, A0, A1), const U *arg) {
ganlikun 0:20e0c61e0684 1298 generate(function_context<R (*)(const T*, A0, A1), const T>(func, arg));
ganlikun 0:20e0c61e0684 1299 }
ganlikun 0:20e0c61e0684 1300
ganlikun 0:20e0c61e0684 1301 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1302 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1303 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1304 */
ganlikun 0:20e0c61e0684 1305 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1306 Callback(R (*func)(volatile T*, A0, A1), volatile U *arg) {
ganlikun 0:20e0c61e0684 1307 generate(function_context<R (*)(volatile T*, A0, A1), volatile T>(func, arg));
ganlikun 0:20e0c61e0684 1308 }
ganlikun 0:20e0c61e0684 1309
ganlikun 0:20e0c61e0684 1310 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1311 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1312 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1313 */
ganlikun 0:20e0c61e0684 1314 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1315 Callback(R (*func)(const volatile T*, A0, A1), const volatile U *arg) {
ganlikun 0:20e0c61e0684 1316 generate(function_context<R (*)(const volatile T*, A0, A1), const volatile T>(func, arg));
ganlikun 0:20e0c61e0684 1317 }
ganlikun 0:20e0c61e0684 1318
ganlikun 0:20e0c61e0684 1319 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 1320 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1321 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1322 */
ganlikun 0:20e0c61e0684 1323 template <typename F>
ganlikun 0:20e0c61e0684 1324 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1))) {
ganlikun 0:20e0c61e0684 1325 generate(f);
ganlikun 0:20e0c61e0684 1326 }
ganlikun 0:20e0c61e0684 1327
ganlikun 0:20e0c61e0684 1328 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 1329 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1330 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1331 */
ganlikun 0:20e0c61e0684 1332 template <typename F>
ganlikun 0:20e0c61e0684 1333 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1) const)) {
ganlikun 0:20e0c61e0684 1334 generate(f);
ganlikun 0:20e0c61e0684 1335 }
ganlikun 0:20e0c61e0684 1336
ganlikun 0:20e0c61e0684 1337 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 1338 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1339 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1340 */
ganlikun 0:20e0c61e0684 1341 template <typename F>
ganlikun 0:20e0c61e0684 1342 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1) volatile)) {
ganlikun 0:20e0c61e0684 1343 generate(f);
ganlikun 0:20e0c61e0684 1344 }
ganlikun 0:20e0c61e0684 1345
ganlikun 0:20e0c61e0684 1346 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 1347 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1348 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1349 */
ganlikun 0:20e0c61e0684 1350 template <typename F>
ganlikun 0:20e0c61e0684 1351 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1) const volatile)) {
ganlikun 0:20e0c61e0684 1352 generate(f);
ganlikun 0:20e0c61e0684 1353 }
ganlikun 0:20e0c61e0684 1354
ganlikun 0:20e0c61e0684 1355 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1356 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1357 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1358 * @deprecated
ganlikun 0:20e0c61e0684 1359 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 1360 */
ganlikun 0:20e0c61e0684 1361 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1362 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1363 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 1364 Callback(U *obj, R (*func)(T*, A0, A1)) {
ganlikun 0:20e0c61e0684 1365 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1366 }
ganlikun 0:20e0c61e0684 1367
ganlikun 0:20e0c61e0684 1368 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1369 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1370 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1371 * @deprecated
ganlikun 0:20e0c61e0684 1372 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 1373 */
ganlikun 0:20e0c61e0684 1374 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1375 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1376 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 1377 Callback(const U *obj, R (*func)(const T*, A0, A1)) {
ganlikun 0:20e0c61e0684 1378 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1379 }
ganlikun 0:20e0c61e0684 1380
ganlikun 0:20e0c61e0684 1381 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1382 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1383 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1384 * @deprecated
ganlikun 0:20e0c61e0684 1385 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 1386 */
ganlikun 0:20e0c61e0684 1387 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1388 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1389 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 1390 Callback(volatile U *obj, R (*func)(volatile T*, A0, A1)) {
ganlikun 0:20e0c61e0684 1391 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1392 }
ganlikun 0:20e0c61e0684 1393
ganlikun 0:20e0c61e0684 1394 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1395 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1396 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1397 * @deprecated
ganlikun 0:20e0c61e0684 1398 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 1399 */
ganlikun 0:20e0c61e0684 1400 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1401 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1402 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 1403 Callback(const volatile U *obj, R (*func)(const volatile T*, A0, A1)) {
ganlikun 0:20e0c61e0684 1404 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1405 }
ganlikun 0:20e0c61e0684 1406
ganlikun 0:20e0c61e0684 1407 /** Destroy a callback
ganlikun 0:20e0c61e0684 1408 */
ganlikun 0:20e0c61e0684 1409 ~Callback() {
ganlikun 0:20e0c61e0684 1410 if (_ops) {
ganlikun 0:20e0c61e0684 1411 _ops->dtor(this);
ganlikun 0:20e0c61e0684 1412 }
ganlikun 0:20e0c61e0684 1413 }
ganlikun 0:20e0c61e0684 1414
ganlikun 0:20e0c61e0684 1415 /** Attach a static function
ganlikun 0:20e0c61e0684 1416 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1417 * @deprecated
ganlikun 0:20e0c61e0684 1418 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1419 */
ganlikun 0:20e0c61e0684 1420 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1421 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1422 void attach(R (*func)(A0, A1)) {
ganlikun 0:20e0c61e0684 1423 this->~Callback();
ganlikun 0:20e0c61e0684 1424 new (this) Callback(func);
ganlikun 0:20e0c61e0684 1425 }
ganlikun 0:20e0c61e0684 1426
ganlikun 0:20e0c61e0684 1427 /** Attach a Callback
ganlikun 0:20e0c61e0684 1428 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 1429 * @deprecated
ganlikun 0:20e0c61e0684 1430 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1431 */
ganlikun 0:20e0c61e0684 1432 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1433 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1434 void attach(const Callback<R(A0, A1)> &func) {
ganlikun 0:20e0c61e0684 1435 this->~Callback();
ganlikun 0:20e0c61e0684 1436 new (this) Callback(func);
ganlikun 0:20e0c61e0684 1437 }
ganlikun 0:20e0c61e0684 1438
ganlikun 0:20e0c61e0684 1439 /** Attach a member function
ganlikun 0:20e0c61e0684 1440 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1441 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1442 * @deprecated
ganlikun 0:20e0c61e0684 1443 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1444 */
ganlikun 0:20e0c61e0684 1445 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1446 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1447 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1448 void attach(U *obj, R (T::*method)(A0, A1)) {
ganlikun 0:20e0c61e0684 1449 this->~Callback();
ganlikun 0:20e0c61e0684 1450 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 1451 }
ganlikun 0:20e0c61e0684 1452
ganlikun 0:20e0c61e0684 1453 /** Attach a member function
ganlikun 0:20e0c61e0684 1454 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1455 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1456 * @deprecated
ganlikun 0:20e0c61e0684 1457 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1458 */
ganlikun 0:20e0c61e0684 1459 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1460 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1461 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1462 void attach(const U *obj, R (T::*method)(A0, A1) const) {
ganlikun 0:20e0c61e0684 1463 this->~Callback();
ganlikun 0:20e0c61e0684 1464 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 1465 }
ganlikun 0:20e0c61e0684 1466
ganlikun 0:20e0c61e0684 1467 /** Attach a member function
ganlikun 0:20e0c61e0684 1468 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1469 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1470 * @deprecated
ganlikun 0:20e0c61e0684 1471 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1472 */
ganlikun 0:20e0c61e0684 1473 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1474 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1475 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1476 void attach(volatile U *obj, R (T::*method)(A0, A1) volatile) {
ganlikun 0:20e0c61e0684 1477 this->~Callback();
ganlikun 0:20e0c61e0684 1478 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 1479 }
ganlikun 0:20e0c61e0684 1480
ganlikun 0:20e0c61e0684 1481 /** Attach a member function
ganlikun 0:20e0c61e0684 1482 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1483 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1484 * @deprecated
ganlikun 0:20e0c61e0684 1485 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1486 */
ganlikun 0:20e0c61e0684 1487 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1488 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1489 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1490 void attach(const volatile U *obj, R (T::*method)(A0, A1) const volatile) {
ganlikun 0:20e0c61e0684 1491 this->~Callback();
ganlikun 0:20e0c61e0684 1492 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 1493 }
ganlikun 0:20e0c61e0684 1494
ganlikun 0:20e0c61e0684 1495 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1496 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1497 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1498 * @deprecated
ganlikun 0:20e0c61e0684 1499 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1500 */
ganlikun 0:20e0c61e0684 1501 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1502 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1503 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1504 void attach(R (*func)(T*, A0, A1), U *arg) {
ganlikun 0:20e0c61e0684 1505 this->~Callback();
ganlikun 0:20e0c61e0684 1506 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 1507 }
ganlikun 0:20e0c61e0684 1508
ganlikun 0:20e0c61e0684 1509 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1510 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1511 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1512 * @deprecated
ganlikun 0:20e0c61e0684 1513 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1514 */
ganlikun 0:20e0c61e0684 1515 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1516 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1517 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1518 void attach(R (*func)(const T*, A0, A1), const U *arg) {
ganlikun 0:20e0c61e0684 1519 this->~Callback();
ganlikun 0:20e0c61e0684 1520 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 1521 }
ganlikun 0:20e0c61e0684 1522
ganlikun 0:20e0c61e0684 1523 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1524 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1525 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1526 * @deprecated
ganlikun 0:20e0c61e0684 1527 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1528 */
ganlikun 0:20e0c61e0684 1529 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1530 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1531 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1532 void attach(R (*func)(volatile T*, A0, A1), volatile U *arg) {
ganlikun 0:20e0c61e0684 1533 this->~Callback();
ganlikun 0:20e0c61e0684 1534 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 1535 }
ganlikun 0:20e0c61e0684 1536
ganlikun 0:20e0c61e0684 1537 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1538 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1539 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1540 * @deprecated
ganlikun 0:20e0c61e0684 1541 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1542 */
ganlikun 0:20e0c61e0684 1543 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1544 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1545 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1546 void attach(R (*func)(const volatile T*, A0, A1), const volatile U *arg) {
ganlikun 0:20e0c61e0684 1547 this->~Callback();
ganlikun 0:20e0c61e0684 1548 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 1549 }
ganlikun 0:20e0c61e0684 1550
ganlikun 0:20e0c61e0684 1551 /** Attach a function object
ganlikun 0:20e0c61e0684 1552 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1553 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1554 * @deprecated
ganlikun 0:20e0c61e0684 1555 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1556 */
ganlikun 0:20e0c61e0684 1557 template <typename F>
ganlikun 0:20e0c61e0684 1558 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1559 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1560 void attach(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1))) {
ganlikun 0:20e0c61e0684 1561 this->~Callback();
ganlikun 0:20e0c61e0684 1562 new (this) Callback(f);
ganlikun 0:20e0c61e0684 1563 }
ganlikun 0:20e0c61e0684 1564
ganlikun 0:20e0c61e0684 1565 /** Attach a function object
ganlikun 0:20e0c61e0684 1566 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1567 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1568 * @deprecated
ganlikun 0:20e0c61e0684 1569 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1570 */
ganlikun 0:20e0c61e0684 1571 template <typename F>
ganlikun 0:20e0c61e0684 1572 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1573 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1574 void attach(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1) const)) {
ganlikun 0:20e0c61e0684 1575 this->~Callback();
ganlikun 0:20e0c61e0684 1576 new (this) Callback(f);
ganlikun 0:20e0c61e0684 1577 }
ganlikun 0:20e0c61e0684 1578
ganlikun 0:20e0c61e0684 1579 /** Attach a function object
ganlikun 0:20e0c61e0684 1580 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1581 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1582 * @deprecated
ganlikun 0:20e0c61e0684 1583 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1584 */
ganlikun 0:20e0c61e0684 1585 template <typename F>
ganlikun 0:20e0c61e0684 1586 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1587 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1588 void attach(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1) volatile)) {
ganlikun 0:20e0c61e0684 1589 this->~Callback();
ganlikun 0:20e0c61e0684 1590 new (this) Callback(f);
ganlikun 0:20e0c61e0684 1591 }
ganlikun 0:20e0c61e0684 1592
ganlikun 0:20e0c61e0684 1593 /** Attach a function object
ganlikun 0:20e0c61e0684 1594 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1595 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1596 * @deprecated
ganlikun 0:20e0c61e0684 1597 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1598 */
ganlikun 0:20e0c61e0684 1599 template <typename F>
ganlikun 0:20e0c61e0684 1600 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1601 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1602 void attach(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1) const volatile)) {
ganlikun 0:20e0c61e0684 1603 this->~Callback();
ganlikun 0:20e0c61e0684 1604 new (this) Callback(f);
ganlikun 0:20e0c61e0684 1605 }
ganlikun 0:20e0c61e0684 1606
ganlikun 0:20e0c61e0684 1607 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1608 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1609 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1610 * @deprecated
ganlikun 0:20e0c61e0684 1611 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 1612 */
ganlikun 0:20e0c61e0684 1613 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1614 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1615 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 1616 void attach(U *obj, R (*func)(T*, A0, A1)) {
ganlikun 0:20e0c61e0684 1617 this->~Callback();
ganlikun 0:20e0c61e0684 1618 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1619 }
ganlikun 0:20e0c61e0684 1620
ganlikun 0:20e0c61e0684 1621 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1622 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1623 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1624 * @deprecated
ganlikun 0:20e0c61e0684 1625 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 1626 */
ganlikun 0:20e0c61e0684 1627 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1628 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1629 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 1630 void attach(const U *obj, R (*func)(const T*, A0, A1)) {
ganlikun 0:20e0c61e0684 1631 this->~Callback();
ganlikun 0:20e0c61e0684 1632 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1633 }
ganlikun 0:20e0c61e0684 1634
ganlikun 0:20e0c61e0684 1635 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1636 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1637 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1638 * @deprecated
ganlikun 0:20e0c61e0684 1639 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 1640 */
ganlikun 0:20e0c61e0684 1641 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1642 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1643 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 1644 void attach(volatile U *obj, R (*func)(volatile T*, A0, A1)) {
ganlikun 0:20e0c61e0684 1645 this->~Callback();
ganlikun 0:20e0c61e0684 1646 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1647 }
ganlikun 0:20e0c61e0684 1648
ganlikun 0:20e0c61e0684 1649 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 1650 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1651 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1652 * @deprecated
ganlikun 0:20e0c61e0684 1653 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 1654 */
ganlikun 0:20e0c61e0684 1655 template <typename T, typename U>
ganlikun 0:20e0c61e0684 1656 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1657 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 1658 void attach(const volatile U *obj, R (*func)(const volatile T*, A0, A1)) {
ganlikun 0:20e0c61e0684 1659 this->~Callback();
ganlikun 0:20e0c61e0684 1660 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1661 }
ganlikun 0:20e0c61e0684 1662
ganlikun 0:20e0c61e0684 1663 /** Assign a callback
ganlikun 0:20e0c61e0684 1664 */
ganlikun 0:20e0c61e0684 1665 Callback &operator=(const Callback &that) {
ganlikun 0:20e0c61e0684 1666 if (this != &that) {
ganlikun 0:20e0c61e0684 1667 this->~Callback();
ganlikun 0:20e0c61e0684 1668 new (this) Callback(that);
ganlikun 0:20e0c61e0684 1669 }
ganlikun 0:20e0c61e0684 1670
ganlikun 0:20e0c61e0684 1671 return *this;
ganlikun 0:20e0c61e0684 1672 }
ganlikun 0:20e0c61e0684 1673
ganlikun 0:20e0c61e0684 1674 /** Call the attached function
ganlikun 0:20e0c61e0684 1675 */
ganlikun 0:20e0c61e0684 1676 R call(A0 a0, A1 a1) const {
ganlikun 0:20e0c61e0684 1677 MBED_ASSERT(_ops);
ganlikun 0:20e0c61e0684 1678 return _ops->call(this, a0, a1);
ganlikun 0:20e0c61e0684 1679 }
ganlikun 0:20e0c61e0684 1680
ganlikun 0:20e0c61e0684 1681 /** Call the attached function
ganlikun 0:20e0c61e0684 1682 */
ganlikun 0:20e0c61e0684 1683 R operator()(A0 a0, A1 a1) const {
ganlikun 0:20e0c61e0684 1684 return call(a0, a1);
ganlikun 0:20e0c61e0684 1685 }
ganlikun 0:20e0c61e0684 1686
ganlikun 0:20e0c61e0684 1687 /** Test if function has been attached
ganlikun 0:20e0c61e0684 1688 */
ganlikun 0:20e0c61e0684 1689 operator bool() const {
ganlikun 0:20e0c61e0684 1690 return _ops;
ganlikun 0:20e0c61e0684 1691 }
ganlikun 0:20e0c61e0684 1692
ganlikun 0:20e0c61e0684 1693 /** Test for equality
ganlikun 0:20e0c61e0684 1694 */
ganlikun 0:20e0c61e0684 1695 friend bool operator==(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 1696 return memcmp(&l, &r, sizeof(Callback)) == 0;
ganlikun 0:20e0c61e0684 1697 }
ganlikun 0:20e0c61e0684 1698
ganlikun 0:20e0c61e0684 1699 /** Test for inequality
ganlikun 0:20e0c61e0684 1700 */
ganlikun 0:20e0c61e0684 1701 friend bool operator!=(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 1702 return !(l == r);
ganlikun 0:20e0c61e0684 1703 }
ganlikun 0:20e0c61e0684 1704
ganlikun 0:20e0c61e0684 1705 /** Static thunk for passing as C-style function
ganlikun 0:20e0c61e0684 1706 * @param func Callback to call passed as void pointer
ganlikun 0:20e0c61e0684 1707 * @param a0 An argument to be called with function func
ganlikun 0:20e0c61e0684 1708 * @param a1 An argument to be called with function func
ganlikun 0:20e0c61e0684 1709 * @return the value as determined by func which is of
ganlikun 0:20e0c61e0684 1710 * type and determined by the signiture of func
ganlikun 0:20e0c61e0684 1711 */
ganlikun 0:20e0c61e0684 1712 static R thunk(void *func, A0 a0, A1 a1) {
ganlikun 0:20e0c61e0684 1713 return static_cast<Callback*>(func)->call(a0, a1);
ganlikun 0:20e0c61e0684 1714 }
ganlikun 0:20e0c61e0684 1715
ganlikun 0:20e0c61e0684 1716 private:
ganlikun 0:20e0c61e0684 1717 // Stored as pointer to function and pointer to optional object
ganlikun 0:20e0c61e0684 1718 // Function pointer is stored as union of possible function types
ganlikun 0:20e0c61e0684 1719 // to garuntee proper size and alignment
ganlikun 0:20e0c61e0684 1720 struct _class;
ganlikun 0:20e0c61e0684 1721 union {
ganlikun 0:20e0c61e0684 1722 void (*_staticfunc)(A0, A1);
ganlikun 0:20e0c61e0684 1723 void (*_boundfunc)(_class*, A0, A1);
ganlikun 0:20e0c61e0684 1724 void (_class::*_methodfunc)(A0, A1);
ganlikun 0:20e0c61e0684 1725 } _func;
ganlikun 0:20e0c61e0684 1726 void *_obj;
ganlikun 0:20e0c61e0684 1727
ganlikun 0:20e0c61e0684 1728 // Dynamically dispatched operations
ganlikun 0:20e0c61e0684 1729 const struct ops {
ganlikun 0:20e0c61e0684 1730 R (*call)(const void*, A0, A1);
ganlikun 0:20e0c61e0684 1731 void (*move)(void*, const void*);
ganlikun 0:20e0c61e0684 1732 void (*dtor)(void*);
ganlikun 0:20e0c61e0684 1733 } *_ops;
ganlikun 0:20e0c61e0684 1734
ganlikun 0:20e0c61e0684 1735 // Generate operations for function object
ganlikun 0:20e0c61e0684 1736 template <typename F>
ganlikun 0:20e0c61e0684 1737 void generate(const F &f) {
ganlikun 0:20e0c61e0684 1738 static const ops ops = {
ganlikun 0:20e0c61e0684 1739 &Callback::function_call<F>,
ganlikun 0:20e0c61e0684 1740 &Callback::function_move<F>,
ganlikun 0:20e0c61e0684 1741 &Callback::function_dtor<F>,
ganlikun 0:20e0c61e0684 1742 };
ganlikun 0:20e0c61e0684 1743
ganlikun 0:20e0c61e0684 1744 MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
ganlikun 0:20e0c61e0684 1745 "Type F must not exceed the size of the Callback class");
ganlikun 0:20e0c61e0684 1746 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 1747 new (this) F(f);
ganlikun 0:20e0c61e0684 1748 _ops = &ops;
ganlikun 0:20e0c61e0684 1749 }
ganlikun 0:20e0c61e0684 1750
ganlikun 0:20e0c61e0684 1751 // Function attributes
ganlikun 0:20e0c61e0684 1752 template <typename F>
ganlikun 0:20e0c61e0684 1753 static R function_call(const void *p, A0 a0, A1 a1) {
ganlikun 0:20e0c61e0684 1754 return (*(F*)p)(a0, a1);
ganlikun 0:20e0c61e0684 1755 }
ganlikun 0:20e0c61e0684 1756
ganlikun 0:20e0c61e0684 1757 template <typename F>
ganlikun 0:20e0c61e0684 1758 static void function_move(void *d, const void *p) {
ganlikun 0:20e0c61e0684 1759 new (d) F(*(F*)p);
ganlikun 0:20e0c61e0684 1760 }
ganlikun 0:20e0c61e0684 1761
ganlikun 0:20e0c61e0684 1762 template <typename F>
ganlikun 0:20e0c61e0684 1763 static void function_dtor(void *p) {
ganlikun 0:20e0c61e0684 1764 ((F*)p)->~F();
ganlikun 0:20e0c61e0684 1765 }
ganlikun 0:20e0c61e0684 1766
ganlikun 0:20e0c61e0684 1767 // Wrappers for functions with context
ganlikun 0:20e0c61e0684 1768 template <typename O, typename M>
ganlikun 0:20e0c61e0684 1769 struct method_context {
ganlikun 0:20e0c61e0684 1770 M method;
ganlikun 0:20e0c61e0684 1771 O *obj;
ganlikun 0:20e0c61e0684 1772
ganlikun 0:20e0c61e0684 1773 method_context(O *obj, M method)
ganlikun 0:20e0c61e0684 1774 : method(method), obj(obj) {}
ganlikun 0:20e0c61e0684 1775
ganlikun 0:20e0c61e0684 1776 R operator()(A0 a0, A1 a1) const {
ganlikun 0:20e0c61e0684 1777 return (obj->*method)(a0, a1);
ganlikun 0:20e0c61e0684 1778 }
ganlikun 0:20e0c61e0684 1779 };
ganlikun 0:20e0c61e0684 1780
ganlikun 0:20e0c61e0684 1781 template <typename F, typename A>
ganlikun 0:20e0c61e0684 1782 struct function_context {
ganlikun 0:20e0c61e0684 1783 F func;
ganlikun 0:20e0c61e0684 1784 A *arg;
ganlikun 0:20e0c61e0684 1785
ganlikun 0:20e0c61e0684 1786 function_context(F func, A *arg)
ganlikun 0:20e0c61e0684 1787 : func(func), arg(arg) {}
ganlikun 0:20e0c61e0684 1788
ganlikun 0:20e0c61e0684 1789 R operator()(A0 a0, A1 a1) const {
ganlikun 0:20e0c61e0684 1790 return func(arg, a0, a1);
ganlikun 0:20e0c61e0684 1791 }
ganlikun 0:20e0c61e0684 1792 };
ganlikun 0:20e0c61e0684 1793 };
ganlikun 0:20e0c61e0684 1794
ganlikun 0:20e0c61e0684 1795 /** Callback class based on template specialization
ganlikun 0:20e0c61e0684 1796 *
ganlikun 0:20e0c61e0684 1797 * @note Synchronization level: Not protected
ganlikun 0:20e0c61e0684 1798 * @ingroup platform
ganlikun 0:20e0c61e0684 1799 */
ganlikun 0:20e0c61e0684 1800 template <typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 1801 class Callback<R(A0, A1, A2)> {
ganlikun 0:20e0c61e0684 1802 public:
ganlikun 0:20e0c61e0684 1803 /** Create a Callback with a static function
ganlikun 0:20e0c61e0684 1804 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1805 */
ganlikun 0:20e0c61e0684 1806 Callback(R (*func)(A0, A1, A2) = 0) {
ganlikun 0:20e0c61e0684 1807 if (!func) {
ganlikun 0:20e0c61e0684 1808 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 1809 } else {
ganlikun 0:20e0c61e0684 1810 generate(func);
ganlikun 0:20e0c61e0684 1811 }
ganlikun 0:20e0c61e0684 1812 }
ganlikun 0:20e0c61e0684 1813
ganlikun 0:20e0c61e0684 1814 /** Attach a Callback
ganlikun 0:20e0c61e0684 1815 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 1816 */
ganlikun 0:20e0c61e0684 1817 Callback(const Callback<R(A0, A1, A2)> &func) {
ganlikun 0:20e0c61e0684 1818 if (func._ops) {
ganlikun 0:20e0c61e0684 1819 func._ops->move(this, &func);
ganlikun 0:20e0c61e0684 1820 }
ganlikun 0:20e0c61e0684 1821 _ops = func._ops;
ganlikun 0:20e0c61e0684 1822 }
ganlikun 0:20e0c61e0684 1823
ganlikun 0:20e0c61e0684 1824 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 1825 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1826 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1827 */
ganlikun 0:20e0c61e0684 1828 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1829 Callback(U *obj, R (T::*method)(A0, A1, A2)) {
ganlikun 0:20e0c61e0684 1830 generate(method_context<T, R (T::*)(A0, A1, A2)>(obj, method));
ganlikun 0:20e0c61e0684 1831 }
ganlikun 0:20e0c61e0684 1832
ganlikun 0:20e0c61e0684 1833 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 1834 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1835 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1836 */
ganlikun 0:20e0c61e0684 1837 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1838 Callback(const U *obj, R (T::*method)(A0, A1, A2) const) {
ganlikun 0:20e0c61e0684 1839 generate(method_context<const T, R (T::*)(A0, A1, A2) const>(obj, method));
ganlikun 0:20e0c61e0684 1840 }
ganlikun 0:20e0c61e0684 1841
ganlikun 0:20e0c61e0684 1842 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 1843 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1844 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1845 */
ganlikun 0:20e0c61e0684 1846 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1847 Callback(volatile U *obj, R (T::*method)(A0, A1, A2) volatile) {
ganlikun 0:20e0c61e0684 1848 generate(method_context<volatile T, R (T::*)(A0, A1, A2) volatile>(obj, method));
ganlikun 0:20e0c61e0684 1849 }
ganlikun 0:20e0c61e0684 1850
ganlikun 0:20e0c61e0684 1851 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 1852 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 1853 * @param method Member function to attach
ganlikun 0:20e0c61e0684 1854 */
ganlikun 0:20e0c61e0684 1855 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1856 Callback(const volatile U *obj, R (T::*method)(A0, A1, A2) const volatile) {
ganlikun 0:20e0c61e0684 1857 generate(method_context<const volatile T, R (T::*)(A0, A1, A2) const volatile>(obj, method));
ganlikun 0:20e0c61e0684 1858 }
ganlikun 0:20e0c61e0684 1859
ganlikun 0:20e0c61e0684 1860 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1861 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1862 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1863 */
ganlikun 0:20e0c61e0684 1864 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1865 Callback(R (*func)(T*, A0, A1, A2), U *arg) {
ganlikun 0:20e0c61e0684 1866 generate(function_context<R (*)(T*, A0, A1, A2), T>(func, arg));
ganlikun 0:20e0c61e0684 1867 }
ganlikun 0:20e0c61e0684 1868
ganlikun 0:20e0c61e0684 1869 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1870 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1871 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1872 */
ganlikun 0:20e0c61e0684 1873 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1874 Callback(R (*func)(const T*, A0, A1, A2), const U *arg) {
ganlikun 0:20e0c61e0684 1875 generate(function_context<R (*)(const T*, A0, A1, A2), const T>(func, arg));
ganlikun 0:20e0c61e0684 1876 }
ganlikun 0:20e0c61e0684 1877
ganlikun 0:20e0c61e0684 1878 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1879 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1880 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1881 */
ganlikun 0:20e0c61e0684 1882 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1883 Callback(R (*func)(volatile T*, A0, A1, A2), volatile U *arg) {
ganlikun 0:20e0c61e0684 1884 generate(function_context<R (*)(volatile T*, A0, A1, A2), volatile T>(func, arg));
ganlikun 0:20e0c61e0684 1885 }
ganlikun 0:20e0c61e0684 1886
ganlikun 0:20e0c61e0684 1887 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1888 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1889 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 1890 */
ganlikun 0:20e0c61e0684 1891 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1892 Callback(R (*func)(const volatile T*, A0, A1, A2), const volatile U *arg) {
ganlikun 0:20e0c61e0684 1893 generate(function_context<R (*)(const volatile T*, A0, A1, A2), const volatile T>(func, arg));
ganlikun 0:20e0c61e0684 1894 }
ganlikun 0:20e0c61e0684 1895
ganlikun 0:20e0c61e0684 1896 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 1897 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1898 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1899 */
ganlikun 0:20e0c61e0684 1900 template <typename F>
ganlikun 0:20e0c61e0684 1901 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2))) {
ganlikun 0:20e0c61e0684 1902 generate(f);
ganlikun 0:20e0c61e0684 1903 }
ganlikun 0:20e0c61e0684 1904
ganlikun 0:20e0c61e0684 1905 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 1906 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1907 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1908 */
ganlikun 0:20e0c61e0684 1909 template <typename F>
ganlikun 0:20e0c61e0684 1910 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2) const)) {
ganlikun 0:20e0c61e0684 1911 generate(f);
ganlikun 0:20e0c61e0684 1912 }
ganlikun 0:20e0c61e0684 1913
ganlikun 0:20e0c61e0684 1914 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 1915 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1916 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1917 */
ganlikun 0:20e0c61e0684 1918 template <typename F>
ganlikun 0:20e0c61e0684 1919 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2) volatile)) {
ganlikun 0:20e0c61e0684 1920 generate(f);
ganlikun 0:20e0c61e0684 1921 }
ganlikun 0:20e0c61e0684 1922
ganlikun 0:20e0c61e0684 1923 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 1924 * @param f Function object to attach
ganlikun 0:20e0c61e0684 1925 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 1926 */
ganlikun 0:20e0c61e0684 1927 template <typename F>
ganlikun 0:20e0c61e0684 1928 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2) const volatile)) {
ganlikun 0:20e0c61e0684 1929 generate(f);
ganlikun 0:20e0c61e0684 1930 }
ganlikun 0:20e0c61e0684 1931
ganlikun 0:20e0c61e0684 1932 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1933 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1934 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1935 * @deprecated
ganlikun 0:20e0c61e0684 1936 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 1937 */
ganlikun 0:20e0c61e0684 1938 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1939 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1940 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 1941 Callback(U *obj, R (*func)(T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 1942 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1943 }
ganlikun 0:20e0c61e0684 1944
ganlikun 0:20e0c61e0684 1945 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1946 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1947 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1948 * @deprecated
ganlikun 0:20e0c61e0684 1949 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 1950 */
ganlikun 0:20e0c61e0684 1951 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1952 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1953 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 1954 Callback(const U *obj, R (*func)(const T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 1955 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1956 }
ganlikun 0:20e0c61e0684 1957
ganlikun 0:20e0c61e0684 1958 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1959 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1960 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1961 * @deprecated
ganlikun 0:20e0c61e0684 1962 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 1963 */
ganlikun 0:20e0c61e0684 1964 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1965 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1966 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 1967 Callback(volatile U *obj, R (*func)(volatile T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 1968 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1969 }
ganlikun 0:20e0c61e0684 1970
ganlikun 0:20e0c61e0684 1971 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 1972 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 1973 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1974 * @deprecated
ganlikun 0:20e0c61e0684 1975 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 1976 */
ganlikun 0:20e0c61e0684 1977 template<typename T, typename U>
ganlikun 0:20e0c61e0684 1978 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 1979 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 1980 Callback(const volatile U *obj, R (*func)(const volatile T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 1981 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 1982 }
ganlikun 0:20e0c61e0684 1983
ganlikun 0:20e0c61e0684 1984 /** Destroy a callback
ganlikun 0:20e0c61e0684 1985 */
ganlikun 0:20e0c61e0684 1986 ~Callback() {
ganlikun 0:20e0c61e0684 1987 if (_ops) {
ganlikun 0:20e0c61e0684 1988 _ops->dtor(this);
ganlikun 0:20e0c61e0684 1989 }
ganlikun 0:20e0c61e0684 1990 }
ganlikun 0:20e0c61e0684 1991
ganlikun 0:20e0c61e0684 1992 /** Attach a static function
ganlikun 0:20e0c61e0684 1993 * @param func Static function to attach
ganlikun 0:20e0c61e0684 1994 * @deprecated
ganlikun 0:20e0c61e0684 1995 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 1996 */
ganlikun 0:20e0c61e0684 1997 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 1998 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 1999 void attach(R (*func)(A0, A1, A2)) {
ganlikun 0:20e0c61e0684 2000 this->~Callback();
ganlikun 0:20e0c61e0684 2001 new (this) Callback(func);
ganlikun 0:20e0c61e0684 2002 }
ganlikun 0:20e0c61e0684 2003
ganlikun 0:20e0c61e0684 2004 /** Attach a Callback
ganlikun 0:20e0c61e0684 2005 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 2006 * @deprecated
ganlikun 0:20e0c61e0684 2007 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2008 */
ganlikun 0:20e0c61e0684 2009 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2010 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2011 void attach(const Callback<R(A0, A1, A2)> &func) {
ganlikun 0:20e0c61e0684 2012 this->~Callback();
ganlikun 0:20e0c61e0684 2013 new (this) Callback(func);
ganlikun 0:20e0c61e0684 2014 }
ganlikun 0:20e0c61e0684 2015
ganlikun 0:20e0c61e0684 2016 /** Attach a member function
ganlikun 0:20e0c61e0684 2017 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2018 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2019 * @deprecated
ganlikun 0:20e0c61e0684 2020 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2021 */
ganlikun 0:20e0c61e0684 2022 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2023 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2024 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2025 void attach(U *obj, R (T::*method)(A0, A1, A2)) {
ganlikun 0:20e0c61e0684 2026 this->~Callback();
ganlikun 0:20e0c61e0684 2027 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 2028 }
ganlikun 0:20e0c61e0684 2029
ganlikun 0:20e0c61e0684 2030 /** Attach a member function
ganlikun 0:20e0c61e0684 2031 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2032 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2033 * @deprecated
ganlikun 0:20e0c61e0684 2034 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2035 */
ganlikun 0:20e0c61e0684 2036 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2037 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2038 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2039 void attach(const U *obj, R (T::*method)(A0, A1, A2) const) {
ganlikun 0:20e0c61e0684 2040 this->~Callback();
ganlikun 0:20e0c61e0684 2041 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 2042 }
ganlikun 0:20e0c61e0684 2043
ganlikun 0:20e0c61e0684 2044 /** Attach a member function
ganlikun 0:20e0c61e0684 2045 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2046 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2047 * @deprecated
ganlikun 0:20e0c61e0684 2048 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2049 */
ganlikun 0:20e0c61e0684 2050 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2051 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2052 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2053 void attach(volatile U *obj, R (T::*method)(A0, A1, A2) volatile) {
ganlikun 0:20e0c61e0684 2054 this->~Callback();
ganlikun 0:20e0c61e0684 2055 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 2056 }
ganlikun 0:20e0c61e0684 2057
ganlikun 0:20e0c61e0684 2058 /** Attach a member function
ganlikun 0:20e0c61e0684 2059 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2060 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2061 * @deprecated
ganlikun 0:20e0c61e0684 2062 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2063 */
ganlikun 0:20e0c61e0684 2064 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2065 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2066 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2067 void attach(const volatile U *obj, R (T::*method)(A0, A1, A2) const volatile) {
ganlikun 0:20e0c61e0684 2068 this->~Callback();
ganlikun 0:20e0c61e0684 2069 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 2070 }
ganlikun 0:20e0c61e0684 2071
ganlikun 0:20e0c61e0684 2072 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2073 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2074 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2075 * @deprecated
ganlikun 0:20e0c61e0684 2076 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2077 */
ganlikun 0:20e0c61e0684 2078 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2079 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2080 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2081 void attach(R (*func)(T*, A0, A1, A2), U *arg) {
ganlikun 0:20e0c61e0684 2082 this->~Callback();
ganlikun 0:20e0c61e0684 2083 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 2084 }
ganlikun 0:20e0c61e0684 2085
ganlikun 0:20e0c61e0684 2086 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2087 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2088 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2089 * @deprecated
ganlikun 0:20e0c61e0684 2090 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2091 */
ganlikun 0:20e0c61e0684 2092 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2093 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2094 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2095 void attach(R (*func)(const T*, A0, A1, A2), const U *arg) {
ganlikun 0:20e0c61e0684 2096 this->~Callback();
ganlikun 0:20e0c61e0684 2097 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 2098 }
ganlikun 0:20e0c61e0684 2099
ganlikun 0:20e0c61e0684 2100 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2101 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2102 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2103 * @deprecated
ganlikun 0:20e0c61e0684 2104 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2105 */
ganlikun 0:20e0c61e0684 2106 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2107 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2108 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2109 void attach(R (*func)(volatile T*, A0, A1, A2), volatile U *arg) {
ganlikun 0:20e0c61e0684 2110 this->~Callback();
ganlikun 0:20e0c61e0684 2111 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 2112 }
ganlikun 0:20e0c61e0684 2113
ganlikun 0:20e0c61e0684 2114 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2115 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2116 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2117 * @deprecated
ganlikun 0:20e0c61e0684 2118 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2119 */
ganlikun 0:20e0c61e0684 2120 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2121 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2122 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2123 void attach(R (*func)(const volatile T*, A0, A1, A2), const volatile U *arg) {
ganlikun 0:20e0c61e0684 2124 this->~Callback();
ganlikun 0:20e0c61e0684 2125 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 2126 }
ganlikun 0:20e0c61e0684 2127
ganlikun 0:20e0c61e0684 2128 /** Attach a function object
ganlikun 0:20e0c61e0684 2129 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2130 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2131 * @deprecated
ganlikun 0:20e0c61e0684 2132 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2133 */
ganlikun 0:20e0c61e0684 2134 template <typename F>
ganlikun 0:20e0c61e0684 2135 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2136 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2137 void attach(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2))) {
ganlikun 0:20e0c61e0684 2138 this->~Callback();
ganlikun 0:20e0c61e0684 2139 new (this) Callback(f);
ganlikun 0:20e0c61e0684 2140 }
ganlikun 0:20e0c61e0684 2141
ganlikun 0:20e0c61e0684 2142 /** Attach a function object
ganlikun 0:20e0c61e0684 2143 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2144 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2145 * @deprecated
ganlikun 0:20e0c61e0684 2146 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2147 */
ganlikun 0:20e0c61e0684 2148 template <typename F>
ganlikun 0:20e0c61e0684 2149 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2150 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2151 void attach(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2) const)) {
ganlikun 0:20e0c61e0684 2152 this->~Callback();
ganlikun 0:20e0c61e0684 2153 new (this) Callback(f);
ganlikun 0:20e0c61e0684 2154 }
ganlikun 0:20e0c61e0684 2155
ganlikun 0:20e0c61e0684 2156 /** Attach a function object
ganlikun 0:20e0c61e0684 2157 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2158 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2159 * @deprecated
ganlikun 0:20e0c61e0684 2160 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2161 */
ganlikun 0:20e0c61e0684 2162 template <typename F>
ganlikun 0:20e0c61e0684 2163 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2164 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2165 void attach(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2) volatile)) {
ganlikun 0:20e0c61e0684 2166 this->~Callback();
ganlikun 0:20e0c61e0684 2167 new (this) Callback(f);
ganlikun 0:20e0c61e0684 2168 }
ganlikun 0:20e0c61e0684 2169
ganlikun 0:20e0c61e0684 2170 /** Attach a function object
ganlikun 0:20e0c61e0684 2171 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2172 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2173 * @deprecated
ganlikun 0:20e0c61e0684 2174 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2175 */
ganlikun 0:20e0c61e0684 2176 template <typename F>
ganlikun 0:20e0c61e0684 2177 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2178 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2179 void attach(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2) const volatile)) {
ganlikun 0:20e0c61e0684 2180 this->~Callback();
ganlikun 0:20e0c61e0684 2181 new (this) Callback(f);
ganlikun 0:20e0c61e0684 2182 }
ganlikun 0:20e0c61e0684 2183
ganlikun 0:20e0c61e0684 2184 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2185 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2186 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2187 * @deprecated
ganlikun 0:20e0c61e0684 2188 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 2189 */
ganlikun 0:20e0c61e0684 2190 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2191 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2192 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 2193 void attach(U *obj, R (*func)(T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 2194 this->~Callback();
ganlikun 0:20e0c61e0684 2195 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2196 }
ganlikun 0:20e0c61e0684 2197
ganlikun 0:20e0c61e0684 2198 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2199 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2200 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2201 * @deprecated
ganlikun 0:20e0c61e0684 2202 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 2203 */
ganlikun 0:20e0c61e0684 2204 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2205 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2206 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 2207 void attach(const U *obj, R (*func)(const T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 2208 this->~Callback();
ganlikun 0:20e0c61e0684 2209 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2210 }
ganlikun 0:20e0c61e0684 2211
ganlikun 0:20e0c61e0684 2212 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2213 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2214 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2215 * @deprecated
ganlikun 0:20e0c61e0684 2216 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 2217 */
ganlikun 0:20e0c61e0684 2218 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2219 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2220 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 2221 void attach(volatile U *obj, R (*func)(volatile T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 2222 this->~Callback();
ganlikun 0:20e0c61e0684 2223 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2224 }
ganlikun 0:20e0c61e0684 2225
ganlikun 0:20e0c61e0684 2226 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2227 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2228 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2229 * @deprecated
ganlikun 0:20e0c61e0684 2230 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 2231 */
ganlikun 0:20e0c61e0684 2232 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2233 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2234 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 2235 void attach(const volatile U *obj, R (*func)(const volatile T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 2236 this->~Callback();
ganlikun 0:20e0c61e0684 2237 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2238 }
ganlikun 0:20e0c61e0684 2239
ganlikun 0:20e0c61e0684 2240 /** Assign a callback
ganlikun 0:20e0c61e0684 2241 */
ganlikun 0:20e0c61e0684 2242 Callback &operator=(const Callback &that) {
ganlikun 0:20e0c61e0684 2243 if (this != &that) {
ganlikun 0:20e0c61e0684 2244 this->~Callback();
ganlikun 0:20e0c61e0684 2245 new (this) Callback(that);
ganlikun 0:20e0c61e0684 2246 }
ganlikun 0:20e0c61e0684 2247
ganlikun 0:20e0c61e0684 2248 return *this;
ganlikun 0:20e0c61e0684 2249 }
ganlikun 0:20e0c61e0684 2250
ganlikun 0:20e0c61e0684 2251 /** Call the attached function
ganlikun 0:20e0c61e0684 2252 */
ganlikun 0:20e0c61e0684 2253 R call(A0 a0, A1 a1, A2 a2) const {
ganlikun 0:20e0c61e0684 2254 MBED_ASSERT(_ops);
ganlikun 0:20e0c61e0684 2255 return _ops->call(this, a0, a1, a2);
ganlikun 0:20e0c61e0684 2256 }
ganlikun 0:20e0c61e0684 2257
ganlikun 0:20e0c61e0684 2258 /** Call the attached function
ganlikun 0:20e0c61e0684 2259 */
ganlikun 0:20e0c61e0684 2260 R operator()(A0 a0, A1 a1, A2 a2) const {
ganlikun 0:20e0c61e0684 2261 return call(a0, a1, a2);
ganlikun 0:20e0c61e0684 2262 }
ganlikun 0:20e0c61e0684 2263
ganlikun 0:20e0c61e0684 2264 /** Test if function has been attached
ganlikun 0:20e0c61e0684 2265 */
ganlikun 0:20e0c61e0684 2266 operator bool() const {
ganlikun 0:20e0c61e0684 2267 return _ops;
ganlikun 0:20e0c61e0684 2268 }
ganlikun 0:20e0c61e0684 2269
ganlikun 0:20e0c61e0684 2270 /** Test for equality
ganlikun 0:20e0c61e0684 2271 */
ganlikun 0:20e0c61e0684 2272 friend bool operator==(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 2273 return memcmp(&l, &r, sizeof(Callback)) == 0;
ganlikun 0:20e0c61e0684 2274 }
ganlikun 0:20e0c61e0684 2275
ganlikun 0:20e0c61e0684 2276 /** Test for inequality
ganlikun 0:20e0c61e0684 2277 */
ganlikun 0:20e0c61e0684 2278 friend bool operator!=(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 2279 return !(l == r);
ganlikun 0:20e0c61e0684 2280 }
ganlikun 0:20e0c61e0684 2281
ganlikun 0:20e0c61e0684 2282 /** Static thunk for passing as C-style function
ganlikun 0:20e0c61e0684 2283 * @param func Callback to call passed as void pointer
ganlikun 0:20e0c61e0684 2284 * @param a0 An argument to be called with function func
ganlikun 0:20e0c61e0684 2285 * @param a1 An argument to be called with function func
ganlikun 0:20e0c61e0684 2286 * @param a2 An argument to be called with function func
ganlikun 0:20e0c61e0684 2287 * @return the value as determined by func which is of
ganlikun 0:20e0c61e0684 2288 * type and determined by the signiture of func
ganlikun 0:20e0c61e0684 2289 */
ganlikun 0:20e0c61e0684 2290 static R thunk(void *func, A0 a0, A1 a1, A2 a2) {
ganlikun 0:20e0c61e0684 2291 return static_cast<Callback*>(func)->call(a0, a1, a2);
ganlikun 0:20e0c61e0684 2292 }
ganlikun 0:20e0c61e0684 2293
ganlikun 0:20e0c61e0684 2294 private:
ganlikun 0:20e0c61e0684 2295 // Stored as pointer to function and pointer to optional object
ganlikun 0:20e0c61e0684 2296 // Function pointer is stored as union of possible function types
ganlikun 0:20e0c61e0684 2297 // to garuntee proper size and alignment
ganlikun 0:20e0c61e0684 2298 struct _class;
ganlikun 0:20e0c61e0684 2299 union {
ganlikun 0:20e0c61e0684 2300 void (*_staticfunc)(A0, A1, A2);
ganlikun 0:20e0c61e0684 2301 void (*_boundfunc)(_class*, A0, A1, A2);
ganlikun 0:20e0c61e0684 2302 void (_class::*_methodfunc)(A0, A1, A2);
ganlikun 0:20e0c61e0684 2303 } _func;
ganlikun 0:20e0c61e0684 2304 void *_obj;
ganlikun 0:20e0c61e0684 2305
ganlikun 0:20e0c61e0684 2306 // Dynamically dispatched operations
ganlikun 0:20e0c61e0684 2307 const struct ops {
ganlikun 0:20e0c61e0684 2308 R (*call)(const void*, A0, A1, A2);
ganlikun 0:20e0c61e0684 2309 void (*move)(void*, const void*);
ganlikun 0:20e0c61e0684 2310 void (*dtor)(void*);
ganlikun 0:20e0c61e0684 2311 } *_ops;
ganlikun 0:20e0c61e0684 2312
ganlikun 0:20e0c61e0684 2313 // Generate operations for function object
ganlikun 0:20e0c61e0684 2314 template <typename F>
ganlikun 0:20e0c61e0684 2315 void generate(const F &f) {
ganlikun 0:20e0c61e0684 2316 static const ops ops = {
ganlikun 0:20e0c61e0684 2317 &Callback::function_call<F>,
ganlikun 0:20e0c61e0684 2318 &Callback::function_move<F>,
ganlikun 0:20e0c61e0684 2319 &Callback::function_dtor<F>,
ganlikun 0:20e0c61e0684 2320 };
ganlikun 0:20e0c61e0684 2321
ganlikun 0:20e0c61e0684 2322 MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
ganlikun 0:20e0c61e0684 2323 "Type F must not exceed the size of the Callback class");
ganlikun 0:20e0c61e0684 2324 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 2325 new (this) F(f);
ganlikun 0:20e0c61e0684 2326 _ops = &ops;
ganlikun 0:20e0c61e0684 2327 }
ganlikun 0:20e0c61e0684 2328
ganlikun 0:20e0c61e0684 2329 // Function attributes
ganlikun 0:20e0c61e0684 2330 template <typename F>
ganlikun 0:20e0c61e0684 2331 static R function_call(const void *p, A0 a0, A1 a1, A2 a2) {
ganlikun 0:20e0c61e0684 2332 return (*(F*)p)(a0, a1, a2);
ganlikun 0:20e0c61e0684 2333 }
ganlikun 0:20e0c61e0684 2334
ganlikun 0:20e0c61e0684 2335 template <typename F>
ganlikun 0:20e0c61e0684 2336 static void function_move(void *d, const void *p) {
ganlikun 0:20e0c61e0684 2337 new (d) F(*(F*)p);
ganlikun 0:20e0c61e0684 2338 }
ganlikun 0:20e0c61e0684 2339
ganlikun 0:20e0c61e0684 2340 template <typename F>
ganlikun 0:20e0c61e0684 2341 static void function_dtor(void *p) {
ganlikun 0:20e0c61e0684 2342 ((F*)p)->~F();
ganlikun 0:20e0c61e0684 2343 }
ganlikun 0:20e0c61e0684 2344
ganlikun 0:20e0c61e0684 2345 // Wrappers for functions with context
ganlikun 0:20e0c61e0684 2346 template <typename O, typename M>
ganlikun 0:20e0c61e0684 2347 struct method_context {
ganlikun 0:20e0c61e0684 2348 M method;
ganlikun 0:20e0c61e0684 2349 O *obj;
ganlikun 0:20e0c61e0684 2350
ganlikun 0:20e0c61e0684 2351 method_context(O *obj, M method)
ganlikun 0:20e0c61e0684 2352 : method(method), obj(obj) {}
ganlikun 0:20e0c61e0684 2353
ganlikun 0:20e0c61e0684 2354 R operator()(A0 a0, A1 a1, A2 a2) const {
ganlikun 0:20e0c61e0684 2355 return (obj->*method)(a0, a1, a2);
ganlikun 0:20e0c61e0684 2356 }
ganlikun 0:20e0c61e0684 2357 };
ganlikun 0:20e0c61e0684 2358
ganlikun 0:20e0c61e0684 2359 template <typename F, typename A>
ganlikun 0:20e0c61e0684 2360 struct function_context {
ganlikun 0:20e0c61e0684 2361 F func;
ganlikun 0:20e0c61e0684 2362 A *arg;
ganlikun 0:20e0c61e0684 2363
ganlikun 0:20e0c61e0684 2364 function_context(F func, A *arg)
ganlikun 0:20e0c61e0684 2365 : func(func), arg(arg) {}
ganlikun 0:20e0c61e0684 2366
ganlikun 0:20e0c61e0684 2367 R operator()(A0 a0, A1 a1, A2 a2) const {
ganlikun 0:20e0c61e0684 2368 return func(arg, a0, a1, a2);
ganlikun 0:20e0c61e0684 2369 }
ganlikun 0:20e0c61e0684 2370 };
ganlikun 0:20e0c61e0684 2371 };
ganlikun 0:20e0c61e0684 2372
ganlikun 0:20e0c61e0684 2373 /** Callback class based on template specialization
ganlikun 0:20e0c61e0684 2374 *
ganlikun 0:20e0c61e0684 2375 * @note Synchronization level: Not protected
ganlikun 0:20e0c61e0684 2376 * @ingroup platform
ganlikun 0:20e0c61e0684 2377 */
ganlikun 0:20e0c61e0684 2378 template <typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 2379 class Callback<R(A0, A1, A2, A3)> {
ganlikun 0:20e0c61e0684 2380 public:
ganlikun 0:20e0c61e0684 2381 /** Create a Callback with a static function
ganlikun 0:20e0c61e0684 2382 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2383 */
ganlikun 0:20e0c61e0684 2384 Callback(R (*func)(A0, A1, A2, A3) = 0) {
ganlikun 0:20e0c61e0684 2385 if (!func) {
ganlikun 0:20e0c61e0684 2386 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 2387 } else {
ganlikun 0:20e0c61e0684 2388 generate(func);
ganlikun 0:20e0c61e0684 2389 }
ganlikun 0:20e0c61e0684 2390 }
ganlikun 0:20e0c61e0684 2391
ganlikun 0:20e0c61e0684 2392 /** Attach a Callback
ganlikun 0:20e0c61e0684 2393 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 2394 */
ganlikun 0:20e0c61e0684 2395 Callback(const Callback<R(A0, A1, A2, A3)> &func) {
ganlikun 0:20e0c61e0684 2396 if (func._ops) {
ganlikun 0:20e0c61e0684 2397 func._ops->move(this, &func);
ganlikun 0:20e0c61e0684 2398 }
ganlikun 0:20e0c61e0684 2399 _ops = func._ops;
ganlikun 0:20e0c61e0684 2400 }
ganlikun 0:20e0c61e0684 2401
ganlikun 0:20e0c61e0684 2402 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 2403 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2404 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2405 */
ganlikun 0:20e0c61e0684 2406 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2407 Callback(U *obj, R (T::*method)(A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2408 generate(method_context<T, R (T::*)(A0, A1, A2, A3)>(obj, method));
ganlikun 0:20e0c61e0684 2409 }
ganlikun 0:20e0c61e0684 2410
ganlikun 0:20e0c61e0684 2411 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 2412 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2413 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2414 */
ganlikun 0:20e0c61e0684 2415 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2416 Callback(const U *obj, R (T::*method)(A0, A1, A2, A3) const) {
ganlikun 0:20e0c61e0684 2417 generate(method_context<const T, R (T::*)(A0, A1, A2, A3) const>(obj, method));
ganlikun 0:20e0c61e0684 2418 }
ganlikun 0:20e0c61e0684 2419
ganlikun 0:20e0c61e0684 2420 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 2421 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2422 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2423 */
ganlikun 0:20e0c61e0684 2424 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2425 Callback(volatile U *obj, R (T::*method)(A0, A1, A2, A3) volatile) {
ganlikun 0:20e0c61e0684 2426 generate(method_context<volatile T, R (T::*)(A0, A1, A2, A3) volatile>(obj, method));
ganlikun 0:20e0c61e0684 2427 }
ganlikun 0:20e0c61e0684 2428
ganlikun 0:20e0c61e0684 2429 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 2430 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2431 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2432 */
ganlikun 0:20e0c61e0684 2433 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2434 Callback(const volatile U *obj, R (T::*method)(A0, A1, A2, A3) const volatile) {
ganlikun 0:20e0c61e0684 2435 generate(method_context<const volatile T, R (T::*)(A0, A1, A2, A3) const volatile>(obj, method));
ganlikun 0:20e0c61e0684 2436 }
ganlikun 0:20e0c61e0684 2437
ganlikun 0:20e0c61e0684 2438 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 2439 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2440 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2441 */
ganlikun 0:20e0c61e0684 2442 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2443 Callback(R (*func)(T*, A0, A1, A2, A3), U *arg) {
ganlikun 0:20e0c61e0684 2444 generate(function_context<R (*)(T*, A0, A1, A2, A3), T>(func, arg));
ganlikun 0:20e0c61e0684 2445 }
ganlikun 0:20e0c61e0684 2446
ganlikun 0:20e0c61e0684 2447 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 2448 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2449 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2450 */
ganlikun 0:20e0c61e0684 2451 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2452 Callback(R (*func)(const T*, A0, A1, A2, A3), const U *arg) {
ganlikun 0:20e0c61e0684 2453 generate(function_context<R (*)(const T*, A0, A1, A2, A3), const T>(func, arg));
ganlikun 0:20e0c61e0684 2454 }
ganlikun 0:20e0c61e0684 2455
ganlikun 0:20e0c61e0684 2456 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 2457 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2458 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2459 */
ganlikun 0:20e0c61e0684 2460 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2461 Callback(R (*func)(volatile T*, A0, A1, A2, A3), volatile U *arg) {
ganlikun 0:20e0c61e0684 2462 generate(function_context<R (*)(volatile T*, A0, A1, A2, A3), volatile T>(func, arg));
ganlikun 0:20e0c61e0684 2463 }
ganlikun 0:20e0c61e0684 2464
ganlikun 0:20e0c61e0684 2465 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 2466 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2467 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2468 */
ganlikun 0:20e0c61e0684 2469 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2470 Callback(R (*func)(const volatile T*, A0, A1, A2, A3), const volatile U *arg) {
ganlikun 0:20e0c61e0684 2471 generate(function_context<R (*)(const volatile T*, A0, A1, A2, A3), const volatile T>(func, arg));
ganlikun 0:20e0c61e0684 2472 }
ganlikun 0:20e0c61e0684 2473
ganlikun 0:20e0c61e0684 2474 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 2475 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2476 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2477 */
ganlikun 0:20e0c61e0684 2478 template <typename F>
ganlikun 0:20e0c61e0684 2479 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3))) {
ganlikun 0:20e0c61e0684 2480 generate(f);
ganlikun 0:20e0c61e0684 2481 }
ganlikun 0:20e0c61e0684 2482
ganlikun 0:20e0c61e0684 2483 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 2484 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2485 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2486 */
ganlikun 0:20e0c61e0684 2487 template <typename F>
ganlikun 0:20e0c61e0684 2488 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3) const)) {
ganlikun 0:20e0c61e0684 2489 generate(f);
ganlikun 0:20e0c61e0684 2490 }
ganlikun 0:20e0c61e0684 2491
ganlikun 0:20e0c61e0684 2492 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 2493 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2494 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2495 */
ganlikun 0:20e0c61e0684 2496 template <typename F>
ganlikun 0:20e0c61e0684 2497 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3) volatile)) {
ganlikun 0:20e0c61e0684 2498 generate(f);
ganlikun 0:20e0c61e0684 2499 }
ganlikun 0:20e0c61e0684 2500
ganlikun 0:20e0c61e0684 2501 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 2502 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2503 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2504 */
ganlikun 0:20e0c61e0684 2505 template <typename F>
ganlikun 0:20e0c61e0684 2506 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3) const volatile)) {
ganlikun 0:20e0c61e0684 2507 generate(f);
ganlikun 0:20e0c61e0684 2508 }
ganlikun 0:20e0c61e0684 2509
ganlikun 0:20e0c61e0684 2510 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 2511 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2512 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2513 * @deprecated
ganlikun 0:20e0c61e0684 2514 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 2515 */
ganlikun 0:20e0c61e0684 2516 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2517 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2518 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 2519 Callback(U *obj, R (*func)(T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2520 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2521 }
ganlikun 0:20e0c61e0684 2522
ganlikun 0:20e0c61e0684 2523 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 2524 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2525 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2526 * @deprecated
ganlikun 0:20e0c61e0684 2527 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 2528 */
ganlikun 0:20e0c61e0684 2529 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2530 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2531 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 2532 Callback(const U *obj, R (*func)(const T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2533 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2534 }
ganlikun 0:20e0c61e0684 2535
ganlikun 0:20e0c61e0684 2536 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 2537 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2538 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2539 * @deprecated
ganlikun 0:20e0c61e0684 2540 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 2541 */
ganlikun 0:20e0c61e0684 2542 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2543 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2544 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 2545 Callback(volatile U *obj, R (*func)(volatile T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2546 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2547 }
ganlikun 0:20e0c61e0684 2548
ganlikun 0:20e0c61e0684 2549 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 2550 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2551 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2552 * @deprecated
ganlikun 0:20e0c61e0684 2553 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 2554 */
ganlikun 0:20e0c61e0684 2555 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2556 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2557 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 2558 Callback(const volatile U *obj, R (*func)(const volatile T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2559 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2560 }
ganlikun 0:20e0c61e0684 2561
ganlikun 0:20e0c61e0684 2562 /** Destroy a callback
ganlikun 0:20e0c61e0684 2563 */
ganlikun 0:20e0c61e0684 2564 ~Callback() {
ganlikun 0:20e0c61e0684 2565 if (_ops) {
ganlikun 0:20e0c61e0684 2566 _ops->dtor(this);
ganlikun 0:20e0c61e0684 2567 }
ganlikun 0:20e0c61e0684 2568 }
ganlikun 0:20e0c61e0684 2569
ganlikun 0:20e0c61e0684 2570 /** Attach a static function
ganlikun 0:20e0c61e0684 2571 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2572 * @deprecated
ganlikun 0:20e0c61e0684 2573 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2574 */
ganlikun 0:20e0c61e0684 2575 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2576 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2577 void attach(R (*func)(A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2578 this->~Callback();
ganlikun 0:20e0c61e0684 2579 new (this) Callback(func);
ganlikun 0:20e0c61e0684 2580 }
ganlikun 0:20e0c61e0684 2581
ganlikun 0:20e0c61e0684 2582 /** Attach a Callback
ganlikun 0:20e0c61e0684 2583 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 2584 * @deprecated
ganlikun 0:20e0c61e0684 2585 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2586 */
ganlikun 0:20e0c61e0684 2587 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2588 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2589 void attach(const Callback<R(A0, A1, A2, A3)> &func) {
ganlikun 0:20e0c61e0684 2590 this->~Callback();
ganlikun 0:20e0c61e0684 2591 new (this) Callback(func);
ganlikun 0:20e0c61e0684 2592 }
ganlikun 0:20e0c61e0684 2593
ganlikun 0:20e0c61e0684 2594 /** Attach a member function
ganlikun 0:20e0c61e0684 2595 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2596 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2597 * @deprecated
ganlikun 0:20e0c61e0684 2598 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2599 */
ganlikun 0:20e0c61e0684 2600 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2601 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2602 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2603 void attach(U *obj, R (T::*method)(A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2604 this->~Callback();
ganlikun 0:20e0c61e0684 2605 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 2606 }
ganlikun 0:20e0c61e0684 2607
ganlikun 0:20e0c61e0684 2608 /** Attach a member function
ganlikun 0:20e0c61e0684 2609 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2610 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2611 * @deprecated
ganlikun 0:20e0c61e0684 2612 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2613 */
ganlikun 0:20e0c61e0684 2614 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2615 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2616 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2617 void attach(const U *obj, R (T::*method)(A0, A1, A2, A3) const) {
ganlikun 0:20e0c61e0684 2618 this->~Callback();
ganlikun 0:20e0c61e0684 2619 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 2620 }
ganlikun 0:20e0c61e0684 2621
ganlikun 0:20e0c61e0684 2622 /** Attach a member function
ganlikun 0:20e0c61e0684 2623 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2624 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2625 * @deprecated
ganlikun 0:20e0c61e0684 2626 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2627 */
ganlikun 0:20e0c61e0684 2628 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2629 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2630 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2631 void attach(volatile U *obj, R (T::*method)(A0, A1, A2, A3) volatile) {
ganlikun 0:20e0c61e0684 2632 this->~Callback();
ganlikun 0:20e0c61e0684 2633 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 2634 }
ganlikun 0:20e0c61e0684 2635
ganlikun 0:20e0c61e0684 2636 /** Attach a member function
ganlikun 0:20e0c61e0684 2637 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2638 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2639 * @deprecated
ganlikun 0:20e0c61e0684 2640 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2641 */
ganlikun 0:20e0c61e0684 2642 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2643 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2644 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2645 void attach(const volatile U *obj, R (T::*method)(A0, A1, A2, A3) const volatile) {
ganlikun 0:20e0c61e0684 2646 this->~Callback();
ganlikun 0:20e0c61e0684 2647 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 2648 }
ganlikun 0:20e0c61e0684 2649
ganlikun 0:20e0c61e0684 2650 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2651 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2652 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2653 * @deprecated
ganlikun 0:20e0c61e0684 2654 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2655 */
ganlikun 0:20e0c61e0684 2656 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2657 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2658 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2659 void attach(R (*func)(T*, A0, A1, A2, A3), U *arg) {
ganlikun 0:20e0c61e0684 2660 this->~Callback();
ganlikun 0:20e0c61e0684 2661 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 2662 }
ganlikun 0:20e0c61e0684 2663
ganlikun 0:20e0c61e0684 2664 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2665 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2666 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2667 * @deprecated
ganlikun 0:20e0c61e0684 2668 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2669 */
ganlikun 0:20e0c61e0684 2670 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2671 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2672 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2673 void attach(R (*func)(const T*, A0, A1, A2, A3), const U *arg) {
ganlikun 0:20e0c61e0684 2674 this->~Callback();
ganlikun 0:20e0c61e0684 2675 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 2676 }
ganlikun 0:20e0c61e0684 2677
ganlikun 0:20e0c61e0684 2678 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2679 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2680 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2681 * @deprecated
ganlikun 0:20e0c61e0684 2682 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2683 */
ganlikun 0:20e0c61e0684 2684 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2685 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2686 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2687 void attach(R (*func)(volatile T*, A0, A1, A2, A3), volatile U *arg) {
ganlikun 0:20e0c61e0684 2688 this->~Callback();
ganlikun 0:20e0c61e0684 2689 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 2690 }
ganlikun 0:20e0c61e0684 2691
ganlikun 0:20e0c61e0684 2692 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2693 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2694 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 2695 * @deprecated
ganlikun 0:20e0c61e0684 2696 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2697 */
ganlikun 0:20e0c61e0684 2698 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2699 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2700 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2701 void attach(R (*func)(const volatile T*, A0, A1, A2, A3), const volatile U *arg) {
ganlikun 0:20e0c61e0684 2702 this->~Callback();
ganlikun 0:20e0c61e0684 2703 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 2704 }
ganlikun 0:20e0c61e0684 2705
ganlikun 0:20e0c61e0684 2706 /** Attach a function object
ganlikun 0:20e0c61e0684 2707 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2708 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2709 * @deprecated
ganlikun 0:20e0c61e0684 2710 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2711 */
ganlikun 0:20e0c61e0684 2712 template <typename F>
ganlikun 0:20e0c61e0684 2713 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2714 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2715 void attach(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3))) {
ganlikun 0:20e0c61e0684 2716 this->~Callback();
ganlikun 0:20e0c61e0684 2717 new (this) Callback(f);
ganlikun 0:20e0c61e0684 2718 }
ganlikun 0:20e0c61e0684 2719
ganlikun 0:20e0c61e0684 2720 /** Attach a function object
ganlikun 0:20e0c61e0684 2721 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2722 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2723 * @deprecated
ganlikun 0:20e0c61e0684 2724 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2725 */
ganlikun 0:20e0c61e0684 2726 template <typename F>
ganlikun 0:20e0c61e0684 2727 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2728 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2729 void attach(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3) const)) {
ganlikun 0:20e0c61e0684 2730 this->~Callback();
ganlikun 0:20e0c61e0684 2731 new (this) Callback(f);
ganlikun 0:20e0c61e0684 2732 }
ganlikun 0:20e0c61e0684 2733
ganlikun 0:20e0c61e0684 2734 /** Attach a function object
ganlikun 0:20e0c61e0684 2735 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2736 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2737 * @deprecated
ganlikun 0:20e0c61e0684 2738 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2739 */
ganlikun 0:20e0c61e0684 2740 template <typename F>
ganlikun 0:20e0c61e0684 2741 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2742 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2743 void attach(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3) volatile)) {
ganlikun 0:20e0c61e0684 2744 this->~Callback();
ganlikun 0:20e0c61e0684 2745 new (this) Callback(f);
ganlikun 0:20e0c61e0684 2746 }
ganlikun 0:20e0c61e0684 2747
ganlikun 0:20e0c61e0684 2748 /** Attach a function object
ganlikun 0:20e0c61e0684 2749 * @param f Function object to attach
ganlikun 0:20e0c61e0684 2750 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 2751 * @deprecated
ganlikun 0:20e0c61e0684 2752 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 2753 */
ganlikun 0:20e0c61e0684 2754 template <typename F>
ganlikun 0:20e0c61e0684 2755 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 2756 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 2757 void attach(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3) const volatile)) {
ganlikun 0:20e0c61e0684 2758 this->~Callback();
ganlikun 0:20e0c61e0684 2759 new (this) Callback(f);
ganlikun 0:20e0c61e0684 2760 }
ganlikun 0:20e0c61e0684 2761
ganlikun 0:20e0c61e0684 2762 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2763 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2764 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2765 * @deprecated
ganlikun 0:20e0c61e0684 2766 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 2767 */
ganlikun 0:20e0c61e0684 2768 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2769 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2770 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 2771 void attach(U *obj, R (*func)(T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2772 this->~Callback();
ganlikun 0:20e0c61e0684 2773 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2774 }
ganlikun 0:20e0c61e0684 2775
ganlikun 0:20e0c61e0684 2776 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2777 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2778 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2779 * @deprecated
ganlikun 0:20e0c61e0684 2780 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 2781 */
ganlikun 0:20e0c61e0684 2782 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2783 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2784 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 2785 void attach(const U *obj, R (*func)(const T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2786 this->~Callback();
ganlikun 0:20e0c61e0684 2787 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2788 }
ganlikun 0:20e0c61e0684 2789
ganlikun 0:20e0c61e0684 2790 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2791 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2792 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2793 * @deprecated
ganlikun 0:20e0c61e0684 2794 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 2795 */
ganlikun 0:20e0c61e0684 2796 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2797 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2798 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 2799 void attach(volatile U *obj, R (*func)(volatile T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2800 this->~Callback();
ganlikun 0:20e0c61e0684 2801 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2802 }
ganlikun 0:20e0c61e0684 2803
ganlikun 0:20e0c61e0684 2804 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 2805 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 2806 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2807 * @deprecated
ganlikun 0:20e0c61e0684 2808 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 2809 */
ganlikun 0:20e0c61e0684 2810 template <typename T, typename U>
ganlikun 0:20e0c61e0684 2811 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 2812 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 2813 void attach(const volatile U *obj, R (*func)(const volatile T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 2814 this->~Callback();
ganlikun 0:20e0c61e0684 2815 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 2816 }
ganlikun 0:20e0c61e0684 2817
ganlikun 0:20e0c61e0684 2818 /** Assign a callback
ganlikun 0:20e0c61e0684 2819 */
ganlikun 0:20e0c61e0684 2820 Callback &operator=(const Callback &that) {
ganlikun 0:20e0c61e0684 2821 if (this != &that) {
ganlikun 0:20e0c61e0684 2822 this->~Callback();
ganlikun 0:20e0c61e0684 2823 new (this) Callback(that);
ganlikun 0:20e0c61e0684 2824 }
ganlikun 0:20e0c61e0684 2825
ganlikun 0:20e0c61e0684 2826 return *this;
ganlikun 0:20e0c61e0684 2827 }
ganlikun 0:20e0c61e0684 2828
ganlikun 0:20e0c61e0684 2829 /** Call the attached function
ganlikun 0:20e0c61e0684 2830 */
ganlikun 0:20e0c61e0684 2831 R call(A0 a0, A1 a1, A2 a2, A3 a3) const {
ganlikun 0:20e0c61e0684 2832 MBED_ASSERT(_ops);
ganlikun 0:20e0c61e0684 2833 return _ops->call(this, a0, a1, a2, a3);
ganlikun 0:20e0c61e0684 2834 }
ganlikun 0:20e0c61e0684 2835
ganlikun 0:20e0c61e0684 2836 /** Call the attached function
ganlikun 0:20e0c61e0684 2837 */
ganlikun 0:20e0c61e0684 2838 R operator()(A0 a0, A1 a1, A2 a2, A3 a3) const {
ganlikun 0:20e0c61e0684 2839 return call(a0, a1, a2, a3);
ganlikun 0:20e0c61e0684 2840 }
ganlikun 0:20e0c61e0684 2841
ganlikun 0:20e0c61e0684 2842 /** Test if function has been attached
ganlikun 0:20e0c61e0684 2843 */
ganlikun 0:20e0c61e0684 2844 operator bool() const {
ganlikun 0:20e0c61e0684 2845 return _ops;
ganlikun 0:20e0c61e0684 2846 }
ganlikun 0:20e0c61e0684 2847
ganlikun 0:20e0c61e0684 2848 /** Test for equality
ganlikun 0:20e0c61e0684 2849 */
ganlikun 0:20e0c61e0684 2850 friend bool operator==(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 2851 return memcmp(&l, &r, sizeof(Callback)) == 0;
ganlikun 0:20e0c61e0684 2852 }
ganlikun 0:20e0c61e0684 2853
ganlikun 0:20e0c61e0684 2854 /** Test for inequality
ganlikun 0:20e0c61e0684 2855 */
ganlikun 0:20e0c61e0684 2856 friend bool operator!=(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 2857 return !(l == r);
ganlikun 0:20e0c61e0684 2858 }
ganlikun 0:20e0c61e0684 2859
ganlikun 0:20e0c61e0684 2860 /** Static thunk for passing as C-style function
ganlikun 0:20e0c61e0684 2861 * @param func Callback to call passed as void pointer
ganlikun 0:20e0c61e0684 2862 * @param a0 An argument to be called with function func
ganlikun 0:20e0c61e0684 2863 * @param a1 An argument to be called with function func
ganlikun 0:20e0c61e0684 2864 * @param a2 An argument to be called with function func
ganlikun 0:20e0c61e0684 2865 * @param a3 An argument to be called with function func
ganlikun 0:20e0c61e0684 2866 * @return the value as determined by func which is of
ganlikun 0:20e0c61e0684 2867 * type and determined by the signiture of func
ganlikun 0:20e0c61e0684 2868 */
ganlikun 0:20e0c61e0684 2869 static R thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3) {
ganlikun 0:20e0c61e0684 2870 return static_cast<Callback*>(func)->call(a0, a1, a2, a3);
ganlikun 0:20e0c61e0684 2871 }
ganlikun 0:20e0c61e0684 2872
ganlikun 0:20e0c61e0684 2873 private:
ganlikun 0:20e0c61e0684 2874 // Stored as pointer to function and pointer to optional object
ganlikun 0:20e0c61e0684 2875 // Function pointer is stored as union of possible function types
ganlikun 0:20e0c61e0684 2876 // to garuntee proper size and alignment
ganlikun 0:20e0c61e0684 2877 struct _class;
ganlikun 0:20e0c61e0684 2878 union {
ganlikun 0:20e0c61e0684 2879 void (*_staticfunc)(A0, A1, A2, A3);
ganlikun 0:20e0c61e0684 2880 void (*_boundfunc)(_class*, A0, A1, A2, A3);
ganlikun 0:20e0c61e0684 2881 void (_class::*_methodfunc)(A0, A1, A2, A3);
ganlikun 0:20e0c61e0684 2882 } _func;
ganlikun 0:20e0c61e0684 2883 void *_obj;
ganlikun 0:20e0c61e0684 2884
ganlikun 0:20e0c61e0684 2885 // Dynamically dispatched operations
ganlikun 0:20e0c61e0684 2886 const struct ops {
ganlikun 0:20e0c61e0684 2887 R (*call)(const void*, A0, A1, A2, A3);
ganlikun 0:20e0c61e0684 2888 void (*move)(void*, const void*);
ganlikun 0:20e0c61e0684 2889 void (*dtor)(void*);
ganlikun 0:20e0c61e0684 2890 } *_ops;
ganlikun 0:20e0c61e0684 2891
ganlikun 0:20e0c61e0684 2892 // Generate operations for function object
ganlikun 0:20e0c61e0684 2893 template <typename F>
ganlikun 0:20e0c61e0684 2894 void generate(const F &f) {
ganlikun 0:20e0c61e0684 2895 static const ops ops = {
ganlikun 0:20e0c61e0684 2896 &Callback::function_call<F>,
ganlikun 0:20e0c61e0684 2897 &Callback::function_move<F>,
ganlikun 0:20e0c61e0684 2898 &Callback::function_dtor<F>,
ganlikun 0:20e0c61e0684 2899 };
ganlikun 0:20e0c61e0684 2900
ganlikun 0:20e0c61e0684 2901 MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
ganlikun 0:20e0c61e0684 2902 "Type F must not exceed the size of the Callback class");
ganlikun 0:20e0c61e0684 2903 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 2904 new (this) F(f);
ganlikun 0:20e0c61e0684 2905 _ops = &ops;
ganlikun 0:20e0c61e0684 2906 }
ganlikun 0:20e0c61e0684 2907
ganlikun 0:20e0c61e0684 2908 // Function attributes
ganlikun 0:20e0c61e0684 2909 template <typename F>
ganlikun 0:20e0c61e0684 2910 static R function_call(const void *p, A0 a0, A1 a1, A2 a2, A3 a3) {
ganlikun 0:20e0c61e0684 2911 return (*(F*)p)(a0, a1, a2, a3);
ganlikun 0:20e0c61e0684 2912 }
ganlikun 0:20e0c61e0684 2913
ganlikun 0:20e0c61e0684 2914 template <typename F>
ganlikun 0:20e0c61e0684 2915 static void function_move(void *d, const void *p) {
ganlikun 0:20e0c61e0684 2916 new (d) F(*(F*)p);
ganlikun 0:20e0c61e0684 2917 }
ganlikun 0:20e0c61e0684 2918
ganlikun 0:20e0c61e0684 2919 template <typename F>
ganlikun 0:20e0c61e0684 2920 static void function_dtor(void *p) {
ganlikun 0:20e0c61e0684 2921 ((F*)p)->~F();
ganlikun 0:20e0c61e0684 2922 }
ganlikun 0:20e0c61e0684 2923
ganlikun 0:20e0c61e0684 2924 // Wrappers for functions with context
ganlikun 0:20e0c61e0684 2925 template <typename O, typename M>
ganlikun 0:20e0c61e0684 2926 struct method_context {
ganlikun 0:20e0c61e0684 2927 M method;
ganlikun 0:20e0c61e0684 2928 O *obj;
ganlikun 0:20e0c61e0684 2929
ganlikun 0:20e0c61e0684 2930 method_context(O *obj, M method)
ganlikun 0:20e0c61e0684 2931 : method(method), obj(obj) {}
ganlikun 0:20e0c61e0684 2932
ganlikun 0:20e0c61e0684 2933 R operator()(A0 a0, A1 a1, A2 a2, A3 a3) const {
ganlikun 0:20e0c61e0684 2934 return (obj->*method)(a0, a1, a2, a3);
ganlikun 0:20e0c61e0684 2935 }
ganlikun 0:20e0c61e0684 2936 };
ganlikun 0:20e0c61e0684 2937
ganlikun 0:20e0c61e0684 2938 template <typename F, typename A>
ganlikun 0:20e0c61e0684 2939 struct function_context {
ganlikun 0:20e0c61e0684 2940 F func;
ganlikun 0:20e0c61e0684 2941 A *arg;
ganlikun 0:20e0c61e0684 2942
ganlikun 0:20e0c61e0684 2943 function_context(F func, A *arg)
ganlikun 0:20e0c61e0684 2944 : func(func), arg(arg) {}
ganlikun 0:20e0c61e0684 2945
ganlikun 0:20e0c61e0684 2946 R operator()(A0 a0, A1 a1, A2 a2, A3 a3) const {
ganlikun 0:20e0c61e0684 2947 return func(arg, a0, a1, a2, a3);
ganlikun 0:20e0c61e0684 2948 }
ganlikun 0:20e0c61e0684 2949 };
ganlikun 0:20e0c61e0684 2950 };
ganlikun 0:20e0c61e0684 2951
ganlikun 0:20e0c61e0684 2952 /** Callback class based on template specialization
ganlikun 0:20e0c61e0684 2953 *
ganlikun 0:20e0c61e0684 2954 * @note Synchronization level: Not protected
ganlikun 0:20e0c61e0684 2955 * @ingroup platform
ganlikun 0:20e0c61e0684 2956 */
ganlikun 0:20e0c61e0684 2957 template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 2958 class Callback<R(A0, A1, A2, A3, A4)> {
ganlikun 0:20e0c61e0684 2959 public:
ganlikun 0:20e0c61e0684 2960 /** Create a Callback with a static function
ganlikun 0:20e0c61e0684 2961 * @param func Static function to attach
ganlikun 0:20e0c61e0684 2962 */
ganlikun 0:20e0c61e0684 2963 Callback(R (*func)(A0, A1, A2, A3, A4) = 0) {
ganlikun 0:20e0c61e0684 2964 if (!func) {
ganlikun 0:20e0c61e0684 2965 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 2966 } else {
ganlikun 0:20e0c61e0684 2967 generate(func);
ganlikun 0:20e0c61e0684 2968 }
ganlikun 0:20e0c61e0684 2969 }
ganlikun 0:20e0c61e0684 2970
ganlikun 0:20e0c61e0684 2971 /** Attach a Callback
ganlikun 0:20e0c61e0684 2972 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 2973 */
ganlikun 0:20e0c61e0684 2974 Callback(const Callback<R(A0, A1, A2, A3, A4)> &func) {
ganlikun 0:20e0c61e0684 2975 if (func._ops) {
ganlikun 0:20e0c61e0684 2976 func._ops->move(this, &func);
ganlikun 0:20e0c61e0684 2977 }
ganlikun 0:20e0c61e0684 2978 _ops = func._ops;
ganlikun 0:20e0c61e0684 2979 }
ganlikun 0:20e0c61e0684 2980
ganlikun 0:20e0c61e0684 2981 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 2982 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2983 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2984 */
ganlikun 0:20e0c61e0684 2985 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2986 Callback(U *obj, R (T::*method)(A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 2987 generate(method_context<T, R (T::*)(A0, A1, A2, A3, A4)>(obj, method));
ganlikun 0:20e0c61e0684 2988 }
ganlikun 0:20e0c61e0684 2989
ganlikun 0:20e0c61e0684 2990 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 2991 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 2992 * @param method Member function to attach
ganlikun 0:20e0c61e0684 2993 */
ganlikun 0:20e0c61e0684 2994 template<typename T, typename U>
ganlikun 0:20e0c61e0684 2995 Callback(const U *obj, R (T::*method)(A0, A1, A2, A3, A4) const) {
ganlikun 0:20e0c61e0684 2996 generate(method_context<const T, R (T::*)(A0, A1, A2, A3, A4) const>(obj, method));
ganlikun 0:20e0c61e0684 2997 }
ganlikun 0:20e0c61e0684 2998
ganlikun 0:20e0c61e0684 2999 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 3000 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 3001 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3002 */
ganlikun 0:20e0c61e0684 3003 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3004 Callback(volatile U *obj, R (T::*method)(A0, A1, A2, A3, A4) volatile) {
ganlikun 0:20e0c61e0684 3005 generate(method_context<volatile T, R (T::*)(A0, A1, A2, A3, A4) volatile>(obj, method));
ganlikun 0:20e0c61e0684 3006 }
ganlikun 0:20e0c61e0684 3007
ganlikun 0:20e0c61e0684 3008 /** Create a Callback with a member function
ganlikun 0:20e0c61e0684 3009 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 3010 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3011 */
ganlikun 0:20e0c61e0684 3012 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3013 Callback(const volatile U *obj, R (T::*method)(A0, A1, A2, A3, A4) const volatile) {
ganlikun 0:20e0c61e0684 3014 generate(method_context<const volatile T, R (T::*)(A0, A1, A2, A3, A4) const volatile>(obj, method));
ganlikun 0:20e0c61e0684 3015 }
ganlikun 0:20e0c61e0684 3016
ganlikun 0:20e0c61e0684 3017 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 3018 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3019 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3020 */
ganlikun 0:20e0c61e0684 3021 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3022 Callback(R (*func)(T*, A0, A1, A2, A3, A4), U *arg) {
ganlikun 0:20e0c61e0684 3023 generate(function_context<R (*)(T*, A0, A1, A2, A3, A4), T>(func, arg));
ganlikun 0:20e0c61e0684 3024 }
ganlikun 0:20e0c61e0684 3025
ganlikun 0:20e0c61e0684 3026 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 3027 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3028 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3029 */
ganlikun 0:20e0c61e0684 3030 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3031 Callback(R (*func)(const T*, A0, A1, A2, A3, A4), const U *arg) {
ganlikun 0:20e0c61e0684 3032 generate(function_context<R (*)(const T*, A0, A1, A2, A3, A4), const T>(func, arg));
ganlikun 0:20e0c61e0684 3033 }
ganlikun 0:20e0c61e0684 3034
ganlikun 0:20e0c61e0684 3035 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 3036 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3037 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3038 */
ganlikun 0:20e0c61e0684 3039 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3040 Callback(R (*func)(volatile T*, A0, A1, A2, A3, A4), volatile U *arg) {
ganlikun 0:20e0c61e0684 3041 generate(function_context<R (*)(volatile T*, A0, A1, A2, A3, A4), volatile T>(func, arg));
ganlikun 0:20e0c61e0684 3042 }
ganlikun 0:20e0c61e0684 3043
ganlikun 0:20e0c61e0684 3044 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 3045 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3046 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3047 */
ganlikun 0:20e0c61e0684 3048 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3049 Callback(R (*func)(const volatile T*, A0, A1, A2, A3, A4), const volatile U *arg) {
ganlikun 0:20e0c61e0684 3050 generate(function_context<R (*)(const volatile T*, A0, A1, A2, A3, A4), const volatile T>(func, arg));
ganlikun 0:20e0c61e0684 3051 }
ganlikun 0:20e0c61e0684 3052
ganlikun 0:20e0c61e0684 3053 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 3054 * @param f Function object to attach
ganlikun 0:20e0c61e0684 3055 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 3056 */
ganlikun 0:20e0c61e0684 3057 template <typename F>
ganlikun 0:20e0c61e0684 3058 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3, A4))) {
ganlikun 0:20e0c61e0684 3059 generate(f);
ganlikun 0:20e0c61e0684 3060 }
ganlikun 0:20e0c61e0684 3061
ganlikun 0:20e0c61e0684 3062 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 3063 * @param f Function object to attach
ganlikun 0:20e0c61e0684 3064 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 3065 */
ganlikun 0:20e0c61e0684 3066 template <typename F>
ganlikun 0:20e0c61e0684 3067 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3, A4) const)) {
ganlikun 0:20e0c61e0684 3068 generate(f);
ganlikun 0:20e0c61e0684 3069 }
ganlikun 0:20e0c61e0684 3070
ganlikun 0:20e0c61e0684 3071 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 3072 * @param f Function object to attach
ganlikun 0:20e0c61e0684 3073 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 3074 */
ganlikun 0:20e0c61e0684 3075 template <typename F>
ganlikun 0:20e0c61e0684 3076 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3, A4) volatile)) {
ganlikun 0:20e0c61e0684 3077 generate(f);
ganlikun 0:20e0c61e0684 3078 }
ganlikun 0:20e0c61e0684 3079
ganlikun 0:20e0c61e0684 3080 /** Create a Callback with a function object
ganlikun 0:20e0c61e0684 3081 * @param f Function object to attach
ganlikun 0:20e0c61e0684 3082 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 3083 */
ganlikun 0:20e0c61e0684 3084 template <typename F>
ganlikun 0:20e0c61e0684 3085 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3, A4) const volatile)) {
ganlikun 0:20e0c61e0684 3086 generate(f);
ganlikun 0:20e0c61e0684 3087 }
ganlikun 0:20e0c61e0684 3088
ganlikun 0:20e0c61e0684 3089 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 3090 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 3091 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3092 * @deprecated
ganlikun 0:20e0c61e0684 3093 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 3094 */
ganlikun 0:20e0c61e0684 3095 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3096 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3097 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 3098 Callback(U *obj, R (*func)(T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 3099 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 3100 }
ganlikun 0:20e0c61e0684 3101
ganlikun 0:20e0c61e0684 3102 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 3103 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 3104 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3105 * @deprecated
ganlikun 0:20e0c61e0684 3106 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 3107 */
ganlikun 0:20e0c61e0684 3108 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3109 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3110 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 3111 Callback(const U *obj, R (*func)(const T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 3112 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 3113 }
ganlikun 0:20e0c61e0684 3114
ganlikun 0:20e0c61e0684 3115 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 3116 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 3117 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3118 * @deprecated
ganlikun 0:20e0c61e0684 3119 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 3120 */
ganlikun 0:20e0c61e0684 3121 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3122 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3123 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 3124 Callback(volatile U *obj, R (*func)(volatile T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 3125 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 3126 }
ganlikun 0:20e0c61e0684 3127
ganlikun 0:20e0c61e0684 3128 /** Create a Callback with a static function and bound pointer
ganlikun 0:20e0c61e0684 3129 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 3130 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3131 * @deprecated
ganlikun 0:20e0c61e0684 3132 * Arguments to callback have been reordered to Callback(func, arg)
ganlikun 0:20e0c61e0684 3133 */
ganlikun 0:20e0c61e0684 3134 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3135 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3136 "Arguments to callback have been reordered to Callback(func, arg)")
ganlikun 0:20e0c61e0684 3137 Callback(const volatile U *obj, R (*func)(const volatile T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 3138 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 3139 }
ganlikun 0:20e0c61e0684 3140
ganlikun 0:20e0c61e0684 3141 /** Destroy a callback
ganlikun 0:20e0c61e0684 3142 */
ganlikun 0:20e0c61e0684 3143 ~Callback() {
ganlikun 0:20e0c61e0684 3144 if (_ops) {
ganlikun 0:20e0c61e0684 3145 _ops->dtor(this);
ganlikun 0:20e0c61e0684 3146 }
ganlikun 0:20e0c61e0684 3147 }
ganlikun 0:20e0c61e0684 3148
ganlikun 0:20e0c61e0684 3149 /** Attach a static function
ganlikun 0:20e0c61e0684 3150 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3151 * @deprecated
ganlikun 0:20e0c61e0684 3152 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3153 */
ganlikun 0:20e0c61e0684 3154 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3155 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3156 void attach(R (*func)(A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 3157 this->~Callback();
ganlikun 0:20e0c61e0684 3158 new (this) Callback(func);
ganlikun 0:20e0c61e0684 3159 }
ganlikun 0:20e0c61e0684 3160
ganlikun 0:20e0c61e0684 3161 /** Attach a Callback
ganlikun 0:20e0c61e0684 3162 * @param func The Callback to attach
ganlikun 0:20e0c61e0684 3163 * @deprecated
ganlikun 0:20e0c61e0684 3164 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3165 */
ganlikun 0:20e0c61e0684 3166 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3167 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3168 void attach(const Callback<R(A0, A1, A2, A3, A4)> &func) {
ganlikun 0:20e0c61e0684 3169 this->~Callback();
ganlikun 0:20e0c61e0684 3170 new (this) Callback(func);
ganlikun 0:20e0c61e0684 3171 }
ganlikun 0:20e0c61e0684 3172
ganlikun 0:20e0c61e0684 3173 /** Attach a member function
ganlikun 0:20e0c61e0684 3174 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 3175 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3176 * @deprecated
ganlikun 0:20e0c61e0684 3177 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3178 */
ganlikun 0:20e0c61e0684 3179 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3180 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3181 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3182 void attach(U *obj, R (T::*method)(A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 3183 this->~Callback();
ganlikun 0:20e0c61e0684 3184 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 3185 }
ganlikun 0:20e0c61e0684 3186
ganlikun 0:20e0c61e0684 3187 /** Attach a member function
ganlikun 0:20e0c61e0684 3188 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 3189 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3190 * @deprecated
ganlikun 0:20e0c61e0684 3191 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3192 */
ganlikun 0:20e0c61e0684 3193 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3194 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3195 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3196 void attach(const U *obj, R (T::*method)(A0, A1, A2, A3, A4) const) {
ganlikun 0:20e0c61e0684 3197 this->~Callback();
ganlikun 0:20e0c61e0684 3198 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 3199 }
ganlikun 0:20e0c61e0684 3200
ganlikun 0:20e0c61e0684 3201 /** Attach a member function
ganlikun 0:20e0c61e0684 3202 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 3203 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3204 * @deprecated
ganlikun 0:20e0c61e0684 3205 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3206 */
ganlikun 0:20e0c61e0684 3207 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3208 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3209 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3210 void attach(volatile U *obj, R (T::*method)(A0, A1, A2, A3, A4) volatile) {
ganlikun 0:20e0c61e0684 3211 this->~Callback();
ganlikun 0:20e0c61e0684 3212 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 3213 }
ganlikun 0:20e0c61e0684 3214
ganlikun 0:20e0c61e0684 3215 /** Attach a member function
ganlikun 0:20e0c61e0684 3216 * @param obj Pointer to object to invoke member function on
ganlikun 0:20e0c61e0684 3217 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3218 * @deprecated
ganlikun 0:20e0c61e0684 3219 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3220 */
ganlikun 0:20e0c61e0684 3221 template<typename T, typename U>
ganlikun 0:20e0c61e0684 3222 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3223 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3224 void attach(const volatile U *obj, R (T::*method)(A0, A1, A2, A3, A4) const volatile) {
ganlikun 0:20e0c61e0684 3225 this->~Callback();
ganlikun 0:20e0c61e0684 3226 new (this) Callback(obj, method);
ganlikun 0:20e0c61e0684 3227 }
ganlikun 0:20e0c61e0684 3228
ganlikun 0:20e0c61e0684 3229 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 3230 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3231 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3232 * @deprecated
ganlikun 0:20e0c61e0684 3233 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3234 */
ganlikun 0:20e0c61e0684 3235 template <typename T, typename U>
ganlikun 0:20e0c61e0684 3236 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3237 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3238 void attach(R (*func)(T*, A0, A1, A2, A3, A4), U *arg) {
ganlikun 0:20e0c61e0684 3239 this->~Callback();
ganlikun 0:20e0c61e0684 3240 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 3241 }
ganlikun 0:20e0c61e0684 3242
ganlikun 0:20e0c61e0684 3243 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 3244 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3245 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3246 * @deprecated
ganlikun 0:20e0c61e0684 3247 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3248 */
ganlikun 0:20e0c61e0684 3249 template <typename T, typename U>
ganlikun 0:20e0c61e0684 3250 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3251 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3252 void attach(R (*func)(const T*, A0, A1, A2, A3, A4), const U *arg) {
ganlikun 0:20e0c61e0684 3253 this->~Callback();
ganlikun 0:20e0c61e0684 3254 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 3255 }
ganlikun 0:20e0c61e0684 3256
ganlikun 0:20e0c61e0684 3257 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 3258 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3259 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3260 * @deprecated
ganlikun 0:20e0c61e0684 3261 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3262 */
ganlikun 0:20e0c61e0684 3263 template <typename T, typename U>
ganlikun 0:20e0c61e0684 3264 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3265 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3266 void attach(R (*func)(volatile T*, A0, A1, A2, A3, A4), volatile U *arg) {
ganlikun 0:20e0c61e0684 3267 this->~Callback();
ganlikun 0:20e0c61e0684 3268 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 3269 }
ganlikun 0:20e0c61e0684 3270
ganlikun 0:20e0c61e0684 3271 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 3272 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3273 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3274 * @deprecated
ganlikun 0:20e0c61e0684 3275 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3276 */
ganlikun 0:20e0c61e0684 3277 template <typename T, typename U>
ganlikun 0:20e0c61e0684 3278 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3279 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3280 void attach(R (*func)(const volatile T*, A0, A1, A2, A3, A4), const volatile U *arg) {
ganlikun 0:20e0c61e0684 3281 this->~Callback();
ganlikun 0:20e0c61e0684 3282 new (this) Callback(func, arg);
ganlikun 0:20e0c61e0684 3283 }
ganlikun 0:20e0c61e0684 3284
ganlikun 0:20e0c61e0684 3285 /** Attach a function object
ganlikun 0:20e0c61e0684 3286 * @param f Function object to attach
ganlikun 0:20e0c61e0684 3287 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 3288 * @deprecated
ganlikun 0:20e0c61e0684 3289 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3290 */
ganlikun 0:20e0c61e0684 3291 template <typename F>
ganlikun 0:20e0c61e0684 3292 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3293 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3294 void attach(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3, A4))) {
ganlikun 0:20e0c61e0684 3295 this->~Callback();
ganlikun 0:20e0c61e0684 3296 new (this) Callback(f);
ganlikun 0:20e0c61e0684 3297 }
ganlikun 0:20e0c61e0684 3298
ganlikun 0:20e0c61e0684 3299 /** Attach a function object
ganlikun 0:20e0c61e0684 3300 * @param f Function object to attach
ganlikun 0:20e0c61e0684 3301 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 3302 * @deprecated
ganlikun 0:20e0c61e0684 3303 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3304 */
ganlikun 0:20e0c61e0684 3305 template <typename F>
ganlikun 0:20e0c61e0684 3306 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3307 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3308 void attach(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3, A4) const)) {
ganlikun 0:20e0c61e0684 3309 this->~Callback();
ganlikun 0:20e0c61e0684 3310 new (this) Callback(f);
ganlikun 0:20e0c61e0684 3311 }
ganlikun 0:20e0c61e0684 3312
ganlikun 0:20e0c61e0684 3313 /** Attach a function object
ganlikun 0:20e0c61e0684 3314 * @param f Function object to attach
ganlikun 0:20e0c61e0684 3315 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 3316 * @deprecated
ganlikun 0:20e0c61e0684 3317 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3318 */
ganlikun 0:20e0c61e0684 3319 template <typename F>
ganlikun 0:20e0c61e0684 3320 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3321 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3322 void attach(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3, A4) volatile)) {
ganlikun 0:20e0c61e0684 3323 this->~Callback();
ganlikun 0:20e0c61e0684 3324 new (this) Callback(f);
ganlikun 0:20e0c61e0684 3325 }
ganlikun 0:20e0c61e0684 3326
ganlikun 0:20e0c61e0684 3327 /** Attach a function object
ganlikun 0:20e0c61e0684 3328 * @param f Function object to attach
ganlikun 0:20e0c61e0684 3329 * @note The function object is limited to a single word of storage
ganlikun 0:20e0c61e0684 3330 * @deprecated
ganlikun 0:20e0c61e0684 3331 * Replaced by simple assignment 'Callback cb = func'
ganlikun 0:20e0c61e0684 3332 */
ganlikun 0:20e0c61e0684 3333 template <typename F>
ganlikun 0:20e0c61e0684 3334 MBED_DEPRECATED_SINCE("mbed-os-5.4",
ganlikun 0:20e0c61e0684 3335 "Replaced by simple assignment 'Callback cb = func")
ganlikun 0:20e0c61e0684 3336 void attach(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R (F::*)(A0, A1, A2, A3, A4) const volatile)) {
ganlikun 0:20e0c61e0684 3337 this->~Callback();
ganlikun 0:20e0c61e0684 3338 new (this) Callback(f);
ganlikun 0:20e0c61e0684 3339 }
ganlikun 0:20e0c61e0684 3340
ganlikun 0:20e0c61e0684 3341 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 3342 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 3343 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3344 * @deprecated
ganlikun 0:20e0c61e0684 3345 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 3346 */
ganlikun 0:20e0c61e0684 3347 template <typename T, typename U>
ganlikun 0:20e0c61e0684 3348 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3349 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 3350 void attach(U *obj, R (*func)(T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 3351 this->~Callback();
ganlikun 0:20e0c61e0684 3352 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 3353 }
ganlikun 0:20e0c61e0684 3354
ganlikun 0:20e0c61e0684 3355 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 3356 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 3357 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3358 * @deprecated
ganlikun 0:20e0c61e0684 3359 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 3360 */
ganlikun 0:20e0c61e0684 3361 template <typename T, typename U>
ganlikun 0:20e0c61e0684 3362 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3363 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 3364 void attach(const U *obj, R (*func)(const T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 3365 this->~Callback();
ganlikun 0:20e0c61e0684 3366 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 3367 }
ganlikun 0:20e0c61e0684 3368
ganlikun 0:20e0c61e0684 3369 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 3370 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 3371 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3372 * @deprecated
ganlikun 0:20e0c61e0684 3373 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 3374 */
ganlikun 0:20e0c61e0684 3375 template <typename T, typename U>
ganlikun 0:20e0c61e0684 3376 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3377 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 3378 void attach(volatile U *obj, R (*func)(volatile T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 3379 this->~Callback();
ganlikun 0:20e0c61e0684 3380 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 3381 }
ganlikun 0:20e0c61e0684 3382
ganlikun 0:20e0c61e0684 3383 /** Attach a static function with a bound pointer
ganlikun 0:20e0c61e0684 3384 * @param obj Pointer to object to bind to function
ganlikun 0:20e0c61e0684 3385 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3386 * @deprecated
ganlikun 0:20e0c61e0684 3387 * Arguments to callback have been reordered to attach(func, arg)
ganlikun 0:20e0c61e0684 3388 */
ganlikun 0:20e0c61e0684 3389 template <typename T, typename U>
ganlikun 0:20e0c61e0684 3390 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3391 "Arguments to callback have been reordered to attach(func, arg)")
ganlikun 0:20e0c61e0684 3392 void attach(const volatile U *obj, R (*func)(const volatile T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 3393 this->~Callback();
ganlikun 0:20e0c61e0684 3394 new (this) Callback(func, obj);
ganlikun 0:20e0c61e0684 3395 }
ganlikun 0:20e0c61e0684 3396
ganlikun 0:20e0c61e0684 3397 /** Assign a callback
ganlikun 0:20e0c61e0684 3398 */
ganlikun 0:20e0c61e0684 3399 Callback &operator=(const Callback &that) {
ganlikun 0:20e0c61e0684 3400 if (this != &that) {
ganlikun 0:20e0c61e0684 3401 this->~Callback();
ganlikun 0:20e0c61e0684 3402 new (this) Callback(that);
ganlikun 0:20e0c61e0684 3403 }
ganlikun 0:20e0c61e0684 3404
ganlikun 0:20e0c61e0684 3405 return *this;
ganlikun 0:20e0c61e0684 3406 }
ganlikun 0:20e0c61e0684 3407
ganlikun 0:20e0c61e0684 3408 /** Call the attached function
ganlikun 0:20e0c61e0684 3409 */
ganlikun 0:20e0c61e0684 3410 R call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) const {
ganlikun 0:20e0c61e0684 3411 MBED_ASSERT(_ops);
ganlikun 0:20e0c61e0684 3412 return _ops->call(this, a0, a1, a2, a3, a4);
ganlikun 0:20e0c61e0684 3413 }
ganlikun 0:20e0c61e0684 3414
ganlikun 0:20e0c61e0684 3415 /** Call the attached function
ganlikun 0:20e0c61e0684 3416 */
ganlikun 0:20e0c61e0684 3417 R operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) const {
ganlikun 0:20e0c61e0684 3418 return call(a0, a1, a2, a3, a4);
ganlikun 0:20e0c61e0684 3419 }
ganlikun 0:20e0c61e0684 3420
ganlikun 0:20e0c61e0684 3421 /** Test if function has been attached
ganlikun 0:20e0c61e0684 3422 */
ganlikun 0:20e0c61e0684 3423 operator bool() const {
ganlikun 0:20e0c61e0684 3424 return _ops;
ganlikun 0:20e0c61e0684 3425 }
ganlikun 0:20e0c61e0684 3426
ganlikun 0:20e0c61e0684 3427 /** Test for equality
ganlikun 0:20e0c61e0684 3428 */
ganlikun 0:20e0c61e0684 3429 friend bool operator==(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 3430 return memcmp(&l, &r, sizeof(Callback)) == 0;
ganlikun 0:20e0c61e0684 3431 }
ganlikun 0:20e0c61e0684 3432
ganlikun 0:20e0c61e0684 3433 /** Test for inequality
ganlikun 0:20e0c61e0684 3434 */
ganlikun 0:20e0c61e0684 3435 friend bool operator!=(const Callback &l, const Callback &r) {
ganlikun 0:20e0c61e0684 3436 return !(l == r);
ganlikun 0:20e0c61e0684 3437 }
ganlikun 0:20e0c61e0684 3438
ganlikun 0:20e0c61e0684 3439 /** Static thunk for passing as C-style function
ganlikun 0:20e0c61e0684 3440 * @param func Callback to call passed as void pointer
ganlikun 0:20e0c61e0684 3441 * @param a0 An argument to be called with function func
ganlikun 0:20e0c61e0684 3442 * @param a1 An argument to be called with function func
ganlikun 0:20e0c61e0684 3443 * @param a2 An argument to be called with function func
ganlikun 0:20e0c61e0684 3444 * @param a3 An argument to be called with function func
ganlikun 0:20e0c61e0684 3445 * @param a4 An argument to be called with function func
ganlikun 0:20e0c61e0684 3446 * @return the value as determined by func which is of
ganlikun 0:20e0c61e0684 3447 * type and determined by the signiture of func
ganlikun 0:20e0c61e0684 3448 */
ganlikun 0:20e0c61e0684 3449 static R thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
ganlikun 0:20e0c61e0684 3450 return static_cast<Callback*>(func)->call(a0, a1, a2, a3, a4);
ganlikun 0:20e0c61e0684 3451 }
ganlikun 0:20e0c61e0684 3452
ganlikun 0:20e0c61e0684 3453 private:
ganlikun 0:20e0c61e0684 3454 // Stored as pointer to function and pointer to optional object
ganlikun 0:20e0c61e0684 3455 // Function pointer is stored as union of possible function types
ganlikun 0:20e0c61e0684 3456 // to garuntee proper size and alignment
ganlikun 0:20e0c61e0684 3457 struct _class;
ganlikun 0:20e0c61e0684 3458 union {
ganlikun 0:20e0c61e0684 3459 void (*_staticfunc)(A0, A1, A2, A3, A4);
ganlikun 0:20e0c61e0684 3460 void (*_boundfunc)(_class*, A0, A1, A2, A3, A4);
ganlikun 0:20e0c61e0684 3461 void (_class::*_methodfunc)(A0, A1, A2, A3, A4);
ganlikun 0:20e0c61e0684 3462 } _func;
ganlikun 0:20e0c61e0684 3463 void *_obj;
ganlikun 0:20e0c61e0684 3464
ganlikun 0:20e0c61e0684 3465 // Dynamically dispatched operations
ganlikun 0:20e0c61e0684 3466 const struct ops {
ganlikun 0:20e0c61e0684 3467 R (*call)(const void*, A0, A1, A2, A3, A4);
ganlikun 0:20e0c61e0684 3468 void (*move)(void*, const void*);
ganlikun 0:20e0c61e0684 3469 void (*dtor)(void*);
ganlikun 0:20e0c61e0684 3470 } *_ops;
ganlikun 0:20e0c61e0684 3471
ganlikun 0:20e0c61e0684 3472 // Generate operations for function object
ganlikun 0:20e0c61e0684 3473 template <typename F>
ganlikun 0:20e0c61e0684 3474 void generate(const F &f) {
ganlikun 0:20e0c61e0684 3475 static const ops ops = {
ganlikun 0:20e0c61e0684 3476 &Callback::function_call<F>,
ganlikun 0:20e0c61e0684 3477 &Callback::function_move<F>,
ganlikun 0:20e0c61e0684 3478 &Callback::function_dtor<F>,
ganlikun 0:20e0c61e0684 3479 };
ganlikun 0:20e0c61e0684 3480
ganlikun 0:20e0c61e0684 3481 MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
ganlikun 0:20e0c61e0684 3482 "Type F must not exceed the size of the Callback class");
ganlikun 0:20e0c61e0684 3483 memset(this, 0, sizeof(Callback));
ganlikun 0:20e0c61e0684 3484 new (this) F(f);
ganlikun 0:20e0c61e0684 3485 _ops = &ops;
ganlikun 0:20e0c61e0684 3486 }
ganlikun 0:20e0c61e0684 3487
ganlikun 0:20e0c61e0684 3488 // Function attributes
ganlikun 0:20e0c61e0684 3489 template <typename F>
ganlikun 0:20e0c61e0684 3490 static R function_call(const void *p, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
ganlikun 0:20e0c61e0684 3491 return (*(F*)p)(a0, a1, a2, a3, a4);
ganlikun 0:20e0c61e0684 3492 }
ganlikun 0:20e0c61e0684 3493
ganlikun 0:20e0c61e0684 3494 template <typename F>
ganlikun 0:20e0c61e0684 3495 static void function_move(void *d, const void *p) {
ganlikun 0:20e0c61e0684 3496 new (d) F(*(F*)p);
ganlikun 0:20e0c61e0684 3497 }
ganlikun 0:20e0c61e0684 3498
ganlikun 0:20e0c61e0684 3499 template <typename F>
ganlikun 0:20e0c61e0684 3500 static void function_dtor(void *p) {
ganlikun 0:20e0c61e0684 3501 ((F*)p)->~F();
ganlikun 0:20e0c61e0684 3502 }
ganlikun 0:20e0c61e0684 3503
ganlikun 0:20e0c61e0684 3504 // Wrappers for functions with context
ganlikun 0:20e0c61e0684 3505 template <typename O, typename M>
ganlikun 0:20e0c61e0684 3506 struct method_context {
ganlikun 0:20e0c61e0684 3507 M method;
ganlikun 0:20e0c61e0684 3508 O *obj;
ganlikun 0:20e0c61e0684 3509
ganlikun 0:20e0c61e0684 3510 method_context(O *obj, M method)
ganlikun 0:20e0c61e0684 3511 : method(method), obj(obj) {}
ganlikun 0:20e0c61e0684 3512
ganlikun 0:20e0c61e0684 3513 R operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) const {
ganlikun 0:20e0c61e0684 3514 return (obj->*method)(a0, a1, a2, a3, a4);
ganlikun 0:20e0c61e0684 3515 }
ganlikun 0:20e0c61e0684 3516 };
ganlikun 0:20e0c61e0684 3517
ganlikun 0:20e0c61e0684 3518 template <typename F, typename A>
ganlikun 0:20e0c61e0684 3519 struct function_context {
ganlikun 0:20e0c61e0684 3520 F func;
ganlikun 0:20e0c61e0684 3521 A *arg;
ganlikun 0:20e0c61e0684 3522
ganlikun 0:20e0c61e0684 3523 function_context(F func, A *arg)
ganlikun 0:20e0c61e0684 3524 : func(func), arg(arg) {}
ganlikun 0:20e0c61e0684 3525
ganlikun 0:20e0c61e0684 3526 R operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) const {
ganlikun 0:20e0c61e0684 3527 return func(arg, a0, a1, a2, a3, a4);
ganlikun 0:20e0c61e0684 3528 }
ganlikun 0:20e0c61e0684 3529 };
ganlikun 0:20e0c61e0684 3530 };
ganlikun 0:20e0c61e0684 3531
ganlikun 0:20e0c61e0684 3532 // Internally used event type
ganlikun 0:20e0c61e0684 3533 typedef Callback<void(int)> event_callback_t;
ganlikun 0:20e0c61e0684 3534
ganlikun 0:20e0c61e0684 3535
ganlikun 0:20e0c61e0684 3536 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3537 *
ganlikun 0:20e0c61e0684 3538 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3539 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3540 */
ganlikun 0:20e0c61e0684 3541 template <typename R>
ganlikun 0:20e0c61e0684 3542 Callback<R()> callback(R (*func)() = 0) {
ganlikun 0:20e0c61e0684 3543 return Callback<R()>(func);
ganlikun 0:20e0c61e0684 3544 }
ganlikun 0:20e0c61e0684 3545
ganlikun 0:20e0c61e0684 3546 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3547 *
ganlikun 0:20e0c61e0684 3548 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3549 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3550 */
ganlikun 0:20e0c61e0684 3551 template <typename R>
ganlikun 0:20e0c61e0684 3552 Callback<R()> callback(const Callback<R()> &func) {
ganlikun 0:20e0c61e0684 3553 return Callback<R()>(func);
ganlikun 0:20e0c61e0684 3554 }
ganlikun 0:20e0c61e0684 3555
ganlikun 0:20e0c61e0684 3556 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3557 *
ganlikun 0:20e0c61e0684 3558 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3559 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3560 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3561 */
ganlikun 0:20e0c61e0684 3562 template<typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3563 Callback<R()> callback(U *obj, R (T::*method)()) {
ganlikun 0:20e0c61e0684 3564 return Callback<R()>(obj, method);
ganlikun 0:20e0c61e0684 3565 }
ganlikun 0:20e0c61e0684 3566
ganlikun 0:20e0c61e0684 3567 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3568 *
ganlikun 0:20e0c61e0684 3569 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3570 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3571 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3572 */
ganlikun 0:20e0c61e0684 3573 template<typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3574 Callback<R()> callback(const U *obj, R (T::*method)() const) {
ganlikun 0:20e0c61e0684 3575 return Callback<R()>(obj, method);
ganlikun 0:20e0c61e0684 3576 }
ganlikun 0:20e0c61e0684 3577
ganlikun 0:20e0c61e0684 3578 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3579 *
ganlikun 0:20e0c61e0684 3580 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3581 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3582 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3583 */
ganlikun 0:20e0c61e0684 3584 template<typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3585 Callback<R()> callback(volatile U *obj, R (T::*method)() volatile) {
ganlikun 0:20e0c61e0684 3586 return Callback<R()>(obj, method);
ganlikun 0:20e0c61e0684 3587 }
ganlikun 0:20e0c61e0684 3588
ganlikun 0:20e0c61e0684 3589 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3590 *
ganlikun 0:20e0c61e0684 3591 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3592 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3593 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3594 */
ganlikun 0:20e0c61e0684 3595 template<typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3596 Callback<R()> callback(const volatile U *obj, R (T::*method)() const volatile) {
ganlikun 0:20e0c61e0684 3597 return Callback<R()>(obj, method);
ganlikun 0:20e0c61e0684 3598 }
ganlikun 0:20e0c61e0684 3599
ganlikun 0:20e0c61e0684 3600 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3601 *
ganlikun 0:20e0c61e0684 3602 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3603 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3604 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3605 */
ganlikun 0:20e0c61e0684 3606 template <typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3607 Callback<R()> callback(R (*func)(T*), U *arg) {
ganlikun 0:20e0c61e0684 3608 return Callback<R()>(func, arg);
ganlikun 0:20e0c61e0684 3609 }
ganlikun 0:20e0c61e0684 3610
ganlikun 0:20e0c61e0684 3611 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3612 *
ganlikun 0:20e0c61e0684 3613 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3614 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3615 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3616 */
ganlikun 0:20e0c61e0684 3617 template <typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3618 Callback<R()> callback(R (*func)(const T*), const U *arg) {
ganlikun 0:20e0c61e0684 3619 return Callback<R()>(func, arg);
ganlikun 0:20e0c61e0684 3620 }
ganlikun 0:20e0c61e0684 3621
ganlikun 0:20e0c61e0684 3622 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3623 *
ganlikun 0:20e0c61e0684 3624 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3625 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3626 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3627 */
ganlikun 0:20e0c61e0684 3628 template <typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3629 Callback<R()> callback(R (*func)(volatile T*), volatile U *arg) {
ganlikun 0:20e0c61e0684 3630 return Callback<R()>(func, arg);
ganlikun 0:20e0c61e0684 3631 }
ganlikun 0:20e0c61e0684 3632
ganlikun 0:20e0c61e0684 3633 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3634 *
ganlikun 0:20e0c61e0684 3635 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3636 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3637 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3638 */
ganlikun 0:20e0c61e0684 3639 template <typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3640 Callback<R()> callback(R (*func)(const volatile T*), const volatile U *arg) {
ganlikun 0:20e0c61e0684 3641 return Callback<R()>(func, arg);
ganlikun 0:20e0c61e0684 3642 }
ganlikun 0:20e0c61e0684 3643
ganlikun 0:20e0c61e0684 3644 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3645 *
ganlikun 0:20e0c61e0684 3646 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3647 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3648 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3649 * @deprecated
ganlikun 0:20e0c61e0684 3650 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 3651 */
ganlikun 0:20e0c61e0684 3652 template <typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3653 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3654 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 3655 Callback<R()> callback(U *obj, R (*func)(T*)) {
ganlikun 0:20e0c61e0684 3656 return Callback<R()>(func, obj);
ganlikun 0:20e0c61e0684 3657 }
ganlikun 0:20e0c61e0684 3658
ganlikun 0:20e0c61e0684 3659 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3660 *
ganlikun 0:20e0c61e0684 3661 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3662 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3663 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3664 * @deprecated
ganlikun 0:20e0c61e0684 3665 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 3666 */
ganlikun 0:20e0c61e0684 3667 template <typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3668 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3669 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 3670 Callback<R()> callback(const U *obj, R (*func)(const T*)) {
ganlikun 0:20e0c61e0684 3671 return Callback<R()>(func, obj);
ganlikun 0:20e0c61e0684 3672 }
ganlikun 0:20e0c61e0684 3673
ganlikun 0:20e0c61e0684 3674 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3675 *
ganlikun 0:20e0c61e0684 3676 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3677 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3678 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3679 * @deprecated
ganlikun 0:20e0c61e0684 3680 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 3681 */
ganlikun 0:20e0c61e0684 3682 template <typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3683 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3684 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 3685 Callback<R()> callback(volatile U *obj, R (*func)(volatile T*)) {
ganlikun 0:20e0c61e0684 3686 return Callback<R()>(func, obj);
ganlikun 0:20e0c61e0684 3687 }
ganlikun 0:20e0c61e0684 3688
ganlikun 0:20e0c61e0684 3689 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3690 *
ganlikun 0:20e0c61e0684 3691 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3692 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3693 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3694 * @deprecated
ganlikun 0:20e0c61e0684 3695 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 3696 */
ganlikun 0:20e0c61e0684 3697 template <typename T, typename U, typename R>
ganlikun 0:20e0c61e0684 3698 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3699 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 3700 Callback<R()> callback(const volatile U *obj, R (*func)(const volatile T*)) {
ganlikun 0:20e0c61e0684 3701 return Callback<R()>(func, obj);
ganlikun 0:20e0c61e0684 3702 }
ganlikun 0:20e0c61e0684 3703
ganlikun 0:20e0c61e0684 3704
ganlikun 0:20e0c61e0684 3705 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3706 *
ganlikun 0:20e0c61e0684 3707 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3708 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3709 */
ganlikun 0:20e0c61e0684 3710 template <typename R, typename A0>
ganlikun 0:20e0c61e0684 3711 Callback<R(A0)> callback(R (*func)(A0) = 0) {
ganlikun 0:20e0c61e0684 3712 return Callback<R(A0)>(func);
ganlikun 0:20e0c61e0684 3713 }
ganlikun 0:20e0c61e0684 3714
ganlikun 0:20e0c61e0684 3715 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3716 *
ganlikun 0:20e0c61e0684 3717 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3718 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3719 */
ganlikun 0:20e0c61e0684 3720 template <typename R, typename A0>
ganlikun 0:20e0c61e0684 3721 Callback<R(A0)> callback(const Callback<R(A0)> &func) {
ganlikun 0:20e0c61e0684 3722 return Callback<R(A0)>(func);
ganlikun 0:20e0c61e0684 3723 }
ganlikun 0:20e0c61e0684 3724
ganlikun 0:20e0c61e0684 3725 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3726 *
ganlikun 0:20e0c61e0684 3727 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3728 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3729 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3730 */
ganlikun 0:20e0c61e0684 3731 template<typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3732 Callback<R(A0)> callback(U *obj, R (T::*method)(A0)) {
ganlikun 0:20e0c61e0684 3733 return Callback<R(A0)>(obj, method);
ganlikun 0:20e0c61e0684 3734 }
ganlikun 0:20e0c61e0684 3735
ganlikun 0:20e0c61e0684 3736 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3737 *
ganlikun 0:20e0c61e0684 3738 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3739 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3740 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3741 */
ganlikun 0:20e0c61e0684 3742 template<typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3743 Callback<R(A0)> callback(const U *obj, R (T::*method)(A0) const) {
ganlikun 0:20e0c61e0684 3744 return Callback<R(A0)>(obj, method);
ganlikun 0:20e0c61e0684 3745 }
ganlikun 0:20e0c61e0684 3746
ganlikun 0:20e0c61e0684 3747 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3748 *
ganlikun 0:20e0c61e0684 3749 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3750 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3751 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3752 */
ganlikun 0:20e0c61e0684 3753 template<typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3754 Callback<R(A0)> callback(volatile U *obj, R (T::*method)(A0) volatile) {
ganlikun 0:20e0c61e0684 3755 return Callback<R(A0)>(obj, method);
ganlikun 0:20e0c61e0684 3756 }
ganlikun 0:20e0c61e0684 3757
ganlikun 0:20e0c61e0684 3758 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3759 *
ganlikun 0:20e0c61e0684 3760 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3761 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3762 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3763 */
ganlikun 0:20e0c61e0684 3764 template<typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3765 Callback<R(A0)> callback(const volatile U *obj, R (T::*method)(A0) const volatile) {
ganlikun 0:20e0c61e0684 3766 return Callback<R(A0)>(obj, method);
ganlikun 0:20e0c61e0684 3767 }
ganlikun 0:20e0c61e0684 3768
ganlikun 0:20e0c61e0684 3769 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3770 *
ganlikun 0:20e0c61e0684 3771 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3772 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3773 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3774 */
ganlikun 0:20e0c61e0684 3775 template <typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3776 Callback<R(A0)> callback(R (*func)(T*, A0), U *arg) {
ganlikun 0:20e0c61e0684 3777 return Callback<R(A0)>(func, arg);
ganlikun 0:20e0c61e0684 3778 }
ganlikun 0:20e0c61e0684 3779
ganlikun 0:20e0c61e0684 3780 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3781 *
ganlikun 0:20e0c61e0684 3782 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3783 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3784 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3785 */
ganlikun 0:20e0c61e0684 3786 template <typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3787 Callback<R(A0)> callback(R (*func)(const T*, A0), const U *arg) {
ganlikun 0:20e0c61e0684 3788 return Callback<R(A0)>(func, arg);
ganlikun 0:20e0c61e0684 3789 }
ganlikun 0:20e0c61e0684 3790
ganlikun 0:20e0c61e0684 3791 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3792 *
ganlikun 0:20e0c61e0684 3793 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3794 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3795 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3796 */
ganlikun 0:20e0c61e0684 3797 template <typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3798 Callback<R(A0)> callback(R (*func)(volatile T*, A0), volatile U *arg) {
ganlikun 0:20e0c61e0684 3799 return Callback<R(A0)>(func, arg);
ganlikun 0:20e0c61e0684 3800 }
ganlikun 0:20e0c61e0684 3801
ganlikun 0:20e0c61e0684 3802 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3803 *
ganlikun 0:20e0c61e0684 3804 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3805 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3806 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3807 */
ganlikun 0:20e0c61e0684 3808 template <typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3809 Callback<R(A0)> callback(R (*func)(const volatile T*, A0), const volatile U *arg) {
ganlikun 0:20e0c61e0684 3810 return Callback<R(A0)>(func, arg);
ganlikun 0:20e0c61e0684 3811 }
ganlikun 0:20e0c61e0684 3812
ganlikun 0:20e0c61e0684 3813 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3814 *
ganlikun 0:20e0c61e0684 3815 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3816 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3817 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3818 * @deprecated
ganlikun 0:20e0c61e0684 3819 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 3820 */
ganlikun 0:20e0c61e0684 3821 template <typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3822 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3823 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 3824 Callback<R(A0)> callback(U *obj, R (*func)(T*, A0)) {
ganlikun 0:20e0c61e0684 3825 return Callback<R(A0)>(func, obj);
ganlikun 0:20e0c61e0684 3826 }
ganlikun 0:20e0c61e0684 3827
ganlikun 0:20e0c61e0684 3828 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3829 *
ganlikun 0:20e0c61e0684 3830 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3831 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3832 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3833 * @deprecated
ganlikun 0:20e0c61e0684 3834 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 3835 */
ganlikun 0:20e0c61e0684 3836 template <typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3837 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3838 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 3839 Callback<R(A0)> callback(const U *obj, R (*func)(const T*, A0)) {
ganlikun 0:20e0c61e0684 3840 return Callback<R(A0)>(func, obj);
ganlikun 0:20e0c61e0684 3841 }
ganlikun 0:20e0c61e0684 3842
ganlikun 0:20e0c61e0684 3843 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3844 *
ganlikun 0:20e0c61e0684 3845 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3846 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3847 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3848 * @deprecated
ganlikun 0:20e0c61e0684 3849 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 3850 */
ganlikun 0:20e0c61e0684 3851 template <typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3852 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3853 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 3854 Callback<R(A0)> callback(volatile U *obj, R (*func)(volatile T*, A0)) {
ganlikun 0:20e0c61e0684 3855 return Callback<R(A0)>(func, obj);
ganlikun 0:20e0c61e0684 3856 }
ganlikun 0:20e0c61e0684 3857
ganlikun 0:20e0c61e0684 3858 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3859 *
ganlikun 0:20e0c61e0684 3860 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3861 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3862 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3863 * @deprecated
ganlikun 0:20e0c61e0684 3864 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 3865 */
ganlikun 0:20e0c61e0684 3866 template <typename T, typename U, typename R, typename A0>
ganlikun 0:20e0c61e0684 3867 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3868 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 3869 Callback<R(A0)> callback(const volatile U *obj, R (*func)(const volatile T*, A0)) {
ganlikun 0:20e0c61e0684 3870 return Callback<R(A0)>(func, obj);
ganlikun 0:20e0c61e0684 3871 }
ganlikun 0:20e0c61e0684 3872
ganlikun 0:20e0c61e0684 3873
ganlikun 0:20e0c61e0684 3874 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3875 *
ganlikun 0:20e0c61e0684 3876 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3877 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3878 */
ganlikun 0:20e0c61e0684 3879 template <typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3880 Callback<R(A0, A1)> callback(R (*func)(A0, A1) = 0) {
ganlikun 0:20e0c61e0684 3881 return Callback<R(A0, A1)>(func);
ganlikun 0:20e0c61e0684 3882 }
ganlikun 0:20e0c61e0684 3883
ganlikun 0:20e0c61e0684 3884 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3885 *
ganlikun 0:20e0c61e0684 3886 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3887 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3888 */
ganlikun 0:20e0c61e0684 3889 template <typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3890 Callback<R(A0, A1)> callback(const Callback<R(A0, A1)> &func) {
ganlikun 0:20e0c61e0684 3891 return Callback<R(A0, A1)>(func);
ganlikun 0:20e0c61e0684 3892 }
ganlikun 0:20e0c61e0684 3893
ganlikun 0:20e0c61e0684 3894 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3895 *
ganlikun 0:20e0c61e0684 3896 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3897 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3898 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3899 */
ganlikun 0:20e0c61e0684 3900 template<typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3901 Callback<R(A0, A1)> callback(U *obj, R (T::*method)(A0, A1)) {
ganlikun 0:20e0c61e0684 3902 return Callback<R(A0, A1)>(obj, method);
ganlikun 0:20e0c61e0684 3903 }
ganlikun 0:20e0c61e0684 3904
ganlikun 0:20e0c61e0684 3905 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3906 *
ganlikun 0:20e0c61e0684 3907 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3908 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3909 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3910 */
ganlikun 0:20e0c61e0684 3911 template<typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3912 Callback<R(A0, A1)> callback(const U *obj, R (T::*method)(A0, A1) const) {
ganlikun 0:20e0c61e0684 3913 return Callback<R(A0, A1)>(obj, method);
ganlikun 0:20e0c61e0684 3914 }
ganlikun 0:20e0c61e0684 3915
ganlikun 0:20e0c61e0684 3916 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3917 *
ganlikun 0:20e0c61e0684 3918 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3919 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3920 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3921 */
ganlikun 0:20e0c61e0684 3922 template<typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3923 Callback<R(A0, A1)> callback(volatile U *obj, R (T::*method)(A0, A1) volatile) {
ganlikun 0:20e0c61e0684 3924 return Callback<R(A0, A1)>(obj, method);
ganlikun 0:20e0c61e0684 3925 }
ganlikun 0:20e0c61e0684 3926
ganlikun 0:20e0c61e0684 3927 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3928 *
ganlikun 0:20e0c61e0684 3929 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3930 * @param method Member function to attach
ganlikun 0:20e0c61e0684 3931 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3932 */
ganlikun 0:20e0c61e0684 3933 template<typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3934 Callback<R(A0, A1)> callback(const volatile U *obj, R (T::*method)(A0, A1) const volatile) {
ganlikun 0:20e0c61e0684 3935 return Callback<R(A0, A1)>(obj, method);
ganlikun 0:20e0c61e0684 3936 }
ganlikun 0:20e0c61e0684 3937
ganlikun 0:20e0c61e0684 3938 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3939 *
ganlikun 0:20e0c61e0684 3940 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3941 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3942 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3943 */
ganlikun 0:20e0c61e0684 3944 template <typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3945 Callback<R(A0, A1)> callback(R (*func)(T*, A0, A1), U *arg) {
ganlikun 0:20e0c61e0684 3946 return Callback<R(A0, A1)>(func, arg);
ganlikun 0:20e0c61e0684 3947 }
ganlikun 0:20e0c61e0684 3948
ganlikun 0:20e0c61e0684 3949 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3950 *
ganlikun 0:20e0c61e0684 3951 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3952 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3953 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3954 */
ganlikun 0:20e0c61e0684 3955 template <typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3956 Callback<R(A0, A1)> callback(R (*func)(const T*, A0, A1), const U *arg) {
ganlikun 0:20e0c61e0684 3957 return Callback<R(A0, A1)>(func, arg);
ganlikun 0:20e0c61e0684 3958 }
ganlikun 0:20e0c61e0684 3959
ganlikun 0:20e0c61e0684 3960 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3961 *
ganlikun 0:20e0c61e0684 3962 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3963 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3964 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3965 */
ganlikun 0:20e0c61e0684 3966 template <typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3967 Callback<R(A0, A1)> callback(R (*func)(volatile T*, A0, A1), volatile U *arg) {
ganlikun 0:20e0c61e0684 3968 return Callback<R(A0, A1)>(func, arg);
ganlikun 0:20e0c61e0684 3969 }
ganlikun 0:20e0c61e0684 3970
ganlikun 0:20e0c61e0684 3971 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3972 *
ganlikun 0:20e0c61e0684 3973 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3974 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 3975 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3976 */
ganlikun 0:20e0c61e0684 3977 template <typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3978 Callback<R(A0, A1)> callback(R (*func)(const volatile T*, A0, A1), const volatile U *arg) {
ganlikun 0:20e0c61e0684 3979 return Callback<R(A0, A1)>(func, arg);
ganlikun 0:20e0c61e0684 3980 }
ganlikun 0:20e0c61e0684 3981
ganlikun 0:20e0c61e0684 3982 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3983 *
ganlikun 0:20e0c61e0684 3984 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 3985 * @param func Static function to attach
ganlikun 0:20e0c61e0684 3986 * @return Callback with infered type
ganlikun 0:20e0c61e0684 3987 * @deprecated
ganlikun 0:20e0c61e0684 3988 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 3989 */
ganlikun 0:20e0c61e0684 3990 template <typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 3991 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 3992 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 3993 Callback<R(A0, A1)> callback(U *obj, R (*func)(T*, A0, A1)) {
ganlikun 0:20e0c61e0684 3994 return Callback<R(A0, A1)>(func, obj);
ganlikun 0:20e0c61e0684 3995 }
ganlikun 0:20e0c61e0684 3996
ganlikun 0:20e0c61e0684 3997 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 3998 *
ganlikun 0:20e0c61e0684 3999 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4000 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4001 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4002 * @deprecated
ganlikun 0:20e0c61e0684 4003 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4004 */
ganlikun 0:20e0c61e0684 4005 template <typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 4006 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4007 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4008 Callback<R(A0, A1)> callback(const U *obj, R (*func)(const T*, A0, A1)) {
ganlikun 0:20e0c61e0684 4009 return Callback<R(A0, A1)>(func, obj);
ganlikun 0:20e0c61e0684 4010 }
ganlikun 0:20e0c61e0684 4011
ganlikun 0:20e0c61e0684 4012 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4013 *
ganlikun 0:20e0c61e0684 4014 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4015 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4016 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4017 * @deprecated
ganlikun 0:20e0c61e0684 4018 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4019 */
ganlikun 0:20e0c61e0684 4020 template <typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 4021 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4022 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4023 Callback<R(A0, A1)> callback(volatile U *obj, R (*func)(volatile T*, A0, A1)) {
ganlikun 0:20e0c61e0684 4024 return Callback<R(A0, A1)>(func, obj);
ganlikun 0:20e0c61e0684 4025 }
ganlikun 0:20e0c61e0684 4026
ganlikun 0:20e0c61e0684 4027 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4028 *
ganlikun 0:20e0c61e0684 4029 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4030 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4031 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4032 * @deprecated
ganlikun 0:20e0c61e0684 4033 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4034 */
ganlikun 0:20e0c61e0684 4035 template <typename T, typename U, typename R, typename A0, typename A1>
ganlikun 0:20e0c61e0684 4036 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4037 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4038 Callback<R(A0, A1)> callback(const volatile U *obj, R (*func)(const volatile T*, A0, A1)) {
ganlikun 0:20e0c61e0684 4039 return Callback<R(A0, A1)>(func, obj);
ganlikun 0:20e0c61e0684 4040 }
ganlikun 0:20e0c61e0684 4041
ganlikun 0:20e0c61e0684 4042
ganlikun 0:20e0c61e0684 4043 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4044 *
ganlikun 0:20e0c61e0684 4045 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4046 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4047 */
ganlikun 0:20e0c61e0684 4048 template <typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4049 Callback<R(A0, A1, A2)> callback(R (*func)(A0, A1, A2) = 0) {
ganlikun 0:20e0c61e0684 4050 return Callback<R(A0, A1, A2)>(func);
ganlikun 0:20e0c61e0684 4051 }
ganlikun 0:20e0c61e0684 4052
ganlikun 0:20e0c61e0684 4053 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4054 *
ganlikun 0:20e0c61e0684 4055 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4056 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4057 */
ganlikun 0:20e0c61e0684 4058 template <typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4059 Callback<R(A0, A1, A2)> callback(const Callback<R(A0, A1, A2)> &func) {
ganlikun 0:20e0c61e0684 4060 return Callback<R(A0, A1, A2)>(func);
ganlikun 0:20e0c61e0684 4061 }
ganlikun 0:20e0c61e0684 4062
ganlikun 0:20e0c61e0684 4063 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4064 *
ganlikun 0:20e0c61e0684 4065 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4066 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4067 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4068 */
ganlikun 0:20e0c61e0684 4069 template<typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4070 Callback<R(A0, A1, A2)> callback(U *obj, R (T::*method)(A0, A1, A2)) {
ganlikun 0:20e0c61e0684 4071 return Callback<R(A0, A1, A2)>(obj, method);
ganlikun 0:20e0c61e0684 4072 }
ganlikun 0:20e0c61e0684 4073
ganlikun 0:20e0c61e0684 4074 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4075 *
ganlikun 0:20e0c61e0684 4076 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4077 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4078 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4079 */
ganlikun 0:20e0c61e0684 4080 template<typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4081 Callback<R(A0, A1, A2)> callback(const U *obj, R (T::*method)(A0, A1, A2) const) {
ganlikun 0:20e0c61e0684 4082 return Callback<R(A0, A1, A2)>(obj, method);
ganlikun 0:20e0c61e0684 4083 }
ganlikun 0:20e0c61e0684 4084
ganlikun 0:20e0c61e0684 4085 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4086 *
ganlikun 0:20e0c61e0684 4087 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4088 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4089 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4090 */
ganlikun 0:20e0c61e0684 4091 template<typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4092 Callback<R(A0, A1, A2)> callback(volatile U *obj, R (T::*method)(A0, A1, A2) volatile) {
ganlikun 0:20e0c61e0684 4093 return Callback<R(A0, A1, A2)>(obj, method);
ganlikun 0:20e0c61e0684 4094 }
ganlikun 0:20e0c61e0684 4095
ganlikun 0:20e0c61e0684 4096 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4097 *
ganlikun 0:20e0c61e0684 4098 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4099 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4100 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4101 */
ganlikun 0:20e0c61e0684 4102 template<typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4103 Callback<R(A0, A1, A2)> callback(const volatile U *obj, R (T::*method)(A0, A1, A2) const volatile) {
ganlikun 0:20e0c61e0684 4104 return Callback<R(A0, A1, A2)>(obj, method);
ganlikun 0:20e0c61e0684 4105 }
ganlikun 0:20e0c61e0684 4106
ganlikun 0:20e0c61e0684 4107 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4108 *
ganlikun 0:20e0c61e0684 4109 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4110 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4111 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4112 */
ganlikun 0:20e0c61e0684 4113 template <typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4114 Callback<R(A0, A1, A2)> callback(R (*func)(T*, A0, A1, A2), U *arg) {
ganlikun 0:20e0c61e0684 4115 return Callback<R(A0, A1, A2)>(func, arg);
ganlikun 0:20e0c61e0684 4116 }
ganlikun 0:20e0c61e0684 4117
ganlikun 0:20e0c61e0684 4118 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4119 *
ganlikun 0:20e0c61e0684 4120 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4121 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4122 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4123 */
ganlikun 0:20e0c61e0684 4124 template <typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4125 Callback<R(A0, A1, A2)> callback(R (*func)(const T*, A0, A1, A2), const U *arg) {
ganlikun 0:20e0c61e0684 4126 return Callback<R(A0, A1, A2)>(func, arg);
ganlikun 0:20e0c61e0684 4127 }
ganlikun 0:20e0c61e0684 4128
ganlikun 0:20e0c61e0684 4129 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4130 *
ganlikun 0:20e0c61e0684 4131 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4132 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4133 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4134 */
ganlikun 0:20e0c61e0684 4135 template <typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4136 Callback<R(A0, A1, A2)> callback(R (*func)(volatile T*, A0, A1, A2), volatile U *arg) {
ganlikun 0:20e0c61e0684 4137 return Callback<R(A0, A1, A2)>(func, arg);
ganlikun 0:20e0c61e0684 4138 }
ganlikun 0:20e0c61e0684 4139
ganlikun 0:20e0c61e0684 4140 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4141 *
ganlikun 0:20e0c61e0684 4142 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4143 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4144 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4145 */
ganlikun 0:20e0c61e0684 4146 template <typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4147 Callback<R(A0, A1, A2)> callback(R (*func)(const volatile T*, A0, A1, A2), const volatile U *arg) {
ganlikun 0:20e0c61e0684 4148 return Callback<R(A0, A1, A2)>(func, arg);
ganlikun 0:20e0c61e0684 4149 }
ganlikun 0:20e0c61e0684 4150
ganlikun 0:20e0c61e0684 4151 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4152 *
ganlikun 0:20e0c61e0684 4153 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4154 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4155 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4156 * @deprecated
ganlikun 0:20e0c61e0684 4157 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4158 */
ganlikun 0:20e0c61e0684 4159 template <typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4160 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4161 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4162 Callback<R(A0, A1, A2)> callback(U *obj, R (*func)(T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 4163 return Callback<R(A0, A1, A2)>(func, obj);
ganlikun 0:20e0c61e0684 4164 }
ganlikun 0:20e0c61e0684 4165
ganlikun 0:20e0c61e0684 4166 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4167 *
ganlikun 0:20e0c61e0684 4168 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4169 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4170 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4171 * @deprecated
ganlikun 0:20e0c61e0684 4172 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4173 */
ganlikun 0:20e0c61e0684 4174 template <typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4175 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4176 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4177 Callback<R(A0, A1, A2)> callback(const U *obj, R (*func)(const T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 4178 return Callback<R(A0, A1, A2)>(func, obj);
ganlikun 0:20e0c61e0684 4179 }
ganlikun 0:20e0c61e0684 4180
ganlikun 0:20e0c61e0684 4181 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4182 *
ganlikun 0:20e0c61e0684 4183 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4184 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4185 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4186 * @deprecated
ganlikun 0:20e0c61e0684 4187 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4188 */
ganlikun 0:20e0c61e0684 4189 template <typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4190 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4191 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4192 Callback<R(A0, A1, A2)> callback(volatile U *obj, R (*func)(volatile T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 4193 return Callback<R(A0, A1, A2)>(func, obj);
ganlikun 0:20e0c61e0684 4194 }
ganlikun 0:20e0c61e0684 4195
ganlikun 0:20e0c61e0684 4196 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4197 *
ganlikun 0:20e0c61e0684 4198 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4199 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4200 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4201 * @deprecated
ganlikun 0:20e0c61e0684 4202 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4203 */
ganlikun 0:20e0c61e0684 4204 template <typename T, typename U, typename R, typename A0, typename A1, typename A2>
ganlikun 0:20e0c61e0684 4205 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4206 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4207 Callback<R(A0, A1, A2)> callback(const volatile U *obj, R (*func)(const volatile T*, A0, A1, A2)) {
ganlikun 0:20e0c61e0684 4208 return Callback<R(A0, A1, A2)>(func, obj);
ganlikun 0:20e0c61e0684 4209 }
ganlikun 0:20e0c61e0684 4210
ganlikun 0:20e0c61e0684 4211
ganlikun 0:20e0c61e0684 4212 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4213 *
ganlikun 0:20e0c61e0684 4214 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4215 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4216 */
ganlikun 0:20e0c61e0684 4217 template <typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4218 Callback<R(A0, A1, A2, A3)> callback(R (*func)(A0, A1, A2, A3) = 0) {
ganlikun 0:20e0c61e0684 4219 return Callback<R(A0, A1, A2, A3)>(func);
ganlikun 0:20e0c61e0684 4220 }
ganlikun 0:20e0c61e0684 4221
ganlikun 0:20e0c61e0684 4222 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4223 *
ganlikun 0:20e0c61e0684 4224 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4225 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4226 */
ganlikun 0:20e0c61e0684 4227 template <typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4228 Callback<R(A0, A1, A2, A3)> callback(const Callback<R(A0, A1, A2, A3)> &func) {
ganlikun 0:20e0c61e0684 4229 return Callback<R(A0, A1, A2, A3)>(func);
ganlikun 0:20e0c61e0684 4230 }
ganlikun 0:20e0c61e0684 4231
ganlikun 0:20e0c61e0684 4232 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4233 *
ganlikun 0:20e0c61e0684 4234 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4235 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4236 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4237 */
ganlikun 0:20e0c61e0684 4238 template<typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4239 Callback<R(A0, A1, A2, A3)> callback(U *obj, R (T::*method)(A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 4240 return Callback<R(A0, A1, A2, A3)>(obj, method);
ganlikun 0:20e0c61e0684 4241 }
ganlikun 0:20e0c61e0684 4242
ganlikun 0:20e0c61e0684 4243 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4244 *
ganlikun 0:20e0c61e0684 4245 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4246 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4247 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4248 */
ganlikun 0:20e0c61e0684 4249 template<typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4250 Callback<R(A0, A1, A2, A3)> callback(const U *obj, R (T::*method)(A0, A1, A2, A3) const) {
ganlikun 0:20e0c61e0684 4251 return Callback<R(A0, A1, A2, A3)>(obj, method);
ganlikun 0:20e0c61e0684 4252 }
ganlikun 0:20e0c61e0684 4253
ganlikun 0:20e0c61e0684 4254 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4255 *
ganlikun 0:20e0c61e0684 4256 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4257 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4258 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4259 */
ganlikun 0:20e0c61e0684 4260 template<typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4261 Callback<R(A0, A1, A2, A3)> callback(volatile U *obj, R (T::*method)(A0, A1, A2, A3) volatile) {
ganlikun 0:20e0c61e0684 4262 return Callback<R(A0, A1, A2, A3)>(obj, method);
ganlikun 0:20e0c61e0684 4263 }
ganlikun 0:20e0c61e0684 4264
ganlikun 0:20e0c61e0684 4265 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4266 *
ganlikun 0:20e0c61e0684 4267 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4268 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4269 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4270 */
ganlikun 0:20e0c61e0684 4271 template<typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4272 Callback<R(A0, A1, A2, A3)> callback(const volatile U *obj, R (T::*method)(A0, A1, A2, A3) const volatile) {
ganlikun 0:20e0c61e0684 4273 return Callback<R(A0, A1, A2, A3)>(obj, method);
ganlikun 0:20e0c61e0684 4274 }
ganlikun 0:20e0c61e0684 4275
ganlikun 0:20e0c61e0684 4276 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4277 *
ganlikun 0:20e0c61e0684 4278 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4279 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4280 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4281 */
ganlikun 0:20e0c61e0684 4282 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4283 Callback<R(A0, A1, A2, A3)> callback(R (*func)(T*, A0, A1, A2, A3), U *arg) {
ganlikun 0:20e0c61e0684 4284 return Callback<R(A0, A1, A2, A3)>(func, arg);
ganlikun 0:20e0c61e0684 4285 }
ganlikun 0:20e0c61e0684 4286
ganlikun 0:20e0c61e0684 4287 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4288 *
ganlikun 0:20e0c61e0684 4289 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4290 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4291 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4292 */
ganlikun 0:20e0c61e0684 4293 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4294 Callback<R(A0, A1, A2, A3)> callback(R (*func)(const T*, A0, A1, A2, A3), const U *arg) {
ganlikun 0:20e0c61e0684 4295 return Callback<R(A0, A1, A2, A3)>(func, arg);
ganlikun 0:20e0c61e0684 4296 }
ganlikun 0:20e0c61e0684 4297
ganlikun 0:20e0c61e0684 4298 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4299 *
ganlikun 0:20e0c61e0684 4300 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4301 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4302 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4303 */
ganlikun 0:20e0c61e0684 4304 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4305 Callback<R(A0, A1, A2, A3)> callback(R (*func)(volatile T*, A0, A1, A2, A3), volatile U *arg) {
ganlikun 0:20e0c61e0684 4306 return Callback<R(A0, A1, A2, A3)>(func, arg);
ganlikun 0:20e0c61e0684 4307 }
ganlikun 0:20e0c61e0684 4308
ganlikun 0:20e0c61e0684 4309 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4310 *
ganlikun 0:20e0c61e0684 4311 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4312 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4313 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4314 */
ganlikun 0:20e0c61e0684 4315 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4316 Callback<R(A0, A1, A2, A3)> callback(R (*func)(const volatile T*, A0, A1, A2, A3), const volatile U *arg) {
ganlikun 0:20e0c61e0684 4317 return Callback<R(A0, A1, A2, A3)>(func, arg);
ganlikun 0:20e0c61e0684 4318 }
ganlikun 0:20e0c61e0684 4319
ganlikun 0:20e0c61e0684 4320 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4321 *
ganlikun 0:20e0c61e0684 4322 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4323 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4324 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4325 * @deprecated
ganlikun 0:20e0c61e0684 4326 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4327 */
ganlikun 0:20e0c61e0684 4328 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4329 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4330 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4331 Callback<R(A0, A1, A2, A3)> callback(U *obj, R (*func)(T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 4332 return Callback<R(A0, A1, A2, A3)>(func, obj);
ganlikun 0:20e0c61e0684 4333 }
ganlikun 0:20e0c61e0684 4334
ganlikun 0:20e0c61e0684 4335 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4336 *
ganlikun 0:20e0c61e0684 4337 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4338 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4339 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4340 * @deprecated
ganlikun 0:20e0c61e0684 4341 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4342 */
ganlikun 0:20e0c61e0684 4343 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4344 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4345 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4346 Callback<R(A0, A1, A2, A3)> callback(const U *obj, R (*func)(const T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 4347 return Callback<R(A0, A1, A2, A3)>(func, obj);
ganlikun 0:20e0c61e0684 4348 }
ganlikun 0:20e0c61e0684 4349
ganlikun 0:20e0c61e0684 4350 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4351 *
ganlikun 0:20e0c61e0684 4352 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4353 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4354 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4355 * @deprecated
ganlikun 0:20e0c61e0684 4356 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4357 */
ganlikun 0:20e0c61e0684 4358 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4359 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4360 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4361 Callback<R(A0, A1, A2, A3)> callback(volatile U *obj, R (*func)(volatile T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 4362 return Callback<R(A0, A1, A2, A3)>(func, obj);
ganlikun 0:20e0c61e0684 4363 }
ganlikun 0:20e0c61e0684 4364
ganlikun 0:20e0c61e0684 4365 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4366 *
ganlikun 0:20e0c61e0684 4367 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4368 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4369 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4370 * @deprecated
ganlikun 0:20e0c61e0684 4371 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4372 */
ganlikun 0:20e0c61e0684 4373 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3>
ganlikun 0:20e0c61e0684 4374 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4375 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4376 Callback<R(A0, A1, A2, A3)> callback(const volatile U *obj, R (*func)(const volatile T*, A0, A1, A2, A3)) {
ganlikun 0:20e0c61e0684 4377 return Callback<R(A0, A1, A2, A3)>(func, obj);
ganlikun 0:20e0c61e0684 4378 }
ganlikun 0:20e0c61e0684 4379
ganlikun 0:20e0c61e0684 4380
ganlikun 0:20e0c61e0684 4381 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4382 *
ganlikun 0:20e0c61e0684 4383 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4384 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4385 */
ganlikun 0:20e0c61e0684 4386 template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4387 Callback<R(A0, A1, A2, A3, A4)> callback(R (*func)(A0, A1, A2, A3, A4) = 0) {
ganlikun 0:20e0c61e0684 4388 return Callback<R(A0, A1, A2, A3, A4)>(func);
ganlikun 0:20e0c61e0684 4389 }
ganlikun 0:20e0c61e0684 4390
ganlikun 0:20e0c61e0684 4391 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4392 *
ganlikun 0:20e0c61e0684 4393 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4394 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4395 */
ganlikun 0:20e0c61e0684 4396 template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4397 Callback<R(A0, A1, A2, A3, A4)> callback(const Callback<R(A0, A1, A2, A3, A4)> &func) {
ganlikun 0:20e0c61e0684 4398 return Callback<R(A0, A1, A2, A3, A4)>(func);
ganlikun 0:20e0c61e0684 4399 }
ganlikun 0:20e0c61e0684 4400
ganlikun 0:20e0c61e0684 4401 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4402 *
ganlikun 0:20e0c61e0684 4403 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4404 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4405 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4406 */
ganlikun 0:20e0c61e0684 4407 template<typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4408 Callback<R(A0, A1, A2, A3, A4)> callback(U *obj, R (T::*method)(A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 4409 return Callback<R(A0, A1, A2, A3, A4)>(obj, method);
ganlikun 0:20e0c61e0684 4410 }
ganlikun 0:20e0c61e0684 4411
ganlikun 0:20e0c61e0684 4412 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4413 *
ganlikun 0:20e0c61e0684 4414 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4415 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4416 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4417 */
ganlikun 0:20e0c61e0684 4418 template<typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4419 Callback<R(A0, A1, A2, A3, A4)> callback(const U *obj, R (T::*method)(A0, A1, A2, A3, A4) const) {
ganlikun 0:20e0c61e0684 4420 return Callback<R(A0, A1, A2, A3, A4)>(obj, method);
ganlikun 0:20e0c61e0684 4421 }
ganlikun 0:20e0c61e0684 4422
ganlikun 0:20e0c61e0684 4423 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4424 *
ganlikun 0:20e0c61e0684 4425 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4426 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4427 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4428 */
ganlikun 0:20e0c61e0684 4429 template<typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4430 Callback<R(A0, A1, A2, A3, A4)> callback(volatile U *obj, R (T::*method)(A0, A1, A2, A3, A4) volatile) {
ganlikun 0:20e0c61e0684 4431 return Callback<R(A0, A1, A2, A3, A4)>(obj, method);
ganlikun 0:20e0c61e0684 4432 }
ganlikun 0:20e0c61e0684 4433
ganlikun 0:20e0c61e0684 4434 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4435 *
ganlikun 0:20e0c61e0684 4436 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4437 * @param method Member function to attach
ganlikun 0:20e0c61e0684 4438 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4439 */
ganlikun 0:20e0c61e0684 4440 template<typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4441 Callback<R(A0, A1, A2, A3, A4)> callback(const volatile U *obj, R (T::*method)(A0, A1, A2, A3, A4) const volatile) {
ganlikun 0:20e0c61e0684 4442 return Callback<R(A0, A1, A2, A3, A4)>(obj, method);
ganlikun 0:20e0c61e0684 4443 }
ganlikun 0:20e0c61e0684 4444
ganlikun 0:20e0c61e0684 4445 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4446 *
ganlikun 0:20e0c61e0684 4447 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4448 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4449 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4450 */
ganlikun 0:20e0c61e0684 4451 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4452 Callback<R(A0, A1, A2, A3, A4)> callback(R (*func)(T*, A0, A1, A2, A3, A4), U *arg) {
ganlikun 0:20e0c61e0684 4453 return Callback<R(A0, A1, A2, A3, A4)>(func, arg);
ganlikun 0:20e0c61e0684 4454 }
ganlikun 0:20e0c61e0684 4455
ganlikun 0:20e0c61e0684 4456 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4457 *
ganlikun 0:20e0c61e0684 4458 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4459 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4460 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4461 */
ganlikun 0:20e0c61e0684 4462 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4463 Callback<R(A0, A1, A2, A3, A4)> callback(R (*func)(const T*, A0, A1, A2, A3, A4), const U *arg) {
ganlikun 0:20e0c61e0684 4464 return Callback<R(A0, A1, A2, A3, A4)>(func, arg);
ganlikun 0:20e0c61e0684 4465 }
ganlikun 0:20e0c61e0684 4466
ganlikun 0:20e0c61e0684 4467 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4468 *
ganlikun 0:20e0c61e0684 4469 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4470 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4471 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4472 */
ganlikun 0:20e0c61e0684 4473 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4474 Callback<R(A0, A1, A2, A3, A4)> callback(R (*func)(volatile T*, A0, A1, A2, A3, A4), volatile U *arg) {
ganlikun 0:20e0c61e0684 4475 return Callback<R(A0, A1, A2, A3, A4)>(func, arg);
ganlikun 0:20e0c61e0684 4476 }
ganlikun 0:20e0c61e0684 4477
ganlikun 0:20e0c61e0684 4478 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4479 *
ganlikun 0:20e0c61e0684 4480 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4481 * @param arg Pointer argument to function
ganlikun 0:20e0c61e0684 4482 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4483 */
ganlikun 0:20e0c61e0684 4484 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4485 Callback<R(A0, A1, A2, A3, A4)> callback(R (*func)(const volatile T*, A0, A1, A2, A3, A4), const volatile U *arg) {
ganlikun 0:20e0c61e0684 4486 return Callback<R(A0, A1, A2, A3, A4)>(func, arg);
ganlikun 0:20e0c61e0684 4487 }
ganlikun 0:20e0c61e0684 4488
ganlikun 0:20e0c61e0684 4489 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4490 *
ganlikun 0:20e0c61e0684 4491 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4492 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4493 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4494 * @deprecated
ganlikun 0:20e0c61e0684 4495 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4496 */
ganlikun 0:20e0c61e0684 4497 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4498 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4499 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4500 Callback<R(A0, A1, A2, A3, A4)> callback(U *obj, R (*func)(T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 4501 return Callback<R(A0, A1, A2, A3, A4)>(func, obj);
ganlikun 0:20e0c61e0684 4502 }
ganlikun 0:20e0c61e0684 4503
ganlikun 0:20e0c61e0684 4504 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4505 *
ganlikun 0:20e0c61e0684 4506 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4507 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4508 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4509 * @deprecated
ganlikun 0:20e0c61e0684 4510 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4511 */
ganlikun 0:20e0c61e0684 4512 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4513 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4514 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4515 Callback<R(A0, A1, A2, A3, A4)> callback(const U *obj, R (*func)(const T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 4516 return Callback<R(A0, A1, A2, A3, A4)>(func, obj);
ganlikun 0:20e0c61e0684 4517 }
ganlikun 0:20e0c61e0684 4518
ganlikun 0:20e0c61e0684 4519 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4520 *
ganlikun 0:20e0c61e0684 4521 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4522 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4523 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4524 * @deprecated
ganlikun 0:20e0c61e0684 4525 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4526 */
ganlikun 0:20e0c61e0684 4527 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4528 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4529 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4530 Callback<R(A0, A1, A2, A3, A4)> callback(volatile U *obj, R (*func)(volatile T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 4531 return Callback<R(A0, A1, A2, A3, A4)>(func, obj);
ganlikun 0:20e0c61e0684 4532 }
ganlikun 0:20e0c61e0684 4533
ganlikun 0:20e0c61e0684 4534 /** Create a callback class with type infered from the arguments
ganlikun 0:20e0c61e0684 4535 *
ganlikun 0:20e0c61e0684 4536 * @param obj Optional pointer to object to bind to function
ganlikun 0:20e0c61e0684 4537 * @param func Static function to attach
ganlikun 0:20e0c61e0684 4538 * @return Callback with infered type
ganlikun 0:20e0c61e0684 4539 * @deprecated
ganlikun 0:20e0c61e0684 4540 * Arguments to callback have been reordered to callback(func, arg)
ganlikun 0:20e0c61e0684 4541 */
ganlikun 0:20e0c61e0684 4542 template <typename T, typename U, typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
ganlikun 0:20e0c61e0684 4543 MBED_DEPRECATED_SINCE("mbed-os-5.1",
ganlikun 0:20e0c61e0684 4544 "Arguments to callback have been reordered to callback(func, arg)")
ganlikun 0:20e0c61e0684 4545 Callback<R(A0, A1, A2, A3, A4)> callback(const volatile U *obj, R (*func)(const volatile T*, A0, A1, A2, A3, A4)) {
ganlikun 0:20e0c61e0684 4546 return Callback<R(A0, A1, A2, A3, A4)>(func, obj);
ganlikun 0:20e0c61e0684 4547 }
ganlikun 0:20e0c61e0684 4548
ganlikun 0:20e0c61e0684 4549
ganlikun 0:20e0c61e0684 4550 } // namespace mbed
ganlikun 0:20e0c61e0684 4551
ganlikun 0:20e0c61e0684 4552 #endif
ganlikun 0:20e0c61e0684 4553