inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

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