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