Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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