Host library for controlling a WiConnect enabled Wi-Fi module.
Dependents: wiconnect-ota_example wiconnect-web_setup_example wiconnect-test-console wiconnect-tcp_server_example ... more
types/Callback.h@11:ea484e1b7fc4, 2014-08-12 (annotated)
- Committer:
- dan_ackme
- Date:
- Tue Aug 12 02:34:46 2014 -0700
- Revision:
- 11:ea484e1b7fc4
- Parent:
- 1:6ec9998427ad
- Child:
- 13:2b51f5267c92
updated documnetation
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dan_ackme | 0:ea85c4bb5e1f | 1 | /* |
dan_ackme | 0:ea85c4bb5e1f | 2 | * Copyright 2014, ACKme Networks |
dan_ackme | 0:ea85c4bb5e1f | 3 | * All Rights Reserved. |
dan_ackme | 0:ea85c4bb5e1f | 4 | * |
dan_ackme | 0:ea85c4bb5e1f | 5 | * This is UNPUBLISHED PROPRIETARY SOURCE CODE of ACKme Networks; |
dan_ackme | 0:ea85c4bb5e1f | 6 | * the contents of this file may not be disclosed to third parties, copied |
dan_ackme | 0:ea85c4bb5e1f | 7 | * or duplicated in any form, in whole or in part, without the prior |
dan_ackme | 0:ea85c4bb5e1f | 8 | * written permission of ACKme Networks. |
dan_ackme | 0:ea85c4bb5e1f | 9 | */ |
dan_ackme | 0:ea85c4bb5e1f | 10 | |
dan_ackme | 0:ea85c4bb5e1f | 11 | #pragma once |
dan_ackme | 0:ea85c4bb5e1f | 12 | |
dan_ackme | 0:ea85c4bb5e1f | 13 | |
dan_ackme | 0:ea85c4bb5e1f | 14 | #include "WiconnectTypes.h" |
dan_ackme | 0:ea85c4bb5e1f | 15 | #include "FunctionPointer.h" |
dan_ackme | 0:ea85c4bb5e1f | 16 | |
dan_ackme | 0:ea85c4bb5e1f | 17 | |
dan_ackme | 0:ea85c4bb5e1f | 18 | |
dan_ackme | 0:ea85c4bb5e1f | 19 | namespace wiconnect |
dan_ackme | 0:ea85c4bb5e1f | 20 | { |
dan_ackme | 0:ea85c4bb5e1f | 21 | |
dan_ackme | 0:ea85c4bb5e1f | 22 | |
dan_ackme | 0:ea85c4bb5e1f | 23 | typedef void (*_Callback)(WiconnectResult result, void *arg1, void *arg2); |
dan_ackme | 0:ea85c4bb5e1f | 24 | |
dan_ackme | 11:ea484e1b7fc4 | 25 | |
dan_ackme | 11:ea484e1b7fc4 | 26 | /** |
dan_ackme | 11:ea484e1b7fc4 | 27 | * @ingroup types_core |
dan_ackme | 11:ea484e1b7fc4 | 28 | * |
dan_ackme | 11:ea484e1b7fc4 | 29 | * @brief Generic callback function. |
dan_ackme | 11:ea484e1b7fc4 | 30 | */ |
dan_ackme | 0:ea85c4bb5e1f | 31 | class Callback : public FunctionPointer |
dan_ackme | 0:ea85c4bb5e1f | 32 | { |
dan_ackme | 0:ea85c4bb5e1f | 33 | public: |
dan_ackme | 0:ea85c4bb5e1f | 34 | /*************************************************************************************************/ |
dan_ackme | 0:ea85c4bb5e1f | 35 | Callback(_Callback func = 0) |
dan_ackme | 0:ea85c4bb5e1f | 36 | { |
dan_ackme | 0:ea85c4bb5e1f | 37 | _function = (void*)func; |
dan_ackme | 0:ea85c4bb5e1f | 38 | _membercaller = NULL; |
dan_ackme | 0:ea85c4bb5e1f | 39 | _object = NULL; |
dan_ackme | 0:ea85c4bb5e1f | 40 | } |
dan_ackme | 0:ea85c4bb5e1f | 41 | |
dan_ackme | 0:ea85c4bb5e1f | 42 | /*************************************************************************************************/ |
dan_ackme | 0:ea85c4bb5e1f | 43 | template<typename T> |
dan_ackme | 0:ea85c4bb5e1f | 44 | Callback(T *object, void (T::*member)(WiconnectResult result, void *arg1, void *arg2)) |
dan_ackme | 0:ea85c4bb5e1f | 45 | { |
dan_ackme | 0:ea85c4bb5e1f | 46 | _object = static_cast<void*>(object); |
dan_ackme | 0:ea85c4bb5e1f | 47 | memcpy(_member, (char*)&member, sizeof(member)); |
dan_ackme | 0:ea85c4bb5e1f | 48 | _membercaller = (void*)&Callback::membercaller<T>; |
dan_ackme | 0:ea85c4bb5e1f | 49 | _function = 0; |
dan_ackme | 0:ea85c4bb5e1f | 50 | } |
dan_ackme | 0:ea85c4bb5e1f | 51 | |
dan_ackme | 0:ea85c4bb5e1f | 52 | /*************************************************************************************************/ |
dan_ackme | 0:ea85c4bb5e1f | 53 | void call(WiconnectResult result, void *arg1, void *arg2) |
dan_ackme | 0:ea85c4bb5e1f | 54 | { |
dan_ackme | 0:ea85c4bb5e1f | 55 | if (_function) |
dan_ackme | 0:ea85c4bb5e1f | 56 | { |
dan_ackme | 0:ea85c4bb5e1f | 57 | ((_Callback)_function)(result, arg1, arg2); |
dan_ackme | 0:ea85c4bb5e1f | 58 | } |
dan_ackme | 0:ea85c4bb5e1f | 59 | else if (_object) |
dan_ackme | 0:ea85c4bb5e1f | 60 | { |
dan_ackme | 0:ea85c4bb5e1f | 61 | typedef void (*membercallerFunc)(void*, char*, WiconnectResult result, void *arg1, void *arg2); |
dan_ackme | 0:ea85c4bb5e1f | 62 | ((membercallerFunc)_membercaller)(_object, _member, result, arg1, arg2); |
dan_ackme | 0:ea85c4bb5e1f | 63 | } |
dan_ackme | 0:ea85c4bb5e1f | 64 | } |
dan_ackme | 0:ea85c4bb5e1f | 65 | |
dan_ackme | 0:ea85c4bb5e1f | 66 | private: |
dan_ackme | 0:ea85c4bb5e1f | 67 | |
dan_ackme | 0:ea85c4bb5e1f | 68 | /*************************************************************************************************/ |
dan_ackme | 0:ea85c4bb5e1f | 69 | template<typename T> |
dan_ackme | 0:ea85c4bb5e1f | 70 | static void membercaller(void *object, char *member, WiconnectResult result, void *arg1, void *arg2) |
dan_ackme | 0:ea85c4bb5e1f | 71 | { |
dan_ackme | 0:ea85c4bb5e1f | 72 | T* o = static_cast<T*>(object); |
dan_ackme | 0:ea85c4bb5e1f | 73 | void (T::*m)(WiconnectResult result, void *arg1, void *arg2); |
dan_ackme | 0:ea85c4bb5e1f | 74 | memcpy((char*)&m, member, sizeof(m)); |
dan_ackme | 0:ea85c4bb5e1f | 75 | (o->*m)(result, arg1, arg2); |
dan_ackme | 0:ea85c4bb5e1f | 76 | } |
dan_ackme | 0:ea85c4bb5e1f | 77 | |
dan_ackme | 0:ea85c4bb5e1f | 78 | }; |
dan_ackme | 0:ea85c4bb5e1f | 79 | |
dan_ackme | 0:ea85c4bb5e1f | 80 | |
dan_ackme | 0:ea85c4bb5e1f | 81 | } |