PIR grove sensor that sends the sensed data to Thingspeak.com through the wifi module ESP 8266

Dependencies:   mbed

Committer:
skrawool
Date:
Mon Dec 05 16:39:27 2016 +0000
Revision:
0:3954a906acc2
PIR grove sensor that sends the sensed data to thingspeak through the wifi module ESP 8266

Who changed what in which revision?

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