lol

Dependencies:   MMA8451Q

Fork of Application by Mateusz Kowalik

Committer:
danix
Date:
Sun Jan 21 22:28:30 2018 +0000
Revision:
12:3a30cdffa27c
Parent:
10:41552d038a69
Working acelerometer and mouse

Who changed what in which revision?

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