Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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