BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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