From 183665a01b3fc6b3dc673f27705528da7797c809 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Thu, 18 Jun 2015 20:19:30 +0100 Subject: [PATCH] setup Gap::onDisconnection --- public/BLE.h | 30 ++++++++++++++++-------------- public/Gap.h | 36 ++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/public/BLE.h b/public/BLE.h index 2771a7a..73d2688 100644 --- a/public/BLE.h +++ b/public/BLE.h @@ -1080,16 +1080,30 @@ public: /** * Used to setup a callback for GAP disconnection. + * + * @note: This API is now *deprecated* and will be dropped in the future. + * You should use the parallel API from GattServer directly. A former call + * to ble.onDisconnection(callback) should be replaced with + * ble.gap().onDisconnection(callback). */ - void onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback); + void onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback) { + gap().onDisconnection(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. + * + * @note: This API is now *deprecated* and will be dropped in the future. + * You should use the parallel API from GattServer directly. A former call + * to ble.addToDisconnectionCallchain(...) should be replaced with + * ble.gap().addToDisconnectionCallchain(...). */ template - void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)); + void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) { + gap().addToDisconnectionCallChain(tptr, mptr); + } /** * Add a callback for the GATT event DATA_SENT (which is triggered when @@ -1178,18 +1192,6 @@ typedef BLE BLEDevice; /* DEPRECATED. This type alias is retained for the sake o /* BLE methods. Most of these simply forward the calls to the underlying * transport.*/ -inline void -BLE::onDisconnection(Gap::DisconnectionEventCallback_t disconnectionCallback) -{ - gap().setOnDisconnection(disconnectionCallback); -} - -template -inline void -BLE::addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) { - gap().addToDisconnectionCallChain(tptr, mptr); -} - inline void BLE::onDataSent(void (*callback)(unsigned count)) { transport->getGattServer().setOnDataSent(callback); diff --git a/public/Gap.h b/public/Gap.h index f3d8f64..8fe222e 100644 --- a/public/Gap.h +++ b/public/Gap.h @@ -266,7 +266,7 @@ public: /** * This call initiates the disconnection procedure, and its completion will * be communicated to the application with an invocation of the - * onDisconnection callback. + * disconnectionCallback. * * @param reason * The reason for disconnection to be sent back to the peer. @@ -770,7 +770,17 @@ public: * @param callback * Pointer to the unique callback. */ - void setOnDisconnection(DisconnectionEventCallback_t callback) {onDisconnection = callback;} + void onDisconnection(DisconnectionEventCallback_t callback) {disconnectionCallback = callback;} + + /** + * Append to a chain of callbacks to be invoked upon disconnection; these + * callbacks receive no context and are therefore different from the + * disconnectionCallback callback. + * @param callback + * function pointer to be invoked upon disconnection; receives no context. + */ + template + void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) {disconnectionCallChain.add(tptr, mptr);} /** * Set the application callback for radio-notification events. @@ -807,20 +817,6 @@ public: */ virtual void setOnPasskeyDisplay(PasskeyDisplayCallback_t callback) {onPasskeyDisplay = 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 - void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) {disconnectionCallChain.add(tptr, mptr);} protected: Gap() : @@ -831,7 +827,7 @@ protected: state(), timeoutCallback(NULL), connectionCallback(NULL), - onDisconnection(NULL), + disconnectionCallback(NULL), onRadioNotification(), onSecuritySetupInitiated(), onSecuritySetupCompleted(), @@ -861,8 +857,8 @@ public: void processDisconnectionEvent(Handle_t handle, DisconnectionReason_t reason) { state.connected = 0; - if (onDisconnection) { - onDisconnection(handle, reason); + if (disconnectionCallback) { + disconnectionCallback(handle, reason); } disconnectionCallChain.call(); } @@ -930,7 +926,7 @@ protected: protected: TimeoutEventCallback_t timeoutCallback; ConnectionEventCallback_t connectionCallback; - DisconnectionEventCallback_t onDisconnection; + DisconnectionEventCallback_t disconnectionCallback; RadioNotificationEventCallback_t onRadioNotification; SecuritySetupInitiatedCallback_t onSecuritySetupInitiated; SecuritySetupCompletedCallback_t onSecuritySetupCompleted;