Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Thu Jun 29 11:01:39 2017 +0000
Revision:
167:1657b442184c
Opencv 3.1 project on GR-PEACH board, 4 apps

Who changed what in which revision?

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