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