Skip to content

Commit fd4b9e5

Browse files
author
Rohit Grover
committed
connection and disconnection callbacks need to take a connection handle
1 parent 8c0e55c commit fd4b9e5

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

hw/BLEDevice.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,13 @@ class BLEDevice
208208
ble_error_t disconnect(void);
209209

210210
/* APIs to set GAP callbacks. */
211-
void onTimeout(Gap::EventCallback_t timeoutCallback);
212-
void onConnection(Gap::EventCallback_t connectionCallback);
211+
void onTimeout(Gap::EventCallback_t timeoutCallback);
212+
213+
void onConnection(Gap::HandleSpecificEventCallback_t connectionCallback);
213214
/**
214215
* Used to setup a callback for GAP disconnection.
215216
*/
216-
void onDisconnection(Gap::EventCallback_t disconnectionCallback);
217+
void onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback);
217218

218219
/**
219220
* Setup a callback for the GATT event DATA_SENT.
@@ -417,13 +418,13 @@ BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback)
417418
}
418419

419420
inline void
420-
BLEDevice::onConnection(Gap::EventCallback_t connectionCallback)
421+
BLEDevice::onConnection(Gap::HandleSpecificEventCallback_t connectionCallback)
421422
{
422423
transport->getGap().setOnConnection(connectionCallback);
423424
}
424425

425426
inline void
426-
BLEDevice::onDisconnection(Gap::EventCallback_t disconnectionCallback)
427+
BLEDevice::onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback)
427428
{
428429
transport->getGap().setOnDisconnection(disconnectionCallback);
429430
}

hw/Gap.h

+23-15
Original file line numberDiff line numberDiff line change
@@ -54,36 +54,44 @@ class Gap
5454
unsigned connected : 1; /**< peripheral is connected to a central */
5555
} GapState_t;
5656

57-
/* Event callback handlers */
5857
typedef void (*EventCallback_t)(void);
58+
typedef uint16_t Handle_t;
59+
typedef void (*HandleSpecificEventCallback_t)(Handle_t);
60+
61+
/* Event callback handlers */
5962
void setOnTimeout(EventCallback_t callback) {
6063
onTimeout = callback;
6164
}
62-
void setOnConnection(EventCallback_t callback) {
65+
void setOnConnection(HandleSpecificEventCallback_t callback) {
6366
onConnection = callback;
6467
}
65-
void setOnDisconnection(EventCallback_t callback) {
68+
void setOnDisconnection(HandleSpecificEventCallback_t callback) {
6669
onDisconnection = callback;
6770
}
6871

69-
void handleEvent(GapEvents::gapEvent_e type) {
72+
void processHandleSpecificEvent(GapEvents::gapEvent_e type, Handle_t handle) {
7073
switch (type) {
71-
case GapEvents::GAP_EVENT_TIMEOUT:
72-
state.advertising = 0;
73-
if (onTimeout) {
74-
onTimeout();
75-
}
76-
break;
7774
case GapEvents::GAP_EVENT_CONNECTED:
7875
state.connected = 1;
7976
if (onConnection) {
80-
onConnection();
77+
onConnection(handle);
8178
}
8279
break;
8380
case GapEvents::GAP_EVENT_DISCONNECTED:
8481
state.connected = 0;
8582
if (onDisconnection) {
86-
onDisconnection();
83+
onDisconnection(handle);
84+
}
85+
break;
86+
}
87+
}
88+
89+
void processEvent(GapEvents::gapEvent_e type) {
90+
switch (type) {
91+
case GapEvents::GAP_EVENT_TIMEOUT:
92+
state.advertising = 0;
93+
if (onTimeout) {
94+
onTimeout();
8795
}
8896
break;
8997
}
@@ -102,9 +110,9 @@ class Gap
102110
GapState_t state;
103111

104112
private:
105-
EventCallback_t onTimeout;
106-
EventCallback_t onConnection;
107-
EventCallback_t onDisconnection;
113+
EventCallback_t onTimeout;
114+
HandleSpecificEventCallback_t onConnection;
115+
HandleSpecificEventCallback_t onDisconnection;
108116
};
109117

110118
#endif // ifndef __GAP_H__

0 commit comments

Comments
 (0)