Skip to content

Commit 33da94e

Browse files
author
Rohit Grover
committed
switch onDataSent() to become independent of attribute handle
1 parent e69eff0 commit 33da94e

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

hw/BLEDevice.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class BLEDevice
201201
/**
202202
* Setup a callback for the GATT event DATA_SENT.
203203
*/
204-
void onDataSent(GattServer::EventCallback_t callback);
204+
void onDataSent(GattServer::ServerEventCallback_t callback);
205205

206206
/**
207207
* Setup a callback for when a characteristic has its value updated by a
@@ -415,7 +415,7 @@ BLEDevice::onDisconnection(Gap::EventCallback_t disconnectionCallback)
415415
}
416416

417417
inline void
418-
BLEDevice::onDataSent(GattServer::EventCallback_t callback)
418+
BLEDevice::onDataSent(GattServer::ServerEventCallback_t callback)
419419
{
420420
transport->getGattServer().setOnDataSent(callback);
421421
}

hw/GattServer.h

+19-11
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ class GattServer
4444

4545
/* Event callback handlers. */
4646
typedef void (*EventCallback_t)(uint16_t attributeHandle);
47-
void setOnDataSent(EventCallback_t callback) {
47+
typedef void (*ServerEventCallback_t)(void); /* independent of any particular attribute */
48+
void setOnDataSent(ServerEventCallback_t callback) {
4849
onDataSent = callback;
4950
}
5051
void setOnDataWritten(EventCallback_t callback) {
@@ -62,11 +63,6 @@ class GattServer
6263

6364
void handleEvent(GattServerEvents::gattEvent_e type, uint16_t charHandle) {
6465
switch (type) {
65-
case GattServerEvents::GATT_EVENT_DATA_SENT:
66-
if (onDataSent) {
67-
onDataSent(charHandle);
68-
}
69-
break;
7066
case GattServerEvents::GATT_EVENT_DATA_WRITTEN:
7167
if (onDataWritten) {
7268
onDataWritten(charHandle);
@@ -90,6 +86,18 @@ class GattServer
9086
}
9187
}
9288

89+
void handleEvent(GattServerEvents::gattEvent_e type) {
90+
switch (type) {
91+
case GattServerEvents::GATT_EVENT_DATA_SENT:
92+
if (onDataSent) {
93+
onDataSent();
94+
}
95+
break;
96+
default:
97+
break;
98+
}
99+
}
100+
93101
protected:
94102
GattServer() : serviceCount(0), characteristicCount(0), onDataSent(NULL), onDataWritten(NULL), onUpdatesEnabled(NULL), onUpdatesDisabled(NULL), onConfirmationReceived(NULL) {
95103
/* empty */
@@ -100,11 +108,11 @@ class GattServer
100108
uint8_t characteristicCount;
101109

102110
private:
103-
EventCallback_t onDataSent;
104-
EventCallback_t onDataWritten;
105-
EventCallback_t onUpdatesEnabled;
106-
EventCallback_t onUpdatesDisabled;
107-
EventCallback_t onConfirmationReceived;
111+
ServerEventCallback_t onDataSent;
112+
EventCallback_t onDataWritten;
113+
EventCallback_t onUpdatesEnabled;
114+
EventCallback_t onUpdatesDisabled;
115+
EventCallback_t onConfirmationReceived;
108116
};
109117

110118
#endif // ifndef __GATT_SERVER_H__

0 commit comments

Comments
 (0)