temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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