fix GattServer::onUpdatesEnabled()

This commit is contained in:
Rohit Grover 2015-06-19 08:46:22 +01:00
parent 16c3c1aa9d
commit 87c8c48d2f
2 changed files with 24 additions and 12 deletions

View file

@ -1192,7 +1192,19 @@ public:
ble_error_t onDataRead(void (*callback)(const GattReadCallbackParams *eventDataP));
template <typename T> 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)
{

View file

@ -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<unsigned> dataSentCallChain;
CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams *> dataWrittenCallChain;
CallChainOfFunctionPointersWithContext<const GattReadCallbackParams *> onDataRead;
EventCallback_t onUpdatesEnabled;
EventCallback_t updatesEnabledCallback;
EventCallback_t onUpdatesDisabled;
EventCallback_t onConfirmationReceived;