mbed-os for GR-LYCHEE

Dependents:   mbed-os-example-blinky-gr-lychee GR-Boads_Camera_sample GR-Boards_Audio_Recoder GR-Boads_Camera_DisplayApp ... more

Committer:
dkato
Date:
Fri Feb 02 05:42:23 2018 +0000
Revision:
0:f782d9c66c49
mbed-os for GR-LYCHEE

Who changed what in which revision?

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