t

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Wed Jun 21 17:46:44 2017 +0100
Revision:
168:e84263d55307
Parent:
160:d5399cc887bb
Child:
176:af195413fb11
This updates the lib to the mbed lib v 145

Who changed what in which revision?

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