mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /* mbed Microcontroller Library
<> 149:156823d33999 2 * Copyright (c) 2006-2015 ARM Limited
AnnaBridge 189:f392fc9709a3 3 * SPDX-License-Identifier: Apache-2.0
<> 149:156823d33999 4 *
<> 149:156823d33999 5 * Licensed under the Apache License, Version 2.0 (the "License");
<> 149:156823d33999 6 * you may not use this file except in compliance with the License.
<> 149:156823d33999 7 * You may obtain a copy of the License at
<> 149:156823d33999 8 *
<> 149:156823d33999 9 * http://www.apache.org/licenses/LICENSE-2.0
<> 149:156823d33999 10 *
<> 149:156823d33999 11 * Unless required by applicable law or agreed to in writing, software
<> 149:156823d33999 12 * distributed under the License is distributed on an "AS IS" BASIS,
<> 149:156823d33999 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 149:156823d33999 14 * See the License for the specific language governing permissions and
<> 149:156823d33999 15 * limitations under the License.
<> 149:156823d33999 16 */
<> 149:156823d33999 17 #ifndef MBED_CALLBACK_H
<> 149:156823d33999 18 #define MBED_CALLBACK_H
<> 149:156823d33999 19
<> 149:156823d33999 20 #include <string.h>
<> 149:156823d33999 21 #include <stdint.h>
<> 149:156823d33999 22 #include <new>
<> 149:156823d33999 23 #include "platform/mbed_assert.h"
<> 160:d5399cc887bb 24 #include "platform/mbed_toolchain.h"
<> 149:156823d33999 25
<> 149:156823d33999 26 namespace mbed {
<> 149:156823d33999 27 /** \addtogroup platform */
AnnaBridge 178:79309dc6340a 28 /** @{*/
AnnaBridge 178:79309dc6340a 29 /**
AnnaBridge 178:79309dc6340a 30 * \defgroup platform_Callback Callback class
AnnaBridge 178:79309dc6340a 31 * @{
AnnaBridge 178:79309dc6340a 32 */
<> 149:156823d33999 33
<> 149:156823d33999 34 /** Callback class based on template specialization
<> 149:156823d33999 35 *
AnnaBridge 167:e84263d55307 36 * @note Synchronization level: Not protected
<> 149:156823d33999 37 */
<> 149:156823d33999 38 template <typename F>
<> 149:156823d33999 39 class Callback;
<> 149:156823d33999 40
<> 149:156823d33999 41 // Internal sfinae declarations
<> 149:156823d33999 42 //
<> 149:156823d33999 43 // These are used to eliminate overloads based on type attributes
<> 149:156823d33999 44 // 1. Does a function object have a call operator
<> 149:156823d33999 45 // 2. Does a function object fit in the available storage
<> 149:156823d33999 46 //
<> 149:156823d33999 47 // These eliminations are handled cleanly by the compiler and avoid
<> 149:156823d33999 48 // massive and misleading error messages when confronted with an
<> 149:156823d33999 49 // invalid type (or worse, runtime failures)
<> 149:156823d33999 50 namespace detail {
AnnaBridge 187:0387e8f68319 51 struct nil {};
AnnaBridge 187:0387e8f68319 52
AnnaBridge 187:0387e8f68319 53 template <bool B, typename R = nil>
AnnaBridge 187:0387e8f68319 54 struct enable_if {
AnnaBridge 187:0387e8f68319 55 typedef R type;
AnnaBridge 187:0387e8f68319 56 };
AnnaBridge 187:0387e8f68319 57
AnnaBridge 187:0387e8f68319 58 template <typename R>
AnnaBridge 187:0387e8f68319 59 struct enable_if<false, R> {};
AnnaBridge 187:0387e8f68319 60
AnnaBridge 187:0387e8f68319 61 template <typename M, M>
AnnaBridge 187:0387e8f68319 62 struct is_type {
AnnaBridge 187:0387e8f68319 63 static const bool value = true;
AnnaBridge 187:0387e8f68319 64 };
<> 149:156823d33999 65 }
<> 149:156823d33999 66
AnnaBridge 167:e84263d55307 67 #define MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, M) \
AnnaBridge 167:e84263d55307 68 typename detail::enable_if< \
AnnaBridge 167:e84263d55307 69 detail::is_type<M, &F::operator()>::value && \
AnnaBridge 167:e84263d55307 70 sizeof(F) <= sizeof(uintptr_t) \
AnnaBridge 167:e84263d55307 71 >::type = detail::nil()
AnnaBridge 167:e84263d55307 72
<> 149:156823d33999 73 /** Callback class based on template specialization
<> 149:156823d33999 74 *
AnnaBridge 167:e84263d55307 75 * @note Synchronization level: Not protected
<> 149:156823d33999 76 */
<> 149:156823d33999 77 template <typename R>
<> 149:156823d33999 78 class Callback<R()> {
<> 149:156823d33999 79 public:
<> 149:156823d33999 80 /** Create a Callback with a static function
<> 149:156823d33999 81 * @param func Static function to attach
<> 149:156823d33999 82 */
AnnaBridge 187:0387e8f68319 83 Callback(R(*func)() = 0)
AnnaBridge 187:0387e8f68319 84 {
<> 149:156823d33999 85 if (!func) {
AnnaBridge 175:af195413fb11 86 memset(this, 0, sizeof(Callback));
<> 149:156823d33999 87 } else {
<> 149:156823d33999 88 generate(func);
<> 149:156823d33999 89 }
<> 149:156823d33999 90 }
<> 149:156823d33999 91
<> 149:156823d33999 92 /** Attach a Callback
<> 149:156823d33999 93 * @param func The Callback to attach
<> 149:156823d33999 94 */
AnnaBridge 187:0387e8f68319 95 Callback(const Callback<R()> &func)
AnnaBridge 187:0387e8f68319 96 {
<> 149:156823d33999 97 if (func._ops) {
<> 149:156823d33999 98 func._ops->move(this, &func);
<> 149:156823d33999 99 }
<> 149:156823d33999 100 _ops = func._ops;
<> 149:156823d33999 101 }
<> 149:156823d33999 102
<> 149:156823d33999 103 /** Create a Callback with a member function
<> 149:156823d33999 104 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 105 * @param method Member function to attach
<> 149:156823d33999 106 */
<> 151:5eaa88a5bcc7 107 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 108 Callback(U *obj, R(T::*method)())
AnnaBridge 187:0387e8f68319 109 {
AnnaBridge 187:0387e8f68319 110 generate(method_context<T, R(T::*)()>(obj, method));
<> 149:156823d33999 111 }
<> 149:156823d33999 112
<> 149:156823d33999 113 /** Create a Callback with a member function
<> 149:156823d33999 114 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 115 * @param method Member function to attach
<> 149:156823d33999 116 */
<> 151:5eaa88a5bcc7 117 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 118 Callback(const U *obj, R(T::*method)() const)
AnnaBridge 187:0387e8f68319 119 {
AnnaBridge 187:0387e8f68319 120 generate(method_context<const T, R(T::*)() const>(obj, method));
<> 149:156823d33999 121 }
<> 149:156823d33999 122
<> 149:156823d33999 123 /** Create a Callback with a member function
<> 149:156823d33999 124 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 125 * @param method Member function to attach
<> 149:156823d33999 126 */
<> 151:5eaa88a5bcc7 127 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 128 Callback(volatile U *obj, R(T::*method)() volatile)
AnnaBridge 187:0387e8f68319 129 {
AnnaBridge 187:0387e8f68319 130 generate(method_context<volatile T, R(T::*)() volatile>(obj, method));
<> 149:156823d33999 131 }
<> 149:156823d33999 132
<> 149:156823d33999 133 /** Create a Callback with a member function
<> 149:156823d33999 134 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 135 * @param method Member function to attach
<> 149:156823d33999 136 */
<> 151:5eaa88a5bcc7 137 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 138 Callback(const volatile U *obj, R(T::*method)() const volatile)
AnnaBridge 187:0387e8f68319 139 {
AnnaBridge 187:0387e8f68319 140 generate(method_context<const volatile T, R(T::*)() const volatile>(obj, method));
<> 149:156823d33999 141 }
<> 149:156823d33999 142
<> 149:156823d33999 143 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 144 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 145 * @param arg Pointer argument to function
<> 149:156823d33999 146 */
<> 151:5eaa88a5bcc7 147 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 148 Callback(R(*func)(T *), U *arg)
AnnaBridge 187:0387e8f68319 149 {
AnnaBridge 187:0387e8f68319 150 generate(function_context<R(*)(T *), T>(func, arg));
<> 149:156823d33999 151 }
<> 149:156823d33999 152
<> 149:156823d33999 153 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 154 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 155 * @param arg Pointer argument to function
<> 149:156823d33999 156 */
<> 151:5eaa88a5bcc7 157 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 158 Callback(R(*func)(const T *), const U *arg)
AnnaBridge 187:0387e8f68319 159 {
AnnaBridge 187:0387e8f68319 160 generate(function_context<R(*)(const T *), const T>(func, arg));
<> 149:156823d33999 161 }
<> 149:156823d33999 162
<> 149:156823d33999 163 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 164 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 165 * @param arg Pointer argument to function
<> 149:156823d33999 166 */
<> 151:5eaa88a5bcc7 167 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 168 Callback(R(*func)(volatile T *), volatile U *arg)
AnnaBridge 187:0387e8f68319 169 {
AnnaBridge 187:0387e8f68319 170 generate(function_context<R(*)(volatile T *), volatile T>(func, arg));
<> 149:156823d33999 171 }
<> 149:156823d33999 172
<> 149:156823d33999 173 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 174 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 175 * @param arg Pointer argument to function
<> 149:156823d33999 176 */
<> 151:5eaa88a5bcc7 177 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 178 Callback(R(*func)(const volatile T *), const volatile U *arg)
AnnaBridge 187:0387e8f68319 179 {
AnnaBridge 187:0387e8f68319 180 generate(function_context<R(*)(const volatile T *), const volatile T>(func, arg));
<> 149:156823d33999 181 }
<> 149:156823d33999 182
<> 149:156823d33999 183 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 184 * @param f Function object to attach
<> 149:156823d33999 185 * @note The function object is limited to a single word of storage
<> 149:156823d33999 186 */
<> 149:156823d33999 187 template <typename F>
AnnaBridge 187:0387e8f68319 188 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)()))
AnnaBridge 187:0387e8f68319 189 {
<> 149:156823d33999 190 generate(f);
<> 149:156823d33999 191 }
<> 149:156823d33999 192
<> 149:156823d33999 193 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 194 * @param f Function object to attach
<> 149:156823d33999 195 * @note The function object is limited to a single word of storage
<> 149:156823d33999 196 */
<> 149:156823d33999 197 template <typename F>
AnnaBridge 187:0387e8f68319 198 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)() const))
AnnaBridge 187:0387e8f68319 199 {
<> 149:156823d33999 200 generate(f);
<> 149:156823d33999 201 }
<> 149:156823d33999 202
<> 149:156823d33999 203 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 204 * @param f Function object to attach
<> 149:156823d33999 205 * @note The function object is limited to a single word of storage
<> 149:156823d33999 206 */
<> 149:156823d33999 207 template <typename F>
AnnaBridge 187:0387e8f68319 208 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)() volatile))
AnnaBridge 187:0387e8f68319 209 {
<> 149:156823d33999 210 generate(f);
<> 149:156823d33999 211 }
<> 149:156823d33999 212
<> 149:156823d33999 213 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 214 * @param f Function object to attach
<> 149:156823d33999 215 * @note The function object is limited to a single word of storage
<> 149:156823d33999 216 */
<> 149:156823d33999 217 template <typename F>
AnnaBridge 187:0387e8f68319 218 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)() const volatile))
AnnaBridge 187:0387e8f68319 219 {
<> 149:156823d33999 220 generate(f);
<> 149:156823d33999 221 }
<> 149:156823d33999 222
<> 149:156823d33999 223 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 224 * @param obj Pointer to object to bind to function
<> 149:156823d33999 225 * @param func Static function to attach
<> 149:156823d33999 226 * @deprecated
<> 149:156823d33999 227 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 228 */
<> 151:5eaa88a5bcc7 229 template<typename T, typename U>
<> 149:156823d33999 230 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 231 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 232 Callback(U *obj, R(*func)(T *))
AnnaBridge 187:0387e8f68319 233 {
<> 149:156823d33999 234 new (this) Callback(func, obj);
<> 149:156823d33999 235 }
<> 149:156823d33999 236
<> 149:156823d33999 237 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 238 * @param obj Pointer to object to bind to function
<> 149:156823d33999 239 * @param func Static function to attach
<> 149:156823d33999 240 * @deprecated
<> 149:156823d33999 241 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 242 */
<> 151:5eaa88a5bcc7 243 template<typename T, typename U>
<> 149:156823d33999 244 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 245 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 246 Callback(const U *obj, R(*func)(const T *))
AnnaBridge 187:0387e8f68319 247 {
<> 149:156823d33999 248 new (this) Callback(func, obj);
<> 149:156823d33999 249 }
<> 149:156823d33999 250
<> 149:156823d33999 251 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 252 * @param obj Pointer to object to bind to function
<> 149:156823d33999 253 * @param func Static function to attach
<> 149:156823d33999 254 * @deprecated
<> 149:156823d33999 255 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 256 */
<> 151:5eaa88a5bcc7 257 template<typename T, typename U>
<> 149:156823d33999 258 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 259 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 260 Callback(volatile U *obj, R(*func)(volatile T *))
AnnaBridge 187:0387e8f68319 261 {
<> 149:156823d33999 262 new (this) Callback(func, obj);
<> 149:156823d33999 263 }
<> 149:156823d33999 264
<> 149:156823d33999 265 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 266 * @param obj Pointer to object to bind to function
<> 149:156823d33999 267 * @param func Static function to attach
<> 149:156823d33999 268 * @deprecated
<> 149:156823d33999 269 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 270 */
<> 151:5eaa88a5bcc7 271 template<typename T, typename U>
<> 149:156823d33999 272 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 273 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 274 Callback(const volatile U *obj, R(*func)(const volatile T *))
AnnaBridge 187:0387e8f68319 275 {
<> 149:156823d33999 276 new (this) Callback(func, obj);
<> 149:156823d33999 277 }
<> 149:156823d33999 278
<> 149:156823d33999 279 /** Destroy a callback
<> 149:156823d33999 280 */
AnnaBridge 187:0387e8f68319 281 ~Callback()
AnnaBridge 187:0387e8f68319 282 {
<> 149:156823d33999 283 if (_ops) {
<> 149:156823d33999 284 _ops->dtor(this);
<> 149:156823d33999 285 }
<> 149:156823d33999 286 }
<> 149:156823d33999 287
<> 149:156823d33999 288 /** Attach a static function
<> 149:156823d33999 289 * @param func Static function to attach
<> 160:d5399cc887bb 290 * @deprecated
<> 160:d5399cc887bb 291 * Replaced by simple assignment 'Callback cb = func'
<> 160:d5399cc887bb 292 */
<> 160:d5399cc887bb 293 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 294 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 295 void attach(R(*func)())
AnnaBridge 187:0387e8f68319 296 {
<> 149:156823d33999 297 this->~Callback();
<> 149:156823d33999 298 new (this) Callback(func);
<> 149:156823d33999 299 }
<> 149:156823d33999 300
<> 149:156823d33999 301 /** Attach a Callback
<> 149:156823d33999 302 * @param func The Callback to attach
<> 160:d5399cc887bb 303 * @deprecated
<> 160:d5399cc887bb 304 * Replaced by simple assignment 'Callback cb = func'
<> 160:d5399cc887bb 305 */
<> 160:d5399cc887bb 306 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 307 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 308 void attach(const Callback<R()> &func)
AnnaBridge 187:0387e8f68319 309 {
<> 149:156823d33999 310 this->~Callback();
<> 149:156823d33999 311 new (this) Callback(func);
<> 149:156823d33999 312 }
<> 149:156823d33999 313
<> 149:156823d33999 314 /** Attach a member function
<> 149:156823d33999 315 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 316 * @param method Member function to attach
<> 160:d5399cc887bb 317 * @deprecated
<> 160:d5399cc887bb 318 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 319 */
<> 151:5eaa88a5bcc7 320 template<typename T, typename U>
<> 160:d5399cc887bb 321 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 322 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 323 void attach(U *obj, R(T::*method)())
AnnaBridge 187:0387e8f68319 324 {
<> 149:156823d33999 325 this->~Callback();
<> 149:156823d33999 326 new (this) Callback(obj, method);
<> 149:156823d33999 327 }
<> 149:156823d33999 328
<> 149:156823d33999 329 /** Attach a member function
<> 149:156823d33999 330 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 331 * @param method Member function to attach
<> 160:d5399cc887bb 332 * @deprecated
<> 160:d5399cc887bb 333 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 334 */
<> 151:5eaa88a5bcc7 335 template<typename T, typename U>
<> 160:d5399cc887bb 336 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 337 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 338 void attach(const U *obj, R(T::*method)() const)
AnnaBridge 187:0387e8f68319 339 {
<> 149:156823d33999 340 this->~Callback();
<> 149:156823d33999 341 new (this) Callback(obj, method);
<> 149:156823d33999 342 }
<> 149:156823d33999 343
<> 149:156823d33999 344 /** Attach a member function
<> 149:156823d33999 345 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 346 * @param method Member function to attach
<> 160:d5399cc887bb 347 * @deprecated
<> 160:d5399cc887bb 348 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 349 */
<> 151:5eaa88a5bcc7 350 template<typename T, typename U>
<> 160:d5399cc887bb 351 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 352 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 353 void attach(volatile U *obj, R(T::*method)() volatile)
AnnaBridge 187:0387e8f68319 354 {
<> 149:156823d33999 355 this->~Callback();
<> 149:156823d33999 356 new (this) Callback(obj, method);
<> 149:156823d33999 357 }
<> 149:156823d33999 358
<> 149:156823d33999 359 /** Attach a member function
<> 149:156823d33999 360 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 361 * @param method Member function to attach
<> 160:d5399cc887bb 362 * @deprecated
<> 160:d5399cc887bb 363 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 364 */
<> 151:5eaa88a5bcc7 365 template<typename T, typename U>
<> 160:d5399cc887bb 366 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 367 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 368 void attach(const volatile U *obj, R(T::*method)() const volatile)
AnnaBridge 187:0387e8f68319 369 {
<> 149:156823d33999 370 this->~Callback();
<> 149:156823d33999 371 new (this) Callback(obj, method);
<> 149:156823d33999 372 }
<> 149:156823d33999 373
<> 149:156823d33999 374 /** Attach a static function with a bound pointer
<> 149:156823d33999 375 * @param func Static function to attach
<> 149:156823d33999 376 * @param arg Pointer argument to function
<> 160:d5399cc887bb 377 * @deprecated
<> 160:d5399cc887bb 378 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 379 */
<> 151:5eaa88a5bcc7 380 template <typename T, typename U>
<> 160:d5399cc887bb 381 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 382 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 383 void attach(R(*func)(T *), U *arg)
AnnaBridge 187:0387e8f68319 384 {
<> 149:156823d33999 385 this->~Callback();
<> 149:156823d33999 386 new (this) Callback(func, arg);
<> 149:156823d33999 387 }
<> 149:156823d33999 388
<> 149:156823d33999 389 /** Attach a static function with a bound pointer
<> 149:156823d33999 390 * @param func Static function to attach
<> 149:156823d33999 391 * @param arg Pointer argument to function
<> 160:d5399cc887bb 392 * @deprecated
<> 160:d5399cc887bb 393 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 394 */
<> 151:5eaa88a5bcc7 395 template <typename T, typename U>
<> 160:d5399cc887bb 396 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 397 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 398 void attach(R(*func)(const T *), const U *arg)
AnnaBridge 187:0387e8f68319 399 {
<> 149:156823d33999 400 this->~Callback();
<> 149:156823d33999 401 new (this) Callback(func, arg);
<> 149:156823d33999 402 }
<> 149:156823d33999 403
<> 149:156823d33999 404 /** Attach a static function with a bound pointer
<> 149:156823d33999 405 * @param func Static function to attach
<> 149:156823d33999 406 * @param arg Pointer argument to function
<> 160:d5399cc887bb 407 * @deprecated
<> 160:d5399cc887bb 408 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 409 */
<> 151:5eaa88a5bcc7 410 template <typename T, typename U>
<> 160:d5399cc887bb 411 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 412 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 413 void attach(R(*func)(volatile T *), volatile U *arg)
AnnaBridge 187:0387e8f68319 414 {
<> 149:156823d33999 415 this->~Callback();
<> 149:156823d33999 416 new (this) Callback(func, arg);
<> 149:156823d33999 417 }
<> 149:156823d33999 418
<> 149:156823d33999 419 /** Attach a static function with a bound pointer
<> 149:156823d33999 420 * @param func Static function to attach
<> 149:156823d33999 421 * @param arg Pointer argument to function
<> 160:d5399cc887bb 422 * @deprecated
<> 160:d5399cc887bb 423 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 424 */
<> 151:5eaa88a5bcc7 425 template <typename T, typename U>
<> 160:d5399cc887bb 426 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 427 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 428 void attach(R(*func)(const volatile T *), const volatile U *arg)
AnnaBridge 187:0387e8f68319 429 {
<> 149:156823d33999 430 this->~Callback();
<> 149:156823d33999 431 new (this) Callback(func, arg);
<> 149:156823d33999 432 }
<> 149:156823d33999 433
<> 149:156823d33999 434 /** Attach a function object
AnnaBridge 167:e84263d55307 435 * @param f Function object to attach
<> 149:156823d33999 436 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 437 * @deprecated
<> 160:d5399cc887bb 438 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 439 */
<> 149:156823d33999 440 template <typename F>
<> 160:d5399cc887bb 441 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 442 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 443 void attach(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)()))
AnnaBridge 187:0387e8f68319 444 {
<> 149:156823d33999 445 this->~Callback();
<> 149:156823d33999 446 new (this) Callback(f);
<> 149:156823d33999 447 }
<> 149:156823d33999 448
<> 149:156823d33999 449 /** Attach a function object
AnnaBridge 167:e84263d55307 450 * @param f Function object to attach
<> 149:156823d33999 451 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 452 * @deprecated
<> 160:d5399cc887bb 453 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 454 */
<> 149:156823d33999 455 template <typename F>
<> 160:d5399cc887bb 456 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 457 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 458 void attach(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)() const))
AnnaBridge 187:0387e8f68319 459 {
<> 149:156823d33999 460 this->~Callback();
<> 149:156823d33999 461 new (this) Callback(f);
<> 149:156823d33999 462 }
<> 149:156823d33999 463
<> 149:156823d33999 464 /** Attach a function object
AnnaBridge 167:e84263d55307 465 * @param f Function object to attach
<> 149:156823d33999 466 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 467 * @deprecated
<> 160:d5399cc887bb 468 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 469 */
<> 149:156823d33999 470 template <typename F>
<> 160:d5399cc887bb 471 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 472 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 473 void attach(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)() volatile))
AnnaBridge 187:0387e8f68319 474 {
<> 149:156823d33999 475 this->~Callback();
<> 149:156823d33999 476 new (this) Callback(f);
<> 149:156823d33999 477 }
<> 149:156823d33999 478
<> 149:156823d33999 479 /** Attach a function object
AnnaBridge 167:e84263d55307 480 * @param f Function object to attach
<> 149:156823d33999 481 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 482 * @deprecated
<> 160:d5399cc887bb 483 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 484 */
<> 149:156823d33999 485 template <typename F>
<> 160:d5399cc887bb 486 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 487 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 488 void attach(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)() const volatile))
AnnaBridge 187:0387e8f68319 489 {
<> 149:156823d33999 490 this->~Callback();
<> 149:156823d33999 491 new (this) Callback(f);
<> 149:156823d33999 492 }
<> 149:156823d33999 493
<> 149:156823d33999 494 /** Attach a static function with a bound pointer
<> 149:156823d33999 495 * @param obj Pointer to object to bind to function
<> 149:156823d33999 496 * @param func Static function to attach
<> 149:156823d33999 497 * @deprecated
<> 149:156823d33999 498 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 499 */
<> 151:5eaa88a5bcc7 500 template <typename T, typename U>
<> 149:156823d33999 501 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 502 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 503 void attach(U *obj, R(*func)(T *))
AnnaBridge 187:0387e8f68319 504 {
<> 149:156823d33999 505 this->~Callback();
<> 149:156823d33999 506 new (this) Callback(func, obj);
<> 149:156823d33999 507 }
<> 149:156823d33999 508
<> 149:156823d33999 509 /** Attach a static function with a bound pointer
<> 149:156823d33999 510 * @param obj Pointer to object to bind to function
<> 149:156823d33999 511 * @param func Static function to attach
<> 149:156823d33999 512 * @deprecated
<> 149:156823d33999 513 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 514 */
<> 151:5eaa88a5bcc7 515 template <typename T, typename U>
<> 149:156823d33999 516 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 517 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 518 void attach(const U *obj, R(*func)(const T *))
AnnaBridge 187:0387e8f68319 519 {
<> 149:156823d33999 520 this->~Callback();
<> 149:156823d33999 521 new (this) Callback(func, obj);
<> 149:156823d33999 522 }
<> 149:156823d33999 523
<> 149:156823d33999 524 /** Attach a static function with a bound pointer
<> 149:156823d33999 525 * @param obj Pointer to object to bind to function
<> 149:156823d33999 526 * @param func Static function to attach
<> 149:156823d33999 527 * @deprecated
<> 149:156823d33999 528 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 529 */
<> 151:5eaa88a5bcc7 530 template <typename T, typename U>
<> 149:156823d33999 531 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 532 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 533 void attach(volatile U *obj, R(*func)(volatile T *))
AnnaBridge 187:0387e8f68319 534 {
<> 149:156823d33999 535 this->~Callback();
<> 149:156823d33999 536 new (this) Callback(func, obj);
<> 149:156823d33999 537 }
<> 149:156823d33999 538
<> 149:156823d33999 539 /** Attach a static function with a bound pointer
<> 149:156823d33999 540 * @param obj Pointer to object to bind to function
<> 149:156823d33999 541 * @param func Static function to attach
<> 149:156823d33999 542 * @deprecated
<> 149:156823d33999 543 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 544 */
<> 151:5eaa88a5bcc7 545 template <typename T, typename U>
<> 149:156823d33999 546 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 547 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 548 void attach(const volatile U *obj, R(*func)(const volatile T *))
AnnaBridge 187:0387e8f68319 549 {
<> 149:156823d33999 550 this->~Callback();
<> 149:156823d33999 551 new (this) Callback(func, obj);
<> 149:156823d33999 552 }
<> 149:156823d33999 553
<> 149:156823d33999 554 /** Assign a callback
<> 149:156823d33999 555 */
AnnaBridge 187:0387e8f68319 556 Callback &operator=(const Callback &that)
AnnaBridge 187:0387e8f68319 557 {
<> 149:156823d33999 558 if (this != &that) {
<> 149:156823d33999 559 this->~Callback();
<> 149:156823d33999 560 new (this) Callback(that);
<> 149:156823d33999 561 }
<> 149:156823d33999 562
<> 149:156823d33999 563 return *this;
<> 149:156823d33999 564 }
<> 149:156823d33999 565
<> 149:156823d33999 566 /** Call the attached function
<> 149:156823d33999 567 */
AnnaBridge 187:0387e8f68319 568 R call() const
AnnaBridge 187:0387e8f68319 569 {
<> 149:156823d33999 570 MBED_ASSERT(_ops);
<> 149:156823d33999 571 return _ops->call(this);
<> 149:156823d33999 572 }
<> 149:156823d33999 573
<> 149:156823d33999 574 /** Call the attached function
<> 149:156823d33999 575 */
AnnaBridge 187:0387e8f68319 576 R operator()() const
AnnaBridge 187:0387e8f68319 577 {
<> 149:156823d33999 578 return call();
<> 149:156823d33999 579 }
<> 149:156823d33999 580
<> 149:156823d33999 581 /** Test if function has been attached
<> 149:156823d33999 582 */
AnnaBridge 187:0387e8f68319 583 operator bool() const
AnnaBridge 187:0387e8f68319 584 {
<> 149:156823d33999 585 return _ops;
<> 149:156823d33999 586 }
<> 149:156823d33999 587
<> 149:156823d33999 588 /** Test for equality
<> 149:156823d33999 589 */
AnnaBridge 187:0387e8f68319 590 friend bool operator==(const Callback &l, const Callback &r)
AnnaBridge 187:0387e8f68319 591 {
<> 149:156823d33999 592 return memcmp(&l, &r, sizeof(Callback)) == 0;
<> 149:156823d33999 593 }
<> 149:156823d33999 594
<> 149:156823d33999 595 /** Test for inequality
<> 149:156823d33999 596 */
AnnaBridge 187:0387e8f68319 597 friend bool operator!=(const Callback &l, const Callback &r)
AnnaBridge 187:0387e8f68319 598 {
<> 149:156823d33999 599 return !(l == r);
<> 149:156823d33999 600 }
<> 149:156823d33999 601
<> 149:156823d33999 602 /** Static thunk for passing as C-style function
<> 149:156823d33999 603 * @param func Callback to call passed as void pointer
AnnaBridge 187:0387e8f68319 604 * @return the value as determined by func which is of
AnnaBridge 188:bcfe06ba3d64 605 * type and determined by the signature of func
<> 149:156823d33999 606 */
AnnaBridge 187:0387e8f68319 607 static R thunk(void *func)
AnnaBridge 187:0387e8f68319 608 {
AnnaBridge 187:0387e8f68319 609 return static_cast<Callback *>(func)->call();
<> 149:156823d33999 610 }
<> 149:156823d33999 611
<> 149:156823d33999 612 private:
<> 149:156823d33999 613 // Stored as pointer to function and pointer to optional object
<> 149:156823d33999 614 // Function pointer is stored as union of possible function types
AnnaBridge 184:08ed48f1de7f 615 // to guarantee proper size and alignment
<> 149:156823d33999 616 struct _class;
<> 149:156823d33999 617 union {
<> 149:156823d33999 618 void (*_staticfunc)();
AnnaBridge 187:0387e8f68319 619 void (*_boundfunc)(_class *);
<> 149:156823d33999 620 void (_class::*_methodfunc)();
<> 149:156823d33999 621 } _func;
<> 149:156823d33999 622 void *_obj;
<> 149:156823d33999 623
<> 149:156823d33999 624 // Dynamically dispatched operations
<> 149:156823d33999 625 const struct ops {
AnnaBridge 187:0387e8f68319 626 R(*call)(const void *);
AnnaBridge 187:0387e8f68319 627 void (*move)(void *, const void *);
AnnaBridge 187:0387e8f68319 628 void (*dtor)(void *);
<> 149:156823d33999 629 } *_ops;
<> 149:156823d33999 630
<> 149:156823d33999 631 // Generate operations for function object
<> 149:156823d33999 632 template <typename F>
AnnaBridge 187:0387e8f68319 633 void generate(const F &f)
AnnaBridge 187:0387e8f68319 634 {
<> 149:156823d33999 635 static const ops ops = {
<> 149:156823d33999 636 &Callback::function_call<F>,
<> 149:156823d33999 637 &Callback::function_move<F>,
<> 149:156823d33999 638 &Callback::function_dtor<F>,
<> 149:156823d33999 639 };
<> 149:156823d33999 640
<> 151:5eaa88a5bcc7 641 MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
AnnaBridge 187:0387e8f68319 642 "Type F must not exceed the size of the Callback class");
AnnaBridge 175:af195413fb11 643 memset(this, 0, sizeof(Callback));
<> 149:156823d33999 644 new (this) F(f);
<> 149:156823d33999 645 _ops = &ops;
<> 149:156823d33999 646 }
<> 149:156823d33999 647
<> 149:156823d33999 648 // Function attributes
<> 149:156823d33999 649 template <typename F>
AnnaBridge 187:0387e8f68319 650 static R function_call(const void *p)
AnnaBridge 187:0387e8f68319 651 {
AnnaBridge 187:0387e8f68319 652 return (*(F *)p)();
<> 149:156823d33999 653 }
<> 149:156823d33999 654
<> 149:156823d33999 655 template <typename F>
AnnaBridge 187:0387e8f68319 656 static void function_move(void *d, const void *p)
AnnaBridge 187:0387e8f68319 657 {
AnnaBridge 187:0387e8f68319 658 new (d) F(*(F *)p);
<> 149:156823d33999 659 }
<> 149:156823d33999 660
<> 149:156823d33999 661 template <typename F>
AnnaBridge 187:0387e8f68319 662 static void function_dtor(void *p)
AnnaBridge 187:0387e8f68319 663 {
AnnaBridge 187:0387e8f68319 664 ((F *)p)->~F();
<> 149:156823d33999 665 }
<> 149:156823d33999 666
<> 149:156823d33999 667 // Wrappers for functions with context
<> 149:156823d33999 668 template <typename O, typename M>
<> 149:156823d33999 669 struct method_context {
<> 149:156823d33999 670 M method;
<> 149:156823d33999 671 O *obj;
<> 149:156823d33999 672
<> 149:156823d33999 673 method_context(O *obj, M method)
<> 149:156823d33999 674 : method(method), obj(obj) {}
<> 149:156823d33999 675
AnnaBridge 187:0387e8f68319 676 R operator()() const
AnnaBridge 187:0387e8f68319 677 {
<> 149:156823d33999 678 return (obj->*method)();
<> 149:156823d33999 679 }
<> 149:156823d33999 680 };
<> 149:156823d33999 681
<> 149:156823d33999 682 template <typename F, typename A>
<> 149:156823d33999 683 struct function_context {
<> 149:156823d33999 684 F func;
<> 149:156823d33999 685 A *arg;
<> 149:156823d33999 686
<> 149:156823d33999 687 function_context(F func, A *arg)
<> 149:156823d33999 688 : func(func), arg(arg) {}
<> 149:156823d33999 689
AnnaBridge 187:0387e8f68319 690 R operator()() const
AnnaBridge 187:0387e8f68319 691 {
<> 149:156823d33999 692 return func(arg);
<> 149:156823d33999 693 }
<> 149:156823d33999 694 };
<> 149:156823d33999 695 };
<> 149:156823d33999 696
<> 149:156823d33999 697 /** Callback class based on template specialization
<> 149:156823d33999 698 *
AnnaBridge 167:e84263d55307 699 * @note Synchronization level: Not protected
<> 149:156823d33999 700 */
<> 149:156823d33999 701 template <typename R, typename A0>
<> 149:156823d33999 702 class Callback<R(A0)> {
<> 149:156823d33999 703 public:
<> 149:156823d33999 704 /** Create a Callback with a static function
<> 149:156823d33999 705 * @param func Static function to attach
<> 149:156823d33999 706 */
AnnaBridge 187:0387e8f68319 707 Callback(R(*func)(A0) = 0)
AnnaBridge 187:0387e8f68319 708 {
<> 149:156823d33999 709 if (!func) {
AnnaBridge 175:af195413fb11 710 memset(this, 0, sizeof(Callback));
<> 149:156823d33999 711 } else {
<> 149:156823d33999 712 generate(func);
<> 149:156823d33999 713 }
<> 149:156823d33999 714 }
<> 149:156823d33999 715
<> 149:156823d33999 716 /** Attach a Callback
<> 149:156823d33999 717 * @param func The Callback to attach
<> 149:156823d33999 718 */
AnnaBridge 187:0387e8f68319 719 Callback(const Callback<R(A0)> &func)
AnnaBridge 187:0387e8f68319 720 {
<> 149:156823d33999 721 if (func._ops) {
<> 149:156823d33999 722 func._ops->move(this, &func);
<> 149:156823d33999 723 }
<> 149:156823d33999 724 _ops = func._ops;
<> 149:156823d33999 725 }
<> 149:156823d33999 726
<> 149:156823d33999 727 /** Create a Callback with a member function
<> 149:156823d33999 728 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 729 * @param method Member function to attach
<> 149:156823d33999 730 */
<> 151:5eaa88a5bcc7 731 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 732 Callback(U *obj, R(T::*method)(A0))
AnnaBridge 187:0387e8f68319 733 {
AnnaBridge 187:0387e8f68319 734 generate(method_context<T, R(T::*)(A0)>(obj, method));
<> 149:156823d33999 735 }
<> 149:156823d33999 736
<> 149:156823d33999 737 /** Create a Callback with a member function
<> 149:156823d33999 738 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 739 * @param method Member function to attach
<> 149:156823d33999 740 */
<> 151:5eaa88a5bcc7 741 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 742 Callback(const U *obj, R(T::*method)(A0) const)
AnnaBridge 187:0387e8f68319 743 {
AnnaBridge 187:0387e8f68319 744 generate(method_context<const T, R(T::*)(A0) const>(obj, method));
<> 149:156823d33999 745 }
<> 149:156823d33999 746
<> 149:156823d33999 747 /** Create a Callback with a member function
<> 149:156823d33999 748 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 749 * @param method Member function to attach
<> 149:156823d33999 750 */
<> 151:5eaa88a5bcc7 751 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 752 Callback(volatile U *obj, R(T::*method)(A0) volatile)
AnnaBridge 187:0387e8f68319 753 {
AnnaBridge 187:0387e8f68319 754 generate(method_context<volatile T, R(T::*)(A0) volatile>(obj, method));
<> 149:156823d33999 755 }
<> 149:156823d33999 756
<> 149:156823d33999 757 /** Create a Callback with a member function
<> 149:156823d33999 758 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 759 * @param method Member function to attach
<> 149:156823d33999 760 */
<> 151:5eaa88a5bcc7 761 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 762 Callback(const volatile U *obj, R(T::*method)(A0) const volatile)
AnnaBridge 187:0387e8f68319 763 {
AnnaBridge 187:0387e8f68319 764 generate(method_context<const volatile T, R(T::*)(A0) const volatile>(obj, method));
<> 149:156823d33999 765 }
<> 149:156823d33999 766
<> 149:156823d33999 767 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 768 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 769 * @param arg Pointer argument to function
<> 149:156823d33999 770 */
<> 151:5eaa88a5bcc7 771 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 772 Callback(R(*func)(T *, A0), U *arg)
AnnaBridge 187:0387e8f68319 773 {
AnnaBridge 187:0387e8f68319 774 generate(function_context<R(*)(T *, A0), T>(func, arg));
<> 149:156823d33999 775 }
<> 149:156823d33999 776
<> 149:156823d33999 777 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 778 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 779 * @param arg Pointer argument to function
<> 149:156823d33999 780 */
<> 151:5eaa88a5bcc7 781 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 782 Callback(R(*func)(const T *, A0), const U *arg)
AnnaBridge 187:0387e8f68319 783 {
AnnaBridge 187:0387e8f68319 784 generate(function_context<R(*)(const T *, A0), const T>(func, arg));
<> 149:156823d33999 785 }
<> 149:156823d33999 786
<> 149:156823d33999 787 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 788 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 789 * @param arg Pointer argument to function
<> 149:156823d33999 790 */
<> 151:5eaa88a5bcc7 791 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 792 Callback(R(*func)(volatile T *, A0), volatile U *arg)
AnnaBridge 187:0387e8f68319 793 {
AnnaBridge 187:0387e8f68319 794 generate(function_context<R(*)(volatile T *, A0), volatile T>(func, arg));
<> 149:156823d33999 795 }
<> 149:156823d33999 796
<> 149:156823d33999 797 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 798 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 799 * @param arg Pointer argument to function
<> 149:156823d33999 800 */
<> 151:5eaa88a5bcc7 801 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 802 Callback(R(*func)(const volatile T *, A0), const volatile U *arg)
AnnaBridge 187:0387e8f68319 803 {
AnnaBridge 187:0387e8f68319 804 generate(function_context<R(*)(const volatile T *, A0), const volatile T>(func, arg));
<> 149:156823d33999 805 }
<> 149:156823d33999 806
<> 149:156823d33999 807 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 808 * @param f Function object to attach
<> 149:156823d33999 809 * @note The function object is limited to a single word of storage
<> 149:156823d33999 810 */
<> 149:156823d33999 811 template <typename F>
AnnaBridge 187:0387e8f68319 812 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0)))
AnnaBridge 187:0387e8f68319 813 {
<> 149:156823d33999 814 generate(f);
<> 149:156823d33999 815 }
<> 149:156823d33999 816
<> 149:156823d33999 817 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 818 * @param f Function object to attach
<> 149:156823d33999 819 * @note The function object is limited to a single word of storage
<> 149:156823d33999 820 */
<> 149:156823d33999 821 template <typename F>
AnnaBridge 187:0387e8f68319 822 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0) const))
AnnaBridge 187:0387e8f68319 823 {
<> 149:156823d33999 824 generate(f);
<> 149:156823d33999 825 }
<> 149:156823d33999 826
<> 149:156823d33999 827 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 828 * @param f Function object to attach
<> 149:156823d33999 829 * @note The function object is limited to a single word of storage
<> 149:156823d33999 830 */
<> 149:156823d33999 831 template <typename F>
AnnaBridge 187:0387e8f68319 832 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0) volatile))
AnnaBridge 187:0387e8f68319 833 {
<> 149:156823d33999 834 generate(f);
<> 149:156823d33999 835 }
<> 149:156823d33999 836
<> 149:156823d33999 837 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 838 * @param f Function object to attach
<> 149:156823d33999 839 * @note The function object is limited to a single word of storage
<> 149:156823d33999 840 */
<> 149:156823d33999 841 template <typename F>
AnnaBridge 187:0387e8f68319 842 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0) const volatile))
AnnaBridge 187:0387e8f68319 843 {
<> 149:156823d33999 844 generate(f);
<> 149:156823d33999 845 }
<> 149:156823d33999 846
<> 149:156823d33999 847 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 848 * @param obj Pointer to object to bind to function
<> 149:156823d33999 849 * @param func Static function to attach
<> 149:156823d33999 850 * @deprecated
<> 149:156823d33999 851 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 852 */
<> 151:5eaa88a5bcc7 853 template<typename T, typename U>
<> 149:156823d33999 854 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 855 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 856 Callback(U *obj, R(*func)(T *, A0))
AnnaBridge 187:0387e8f68319 857 {
<> 149:156823d33999 858 new (this) Callback(func, obj);
<> 149:156823d33999 859 }
<> 149:156823d33999 860
<> 149:156823d33999 861 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 862 * @param obj Pointer to object to bind to function
<> 149:156823d33999 863 * @param func Static function to attach
<> 149:156823d33999 864 * @deprecated
<> 149:156823d33999 865 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 866 */
<> 151:5eaa88a5bcc7 867 template<typename T, typename U>
<> 149:156823d33999 868 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 869 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 870 Callback(const U *obj, R(*func)(const T *, A0))
AnnaBridge 187:0387e8f68319 871 {
<> 149:156823d33999 872 new (this) Callback(func, obj);
<> 149:156823d33999 873 }
<> 149:156823d33999 874
<> 149:156823d33999 875 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 876 * @param obj Pointer to object to bind to function
<> 149:156823d33999 877 * @param func Static function to attach
<> 149:156823d33999 878 * @deprecated
<> 149:156823d33999 879 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 880 */
<> 151:5eaa88a5bcc7 881 template<typename T, typename U>
<> 149:156823d33999 882 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 883 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 884 Callback(volatile U *obj, R(*func)(volatile T *, A0))
AnnaBridge 187:0387e8f68319 885 {
<> 149:156823d33999 886 new (this) Callback(func, obj);
<> 149:156823d33999 887 }
<> 149:156823d33999 888
<> 149:156823d33999 889 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 890 * @param obj Pointer to object to bind to function
<> 149:156823d33999 891 * @param func Static function to attach
<> 149:156823d33999 892 * @deprecated
<> 149:156823d33999 893 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 894 */
<> 151:5eaa88a5bcc7 895 template<typename T, typename U>
<> 149:156823d33999 896 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 897 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 898 Callback(const volatile U *obj, R(*func)(const volatile T *, A0))
AnnaBridge 187:0387e8f68319 899 {
<> 149:156823d33999 900 new (this) Callback(func, obj);
<> 149:156823d33999 901 }
<> 149:156823d33999 902
<> 149:156823d33999 903 /** Destroy a callback
<> 149:156823d33999 904 */
AnnaBridge 187:0387e8f68319 905 ~Callback()
AnnaBridge 187:0387e8f68319 906 {
<> 149:156823d33999 907 if (_ops) {
<> 149:156823d33999 908 _ops->dtor(this);
<> 149:156823d33999 909 }
<> 149:156823d33999 910 }
<> 149:156823d33999 911
<> 149:156823d33999 912 /** Attach a static function
<> 149:156823d33999 913 * @param func Static function to attach
<> 160:d5399cc887bb 914 * @deprecated
<> 160:d5399cc887bb 915 * Replaced by simple assignment 'Callback cb = func'
<> 160:d5399cc887bb 916 */
<> 160:d5399cc887bb 917 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 918 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 919 void attach(R(*func)(A0))
AnnaBridge 187:0387e8f68319 920 {
<> 149:156823d33999 921 this->~Callback();
<> 149:156823d33999 922 new (this) Callback(func);
<> 149:156823d33999 923 }
<> 149:156823d33999 924
<> 149:156823d33999 925 /** Attach a Callback
<> 149:156823d33999 926 * @param func The Callback to attach
<> 160:d5399cc887bb 927 * @deprecated
<> 160:d5399cc887bb 928 * Replaced by simple assignment 'Callback cb = func'
<> 160:d5399cc887bb 929 */
<> 160:d5399cc887bb 930 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 931 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 932 void attach(const Callback<R(A0)> &func)
AnnaBridge 187:0387e8f68319 933 {
<> 149:156823d33999 934 this->~Callback();
<> 149:156823d33999 935 new (this) Callback(func);
<> 149:156823d33999 936 }
<> 149:156823d33999 937
<> 149:156823d33999 938 /** Attach a member function
<> 149:156823d33999 939 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 940 * @param method Member function to attach
<> 160:d5399cc887bb 941 * @deprecated
<> 160:d5399cc887bb 942 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 943 */
<> 151:5eaa88a5bcc7 944 template<typename T, typename U>
<> 160:d5399cc887bb 945 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 946 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 947 void attach(U *obj, R(T::*method)(A0))
AnnaBridge 187:0387e8f68319 948 {
<> 149:156823d33999 949 this->~Callback();
<> 149:156823d33999 950 new (this) Callback(obj, method);
<> 149:156823d33999 951 }
<> 149:156823d33999 952
<> 149:156823d33999 953 /** Attach a member function
<> 149:156823d33999 954 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 955 * @param method Member function to attach
<> 160:d5399cc887bb 956 * @deprecated
<> 160:d5399cc887bb 957 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 958 */
<> 151:5eaa88a5bcc7 959 template<typename T, typename U>
<> 160:d5399cc887bb 960 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 961 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 962 void attach(const U *obj, R(T::*method)(A0) const)
AnnaBridge 187:0387e8f68319 963 {
<> 149:156823d33999 964 this->~Callback();
<> 149:156823d33999 965 new (this) Callback(obj, method);
<> 149:156823d33999 966 }
<> 149:156823d33999 967
<> 149:156823d33999 968 /** Attach a member function
<> 149:156823d33999 969 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 970 * @param method Member function to attach
<> 160:d5399cc887bb 971 * @deprecated
<> 160:d5399cc887bb 972 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 973 */
<> 151:5eaa88a5bcc7 974 template<typename T, typename U>
<> 160:d5399cc887bb 975 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 976 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 977 void attach(volatile U *obj, R(T::*method)(A0) volatile)
AnnaBridge 187:0387e8f68319 978 {
<> 149:156823d33999 979 this->~Callback();
<> 149:156823d33999 980 new (this) Callback(obj, method);
<> 149:156823d33999 981 }
<> 149:156823d33999 982
<> 149:156823d33999 983 /** Attach a member function
<> 149:156823d33999 984 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 985 * @param method Member function to attach
<> 160:d5399cc887bb 986 * @deprecated
<> 160:d5399cc887bb 987 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 988 */
<> 151:5eaa88a5bcc7 989 template<typename T, typename U>
<> 160:d5399cc887bb 990 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 991 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 992 void attach(const volatile U *obj, R(T::*method)(A0) const volatile)
AnnaBridge 187:0387e8f68319 993 {
<> 149:156823d33999 994 this->~Callback();
<> 149:156823d33999 995 new (this) Callback(obj, method);
<> 149:156823d33999 996 }
<> 149:156823d33999 997
<> 149:156823d33999 998 /** Attach a static function with a bound pointer
<> 149:156823d33999 999 * @param func Static function to attach
<> 149:156823d33999 1000 * @param arg Pointer argument to function
<> 160:d5399cc887bb 1001 * @deprecated
<> 160:d5399cc887bb 1002 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1003 */
<> 151:5eaa88a5bcc7 1004 template <typename T, typename U>
<> 160:d5399cc887bb 1005 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1006 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1007 void attach(R(*func)(T *, A0), U *arg)
AnnaBridge 187:0387e8f68319 1008 {
<> 149:156823d33999 1009 this->~Callback();
<> 149:156823d33999 1010 new (this) Callback(func, arg);
<> 149:156823d33999 1011 }
<> 149:156823d33999 1012
<> 149:156823d33999 1013 /** Attach a static function with a bound pointer
<> 149:156823d33999 1014 * @param func Static function to attach
<> 149:156823d33999 1015 * @param arg Pointer argument to function
<> 160:d5399cc887bb 1016 * @deprecated
<> 160:d5399cc887bb 1017 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1018 */
<> 151:5eaa88a5bcc7 1019 template <typename T, typename U>
<> 160:d5399cc887bb 1020 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1021 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1022 void attach(R(*func)(const T *, A0), const U *arg)
AnnaBridge 187:0387e8f68319 1023 {
<> 149:156823d33999 1024 this->~Callback();
<> 149:156823d33999 1025 new (this) Callback(func, arg);
<> 149:156823d33999 1026 }
<> 149:156823d33999 1027
<> 149:156823d33999 1028 /** Attach a static function with a bound pointer
<> 149:156823d33999 1029 * @param func Static function to attach
<> 149:156823d33999 1030 * @param arg Pointer argument to function
<> 160:d5399cc887bb 1031 * @deprecated
<> 160:d5399cc887bb 1032 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1033 */
<> 151:5eaa88a5bcc7 1034 template <typename T, typename U>
<> 160:d5399cc887bb 1035 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1036 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1037 void attach(R(*func)(volatile T *, A0), volatile U *arg)
AnnaBridge 187:0387e8f68319 1038 {
<> 149:156823d33999 1039 this->~Callback();
<> 149:156823d33999 1040 new (this) Callback(func, arg);
<> 149:156823d33999 1041 }
<> 149:156823d33999 1042
<> 149:156823d33999 1043 /** Attach a static function with a bound pointer
<> 149:156823d33999 1044 * @param func Static function to attach
<> 149:156823d33999 1045 * @param arg Pointer argument to function
<> 160:d5399cc887bb 1046 * @deprecated
<> 160:d5399cc887bb 1047 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1048 */
<> 151:5eaa88a5bcc7 1049 template <typename T, typename U>
<> 160:d5399cc887bb 1050 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1051 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1052 void attach(R(*func)(const volatile T *, A0), const volatile U *arg)
AnnaBridge 187:0387e8f68319 1053 {
<> 149:156823d33999 1054 this->~Callback();
<> 149:156823d33999 1055 new (this) Callback(func, arg);
<> 149:156823d33999 1056 }
<> 149:156823d33999 1057
<> 149:156823d33999 1058 /** Attach a function object
AnnaBridge 167:e84263d55307 1059 * @param f Function object to attach
<> 149:156823d33999 1060 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 1061 * @deprecated
<> 160:d5399cc887bb 1062 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1063 */
<> 149:156823d33999 1064 template <typename F>
<> 160:d5399cc887bb 1065 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1066 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1067 void attach(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0)))
AnnaBridge 187:0387e8f68319 1068 {
<> 149:156823d33999 1069 this->~Callback();
<> 149:156823d33999 1070 new (this) Callback(f);
<> 149:156823d33999 1071 }
<> 149:156823d33999 1072
<> 149:156823d33999 1073 /** Attach a function object
AnnaBridge 167:e84263d55307 1074 * @param f Function object to attach
<> 149:156823d33999 1075 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 1076 * @deprecated
<> 160:d5399cc887bb 1077 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1078 */
<> 149:156823d33999 1079 template <typename F>
<> 160:d5399cc887bb 1080 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1081 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1082 void attach(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0) const))
AnnaBridge 187:0387e8f68319 1083 {
<> 149:156823d33999 1084 this->~Callback();
<> 149:156823d33999 1085 new (this) Callback(f);
<> 149:156823d33999 1086 }
<> 149:156823d33999 1087
<> 149:156823d33999 1088 /** Attach a function object
AnnaBridge 167:e84263d55307 1089 * @param f Function object to attach
<> 149:156823d33999 1090 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 1091 * @deprecated
<> 160:d5399cc887bb 1092 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1093 */
<> 149:156823d33999 1094 template <typename F>
<> 160:d5399cc887bb 1095 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1096 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1097 void attach(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0) volatile))
AnnaBridge 187:0387e8f68319 1098 {
<> 149:156823d33999 1099 this->~Callback();
<> 149:156823d33999 1100 new (this) Callback(f);
<> 149:156823d33999 1101 }
<> 149:156823d33999 1102
<> 149:156823d33999 1103 /** Attach a function object
AnnaBridge 167:e84263d55307 1104 * @param f Function object to attach
<> 149:156823d33999 1105 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 1106 * @deprecated
<> 160:d5399cc887bb 1107 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1108 */
<> 149:156823d33999 1109 template <typename F>
<> 160:d5399cc887bb 1110 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1111 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1112 void attach(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0) const volatile))
AnnaBridge 187:0387e8f68319 1113 {
<> 149:156823d33999 1114 this->~Callback();
<> 149:156823d33999 1115 new (this) Callback(f);
<> 149:156823d33999 1116 }
<> 149:156823d33999 1117
<> 149:156823d33999 1118 /** Attach a static function with a bound pointer
<> 149:156823d33999 1119 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1120 * @param func Static function to attach
<> 149:156823d33999 1121 * @deprecated
<> 149:156823d33999 1122 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 1123 */
<> 151:5eaa88a5bcc7 1124 template <typename T, typename U>
<> 149:156823d33999 1125 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1126 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 1127 void attach(U *obj, R(*func)(T *, A0))
AnnaBridge 187:0387e8f68319 1128 {
<> 149:156823d33999 1129 this->~Callback();
<> 149:156823d33999 1130 new (this) Callback(func, obj);
<> 149:156823d33999 1131 }
<> 149:156823d33999 1132
<> 149:156823d33999 1133 /** Attach a static function with a bound pointer
<> 149:156823d33999 1134 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1135 * @param func Static function to attach
<> 149:156823d33999 1136 * @deprecated
<> 149:156823d33999 1137 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 1138 */
<> 151:5eaa88a5bcc7 1139 template <typename T, typename U>
<> 149:156823d33999 1140 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1141 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 1142 void attach(const U *obj, R(*func)(const T *, A0))
AnnaBridge 187:0387e8f68319 1143 {
<> 149:156823d33999 1144 this->~Callback();
<> 149:156823d33999 1145 new (this) Callback(func, obj);
<> 149:156823d33999 1146 }
<> 149:156823d33999 1147
<> 149:156823d33999 1148 /** Attach a static function with a bound pointer
<> 149:156823d33999 1149 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1150 * @param func Static function to attach
<> 149:156823d33999 1151 * @deprecated
<> 149:156823d33999 1152 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 1153 */
<> 151:5eaa88a5bcc7 1154 template <typename T, typename U>
<> 149:156823d33999 1155 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1156 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 1157 void attach(volatile U *obj, R(*func)(volatile T *, A0))
AnnaBridge 187:0387e8f68319 1158 {
<> 149:156823d33999 1159 this->~Callback();
<> 149:156823d33999 1160 new (this) Callback(func, obj);
<> 149:156823d33999 1161 }
<> 149:156823d33999 1162
<> 149:156823d33999 1163 /** Attach a static function with a bound pointer
<> 149:156823d33999 1164 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1165 * @param func Static function to attach
<> 149:156823d33999 1166 * @deprecated
<> 149:156823d33999 1167 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 1168 */
<> 151:5eaa88a5bcc7 1169 template <typename T, typename U>
<> 149:156823d33999 1170 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1171 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 1172 void attach(const volatile U *obj, R(*func)(const volatile T *, A0))
AnnaBridge 187:0387e8f68319 1173 {
<> 149:156823d33999 1174 this->~Callback();
<> 149:156823d33999 1175 new (this) Callback(func, obj);
<> 149:156823d33999 1176 }
<> 149:156823d33999 1177
<> 149:156823d33999 1178 /** Assign a callback
<> 149:156823d33999 1179 */
AnnaBridge 187:0387e8f68319 1180 Callback &operator=(const Callback &that)
AnnaBridge 187:0387e8f68319 1181 {
<> 149:156823d33999 1182 if (this != &that) {
<> 149:156823d33999 1183 this->~Callback();
<> 149:156823d33999 1184 new (this) Callback(that);
<> 149:156823d33999 1185 }
<> 149:156823d33999 1186
<> 149:156823d33999 1187 return *this;
<> 149:156823d33999 1188 }
<> 149:156823d33999 1189
<> 149:156823d33999 1190 /** Call the attached function
<> 149:156823d33999 1191 */
AnnaBridge 187:0387e8f68319 1192 R call(A0 a0) const
AnnaBridge 187:0387e8f68319 1193 {
<> 149:156823d33999 1194 MBED_ASSERT(_ops);
<> 149:156823d33999 1195 return _ops->call(this, a0);
<> 149:156823d33999 1196 }
<> 149:156823d33999 1197
<> 149:156823d33999 1198 /** Call the attached function
<> 149:156823d33999 1199 */
AnnaBridge 187:0387e8f68319 1200 R operator()(A0 a0) const
AnnaBridge 187:0387e8f68319 1201 {
<> 149:156823d33999 1202 return call(a0);
<> 149:156823d33999 1203 }
<> 149:156823d33999 1204
<> 149:156823d33999 1205 /** Test if function has been attached
<> 149:156823d33999 1206 */
AnnaBridge 187:0387e8f68319 1207 operator bool() const
AnnaBridge 187:0387e8f68319 1208 {
<> 149:156823d33999 1209 return _ops;
<> 149:156823d33999 1210 }
<> 149:156823d33999 1211
<> 149:156823d33999 1212 /** Test for equality
<> 149:156823d33999 1213 */
AnnaBridge 187:0387e8f68319 1214 friend bool operator==(const Callback &l, const Callback &r)
AnnaBridge 187:0387e8f68319 1215 {
<> 149:156823d33999 1216 return memcmp(&l, &r, sizeof(Callback)) == 0;
<> 149:156823d33999 1217 }
<> 149:156823d33999 1218
<> 149:156823d33999 1219 /** Test for inequality
<> 149:156823d33999 1220 */
AnnaBridge 187:0387e8f68319 1221 friend bool operator!=(const Callback &l, const Callback &r)
AnnaBridge 187:0387e8f68319 1222 {
<> 149:156823d33999 1223 return !(l == r);
<> 149:156823d33999 1224 }
<> 149:156823d33999 1225
<> 149:156823d33999 1226 /** Static thunk for passing as C-style function
<> 149:156823d33999 1227 * @param func Callback to call passed as void pointer
AnnaBridge 167:e84263d55307 1228 * @param a0 An argument to be called with function func
AnnaBridge 187:0387e8f68319 1229 * @return the value as determined by func which is of
AnnaBridge 188:bcfe06ba3d64 1230 * type and determined by the signature of func
<> 149:156823d33999 1231 */
AnnaBridge 187:0387e8f68319 1232 static R thunk(void *func, A0 a0)
AnnaBridge 187:0387e8f68319 1233 {
AnnaBridge 187:0387e8f68319 1234 return static_cast<Callback *>(func)->call(a0);
<> 149:156823d33999 1235 }
<> 149:156823d33999 1236
<> 149:156823d33999 1237 private:
<> 149:156823d33999 1238 // Stored as pointer to function and pointer to optional object
<> 149:156823d33999 1239 // Function pointer is stored as union of possible function types
AnnaBridge 184:08ed48f1de7f 1240 // to guarantee proper size and alignment
<> 149:156823d33999 1241 struct _class;
<> 149:156823d33999 1242 union {
<> 149:156823d33999 1243 void (*_staticfunc)(A0);
AnnaBridge 187:0387e8f68319 1244 void (*_boundfunc)(_class *, A0);
<> 149:156823d33999 1245 void (_class::*_methodfunc)(A0);
<> 149:156823d33999 1246 } _func;
<> 149:156823d33999 1247 void *_obj;
<> 149:156823d33999 1248
<> 149:156823d33999 1249 // Dynamically dispatched operations
<> 149:156823d33999 1250 const struct ops {
AnnaBridge 187:0387e8f68319 1251 R(*call)(const void *, A0);
AnnaBridge 187:0387e8f68319 1252 void (*move)(void *, const void *);
AnnaBridge 187:0387e8f68319 1253 void (*dtor)(void *);
<> 149:156823d33999 1254 } *_ops;
<> 149:156823d33999 1255
<> 149:156823d33999 1256 // Generate operations for function object
<> 149:156823d33999 1257 template <typename F>
AnnaBridge 187:0387e8f68319 1258 void generate(const F &f)
AnnaBridge 187:0387e8f68319 1259 {
<> 149:156823d33999 1260 static const ops ops = {
<> 149:156823d33999 1261 &Callback::function_call<F>,
<> 149:156823d33999 1262 &Callback::function_move<F>,
<> 149:156823d33999 1263 &Callback::function_dtor<F>,
<> 149:156823d33999 1264 };
<> 149:156823d33999 1265
<> 151:5eaa88a5bcc7 1266 MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
AnnaBridge 187:0387e8f68319 1267 "Type F must not exceed the size of the Callback class");
AnnaBridge 175:af195413fb11 1268 memset(this, 0, sizeof(Callback));
<> 149:156823d33999 1269 new (this) F(f);
<> 149:156823d33999 1270 _ops = &ops;
<> 149:156823d33999 1271 }
<> 149:156823d33999 1272
<> 149:156823d33999 1273 // Function attributes
<> 149:156823d33999 1274 template <typename F>
AnnaBridge 187:0387e8f68319 1275 static R function_call(const void *p, A0 a0)
AnnaBridge 187:0387e8f68319 1276 {
AnnaBridge 187:0387e8f68319 1277 return (*(F *)p)(a0);
<> 149:156823d33999 1278 }
<> 149:156823d33999 1279
<> 149:156823d33999 1280 template <typename F>
AnnaBridge 187:0387e8f68319 1281 static void function_move(void *d, const void *p)
AnnaBridge 187:0387e8f68319 1282 {
AnnaBridge 187:0387e8f68319 1283 new (d) F(*(F *)p);
<> 149:156823d33999 1284 }
<> 149:156823d33999 1285
<> 149:156823d33999 1286 template <typename F>
AnnaBridge 187:0387e8f68319 1287 static void function_dtor(void *p)
AnnaBridge 187:0387e8f68319 1288 {
AnnaBridge 187:0387e8f68319 1289 ((F *)p)->~F();
<> 149:156823d33999 1290 }
<> 149:156823d33999 1291
<> 149:156823d33999 1292 // Wrappers for functions with context
<> 149:156823d33999 1293 template <typename O, typename M>
<> 149:156823d33999 1294 struct method_context {
<> 149:156823d33999 1295 M method;
<> 149:156823d33999 1296 O *obj;
<> 149:156823d33999 1297
<> 149:156823d33999 1298 method_context(O *obj, M method)
<> 149:156823d33999 1299 : method(method), obj(obj) {}
<> 149:156823d33999 1300
AnnaBridge 187:0387e8f68319 1301 R operator()(A0 a0) const
AnnaBridge 187:0387e8f68319 1302 {
<> 149:156823d33999 1303 return (obj->*method)(a0);
<> 149:156823d33999 1304 }
<> 149:156823d33999 1305 };
<> 149:156823d33999 1306
<> 149:156823d33999 1307 template <typename F, typename A>
<> 149:156823d33999 1308 struct function_context {
<> 149:156823d33999 1309 F func;
<> 149:156823d33999 1310 A *arg;
<> 149:156823d33999 1311
<> 149:156823d33999 1312 function_context(F func, A *arg)
<> 149:156823d33999 1313 : func(func), arg(arg) {}
<> 149:156823d33999 1314
AnnaBridge 187:0387e8f68319 1315 R operator()(A0 a0) const
AnnaBridge 187:0387e8f68319 1316 {
<> 149:156823d33999 1317 return func(arg, a0);
<> 149:156823d33999 1318 }
<> 149:156823d33999 1319 };
<> 149:156823d33999 1320 };
<> 149:156823d33999 1321
<> 149:156823d33999 1322 /** Callback class based on template specialization
<> 149:156823d33999 1323 *
AnnaBridge 167:e84263d55307 1324 * @note Synchronization level: Not protected
<> 149:156823d33999 1325 */
<> 149:156823d33999 1326 template <typename R, typename A0, typename A1>
<> 149:156823d33999 1327 class Callback<R(A0, A1)> {
<> 149:156823d33999 1328 public:
<> 149:156823d33999 1329 /** Create a Callback with a static function
<> 149:156823d33999 1330 * @param func Static function to attach
<> 149:156823d33999 1331 */
AnnaBridge 187:0387e8f68319 1332 Callback(R(*func)(A0, A1) = 0)
AnnaBridge 187:0387e8f68319 1333 {
<> 149:156823d33999 1334 if (!func) {
AnnaBridge 175:af195413fb11 1335 memset(this, 0, sizeof(Callback));
<> 149:156823d33999 1336 } else {
<> 149:156823d33999 1337 generate(func);
<> 149:156823d33999 1338 }
<> 149:156823d33999 1339 }
<> 149:156823d33999 1340
<> 149:156823d33999 1341 /** Attach a Callback
<> 149:156823d33999 1342 * @param func The Callback to attach
<> 149:156823d33999 1343 */
AnnaBridge 187:0387e8f68319 1344 Callback(const Callback<R(A0, A1)> &func)
AnnaBridge 187:0387e8f68319 1345 {
<> 149:156823d33999 1346 if (func._ops) {
<> 149:156823d33999 1347 func._ops->move(this, &func);
<> 149:156823d33999 1348 }
<> 149:156823d33999 1349 _ops = func._ops;
<> 149:156823d33999 1350 }
<> 149:156823d33999 1351
<> 149:156823d33999 1352 /** Create a Callback with a member function
<> 149:156823d33999 1353 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 1354 * @param method Member function to attach
<> 149:156823d33999 1355 */
<> 151:5eaa88a5bcc7 1356 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 1357 Callback(U *obj, R(T::*method)(A0, A1))
AnnaBridge 187:0387e8f68319 1358 {
AnnaBridge 187:0387e8f68319 1359 generate(method_context<T, R(T::*)(A0, A1)>(obj, method));
<> 149:156823d33999 1360 }
<> 149:156823d33999 1361
<> 149:156823d33999 1362 /** Create a Callback with a member function
<> 149:156823d33999 1363 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 1364 * @param method Member function to attach
<> 149:156823d33999 1365 */
<> 151:5eaa88a5bcc7 1366 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 1367 Callback(const U *obj, R(T::*method)(A0, A1) const)
AnnaBridge 187:0387e8f68319 1368 {
AnnaBridge 187:0387e8f68319 1369 generate(method_context<const T, R(T::*)(A0, A1) const>(obj, method));
<> 149:156823d33999 1370 }
<> 149:156823d33999 1371
<> 149:156823d33999 1372 /** Create a Callback with a member function
<> 149:156823d33999 1373 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 1374 * @param method Member function to attach
<> 149:156823d33999 1375 */
<> 151:5eaa88a5bcc7 1376 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 1377 Callback(volatile U *obj, R(T::*method)(A0, A1) volatile)
AnnaBridge 187:0387e8f68319 1378 {
AnnaBridge 187:0387e8f68319 1379 generate(method_context<volatile T, R(T::*)(A0, A1) volatile>(obj, method));
<> 149:156823d33999 1380 }
<> 149:156823d33999 1381
<> 149:156823d33999 1382 /** Create a Callback with a member function
<> 149:156823d33999 1383 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 1384 * @param method Member function to attach
<> 149:156823d33999 1385 */
<> 151:5eaa88a5bcc7 1386 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 1387 Callback(const volatile U *obj, R(T::*method)(A0, A1) const volatile)
AnnaBridge 187:0387e8f68319 1388 {
AnnaBridge 187:0387e8f68319 1389 generate(method_context<const volatile T, R(T::*)(A0, A1) const volatile>(obj, method));
<> 149:156823d33999 1390 }
<> 149:156823d33999 1391
<> 149:156823d33999 1392 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 1393 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 1394 * @param arg Pointer argument to function
<> 149:156823d33999 1395 */
<> 151:5eaa88a5bcc7 1396 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 1397 Callback(R(*func)(T *, A0, A1), U *arg)
AnnaBridge 187:0387e8f68319 1398 {
AnnaBridge 187:0387e8f68319 1399 generate(function_context<R(*)(T *, A0, A1), T>(func, arg));
<> 149:156823d33999 1400 }
<> 149:156823d33999 1401
<> 149:156823d33999 1402 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 1403 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 1404 * @param arg Pointer argument to function
<> 149:156823d33999 1405 */
<> 151:5eaa88a5bcc7 1406 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 1407 Callback(R(*func)(const T *, A0, A1), const U *arg)
AnnaBridge 187:0387e8f68319 1408 {
AnnaBridge 187:0387e8f68319 1409 generate(function_context<R(*)(const T *, A0, A1), const T>(func, arg));
<> 149:156823d33999 1410 }
<> 149:156823d33999 1411
<> 149:156823d33999 1412 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 1413 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 1414 * @param arg Pointer argument to function
<> 149:156823d33999 1415 */
<> 151:5eaa88a5bcc7 1416 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 1417 Callback(R(*func)(volatile T *, A0, A1), volatile U *arg)
AnnaBridge 187:0387e8f68319 1418 {
AnnaBridge 187:0387e8f68319 1419 generate(function_context<R(*)(volatile T *, A0, A1), volatile T>(func, arg));
<> 149:156823d33999 1420 }
<> 149:156823d33999 1421
<> 149:156823d33999 1422 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 1423 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 1424 * @param arg Pointer argument to function
<> 149:156823d33999 1425 */
<> 151:5eaa88a5bcc7 1426 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 1427 Callback(R(*func)(const volatile T *, A0, A1), const volatile U *arg)
AnnaBridge 187:0387e8f68319 1428 {
AnnaBridge 187:0387e8f68319 1429 generate(function_context<R(*)(const volatile T *, A0, A1), const volatile T>(func, arg));
<> 149:156823d33999 1430 }
<> 149:156823d33999 1431
<> 149:156823d33999 1432 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 1433 * @param f Function object to attach
<> 149:156823d33999 1434 * @note The function object is limited to a single word of storage
<> 149:156823d33999 1435 */
<> 149:156823d33999 1436 template <typename F>
AnnaBridge 187:0387e8f68319 1437 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1)))
AnnaBridge 187:0387e8f68319 1438 {
<> 149:156823d33999 1439 generate(f);
<> 149:156823d33999 1440 }
<> 149:156823d33999 1441
<> 149:156823d33999 1442 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 1443 * @param f Function object to attach
<> 149:156823d33999 1444 * @note The function object is limited to a single word of storage
<> 149:156823d33999 1445 */
<> 149:156823d33999 1446 template <typename F>
AnnaBridge 187:0387e8f68319 1447 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1) const))
AnnaBridge 187:0387e8f68319 1448 {
<> 149:156823d33999 1449 generate(f);
<> 149:156823d33999 1450 }
<> 149:156823d33999 1451
<> 149:156823d33999 1452 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 1453 * @param f Function object to attach
<> 149:156823d33999 1454 * @note The function object is limited to a single word of storage
<> 149:156823d33999 1455 */
<> 149:156823d33999 1456 template <typename F>
AnnaBridge 187:0387e8f68319 1457 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1) volatile))
AnnaBridge 187:0387e8f68319 1458 {
<> 149:156823d33999 1459 generate(f);
<> 149:156823d33999 1460 }
<> 149:156823d33999 1461
<> 149:156823d33999 1462 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 1463 * @param f Function object to attach
<> 149:156823d33999 1464 * @note The function object is limited to a single word of storage
<> 149:156823d33999 1465 */
<> 149:156823d33999 1466 template <typename F>
AnnaBridge 187:0387e8f68319 1467 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1) const volatile))
AnnaBridge 187:0387e8f68319 1468 {
<> 149:156823d33999 1469 generate(f);
<> 149:156823d33999 1470 }
<> 149:156823d33999 1471
<> 149:156823d33999 1472 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 1473 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1474 * @param func Static function to attach
<> 149:156823d33999 1475 * @deprecated
<> 149:156823d33999 1476 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 1477 */
<> 151:5eaa88a5bcc7 1478 template<typename T, typename U>
<> 149:156823d33999 1479 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1480 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 1481 Callback(U *obj, R(*func)(T *, A0, A1))
AnnaBridge 187:0387e8f68319 1482 {
<> 149:156823d33999 1483 new (this) Callback(func, obj);
<> 149:156823d33999 1484 }
<> 149:156823d33999 1485
<> 149:156823d33999 1486 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 1487 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1488 * @param func Static function to attach
<> 149:156823d33999 1489 * @deprecated
<> 149:156823d33999 1490 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 1491 */
<> 151:5eaa88a5bcc7 1492 template<typename T, typename U>
<> 149:156823d33999 1493 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1494 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 1495 Callback(const U *obj, R(*func)(const T *, A0, A1))
AnnaBridge 187:0387e8f68319 1496 {
<> 149:156823d33999 1497 new (this) Callback(func, obj);
<> 149:156823d33999 1498 }
<> 149:156823d33999 1499
<> 149:156823d33999 1500 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 1501 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1502 * @param func Static function to attach
<> 149:156823d33999 1503 * @deprecated
<> 149:156823d33999 1504 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 1505 */
<> 151:5eaa88a5bcc7 1506 template<typename T, typename U>
<> 149:156823d33999 1507 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1508 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 1509 Callback(volatile U *obj, R(*func)(volatile T *, A0, A1))
AnnaBridge 187:0387e8f68319 1510 {
<> 149:156823d33999 1511 new (this) Callback(func, obj);
<> 149:156823d33999 1512 }
<> 149:156823d33999 1513
<> 149:156823d33999 1514 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 1515 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1516 * @param func Static function to attach
<> 149:156823d33999 1517 * @deprecated
<> 149:156823d33999 1518 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 1519 */
<> 151:5eaa88a5bcc7 1520 template<typename T, typename U>
<> 149:156823d33999 1521 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1522 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 1523 Callback(const volatile U *obj, R(*func)(const volatile T *, A0, A1))
AnnaBridge 187:0387e8f68319 1524 {
<> 149:156823d33999 1525 new (this) Callback(func, obj);
<> 149:156823d33999 1526 }
<> 149:156823d33999 1527
<> 149:156823d33999 1528 /** Destroy a callback
<> 149:156823d33999 1529 */
AnnaBridge 187:0387e8f68319 1530 ~Callback()
AnnaBridge 187:0387e8f68319 1531 {
<> 149:156823d33999 1532 if (_ops) {
<> 149:156823d33999 1533 _ops->dtor(this);
<> 149:156823d33999 1534 }
<> 149:156823d33999 1535 }
<> 149:156823d33999 1536
<> 149:156823d33999 1537 /** Attach a static function
<> 149:156823d33999 1538 * @param func Static function to attach
<> 160:d5399cc887bb 1539 * @deprecated
<> 160:d5399cc887bb 1540 * Replaced by simple assignment 'Callback cb = func'
<> 160:d5399cc887bb 1541 */
<> 160:d5399cc887bb 1542 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1543 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1544 void attach(R(*func)(A0, A1))
AnnaBridge 187:0387e8f68319 1545 {
<> 149:156823d33999 1546 this->~Callback();
<> 149:156823d33999 1547 new (this) Callback(func);
<> 149:156823d33999 1548 }
<> 149:156823d33999 1549
<> 149:156823d33999 1550 /** Attach a Callback
<> 149:156823d33999 1551 * @param func The Callback to attach
<> 160:d5399cc887bb 1552 * @deprecated
<> 160:d5399cc887bb 1553 * Replaced by simple assignment 'Callback cb = func'
<> 160:d5399cc887bb 1554 */
<> 160:d5399cc887bb 1555 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1556 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1557 void attach(const Callback<R(A0, A1)> &func)
AnnaBridge 187:0387e8f68319 1558 {
<> 149:156823d33999 1559 this->~Callback();
<> 149:156823d33999 1560 new (this) Callback(func);
<> 149:156823d33999 1561 }
<> 149:156823d33999 1562
<> 149:156823d33999 1563 /** Attach a member function
<> 149:156823d33999 1564 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 1565 * @param method Member function to attach
<> 160:d5399cc887bb 1566 * @deprecated
<> 160:d5399cc887bb 1567 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1568 */
<> 151:5eaa88a5bcc7 1569 template<typename T, typename U>
<> 160:d5399cc887bb 1570 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1571 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1572 void attach(U *obj, R(T::*method)(A0, A1))
AnnaBridge 187:0387e8f68319 1573 {
<> 149:156823d33999 1574 this->~Callback();
<> 149:156823d33999 1575 new (this) Callback(obj, method);
<> 149:156823d33999 1576 }
<> 149:156823d33999 1577
<> 149:156823d33999 1578 /** Attach a member function
<> 149:156823d33999 1579 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 1580 * @param method Member function to attach
<> 160:d5399cc887bb 1581 * @deprecated
<> 160:d5399cc887bb 1582 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1583 */
<> 151:5eaa88a5bcc7 1584 template<typename T, typename U>
<> 160:d5399cc887bb 1585 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1586 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1587 void attach(const U *obj, R(T::*method)(A0, A1) const)
AnnaBridge 187:0387e8f68319 1588 {
<> 149:156823d33999 1589 this->~Callback();
<> 149:156823d33999 1590 new (this) Callback(obj, method);
<> 149:156823d33999 1591 }
<> 149:156823d33999 1592
<> 149:156823d33999 1593 /** Attach a member function
<> 149:156823d33999 1594 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 1595 * @param method Member function to attach
<> 160:d5399cc887bb 1596 * @deprecated
<> 160:d5399cc887bb 1597 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1598 */
<> 151:5eaa88a5bcc7 1599 template<typename T, typename U>
<> 160:d5399cc887bb 1600 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1601 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1602 void attach(volatile U *obj, R(T::*method)(A0, A1) volatile)
AnnaBridge 187:0387e8f68319 1603 {
<> 149:156823d33999 1604 this->~Callback();
<> 149:156823d33999 1605 new (this) Callback(obj, method);
<> 149:156823d33999 1606 }
<> 149:156823d33999 1607
<> 149:156823d33999 1608 /** Attach a member function
<> 149:156823d33999 1609 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 1610 * @param method Member function to attach
<> 160:d5399cc887bb 1611 * @deprecated
<> 160:d5399cc887bb 1612 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1613 */
<> 151:5eaa88a5bcc7 1614 template<typename T, typename U>
<> 160:d5399cc887bb 1615 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1616 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1617 void attach(const volatile U *obj, R(T::*method)(A0, A1) const volatile)
AnnaBridge 187:0387e8f68319 1618 {
<> 149:156823d33999 1619 this->~Callback();
<> 149:156823d33999 1620 new (this) Callback(obj, method);
<> 149:156823d33999 1621 }
<> 149:156823d33999 1622
<> 149:156823d33999 1623 /** Attach a static function with a bound pointer
<> 149:156823d33999 1624 * @param func Static function to attach
<> 149:156823d33999 1625 * @param arg Pointer argument to function
<> 160:d5399cc887bb 1626 * @deprecated
<> 160:d5399cc887bb 1627 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1628 */
<> 151:5eaa88a5bcc7 1629 template <typename T, typename U>
<> 160:d5399cc887bb 1630 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1631 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1632 void attach(R(*func)(T *, A0, A1), U *arg)
AnnaBridge 187:0387e8f68319 1633 {
<> 149:156823d33999 1634 this->~Callback();
<> 149:156823d33999 1635 new (this) Callback(func, arg);
<> 149:156823d33999 1636 }
<> 149:156823d33999 1637
<> 149:156823d33999 1638 /** Attach a static function with a bound pointer
<> 149:156823d33999 1639 * @param func Static function to attach
<> 149:156823d33999 1640 * @param arg Pointer argument to function
<> 160:d5399cc887bb 1641 * @deprecated
<> 160:d5399cc887bb 1642 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1643 */
<> 151:5eaa88a5bcc7 1644 template <typename T, typename U>
<> 160:d5399cc887bb 1645 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1646 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1647 void attach(R(*func)(const T *, A0, A1), const U *arg)
AnnaBridge 187:0387e8f68319 1648 {
<> 149:156823d33999 1649 this->~Callback();
<> 149:156823d33999 1650 new (this) Callback(func, arg);
<> 149:156823d33999 1651 }
<> 149:156823d33999 1652
<> 149:156823d33999 1653 /** Attach a static function with a bound pointer
<> 149:156823d33999 1654 * @param func Static function to attach
<> 149:156823d33999 1655 * @param arg Pointer argument to function
<> 160:d5399cc887bb 1656 * @deprecated
<> 160:d5399cc887bb 1657 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1658 */
<> 151:5eaa88a5bcc7 1659 template <typename T, typename U>
<> 160:d5399cc887bb 1660 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1661 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1662 void attach(R(*func)(volatile T *, A0, A1), volatile U *arg)
AnnaBridge 187:0387e8f68319 1663 {
<> 149:156823d33999 1664 this->~Callback();
<> 149:156823d33999 1665 new (this) Callback(func, arg);
<> 149:156823d33999 1666 }
<> 149:156823d33999 1667
<> 149:156823d33999 1668 /** Attach a static function with a bound pointer
<> 149:156823d33999 1669 * @param func Static function to attach
<> 149:156823d33999 1670 * @param arg Pointer argument to function
<> 160:d5399cc887bb 1671 * @deprecated
<> 160:d5399cc887bb 1672 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1673 */
<> 151:5eaa88a5bcc7 1674 template <typename T, typename U>
<> 160:d5399cc887bb 1675 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1676 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1677 void attach(R(*func)(const volatile T *, A0, A1), const volatile U *arg)
AnnaBridge 187:0387e8f68319 1678 {
<> 149:156823d33999 1679 this->~Callback();
<> 149:156823d33999 1680 new (this) Callback(func, arg);
<> 149:156823d33999 1681 }
<> 149:156823d33999 1682
<> 149:156823d33999 1683 /** Attach a function object
AnnaBridge 167:e84263d55307 1684 * @param f Function object to attach
<> 149:156823d33999 1685 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 1686 * @deprecated
<> 160:d5399cc887bb 1687 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1688 */
<> 149:156823d33999 1689 template <typename F>
<> 160:d5399cc887bb 1690 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1691 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1692 void attach(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1)))
AnnaBridge 187:0387e8f68319 1693 {
<> 149:156823d33999 1694 this->~Callback();
<> 149:156823d33999 1695 new (this) Callback(f);
<> 149:156823d33999 1696 }
<> 149:156823d33999 1697
<> 149:156823d33999 1698 /** Attach a function object
AnnaBridge 167:e84263d55307 1699 * @param f Function object to attach
<> 149:156823d33999 1700 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 1701 * @deprecated
<> 160:d5399cc887bb 1702 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1703 */
<> 149:156823d33999 1704 template <typename F>
<> 160:d5399cc887bb 1705 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1706 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1707 void attach(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1) const))
AnnaBridge 187:0387e8f68319 1708 {
<> 149:156823d33999 1709 this->~Callback();
<> 149:156823d33999 1710 new (this) Callback(f);
<> 149:156823d33999 1711 }
<> 149:156823d33999 1712
<> 149:156823d33999 1713 /** Attach a function object
AnnaBridge 167:e84263d55307 1714 * @param f Function object to attach
<> 149:156823d33999 1715 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 1716 * @deprecated
<> 160:d5399cc887bb 1717 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1718 */
<> 149:156823d33999 1719 template <typename F>
<> 160:d5399cc887bb 1720 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1721 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1722 void attach(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1) volatile))
AnnaBridge 187:0387e8f68319 1723 {
<> 149:156823d33999 1724 this->~Callback();
<> 149:156823d33999 1725 new (this) Callback(f);
<> 149:156823d33999 1726 }
<> 149:156823d33999 1727
<> 149:156823d33999 1728 /** Attach a function object
AnnaBridge 167:e84263d55307 1729 * @param f Function object to attach
<> 149:156823d33999 1730 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 1731 * @deprecated
<> 160:d5399cc887bb 1732 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 1733 */
<> 149:156823d33999 1734 template <typename F>
<> 160:d5399cc887bb 1735 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 1736 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 1737 void attach(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1) const volatile))
AnnaBridge 187:0387e8f68319 1738 {
<> 149:156823d33999 1739 this->~Callback();
<> 149:156823d33999 1740 new (this) Callback(f);
<> 149:156823d33999 1741 }
<> 149:156823d33999 1742
<> 149:156823d33999 1743 /** Attach a static function with a bound pointer
<> 149:156823d33999 1744 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1745 * @param func Static function to attach
<> 149:156823d33999 1746 * @deprecated
<> 149:156823d33999 1747 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 1748 */
<> 151:5eaa88a5bcc7 1749 template <typename T, typename U>
<> 149:156823d33999 1750 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1751 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 1752 void attach(U *obj, R(*func)(T *, A0, A1))
AnnaBridge 187:0387e8f68319 1753 {
<> 149:156823d33999 1754 this->~Callback();
<> 149:156823d33999 1755 new (this) Callback(func, obj);
<> 149:156823d33999 1756 }
<> 149:156823d33999 1757
<> 149:156823d33999 1758 /** Attach a static function with a bound pointer
<> 149:156823d33999 1759 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1760 * @param func Static function to attach
<> 149:156823d33999 1761 * @deprecated
<> 149:156823d33999 1762 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 1763 */
<> 151:5eaa88a5bcc7 1764 template <typename T, typename U>
<> 149:156823d33999 1765 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1766 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 1767 void attach(const U *obj, R(*func)(const T *, A0, A1))
AnnaBridge 187:0387e8f68319 1768 {
<> 149:156823d33999 1769 this->~Callback();
<> 149:156823d33999 1770 new (this) Callback(func, obj);
<> 149:156823d33999 1771 }
<> 149:156823d33999 1772
<> 149:156823d33999 1773 /** Attach a static function with a bound pointer
<> 149:156823d33999 1774 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1775 * @param func Static function to attach
<> 149:156823d33999 1776 * @deprecated
<> 149:156823d33999 1777 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 1778 */
<> 151:5eaa88a5bcc7 1779 template <typename T, typename U>
<> 149:156823d33999 1780 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1781 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 1782 void attach(volatile U *obj, R(*func)(volatile T *, A0, A1))
AnnaBridge 187:0387e8f68319 1783 {
<> 149:156823d33999 1784 this->~Callback();
<> 149:156823d33999 1785 new (this) Callback(func, obj);
<> 149:156823d33999 1786 }
<> 149:156823d33999 1787
<> 149:156823d33999 1788 /** Attach a static function with a bound pointer
<> 149:156823d33999 1789 * @param obj Pointer to object to bind to function
<> 149:156823d33999 1790 * @param func Static function to attach
<> 149:156823d33999 1791 * @deprecated
<> 149:156823d33999 1792 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 1793 */
<> 151:5eaa88a5bcc7 1794 template <typename T, typename U>
<> 149:156823d33999 1795 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 1796 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 1797 void attach(const volatile U *obj, R(*func)(const volatile T *, A0, A1))
AnnaBridge 187:0387e8f68319 1798 {
<> 149:156823d33999 1799 this->~Callback();
<> 149:156823d33999 1800 new (this) Callback(func, obj);
<> 149:156823d33999 1801 }
<> 149:156823d33999 1802
<> 149:156823d33999 1803 /** Assign a callback
<> 149:156823d33999 1804 */
AnnaBridge 187:0387e8f68319 1805 Callback &operator=(const Callback &that)
AnnaBridge 187:0387e8f68319 1806 {
<> 149:156823d33999 1807 if (this != &that) {
<> 149:156823d33999 1808 this->~Callback();
<> 149:156823d33999 1809 new (this) Callback(that);
<> 149:156823d33999 1810 }
<> 149:156823d33999 1811
<> 149:156823d33999 1812 return *this;
<> 149:156823d33999 1813 }
<> 149:156823d33999 1814
<> 149:156823d33999 1815 /** Call the attached function
<> 149:156823d33999 1816 */
AnnaBridge 187:0387e8f68319 1817 R call(A0 a0, A1 a1) const
AnnaBridge 187:0387e8f68319 1818 {
<> 149:156823d33999 1819 MBED_ASSERT(_ops);
<> 149:156823d33999 1820 return _ops->call(this, a0, a1);
<> 149:156823d33999 1821 }
<> 149:156823d33999 1822
<> 149:156823d33999 1823 /** Call the attached function
<> 149:156823d33999 1824 */
AnnaBridge 187:0387e8f68319 1825 R operator()(A0 a0, A1 a1) const
AnnaBridge 187:0387e8f68319 1826 {
<> 149:156823d33999 1827 return call(a0, a1);
<> 149:156823d33999 1828 }
<> 149:156823d33999 1829
<> 149:156823d33999 1830 /** Test if function has been attached
<> 149:156823d33999 1831 */
AnnaBridge 187:0387e8f68319 1832 operator bool() const
AnnaBridge 187:0387e8f68319 1833 {
<> 149:156823d33999 1834 return _ops;
<> 149:156823d33999 1835 }
<> 149:156823d33999 1836
<> 149:156823d33999 1837 /** Test for equality
<> 149:156823d33999 1838 */
AnnaBridge 187:0387e8f68319 1839 friend bool operator==(const Callback &l, const Callback &r)
AnnaBridge 187:0387e8f68319 1840 {
<> 149:156823d33999 1841 return memcmp(&l, &r, sizeof(Callback)) == 0;
<> 149:156823d33999 1842 }
<> 149:156823d33999 1843
<> 149:156823d33999 1844 /** Test for inequality
<> 149:156823d33999 1845 */
AnnaBridge 187:0387e8f68319 1846 friend bool operator!=(const Callback &l, const Callback &r)
AnnaBridge 187:0387e8f68319 1847 {
<> 149:156823d33999 1848 return !(l == r);
<> 149:156823d33999 1849 }
<> 149:156823d33999 1850
<> 149:156823d33999 1851 /** Static thunk for passing as C-style function
<> 149:156823d33999 1852 * @param func Callback to call passed as void pointer
AnnaBridge 167:e84263d55307 1853 * @param a0 An argument to be called with function func
AnnaBridge 167:e84263d55307 1854 * @param a1 An argument to be called with function func
AnnaBridge 187:0387e8f68319 1855 * @return the value as determined by func which is of
AnnaBridge 188:bcfe06ba3d64 1856 * type and determined by the signature of func
<> 149:156823d33999 1857 */
AnnaBridge 187:0387e8f68319 1858 static R thunk(void *func, A0 a0, A1 a1)
AnnaBridge 187:0387e8f68319 1859 {
AnnaBridge 187:0387e8f68319 1860 return static_cast<Callback *>(func)->call(a0, a1);
<> 149:156823d33999 1861 }
<> 149:156823d33999 1862
<> 149:156823d33999 1863 private:
<> 149:156823d33999 1864 // Stored as pointer to function and pointer to optional object
<> 149:156823d33999 1865 // Function pointer is stored as union of possible function types
AnnaBridge 184:08ed48f1de7f 1866 // to guarantee proper size and alignment
<> 149:156823d33999 1867 struct _class;
<> 149:156823d33999 1868 union {
<> 149:156823d33999 1869 void (*_staticfunc)(A0, A1);
AnnaBridge 187:0387e8f68319 1870 void (*_boundfunc)(_class *, A0, A1);
<> 149:156823d33999 1871 void (_class::*_methodfunc)(A0, A1);
<> 149:156823d33999 1872 } _func;
<> 149:156823d33999 1873 void *_obj;
<> 149:156823d33999 1874
<> 149:156823d33999 1875 // Dynamically dispatched operations
<> 149:156823d33999 1876 const struct ops {
AnnaBridge 187:0387e8f68319 1877 R(*call)(const void *, A0, A1);
AnnaBridge 187:0387e8f68319 1878 void (*move)(void *, const void *);
AnnaBridge 187:0387e8f68319 1879 void (*dtor)(void *);
<> 149:156823d33999 1880 } *_ops;
<> 149:156823d33999 1881
<> 149:156823d33999 1882 // Generate operations for function object
<> 149:156823d33999 1883 template <typename F>
AnnaBridge 187:0387e8f68319 1884 void generate(const F &f)
AnnaBridge 187:0387e8f68319 1885 {
<> 149:156823d33999 1886 static const ops ops = {
<> 149:156823d33999 1887 &Callback::function_call<F>,
<> 149:156823d33999 1888 &Callback::function_move<F>,
<> 149:156823d33999 1889 &Callback::function_dtor<F>,
<> 149:156823d33999 1890 };
<> 149:156823d33999 1891
<> 151:5eaa88a5bcc7 1892 MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
AnnaBridge 187:0387e8f68319 1893 "Type F must not exceed the size of the Callback class");
AnnaBridge 175:af195413fb11 1894 memset(this, 0, sizeof(Callback));
<> 149:156823d33999 1895 new (this) F(f);
<> 149:156823d33999 1896 _ops = &ops;
<> 149:156823d33999 1897 }
<> 149:156823d33999 1898
<> 149:156823d33999 1899 // Function attributes
<> 149:156823d33999 1900 template <typename F>
AnnaBridge 187:0387e8f68319 1901 static R function_call(const void *p, A0 a0, A1 a1)
AnnaBridge 187:0387e8f68319 1902 {
AnnaBridge 187:0387e8f68319 1903 return (*(F *)p)(a0, a1);
<> 149:156823d33999 1904 }
<> 149:156823d33999 1905
<> 149:156823d33999 1906 template <typename F>
AnnaBridge 187:0387e8f68319 1907 static void function_move(void *d, const void *p)
AnnaBridge 187:0387e8f68319 1908 {
AnnaBridge 187:0387e8f68319 1909 new (d) F(*(F *)p);
<> 149:156823d33999 1910 }
<> 149:156823d33999 1911
<> 149:156823d33999 1912 template <typename F>
AnnaBridge 187:0387e8f68319 1913 static void function_dtor(void *p)
AnnaBridge 187:0387e8f68319 1914 {
AnnaBridge 187:0387e8f68319 1915 ((F *)p)->~F();
<> 149:156823d33999 1916 }
<> 149:156823d33999 1917
<> 149:156823d33999 1918 // Wrappers for functions with context
<> 149:156823d33999 1919 template <typename O, typename M>
<> 149:156823d33999 1920 struct method_context {
<> 149:156823d33999 1921 M method;
<> 149:156823d33999 1922 O *obj;
<> 149:156823d33999 1923
<> 149:156823d33999 1924 method_context(O *obj, M method)
<> 149:156823d33999 1925 : method(method), obj(obj) {}
<> 149:156823d33999 1926
AnnaBridge 187:0387e8f68319 1927 R operator()(A0 a0, A1 a1) const
AnnaBridge 187:0387e8f68319 1928 {
<> 149:156823d33999 1929 return (obj->*method)(a0, a1);
<> 149:156823d33999 1930 }
<> 149:156823d33999 1931 };
<> 149:156823d33999 1932
<> 149:156823d33999 1933 template <typename F, typename A>
<> 149:156823d33999 1934 struct function_context {
<> 149:156823d33999 1935 F func;
<> 149:156823d33999 1936 A *arg;
<> 149:156823d33999 1937
<> 149:156823d33999 1938 function_context(F func, A *arg)
<> 149:156823d33999 1939 : func(func), arg(arg) {}
<> 149:156823d33999 1940
AnnaBridge 187:0387e8f68319 1941 R operator()(A0 a0, A1 a1) const
AnnaBridge 187:0387e8f68319 1942 {
<> 149:156823d33999 1943 return func(arg, a0, a1);
<> 149:156823d33999 1944 }
<> 149:156823d33999 1945 };
<> 149:156823d33999 1946 };
<> 149:156823d33999 1947
<> 149:156823d33999 1948 /** Callback class based on template specialization
<> 149:156823d33999 1949 *
AnnaBridge 167:e84263d55307 1950 * @note Synchronization level: Not protected
<> 149:156823d33999 1951 */
<> 149:156823d33999 1952 template <typename R, typename A0, typename A1, typename A2>
<> 149:156823d33999 1953 class Callback<R(A0, A1, A2)> {
<> 149:156823d33999 1954 public:
<> 149:156823d33999 1955 /** Create a Callback with a static function
<> 149:156823d33999 1956 * @param func Static function to attach
<> 149:156823d33999 1957 */
AnnaBridge 187:0387e8f68319 1958 Callback(R(*func)(A0, A1, A2) = 0)
AnnaBridge 187:0387e8f68319 1959 {
<> 149:156823d33999 1960 if (!func) {
AnnaBridge 175:af195413fb11 1961 memset(this, 0, sizeof(Callback));
<> 149:156823d33999 1962 } else {
<> 149:156823d33999 1963 generate(func);
<> 149:156823d33999 1964 }
<> 149:156823d33999 1965 }
<> 149:156823d33999 1966
<> 149:156823d33999 1967 /** Attach a Callback
<> 149:156823d33999 1968 * @param func The Callback to attach
<> 149:156823d33999 1969 */
AnnaBridge 187:0387e8f68319 1970 Callback(const Callback<R(A0, A1, A2)> &func)
AnnaBridge 187:0387e8f68319 1971 {
<> 149:156823d33999 1972 if (func._ops) {
<> 149:156823d33999 1973 func._ops->move(this, &func);
<> 149:156823d33999 1974 }
<> 149:156823d33999 1975 _ops = func._ops;
<> 149:156823d33999 1976 }
<> 149:156823d33999 1977
<> 149:156823d33999 1978 /** Create a Callback with a member function
<> 149:156823d33999 1979 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 1980 * @param method Member function to attach
<> 149:156823d33999 1981 */
<> 151:5eaa88a5bcc7 1982 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 1983 Callback(U *obj, R(T::*method)(A0, A1, A2))
AnnaBridge 187:0387e8f68319 1984 {
AnnaBridge 187:0387e8f68319 1985 generate(method_context<T, R(T::*)(A0, A1, A2)>(obj, method));
<> 149:156823d33999 1986 }
<> 149:156823d33999 1987
<> 149:156823d33999 1988 /** Create a Callback with a member function
<> 149:156823d33999 1989 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 1990 * @param method Member function to attach
<> 149:156823d33999 1991 */
<> 151:5eaa88a5bcc7 1992 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 1993 Callback(const U *obj, R(T::*method)(A0, A1, A2) const)
AnnaBridge 187:0387e8f68319 1994 {
AnnaBridge 187:0387e8f68319 1995 generate(method_context<const T, R(T::*)(A0, A1, A2) const>(obj, method));
<> 149:156823d33999 1996 }
<> 149:156823d33999 1997
<> 149:156823d33999 1998 /** Create a Callback with a member function
<> 149:156823d33999 1999 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2000 * @param method Member function to attach
<> 149:156823d33999 2001 */
<> 151:5eaa88a5bcc7 2002 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2003 Callback(volatile U *obj, R(T::*method)(A0, A1, A2) volatile)
AnnaBridge 187:0387e8f68319 2004 {
AnnaBridge 187:0387e8f68319 2005 generate(method_context<volatile T, R(T::*)(A0, A1, A2) volatile>(obj, method));
<> 149:156823d33999 2006 }
<> 149:156823d33999 2007
<> 149:156823d33999 2008 /** Create a Callback with a member function
<> 149:156823d33999 2009 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2010 * @param method Member function to attach
<> 149:156823d33999 2011 */
<> 151:5eaa88a5bcc7 2012 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2013 Callback(const volatile U *obj, R(T::*method)(A0, A1, A2) const volatile)
AnnaBridge 187:0387e8f68319 2014 {
AnnaBridge 187:0387e8f68319 2015 generate(method_context<const volatile T, R(T::*)(A0, A1, A2) const volatile>(obj, method));
<> 149:156823d33999 2016 }
<> 149:156823d33999 2017
<> 149:156823d33999 2018 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2019 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 2020 * @param arg Pointer argument to function
<> 149:156823d33999 2021 */
<> 151:5eaa88a5bcc7 2022 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2023 Callback(R(*func)(T *, A0, A1, A2), U *arg)
AnnaBridge 187:0387e8f68319 2024 {
AnnaBridge 187:0387e8f68319 2025 generate(function_context<R(*)(T *, A0, A1, A2), T>(func, arg));
<> 149:156823d33999 2026 }
<> 149:156823d33999 2027
<> 149:156823d33999 2028 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2029 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 2030 * @param arg Pointer argument to function
<> 149:156823d33999 2031 */
<> 151:5eaa88a5bcc7 2032 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2033 Callback(R(*func)(const T *, A0, A1, A2), const U *arg)
AnnaBridge 187:0387e8f68319 2034 {
AnnaBridge 187:0387e8f68319 2035 generate(function_context<R(*)(const T *, A0, A1, A2), const T>(func, arg));
<> 149:156823d33999 2036 }
<> 149:156823d33999 2037
<> 149:156823d33999 2038 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2039 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 2040 * @param arg Pointer argument to function
<> 149:156823d33999 2041 */
<> 151:5eaa88a5bcc7 2042 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2043 Callback(R(*func)(volatile T *, A0, A1, A2), volatile U *arg)
AnnaBridge 187:0387e8f68319 2044 {
AnnaBridge 187:0387e8f68319 2045 generate(function_context<R(*)(volatile T *, A0, A1, A2), volatile T>(func, arg));
<> 149:156823d33999 2046 }
<> 149:156823d33999 2047
<> 149:156823d33999 2048 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2049 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 2050 * @param arg Pointer argument to function
<> 149:156823d33999 2051 */
<> 151:5eaa88a5bcc7 2052 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2053 Callback(R(*func)(const volatile T *, A0, A1, A2), const volatile U *arg)
AnnaBridge 187:0387e8f68319 2054 {
AnnaBridge 187:0387e8f68319 2055 generate(function_context<R(*)(const volatile T *, A0, A1, A2), const volatile T>(func, arg));
<> 149:156823d33999 2056 }
<> 149:156823d33999 2057
<> 149:156823d33999 2058 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 2059 * @param f Function object to attach
<> 149:156823d33999 2060 * @note The function object is limited to a single word of storage
<> 149:156823d33999 2061 */
<> 149:156823d33999 2062 template <typename F>
AnnaBridge 187:0387e8f68319 2063 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2)))
AnnaBridge 187:0387e8f68319 2064 {
<> 149:156823d33999 2065 generate(f);
<> 149:156823d33999 2066 }
<> 149:156823d33999 2067
<> 149:156823d33999 2068 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 2069 * @param f Function object to attach
<> 149:156823d33999 2070 * @note The function object is limited to a single word of storage
<> 149:156823d33999 2071 */
<> 149:156823d33999 2072 template <typename F>
AnnaBridge 187:0387e8f68319 2073 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2) const))
AnnaBridge 187:0387e8f68319 2074 {
<> 149:156823d33999 2075 generate(f);
<> 149:156823d33999 2076 }
<> 149:156823d33999 2077
<> 149:156823d33999 2078 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 2079 * @param f Function object to attach
<> 149:156823d33999 2080 * @note The function object is limited to a single word of storage
<> 149:156823d33999 2081 */
<> 149:156823d33999 2082 template <typename F>
AnnaBridge 187:0387e8f68319 2083 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2) volatile))
AnnaBridge 187:0387e8f68319 2084 {
<> 149:156823d33999 2085 generate(f);
<> 149:156823d33999 2086 }
<> 149:156823d33999 2087
<> 149:156823d33999 2088 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 2089 * @param f Function object to attach
<> 149:156823d33999 2090 * @note The function object is limited to a single word of storage
<> 149:156823d33999 2091 */
<> 149:156823d33999 2092 template <typename F>
AnnaBridge 187:0387e8f68319 2093 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2) const volatile))
AnnaBridge 187:0387e8f68319 2094 {
<> 149:156823d33999 2095 generate(f);
<> 149:156823d33999 2096 }
<> 149:156823d33999 2097
<> 149:156823d33999 2098 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2099 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2100 * @param func Static function to attach
<> 149:156823d33999 2101 * @deprecated
<> 149:156823d33999 2102 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 2103 */
<> 151:5eaa88a5bcc7 2104 template<typename T, typename U>
<> 149:156823d33999 2105 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2106 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 2107 Callback(U *obj, R(*func)(T *, A0, A1, A2))
AnnaBridge 187:0387e8f68319 2108 {
<> 149:156823d33999 2109 new (this) Callback(func, obj);
<> 149:156823d33999 2110 }
<> 149:156823d33999 2111
<> 149:156823d33999 2112 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2113 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2114 * @param func Static function to attach
<> 149:156823d33999 2115 * @deprecated
<> 149:156823d33999 2116 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 2117 */
<> 151:5eaa88a5bcc7 2118 template<typename T, typename U>
<> 149:156823d33999 2119 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2120 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 2121 Callback(const U *obj, R(*func)(const T *, A0, A1, A2))
AnnaBridge 187:0387e8f68319 2122 {
<> 149:156823d33999 2123 new (this) Callback(func, obj);
<> 149:156823d33999 2124 }
<> 149:156823d33999 2125
<> 149:156823d33999 2126 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2127 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2128 * @param func Static function to attach
<> 149:156823d33999 2129 * @deprecated
<> 149:156823d33999 2130 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 2131 */
<> 151:5eaa88a5bcc7 2132 template<typename T, typename U>
<> 149:156823d33999 2133 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2134 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 2135 Callback(volatile U *obj, R(*func)(volatile T *, A0, A1, A2))
AnnaBridge 187:0387e8f68319 2136 {
<> 149:156823d33999 2137 new (this) Callback(func, obj);
<> 149:156823d33999 2138 }
<> 149:156823d33999 2139
<> 149:156823d33999 2140 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2141 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2142 * @param func Static function to attach
<> 149:156823d33999 2143 * @deprecated
<> 149:156823d33999 2144 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 2145 */
<> 151:5eaa88a5bcc7 2146 template<typename T, typename U>
<> 149:156823d33999 2147 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2148 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 2149 Callback(const volatile U *obj, R(*func)(const volatile T *, A0, A1, A2))
AnnaBridge 187:0387e8f68319 2150 {
<> 149:156823d33999 2151 new (this) Callback(func, obj);
<> 149:156823d33999 2152 }
<> 149:156823d33999 2153
<> 149:156823d33999 2154 /** Destroy a callback
<> 149:156823d33999 2155 */
AnnaBridge 187:0387e8f68319 2156 ~Callback()
AnnaBridge 187:0387e8f68319 2157 {
<> 149:156823d33999 2158 if (_ops) {
<> 149:156823d33999 2159 _ops->dtor(this);
<> 149:156823d33999 2160 }
<> 149:156823d33999 2161 }
<> 149:156823d33999 2162
<> 149:156823d33999 2163 /** Attach a static function
<> 149:156823d33999 2164 * @param func Static function to attach
<> 160:d5399cc887bb 2165 * @deprecated
<> 160:d5399cc887bb 2166 * Replaced by simple assignment 'Callback cb = func'
<> 160:d5399cc887bb 2167 */
<> 160:d5399cc887bb 2168 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2169 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2170 void attach(R(*func)(A0, A1, A2))
AnnaBridge 187:0387e8f68319 2171 {
<> 149:156823d33999 2172 this->~Callback();
<> 149:156823d33999 2173 new (this) Callback(func);
<> 149:156823d33999 2174 }
<> 149:156823d33999 2175
<> 149:156823d33999 2176 /** Attach a Callback
<> 149:156823d33999 2177 * @param func The Callback to attach
<> 160:d5399cc887bb 2178 * @deprecated
<> 160:d5399cc887bb 2179 * Replaced by simple assignment 'Callback cb = func'
<> 160:d5399cc887bb 2180 */
<> 160:d5399cc887bb 2181 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2182 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2183 void attach(const Callback<R(A0, A1, A2)> &func)
AnnaBridge 187:0387e8f68319 2184 {
<> 149:156823d33999 2185 this->~Callback();
<> 149:156823d33999 2186 new (this) Callback(func);
<> 149:156823d33999 2187 }
<> 149:156823d33999 2188
<> 149:156823d33999 2189 /** Attach a member function
<> 149:156823d33999 2190 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2191 * @param method Member function to attach
<> 160:d5399cc887bb 2192 * @deprecated
<> 160:d5399cc887bb 2193 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2194 */
<> 151:5eaa88a5bcc7 2195 template<typename T, typename U>
<> 160:d5399cc887bb 2196 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2197 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2198 void attach(U *obj, R(T::*method)(A0, A1, A2))
AnnaBridge 187:0387e8f68319 2199 {
<> 149:156823d33999 2200 this->~Callback();
<> 149:156823d33999 2201 new (this) Callback(obj, method);
<> 149:156823d33999 2202 }
<> 149:156823d33999 2203
<> 149:156823d33999 2204 /** Attach a member function
<> 149:156823d33999 2205 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2206 * @param method Member function to attach
<> 160:d5399cc887bb 2207 * @deprecated
<> 160:d5399cc887bb 2208 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2209 */
<> 151:5eaa88a5bcc7 2210 template<typename T, typename U>
<> 160:d5399cc887bb 2211 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2212 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2213 void attach(const U *obj, R(T::*method)(A0, A1, A2) const)
AnnaBridge 187:0387e8f68319 2214 {
<> 149:156823d33999 2215 this->~Callback();
<> 149:156823d33999 2216 new (this) Callback(obj, method);
<> 149:156823d33999 2217 }
<> 149:156823d33999 2218
<> 149:156823d33999 2219 /** Attach a member function
<> 149:156823d33999 2220 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2221 * @param method Member function to attach
<> 160:d5399cc887bb 2222 * @deprecated
<> 160:d5399cc887bb 2223 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2224 */
<> 151:5eaa88a5bcc7 2225 template<typename T, typename U>
<> 160:d5399cc887bb 2226 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2227 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2228 void attach(volatile U *obj, R(T::*method)(A0, A1, A2) volatile)
AnnaBridge 187:0387e8f68319 2229 {
<> 149:156823d33999 2230 this->~Callback();
<> 149:156823d33999 2231 new (this) Callback(obj, method);
<> 149:156823d33999 2232 }
<> 149:156823d33999 2233
<> 149:156823d33999 2234 /** Attach a member function
<> 149:156823d33999 2235 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2236 * @param method Member function to attach
<> 160:d5399cc887bb 2237 * @deprecated
<> 160:d5399cc887bb 2238 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2239 */
<> 151:5eaa88a5bcc7 2240 template<typename T, typename U>
<> 160:d5399cc887bb 2241 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2242 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2243 void attach(const volatile U *obj, R(T::*method)(A0, A1, A2) const volatile)
AnnaBridge 187:0387e8f68319 2244 {
<> 149:156823d33999 2245 this->~Callback();
<> 149:156823d33999 2246 new (this) Callback(obj, method);
<> 149:156823d33999 2247 }
<> 149:156823d33999 2248
<> 149:156823d33999 2249 /** Attach a static function with a bound pointer
<> 149:156823d33999 2250 * @param func Static function to attach
<> 149:156823d33999 2251 * @param arg Pointer argument to function
<> 160:d5399cc887bb 2252 * @deprecated
<> 160:d5399cc887bb 2253 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2254 */
<> 151:5eaa88a5bcc7 2255 template <typename T, typename U>
<> 160:d5399cc887bb 2256 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2257 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2258 void attach(R(*func)(T *, A0, A1, A2), U *arg)
AnnaBridge 187:0387e8f68319 2259 {
<> 149:156823d33999 2260 this->~Callback();
<> 149:156823d33999 2261 new (this) Callback(func, arg);
<> 149:156823d33999 2262 }
<> 149:156823d33999 2263
<> 149:156823d33999 2264 /** Attach a static function with a bound pointer
<> 149:156823d33999 2265 * @param func Static function to attach
<> 149:156823d33999 2266 * @param arg Pointer argument to function
<> 160:d5399cc887bb 2267 * @deprecated
<> 160:d5399cc887bb 2268 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2269 */
<> 151:5eaa88a5bcc7 2270 template <typename T, typename U>
<> 160:d5399cc887bb 2271 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2272 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2273 void attach(R(*func)(const T *, A0, A1, A2), const U *arg)
AnnaBridge 187:0387e8f68319 2274 {
<> 149:156823d33999 2275 this->~Callback();
<> 149:156823d33999 2276 new (this) Callback(func, arg);
<> 149:156823d33999 2277 }
<> 149:156823d33999 2278
<> 149:156823d33999 2279 /** Attach a static function with a bound pointer
<> 149:156823d33999 2280 * @param func Static function to attach
<> 149:156823d33999 2281 * @param arg Pointer argument to function
<> 160:d5399cc887bb 2282 * @deprecated
<> 160:d5399cc887bb 2283 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2284 */
<> 151:5eaa88a5bcc7 2285 template <typename T, typename U>
<> 160:d5399cc887bb 2286 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2287 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2288 void attach(R(*func)(volatile T *, A0, A1, A2), volatile U *arg)
AnnaBridge 187:0387e8f68319 2289 {
<> 149:156823d33999 2290 this->~Callback();
<> 149:156823d33999 2291 new (this) Callback(func, arg);
<> 149:156823d33999 2292 }
<> 149:156823d33999 2293
<> 149:156823d33999 2294 /** Attach a static function with a bound pointer
<> 149:156823d33999 2295 * @param func Static function to attach
<> 149:156823d33999 2296 * @param arg Pointer argument to function
<> 160:d5399cc887bb 2297 * @deprecated
<> 160:d5399cc887bb 2298 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2299 */
<> 151:5eaa88a5bcc7 2300 template <typename T, typename U>
<> 160:d5399cc887bb 2301 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2302 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2303 void attach(R(*func)(const volatile T *, A0, A1, A2), const volatile U *arg)
AnnaBridge 187:0387e8f68319 2304 {
<> 149:156823d33999 2305 this->~Callback();
<> 149:156823d33999 2306 new (this) Callback(func, arg);
<> 149:156823d33999 2307 }
<> 149:156823d33999 2308
<> 149:156823d33999 2309 /** Attach a function object
AnnaBridge 167:e84263d55307 2310 * @param f Function object to attach
<> 149:156823d33999 2311 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 2312 * @deprecated
<> 160:d5399cc887bb 2313 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2314 */
<> 149:156823d33999 2315 template <typename F>
<> 160:d5399cc887bb 2316 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2317 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2318 void attach(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2)))
AnnaBridge 187:0387e8f68319 2319 {
<> 149:156823d33999 2320 this->~Callback();
<> 149:156823d33999 2321 new (this) Callback(f);
<> 149:156823d33999 2322 }
<> 149:156823d33999 2323
<> 149:156823d33999 2324 /** Attach a function object
AnnaBridge 167:e84263d55307 2325 * @param f Function object to attach
<> 149:156823d33999 2326 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 2327 * @deprecated
<> 160:d5399cc887bb 2328 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2329 */
<> 149:156823d33999 2330 template <typename F>
<> 160:d5399cc887bb 2331 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2332 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2333 void attach(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2) const))
AnnaBridge 187:0387e8f68319 2334 {
<> 149:156823d33999 2335 this->~Callback();
<> 149:156823d33999 2336 new (this) Callback(f);
<> 149:156823d33999 2337 }
<> 149:156823d33999 2338
<> 149:156823d33999 2339 /** Attach a function object
AnnaBridge 167:e84263d55307 2340 * @param f Function object to attach
<> 149:156823d33999 2341 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 2342 * @deprecated
<> 160:d5399cc887bb 2343 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2344 */
<> 149:156823d33999 2345 template <typename F>
<> 160:d5399cc887bb 2346 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2347 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2348 void attach(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2) volatile))
AnnaBridge 187:0387e8f68319 2349 {
<> 149:156823d33999 2350 this->~Callback();
<> 149:156823d33999 2351 new (this) Callback(f);
<> 149:156823d33999 2352 }
<> 149:156823d33999 2353
<> 149:156823d33999 2354 /** Attach a function object
AnnaBridge 167:e84263d55307 2355 * @param f Function object to attach
<> 149:156823d33999 2356 * @note The function object is limited to a single word of storage
<> 160:d5399cc887bb 2357 * @deprecated
<> 160:d5399cc887bb 2358 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2359 */
<> 149:156823d33999 2360 template <typename F>
<> 160:d5399cc887bb 2361 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2362 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2363 void attach(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2) const volatile))
AnnaBridge 187:0387e8f68319 2364 {
<> 149:156823d33999 2365 this->~Callback();
<> 149:156823d33999 2366 new (this) Callback(f);
<> 149:156823d33999 2367 }
<> 149:156823d33999 2368
<> 149:156823d33999 2369 /** Attach a static function with a bound pointer
<> 149:156823d33999 2370 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2371 * @param func Static function to attach
<> 149:156823d33999 2372 * @deprecated
<> 149:156823d33999 2373 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 2374 */
<> 151:5eaa88a5bcc7 2375 template <typename T, typename U>
<> 149:156823d33999 2376 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2377 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 2378 void attach(U *obj, R(*func)(T *, A0, A1, A2))
AnnaBridge 187:0387e8f68319 2379 {
<> 149:156823d33999 2380 this->~Callback();
<> 149:156823d33999 2381 new (this) Callback(func, obj);
<> 149:156823d33999 2382 }
<> 149:156823d33999 2383
<> 149:156823d33999 2384 /** Attach a static function with a bound pointer
<> 149:156823d33999 2385 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2386 * @param func Static function to attach
<> 149:156823d33999 2387 * @deprecated
<> 149:156823d33999 2388 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 2389 */
<> 151:5eaa88a5bcc7 2390 template <typename T, typename U>
<> 149:156823d33999 2391 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2392 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 2393 void attach(const U *obj, R(*func)(const T *, A0, A1, A2))
AnnaBridge 187:0387e8f68319 2394 {
<> 149:156823d33999 2395 this->~Callback();
<> 149:156823d33999 2396 new (this) Callback(func, obj);
<> 149:156823d33999 2397 }
<> 149:156823d33999 2398
<> 149:156823d33999 2399 /** Attach a static function with a bound pointer
<> 149:156823d33999 2400 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2401 * @param func Static function to attach
<> 149:156823d33999 2402 * @deprecated
<> 149:156823d33999 2403 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 2404 */
<> 151:5eaa88a5bcc7 2405 template <typename T, typename U>
<> 149:156823d33999 2406 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2407 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 2408 void attach(volatile U *obj, R(*func)(volatile T *, A0, A1, A2))
AnnaBridge 187:0387e8f68319 2409 {
<> 149:156823d33999 2410 this->~Callback();
<> 149:156823d33999 2411 new (this) Callback(func, obj);
<> 149:156823d33999 2412 }
<> 149:156823d33999 2413
<> 149:156823d33999 2414 /** Attach a static function with a bound pointer
<> 149:156823d33999 2415 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2416 * @param func Static function to attach
<> 149:156823d33999 2417 * @deprecated
<> 149:156823d33999 2418 * Arguments to callback have been reordered to attach(func, arg)
<> 149:156823d33999 2419 */
<> 151:5eaa88a5bcc7 2420 template <typename T, typename U>
<> 149:156823d33999 2421 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2422 "Arguments to callback have been reordered to attach(func, arg)")
AnnaBridge 187:0387e8f68319 2423 void attach(const volatile U *obj, R(*func)(const volatile T *, A0, A1, A2))
AnnaBridge 187:0387e8f68319 2424 {
<> 149:156823d33999 2425 this->~Callback();
<> 149:156823d33999 2426 new (this) Callback(func, obj);
<> 149:156823d33999 2427 }
<> 149:156823d33999 2428
<> 149:156823d33999 2429 /** Assign a callback
<> 149:156823d33999 2430 */
AnnaBridge 187:0387e8f68319 2431 Callback &operator=(const Callback &that)
AnnaBridge 187:0387e8f68319 2432 {
<> 149:156823d33999 2433 if (this != &that) {
<> 149:156823d33999 2434 this->~Callback();
<> 149:156823d33999 2435 new (this) Callback(that);
<> 149:156823d33999 2436 }
<> 149:156823d33999 2437
<> 149:156823d33999 2438 return *this;
<> 149:156823d33999 2439 }
<> 149:156823d33999 2440
<> 149:156823d33999 2441 /** Call the attached function
<> 149:156823d33999 2442 */
AnnaBridge 187:0387e8f68319 2443 R call(A0 a0, A1 a1, A2 a2) const
AnnaBridge 187:0387e8f68319 2444 {
<> 149:156823d33999 2445 MBED_ASSERT(_ops);
<> 149:156823d33999 2446 return _ops->call(this, a0, a1, a2);
<> 149:156823d33999 2447 }
<> 149:156823d33999 2448
<> 149:156823d33999 2449 /** Call the attached function
<> 149:156823d33999 2450 */
AnnaBridge 187:0387e8f68319 2451 R operator()(A0 a0, A1 a1, A2 a2) const
AnnaBridge 187:0387e8f68319 2452 {
<> 149:156823d33999 2453 return call(a0, a1, a2);
<> 149:156823d33999 2454 }
<> 149:156823d33999 2455
<> 149:156823d33999 2456 /** Test if function has been attached
<> 149:156823d33999 2457 */
AnnaBridge 187:0387e8f68319 2458 operator bool() const
AnnaBridge 187:0387e8f68319 2459 {
<> 149:156823d33999 2460 return _ops;
<> 149:156823d33999 2461 }
<> 149:156823d33999 2462
<> 149:156823d33999 2463 /** Test for equality
<> 149:156823d33999 2464 */
AnnaBridge 187:0387e8f68319 2465 friend bool operator==(const Callback &l, const Callback &r)
AnnaBridge 187:0387e8f68319 2466 {
<> 149:156823d33999 2467 return memcmp(&l, &r, sizeof(Callback)) == 0;
<> 149:156823d33999 2468 }
<> 149:156823d33999 2469
<> 149:156823d33999 2470 /** Test for inequality
<> 149:156823d33999 2471 */
AnnaBridge 187:0387e8f68319 2472 friend bool operator!=(const Callback &l, const Callback &r)
AnnaBridge 187:0387e8f68319 2473 {
<> 149:156823d33999 2474 return !(l == r);
<> 149:156823d33999 2475 }
<> 149:156823d33999 2476
<> 149:156823d33999 2477 /** Static thunk for passing as C-style function
<> 149:156823d33999 2478 * @param func Callback to call passed as void pointer
AnnaBridge 167:e84263d55307 2479 * @param a0 An argument to be called with function func
AnnaBridge 167:e84263d55307 2480 * @param a1 An argument to be called with function func
AnnaBridge 167:e84263d55307 2481 * @param a2 An argument to be called with function func
AnnaBridge 187:0387e8f68319 2482 * @return the value as determined by func which is of
AnnaBridge 188:bcfe06ba3d64 2483 * type and determined by the signature of func
<> 149:156823d33999 2484 */
AnnaBridge 187:0387e8f68319 2485 static R thunk(void *func, A0 a0, A1 a1, A2 a2)
AnnaBridge 187:0387e8f68319 2486 {
AnnaBridge 187:0387e8f68319 2487 return static_cast<Callback *>(func)->call(a0, a1, a2);
<> 149:156823d33999 2488 }
<> 149:156823d33999 2489
<> 149:156823d33999 2490 private:
<> 149:156823d33999 2491 // Stored as pointer to function and pointer to optional object
<> 149:156823d33999 2492 // Function pointer is stored as union of possible function types
AnnaBridge 184:08ed48f1de7f 2493 // to guarantee proper size and alignment
<> 149:156823d33999 2494 struct _class;
<> 149:156823d33999 2495 union {
<> 149:156823d33999 2496 void (*_staticfunc)(A0, A1, A2);
AnnaBridge 187:0387e8f68319 2497 void (*_boundfunc)(_class *, A0, A1, A2);
<> 149:156823d33999 2498 void (_class::*_methodfunc)(A0, A1, A2);
<> 149:156823d33999 2499 } _func;
<> 149:156823d33999 2500 void *_obj;
<> 149:156823d33999 2501
<> 149:156823d33999 2502 // Dynamically dispatched operations
<> 149:156823d33999 2503 const struct ops {
AnnaBridge 187:0387e8f68319 2504 R(*call)(const void *, A0, A1, A2);
AnnaBridge 187:0387e8f68319 2505 void (*move)(void *, const void *);
AnnaBridge 187:0387e8f68319 2506 void (*dtor)(void *);
<> 149:156823d33999 2507 } *_ops;
<> 149:156823d33999 2508
<> 149:156823d33999 2509 // Generate operations for function object
<> 149:156823d33999 2510 template <typename F>
AnnaBridge 187:0387e8f68319 2511 void generate(const F &f)
AnnaBridge 187:0387e8f68319 2512 {
<> 149:156823d33999 2513 static const ops ops = {
<> 149:156823d33999 2514 &Callback::function_call<F>,
<> 149:156823d33999 2515 &Callback::function_move<F>,
<> 149:156823d33999 2516 &Callback::function_dtor<F>,
<> 149:156823d33999 2517 };
<> 149:156823d33999 2518
<> 151:5eaa88a5bcc7 2519 MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
AnnaBridge 187:0387e8f68319 2520 "Type F must not exceed the size of the Callback class");
AnnaBridge 175:af195413fb11 2521 memset(this, 0, sizeof(Callback));
<> 149:156823d33999 2522 new (this) F(f);
<> 149:156823d33999 2523 _ops = &ops;
<> 149:156823d33999 2524 }
<> 149:156823d33999 2525
<> 149:156823d33999 2526 // Function attributes
<> 149:156823d33999 2527 template <typename F>
AnnaBridge 187:0387e8f68319 2528 static R function_call(const void *p, A0 a0, A1 a1, A2 a2)
AnnaBridge 187:0387e8f68319 2529 {
AnnaBridge 187:0387e8f68319 2530 return (*(F *)p)(a0, a1, a2);
<> 149:156823d33999 2531 }
<> 149:156823d33999 2532
<> 149:156823d33999 2533 template <typename F>
AnnaBridge 187:0387e8f68319 2534 static void function_move(void *d, const void *p)
AnnaBridge 187:0387e8f68319 2535 {
AnnaBridge 187:0387e8f68319 2536 new (d) F(*(F *)p);
<> 149:156823d33999 2537 }
<> 149:156823d33999 2538
<> 149:156823d33999 2539 template <typename F>
AnnaBridge 187:0387e8f68319 2540 static void function_dtor(void *p)
AnnaBridge 187:0387e8f68319 2541 {
AnnaBridge 187:0387e8f68319 2542 ((F *)p)->~F();
<> 149:156823d33999 2543 }
<> 149:156823d33999 2544
<> 149:156823d33999 2545 // Wrappers for functions with context
<> 149:156823d33999 2546 template <typename O, typename M>
<> 149:156823d33999 2547 struct method_context {
<> 149:156823d33999 2548 M method;
<> 149:156823d33999 2549 O *obj;
<> 149:156823d33999 2550
<> 149:156823d33999 2551 method_context(O *obj, M method)
<> 149:156823d33999 2552 : method(method), obj(obj) {}
<> 149:156823d33999 2553
AnnaBridge 187:0387e8f68319 2554 R operator()(A0 a0, A1 a1, A2 a2) const
AnnaBridge 187:0387e8f68319 2555 {
<> 149:156823d33999 2556 return (obj->*method)(a0, a1, a2);
<> 149:156823d33999 2557 }
<> 149:156823d33999 2558 };
<> 149:156823d33999 2559
<> 149:156823d33999 2560 template <typename F, typename A>
<> 149:156823d33999 2561 struct function_context {
<> 149:156823d33999 2562 F func;
<> 149:156823d33999 2563 A *arg;
<> 149:156823d33999 2564
<> 149:156823d33999 2565 function_context(F func, A *arg)
<> 149:156823d33999 2566 : func(func), arg(arg) {}
<> 149:156823d33999 2567
AnnaBridge 187:0387e8f68319 2568 R operator()(A0 a0, A1 a1, A2 a2) const
AnnaBridge 187:0387e8f68319 2569 {
<> 149:156823d33999 2570 return func(arg, a0, a1, a2);
<> 149:156823d33999 2571 }
<> 149:156823d33999 2572 };
<> 149:156823d33999 2573 };
<> 149:156823d33999 2574
<> 149:156823d33999 2575 /** Callback class based on template specialization
<> 149:156823d33999 2576 *
AnnaBridge 167:e84263d55307 2577 * @note Synchronization level: Not protected
<> 149:156823d33999 2578 */
<> 149:156823d33999 2579 template <typename R, typename A0, typename A1, typename A2, typename A3>
<> 149:156823d33999 2580 class Callback<R(A0, A1, A2, A3)> {
<> 149:156823d33999 2581 public:
<> 149:156823d33999 2582 /** Create a Callback with a static function
<> 149:156823d33999 2583 * @param func Static function to attach
<> 149:156823d33999 2584 */
AnnaBridge 187:0387e8f68319 2585 Callback(R(*func)(A0, A1, A2, A3) = 0)
AnnaBridge 187:0387e8f68319 2586 {
<> 149:156823d33999 2587 if (!func) {
AnnaBridge 175:af195413fb11 2588 memset(this, 0, sizeof(Callback));
<> 149:156823d33999 2589 } else {
<> 149:156823d33999 2590 generate(func);
<> 149:156823d33999 2591 }
<> 149:156823d33999 2592 }
<> 149:156823d33999 2593
<> 149:156823d33999 2594 /** Attach a Callback
<> 149:156823d33999 2595 * @param func The Callback to attach
<> 149:156823d33999 2596 */
AnnaBridge 187:0387e8f68319 2597 Callback(const Callback<R(A0, A1, A2, A3)> &func)
AnnaBridge 187:0387e8f68319 2598 {
<> 149:156823d33999 2599 if (func._ops) {
<> 149:156823d33999 2600 func._ops->move(this, &func);
<> 149:156823d33999 2601 }
<> 149:156823d33999 2602 _ops = func._ops;
<> 149:156823d33999 2603 }
<> 149:156823d33999 2604
<> 149:156823d33999 2605 /** Create a Callback with a member function
<> 149:156823d33999 2606 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2607 * @param method Member function to attach
<> 149:156823d33999 2608 */
<> 151:5eaa88a5bcc7 2609 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2610 Callback(U *obj, R(T::*method)(A0, A1, A2, A3))
AnnaBridge 187:0387e8f68319 2611 {
AnnaBridge 187:0387e8f68319 2612 generate(method_context<T, R(T::*)(A0, A1, A2, A3)>(obj, method));
<> 149:156823d33999 2613 }
<> 149:156823d33999 2614
<> 149:156823d33999 2615 /** Create a Callback with a member function
<> 149:156823d33999 2616 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2617 * @param method Member function to attach
<> 149:156823d33999 2618 */
<> 151:5eaa88a5bcc7 2619 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2620 Callback(const U *obj, R(T::*method)(A0, A1, A2, A3) const)
AnnaBridge 187:0387e8f68319 2621 {
AnnaBridge 187:0387e8f68319 2622 generate(method_context<const T, R(T::*)(A0, A1, A2, A3) const>(obj, method));
<> 149:156823d33999 2623 }
<> 149:156823d33999 2624
<> 149:156823d33999 2625 /** Create a Callback with a member function
<> 149:156823d33999 2626 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2627 * @param method Member function to attach
<> 149:156823d33999 2628 */
<> 151:5eaa88a5bcc7 2629 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2630 Callback(volatile U *obj, R(T::*method)(A0, A1, A2, A3) volatile)
AnnaBridge 187:0387e8f68319 2631 {
AnnaBridge 187:0387e8f68319 2632 generate(method_context<volatile T, R(T::*)(A0, A1, A2, A3) volatile>(obj, method));
<> 149:156823d33999 2633 }
<> 149:156823d33999 2634
<> 149:156823d33999 2635 /** Create a Callback with a member function
<> 149:156823d33999 2636 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2637 * @param method Member function to attach
<> 149:156823d33999 2638 */
<> 151:5eaa88a5bcc7 2639 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2640 Callback(const volatile U *obj, R(T::*method)(A0, A1, A2, A3) const volatile)
AnnaBridge 187:0387e8f68319 2641 {
AnnaBridge 187:0387e8f68319 2642 generate(method_context<const volatile T, R(T::*)(A0, A1, A2, A3) const volatile>(obj, method));
<> 149:156823d33999 2643 }
<> 149:156823d33999 2644
<> 149:156823d33999 2645 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2646 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 2647 * @param arg Pointer argument to function
<> 149:156823d33999 2648 */
<> 151:5eaa88a5bcc7 2649 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2650 Callback(R(*func)(T *, A0, A1, A2, A3), U *arg)
AnnaBridge 187:0387e8f68319 2651 {
AnnaBridge 187:0387e8f68319 2652 generate(function_context<R(*)(T *, A0, A1, A2, A3), T>(func, arg));
<> 149:156823d33999 2653 }
<> 149:156823d33999 2654
<> 149:156823d33999 2655 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2656 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 2657 * @param arg Pointer argument to function
<> 149:156823d33999 2658 */
<> 151:5eaa88a5bcc7 2659 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2660 Callback(R(*func)(const T *, A0, A1, A2, A3), const U *arg)
AnnaBridge 187:0387e8f68319 2661 {
AnnaBridge 187:0387e8f68319 2662 generate(function_context<R(*)(const T *, A0, A1, A2, A3), const T>(func, arg));
<> 149:156823d33999 2663 }
<> 149:156823d33999 2664
<> 149:156823d33999 2665 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2666 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 2667 * @param arg Pointer argument to function
<> 149:156823d33999 2668 */
<> 151:5eaa88a5bcc7 2669 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2670 Callback(R(*func)(volatile T *, A0, A1, A2, A3), volatile U *arg)
AnnaBridge 187:0387e8f68319 2671 {
AnnaBridge 187:0387e8f68319 2672 generate(function_context<R(*)(volatile T *, A0, A1, A2, A3), volatile T>(func, arg));
<> 149:156823d33999 2673 }
<> 149:156823d33999 2674
<> 149:156823d33999 2675 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2676 * @param func Static function to attach
AnnaBridge 187:0387e8f68319 2677 * @param arg Pointer argument to function
<> 149:156823d33999 2678 */
<> 151:5eaa88a5bcc7 2679 template<typename T, typename U>
AnnaBridge 187:0387e8f68319 2680 Callback(R(*func)(const volatile T *, A0, A1, A2, A3), const volatile U *arg)
AnnaBridge 187:0387e8f68319 2681 {
AnnaBridge 187:0387e8f68319 2682 generate(function_context<R(*)(const volatile T *, A0, A1, A2, A3), const volatile T>(func, arg));
<> 149:156823d33999 2683 }
<> 149:156823d33999 2684
<> 149:156823d33999 2685 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 2686 * @param f Function object to attach
<> 149:156823d33999 2687 * @note The function object is limited to a single word of storage
<> 149:156823d33999 2688 */
<> 149:156823d33999 2689 template <typename F>
AnnaBridge 187:0387e8f68319 2690 Callback(F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2, A3)))
AnnaBridge 187:0387e8f68319 2691 {
<> 149:156823d33999 2692 generate(f);
<> 149:156823d33999 2693 }
<> 149:156823d33999 2694
<> 149:156823d33999 2695 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 2696 * @param f Function object to attach
<> 149:156823d33999 2697 * @note The function object is limited to a single word of storage
<> 149:156823d33999 2698 */
<> 149:156823d33999 2699 template <typename F>
AnnaBridge 187:0387e8f68319 2700 Callback(const F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2, A3) const))
AnnaBridge 187:0387e8f68319 2701 {
<> 149:156823d33999 2702 generate(f);
<> 149:156823d33999 2703 }
<> 149:156823d33999 2704
<> 149:156823d33999 2705 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 2706 * @param f Function object to attach
<> 149:156823d33999 2707 * @note The function object is limited to a single word of storage
<> 149:156823d33999 2708 */
<> 149:156823d33999 2709 template <typename F>
AnnaBridge 187:0387e8f68319 2710 Callback(volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2, A3) volatile))
AnnaBridge 187:0387e8f68319 2711 {
<> 149:156823d33999 2712 generate(f);
<> 149:156823d33999 2713 }
<> 149:156823d33999 2714
<> 149:156823d33999 2715 /** Create a Callback with a function object
AnnaBridge 167:e84263d55307 2716 * @param f Function object to attach
<> 149:156823d33999 2717 * @note The function object is limited to a single word of storage
<> 149:156823d33999 2718 */
<> 149:156823d33999 2719 template <typename F>
AnnaBridge 187:0387e8f68319 2720 Callback(const volatile F f, MBED_ENABLE_IF_CALLBACK_COMPATIBLE(F, R(F::*)(A0, A1, A2, A3) const volatile))
AnnaBridge 187:0387e8f68319 2721 {
<> 149:156823d33999 2722 generate(f);
<> 149:156823d33999 2723 }
<> 149:156823d33999 2724
<> 149:156823d33999 2725 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2726 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2727 * @param func Static function to attach
<> 149:156823d33999 2728 * @deprecated
<> 149:156823d33999 2729 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 2730 */
<> 151:5eaa88a5bcc7 2731 template<typename T, typename U>
<> 149:156823d33999 2732 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2733 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 2734 Callback(U *obj, R(*func)(T *, A0, A1, A2, A3))
AnnaBridge 187:0387e8f68319 2735 {
<> 149:156823d33999 2736 new (this) Callback(func, obj);
<> 149:156823d33999 2737 }
<> 149:156823d33999 2738
<> 149:156823d33999 2739 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2740 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2741 * @param func Static function to attach
<> 149:156823d33999 2742 * @deprecated
<> 149:156823d33999 2743 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 2744 */
<> 151:5eaa88a5bcc7 2745 template<typename T, typename U>
<> 149:156823d33999 2746 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2747 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 2748 Callback(const U *obj, R(*func)(const T *, A0, A1, A2, A3))
AnnaBridge 187:0387e8f68319 2749 {
<> 149:156823d33999 2750 new (this) Callback(func, obj);
<> 149:156823d33999 2751 }
<> 149:156823d33999 2752
<> 149:156823d33999 2753 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2754 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2755 * @param func Static function to attach
<> 149:156823d33999 2756 * @deprecated
<> 149:156823d33999 2757 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 2758 */
<> 151:5eaa88a5bcc7 2759 template<typename T, typename U>
<> 149:156823d33999 2760 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2761 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 2762 Callback(volatile U *obj, R(*func)(volatile T *, A0, A1, A2, A3))
AnnaBridge 187:0387e8f68319 2763 {
<> 149:156823d33999 2764 new (this) Callback(func, obj);
<> 149:156823d33999 2765 }
<> 149:156823d33999 2766
<> 149:156823d33999 2767 /** Create a Callback with a static function and bound pointer
<> 149:156823d33999 2768 * @param obj Pointer to object to bind to function
<> 149:156823d33999 2769 * @param func Static function to attach
<> 149:156823d33999 2770 * @deprecated
<> 149:156823d33999 2771 * Arguments to callback have been reordered to Callback(func, arg)
<> 149:156823d33999 2772 */
<> 151:5eaa88a5bcc7 2773 template<typename T, typename U>
<> 149:156823d33999 2774 MBED_DEPRECATED_SINCE("mbed-os-5.1",
AnnaBridge 187:0387e8f68319 2775 "Arguments to callback have been reordered to Callback(func, arg)")
AnnaBridge 187:0387e8f68319 2776 Callback(const volatile U *obj, R(*func)(const volatile T *, A0, A1, A2, A3))
AnnaBridge 187:0387e8f68319 2777 {
<> 149:156823d33999 2778 new (this) Callback(func, obj);
<> 149:156823d33999 2779 }
<> 149:156823d33999 2780
<> 149:156823d33999 2781 /** Destroy a callback
<> 149:156823d33999 2782 */
AnnaBridge 187:0387e8f68319 2783 ~Callback()
AnnaBridge 187:0387e8f68319 2784 {
<> 149:156823d33999 2785 if (_ops) {
<> 149:156823d33999 2786 _ops->dtor(this);
<> 149:156823d33999 2787 }
<> 149:156823d33999 2788 }
<> 149:156823d33999 2789
<> 149:156823d33999 2790 /** Attach a static function
<> 149:156823d33999 2791 * @param func Static function to attach
<> 160:d5399cc887bb 2792 * @deprecated
<> 160:d5399cc887bb 2793 * Replaced by simple assignment 'Callback cb = func'
<> 160:d5399cc887bb 2794 */
<> 160:d5399cc887bb 2795 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2796 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2797 void attach(R(*func)(A0, A1, A2, A3))
AnnaBridge 187:0387e8f68319 2798 {
<> 149:156823d33999 2799 this->~Callback();
<> 149:156823d33999 2800 new (this) Callback(func);
<> 149:156823d33999 2801 }
<> 149:156823d33999 2802
<> 149:156823d33999 2803 /** Attach a Callback
<> 149:156823d33999 2804 * @param func The Callback to attach
<> 160:d5399cc887bb 2805 * @deprecated
<> 160:d5399cc887bb 2806 * Replaced by simple assignment 'Callback cb = func'
<> 160:d5399cc887bb 2807 */
<> 160:d5399cc887bb 2808 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2809 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2810 void attach(const Callback<R(A0, A1, A2, A3)> &func)
AnnaBridge 187:0387e8f68319 2811 {
<> 149:156823d33999 2812 this->~Callback();
<> 149:156823d33999 2813 new (this) Callback(func);
<> 149:156823d33999 2814 }
<> 149:156823d33999 2815
<> 149:156823d33999 2816 /** Attach a member function
<> 149:156823d33999 2817 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2818 * @param method Member function to attach
<> 160:d5399cc887bb 2819 * @deprecated
<> 160:d5399cc887bb 2820 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2821 */
<> 151:5eaa88a5bcc7 2822 template<typename T, typename U>
<> 160:d5399cc887bb 2823 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2824 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2825 void attach(U *obj, R(T::*method)(A0, A1, A2, A3))
AnnaBridge 187:0387e8f68319 2826 {
<> 149:156823d33999 2827 this->~Callback();
<> 149:156823d33999 2828 new (this) Callback(obj, method);
<> 149:156823d33999 2829 }
<> 149:156823d33999 2830
<> 149:156823d33999 2831 /** Attach a member function
<> 149:156823d33999 2832 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2833 * @param method Member function to attach
<> 160:d5399cc887bb 2834 * @deprecated
<> 160:d5399cc887bb 2835 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2836 */
<> 151:5eaa88a5bcc7 2837 template<typename T, typename U>
<> 160:d5399cc887bb 2838 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2839 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2840 void attach(const U *obj, R(T::*method)(A0, A1, A2, A3) const)
AnnaBridge 187:0387e8f68319 2841 {
<> 149:156823d33999 2842 this->~Callback();
<> 149:156823d33999 2843 new (this) Callback(obj, method);
<> 149:156823d33999 2844 }
<> 149:156823d33999 2845
<> 149:156823d33999 2846 /** Attach a member function
<> 149:156823d33999 2847 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2848 * @param method Member function to attach
<> 160:d5399cc887bb 2849 * @deprecated
<> 160:d5399cc887bb 2850 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2851 */
<> 151:5eaa88a5bcc7 2852 template<typename T, typename U>
<> 160:d5399cc887bb 2853 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2854 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2855 void attach(volatile U *obj, R(T::*method)(A0, A1, A2, A3) volatile)
AnnaBridge 187:0387e8f68319 2856 {
<> 149:156823d33999 2857 this->~Callback();
<> 149:156823d33999 2858 new (this) Callback(obj, method);
<> 149:156823d33999 2859 }
<> 149:156823d33999 2860
<> 149:156823d33999 2861 /** Attach a member function
<> 149:156823d33999 2862 * @param obj Pointer to object to invoke member function on
<> 149:156823d33999 2863 * @param method Member function to attach
<> 160:d5399cc887bb 2864 * @deprecated
<> 160:d5399cc887bb 2865 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2866 */
<> 151:5eaa88a5bcc7 2867 template<typename T, typename U>
<> 160:d5399cc887bb 2868 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2869 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2870 void attach(const volatile U *obj, R(T::*method)(A0, A1, A2, A3) const volatile)
AnnaBridge 187:0387e8f68319 2871 {
<> 149:156823d33999 2872 this->~Callback();
<> 149:156823d33999 2873 new (this) Callback(obj, method);
<> 149:156823d33999 2874 }
<> 149:156823d33999 2875
<> 149:156823d33999 2876 /** Attach a static function with a bound pointer
<> 149:156823d33999 2877 * @param func Static function to attach
<> 149:156823d33999 2878 * @param arg Pointer argument to function
<> 160:d5399cc887bb 2879 * @deprecated
<> 160:d5399cc887bb 2880 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2881 */
<> 151:5eaa88a5bcc7 2882 template <typename T, typename U>
<> 160:d5399cc887bb 2883 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2884 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2885 void attach(R(*func)(T *, A0, A1, A2, A3), U *arg)
AnnaBridge 187:0387e8f68319 2886 {
<> 149:156823d33999 2887 this->~Callback();
<> 149:156823d33999 2888 new (this) Callback(func, arg);
<> 149:156823d33999 2889 }
<> 149:156823d33999 2890
<> 149:156823d33999 2891 /** Attach a static function with a bound pointer
<> 149:156823d33999 2892 * @param func Static function to attach
<> 149:156823d33999 2893 * @param arg Pointer argument to function
<> 160:d5399cc887bb 2894 * @deprecated
<> 160:d5399cc887bb 2895 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2896 */
<> 151:5eaa88a5bcc7 2897 template <typename T, typename U>
<> 160:d5399cc887bb 2898 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2899 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2900 void attach(R(*func)(const T *, A0, A1, A2, A3), const U *arg)
AnnaBridge 187:0387e8f68319 2901 {
<> 149:156823d33999 2902 this->~Callback();
<> 149:156823d33999 2903 new (this) Callback(func, arg);
<> 149:156823d33999 2904 }
<> 149:156823d33999 2905
<> 149:156823d33999 2906 /** Attach a static function with a bound pointer
<> 149:156823d33999 2907 * @param func Static function to attach
<> 149:156823d33999 2908 * @param arg Pointer argument to function
<> 160:d5399cc887bb 2909 * @deprecated
<> 160:d5399cc887bb 2910 * Replaced by simple assignment 'Callback cb = func'
<> 149:156823d33999 2911 */
<> 151:5eaa88a5bcc7 2912 template <typename T, typename U>
<> 160:d5399cc887bb 2913 MBED_DEPRECATED_SINCE("mbed-os-5.4",
AnnaBridge 187:0387e8f68319 2914 "Replaced by simple assignment 'Callback cb = func")
AnnaBridge 187:0387e8f68319 2915 void attach(R(*func)(volatile T *, A0, A1, A2, A3), volatile U *arg)
AnnaBridge 187:0387e8f68319 2916 {
<>