Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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