BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:47:08 2018 +0000
Revision:
1:9c5af431a1f1
sdf

Who changed what in which revision?

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