Skip to content

Commit e73db5a

Browse files
committed
Introduce new GattServer::EventHandler callback functions for those previously deprecated
1 parent fe906c1 commit e73db5a

File tree

3 files changed

+84
-1
lines changed

3 files changed

+84
-1
lines changed

connectivity/FEATURE_BLE/include/ble/GattServer.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,49 @@ class GattServer {
120120
(void)connectionHandle;
121121
(void)attMtuSize;
122122
}
123+
124+
/**
125+
* Function invoked when the server has sent data to a client as
126+
* part of a notification/indication.
127+
*
128+
* @note params has a temporary scope and should be copied by the
129+
* application if needed later
130+
*/
131+
virtual void onDataSent(const GattDataSentCallbackParams* params) {
132+
(void)params;
133+
}
134+
135+
/**
136+
* Function invoked when the client has subscribed to characteristic updates
137+
*
138+
* @note params has a temporary scope and should be copied by the
139+
* application if needed later
140+
*/
141+
virtual void onUpdatesEnabled(const GattUpdatesEnabledCallbackParams* params) {
142+
(void)params;
143+
}
144+
145+
/**
146+
* Function invoked when the client has unsubscribed to characteristic updates
147+
*
148+
* @note params has a temporary scope and should be copied by the
149+
* application if needed later
150+
*/
151+
virtual void onUpdatesDisabled(const GattUpdatesDisabledCallbackParams* params) {
152+
(void)params;
153+
}
154+
155+
/**
156+
* Function invoked when an ACK has been received for an
157+
* indication sent to the client.
158+
*
159+
* @note params has a temporary scope and should be copied by the
160+
* application if needed later
161+
*/
162+
virtual void onConfirmationReceived(const GattConfirmationReceivedCallbackParams* params) {
163+
(void)params;
164+
}
165+
123166
protected:
124167
/**
125168
* Prevent polymorphic deletion and avoid unnecessary virtual destructor

connectivity/FEATURE_BLE/include/ble/gatt/GattCallbackParamTypes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ struct GattDataSentCallbackParams {
399399
/**
400400
* Attribute Handle to which the event applies
401401
*/
402-
GattAttribute::Handle_t handle;
402+
GattAttribute::Handle_t attHandle;
403403

404404
};
405405

connectivity/FEATURE_BLE/source/cordio/source/GattServerImpl.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,22 +1497,62 @@ void GattServer::handleEvent(
14971497
{
14981498
switch (type) {
14991499
case GattServerEvents::GATT_EVENT_UPDATES_ENABLED:
1500+
1501+
if(eventHandler) {
1502+
GattUpdatesEnabledCallbackParams params({
1503+
.connHandle = connHandle,
1504+
.attHandle = attributeHandle
1505+
});
1506+
eventHandler->onUpdatesEnabled(&params);
1507+
}
1508+
1509+
// Execute deprecated callback
15001510
if (updatesEnabledCallback) {
15011511
updatesEnabledCallback(attributeHandle);
15021512
}
15031513
break;
15041514
case GattServerEvents::GATT_EVENT_UPDATES_DISABLED:
1515+
1516+
if(eventHandler) {
1517+
GattUpdatesDisabledCallbackParams params({
1518+
.connHandle = connHandle,
1519+
.attHandle = attributeHandle
1520+
});
1521+
eventHandler->onUpdatesDisabled(&params);
1522+
}
1523+
1524+
// Execute deprecated callback
15051525
if (updatesDisabledCallback) {
15061526
updatesDisabledCallback(attributeHandle);
15071527
}
15081528
break;
15091529
case GattServerEvents::GATT_EVENT_CONFIRMATION_RECEIVED:
1530+
1531+
if(eventHandler) {
1532+
GattConfirmationReceivedCallbackParams params({
1533+
.connHandle = connHandle,
1534+
.attHandle = attributeHandle
1535+
});
1536+
eventHandler->onConfirmationReceived(&params);
1537+
}
1538+
1539+
// Execute deprecated callback
15101540
if (confirmationReceivedCallback) {
15111541
confirmationReceivedCallback(attributeHandle);
15121542
}
15131543
break;
15141544

15151545
case GattServerEvents::GATT_EVENT_DATA_SENT:
1546+
1547+
if(eventHandler) {
1548+
GattDataSentCallbackParams params({
1549+
.connHandle = connHandle,
1550+
.attHandle = attributeHandle
1551+
});
1552+
eventHandler->onDataSent(&params);
1553+
}
1554+
1555+
// Execute deprecated callback
15161556
// Called every time a notification or indication has been sent
15171557
handleDataSentEvent(1);
15181558
break;

0 commit comments

Comments
 (0)