test

Committer:
elijahsj
Date:
Mon Nov 09 00:02:47 2020 -0500
Revision:
1:8a094db1347f
test

Who changed what in which revision?

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