BLE_API_Tiny_BLE
Fork of BLE_API by
Revision 244:aa639ef2f290, committed 2014-12-11
- Comitter:
- rgrover1
- Date:
- Thu Dec 11 11:52:32 2014 +0000
- Parent:
- 243:98f930d14515
- Child:
- 245:712e0719d7e9
- Commit message:
- Synchronized with git rev 709abe6a
Author: Rohit Grover
add BLEDevice::addToDisconnectionCallChain()
Changed in this revision
public/BLEDevice.h | Show annotated file Show diff for this revision Revisions of this file |
public/Gap.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/public/BLEDevice.h Tue Dec 09 13:15:19 2014 +0000 +++ b/public/BLEDevice.h Thu Dec 11 11:52:32 2014 +0000 @@ -216,6 +216,14 @@ void onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback); /** + * Append to a chain of callbacks to be invoked upon disconnection; these + * callbacks receive no context and are therefore different from the + * onDisconnection callback. + */ + template<typename T> + void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)); + + /** * Setup a callback for the GATT event DATA_SENT. */ void onDataSent(GattServer::ServerEventCallbackWithCount_t callback); @@ -510,6 +518,12 @@ transport->getGap().setOnDisconnection(disconnectionCallback); } +template<typename T> +inline void +BLEDevice::addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) { + transport->getGap().addToDisconnectionCallChain(tptr, mptr); +} + inline void BLEDevice::onDataSent(GattServer::ServerEventCallbackWithCount_t callback) {
--- a/public/Gap.h Tue Dec 09 13:15:19 2014 +0000 +++ b/public/Gap.h Thu Dec 11 11:52:32 2014 +0000 @@ -20,6 +20,9 @@ #include "GapAdvertisingData.h" #include "GapAdvertisingParams.h" #include "GapEvents.h" +#include "CallChain.h" + +using namespace mbed; class Gap { public: @@ -96,14 +99,36 @@ /* Event callback handlers */ void setOnTimeout(EventCallback_t callback) {onTimeout = callback;} void setOnConnection(ConnectionEventCallback_t callback) {onConnection = callback;} + + /** + * Set the application callback for disconnection events. + * @param callback + * Pointer to the unique callback. + */ void setOnDisconnection(DisconnectionEventCallback_t callback) {onDisconnection = callback;} + /** + * Append to a chain of callbacks to be invoked upon disconnection; these + * callbacks receive no context and are therefore different from the + * onDisconnection callback. + * @param callback + * function pointer to be invoked upon disconnection; receives no context. + * + * @note the disconnection CallChain should have been merged with + * onDisconnctionCallback; but this was not possible because + * FunctionPointer (which is a building block for CallChain) doesn't + * accept variadic templates. + */ + template<typename T> + void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) {disconnectionCallChain.add(tptr, mptr);} + GapState_t getState(void) const { return state; } protected: - Gap() : state(), onTimeout(NULL), onConnection(NULL), onDisconnection(NULL) { + /* Default constructor. */ + Gap() : state(), onTimeout(NULL), onConnection(NULL), onDisconnection(NULL), disconnectionCallChain() { /* empty */ } @@ -120,6 +145,7 @@ if (onDisconnection) { onDisconnection(handle, reason); } + disconnectionCallChain.call(); } void processEvent(GapEvents::gapEvent_e type) { @@ -140,6 +166,7 @@ EventCallback_t onTimeout; ConnectionEventCallback_t onConnection; DisconnectionEventCallback_t onDisconnection; + CallChain disconnectionCallChain; private: /* disallow copy and assignment */