From 87c8c48d2f6ad1899f0e167c1ef72dd9314f364b Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Fri, 19 Jun 2015 08:46:22 +0100 Subject: [PATCH] fix GattServer::onUpdatesEnabled() --- public/BLE.h | 20 +++++++++++++------- public/GattServer.h | 16 +++++++++++----- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/public/BLE.h b/public/BLE.h index 574957f..e7136a5 100644 --- a/public/BLE.h +++ b/public/BLE.h @@ -1192,7 +1192,19 @@ public: ble_error_t onDataRead(void (*callback)(const GattReadCallbackParams *eventDataP)); template ble_error_t onDataRead(T * objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context)); - void onUpdatesEnabled(GattServer::EventCallback_t callback); + /** + * Setup a callback for when notifications/indications are enabled for a + * characteristic on the local GattServer. + * + * @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.onUpdatesEnabled(...) should be replaced with + * ble.gattServer().onUpdatesEnabled(...). + */ + void onUpdatesEnabled(GattServer::EventCallback_t callback) { + gattServer().onUpdatesEnabled(callback); + } + void onUpdatesDisabled(GattServer::EventCallback_t callback); void onConfirmationReceived(GattServer::EventCallback_t callback); @@ -1298,12 +1310,6 @@ BLE::onDataRead(T *objPtr, void (T::*memberPtr)(const GattReadCallbackParams *co return transport->getGattServer().setOnDataRead(objPtr, memberPtr); } -inline void -BLE::onUpdatesEnabled(GattServer::EventCallback_t callback) -{ - transport->getGattServer().setOnUpdatesEnabled(callback); -} - inline void BLE::onUpdatesDisabled(GattServer::EventCallback_t callback) { diff --git a/public/GattServer.h b/public/GattServer.h index 18f9aa0..9874a26 100644 --- a/public/GattServer.h +++ b/public/GattServer.h @@ -37,7 +37,7 @@ protected: dataSentCallChain(), dataWrittenCallChain(), onDataRead(), - onUpdatesEnabled(NULL), + updatesEnabledCallback(NULL), onUpdatesDisabled(NULL), onConfirmationReceived(NULL) { /* empty */ @@ -205,7 +205,13 @@ public: onDataRead.add(objPtr, memberPtr); return BLE_ERROR_NONE; } - void setOnUpdatesEnabled(EventCallback_t callback) {onUpdatesEnabled = callback;} + + /** + * Setup a callback for when notifications/indications are enabled for a + * characteristic on the local GattServer. + */ + void onUpdatesEnabled(EventCallback_t callback) {updatesEnabledCallback = callback;} + void setOnUpdatesDisabled(EventCallback_t callback) {onUpdatesDisabled = callback;} void setOnConfirmationReceived(EventCallback_t callback) {onConfirmationReceived = callback;} @@ -225,8 +231,8 @@ protected: void handleEvent(GattServerEvents::gattEvent_e type, GattAttribute::Handle_t charHandle) { switch (type) { case GattServerEvents::GATT_EVENT_UPDATES_ENABLED: - if (onUpdatesEnabled) { - onUpdatesEnabled(charHandle); + if (updatesEnabledCallback) { + updatesEnabledCallback(charHandle); } break; case GattServerEvents::GATT_EVENT_UPDATES_DISABLED: @@ -258,7 +264,7 @@ private: CallChainOfFunctionPointersWithContext dataSentCallChain; CallChainOfFunctionPointersWithContext dataWrittenCallChain; CallChainOfFunctionPointersWithContext onDataRead; - EventCallback_t onUpdatesEnabled; + EventCallback_t updatesEnabledCallback; EventCallback_t onUpdatesDisabled; EventCallback_t onConfirmationReceived;