connection and disconnection callbacks need to take a connection handle

master
Rohit Grover 2014-07-10 12:12:06 +01:00
parent 8c0e55c918
commit fd4b9e57cb
2 changed files with 29 additions and 20 deletions

View File

@ -208,12 +208,13 @@ public:
ble_error_t disconnect(void);
/* APIs to set GAP callbacks. */
void onTimeout(Gap::EventCallback_t timeoutCallback);
void onConnection(Gap::EventCallback_t connectionCallback);
void onTimeout(Gap::EventCallback_t timeoutCallback);
void onConnection(Gap::HandleSpecificEventCallback_t connectionCallback);
/**
* Used to setup a callback for GAP disconnection.
*/
void onDisconnection(Gap::EventCallback_t disconnectionCallback);
void onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback);
/**
* Setup a callback for the GATT event DATA_SENT.
@ -417,13 +418,13 @@ BLEDevice::onTimeout(Gap::EventCallback_t timeoutCallback)
}
inline void
BLEDevice::onConnection(Gap::EventCallback_t connectionCallback)
BLEDevice::onConnection(Gap::HandleSpecificEventCallback_t connectionCallback)
{
transport->getGap().setOnConnection(connectionCallback);
}
inline void
BLEDevice::onDisconnection(Gap::EventCallback_t disconnectionCallback)
BLEDevice::onDisconnection(Gap::HandleSpecificEventCallback_t disconnectionCallback)
{
transport->getGap().setOnDisconnection(disconnectionCallback);
}

View File

@ -54,36 +54,44 @@ public:
unsigned connected : 1; /**< peripheral is connected to a central */
} GapState_t;
/* Event callback handlers */
typedef void (*EventCallback_t)(void);
typedef uint16_t Handle_t;
typedef void (*HandleSpecificEventCallback_t)(Handle_t);
/* Event callback handlers */
void setOnTimeout(EventCallback_t callback) {
onTimeout = callback;
}
void setOnConnection(EventCallback_t callback) {
void setOnConnection(HandleSpecificEventCallback_t callback) {
onConnection = callback;
}
void setOnDisconnection(EventCallback_t callback) {
void setOnDisconnection(HandleSpecificEventCallback_t callback) {
onDisconnection = callback;
}
void handleEvent(GapEvents::gapEvent_e type) {
void processHandleSpecificEvent(GapEvents::gapEvent_e type, Handle_t handle) {
switch (type) {
case GapEvents::GAP_EVENT_TIMEOUT:
state.advertising = 0;
if (onTimeout) {
onTimeout();
}
break;
case GapEvents::GAP_EVENT_CONNECTED:
state.connected = 1;
if (onConnection) {
onConnection();
onConnection(handle);
}
break;
case GapEvents::GAP_EVENT_DISCONNECTED:
state.connected = 0;
if (onDisconnection) {
onDisconnection();
onDisconnection(handle);
}
break;
}
}
void processEvent(GapEvents::gapEvent_e type) {
switch (type) {
case GapEvents::GAP_EVENT_TIMEOUT:
state.advertising = 0;
if (onTimeout) {
onTimeout();
}
break;
}
@ -102,9 +110,9 @@ protected:
GapState_t state;
private:
EventCallback_t onTimeout;
EventCallback_t onConnection;
EventCallback_t onDisconnection;
EventCallback_t onTimeout;
HandleSpecificEventCallback_t onConnection;
HandleSpecificEventCallback_t onDisconnection;
};
#endif // ifndef __GAP_H__