Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
Diff: hw/Gap.h
- Revision:
- 63:653378e782ea
- Parent:
- 40:d405c9b1419d
- Child:
- 73:eeb1ac3545e9
--- a/hw/Gap.h Mon Jun 02 14:58:56 2014 +0100
+++ b/hw/Gap.h Wed Jun 04 09:36:31 2014 +0100
@@ -32,9 +32,6 @@
/**************************************************************************/
class Gap
{
-private:
- GapEvents *m_pEventHandler;
-
public:
typedef enum addr_type_e {
ADDR_TYPE_PUBLIC = 0,
@@ -53,41 +50,62 @@
/* Describes the current state of the device (more than one bit can be
*set) */
- typedef struct GapState_s
- {
- unsigned advertising : 1; /**< The device is current
- *advertising */
- unsigned connected : 1; /**< The peripheral is
- *connected to a central
- *device */
+ typedef struct GapState_s {
+ unsigned advertising : 1; /**< peripheral is currently advertising */
+ unsigned connected : 1; /**< peripheral is connected to a central */
} GapState_t;
/* Event callback handlers */
- void setEventHandler(GapEvents *pEventHandler) {
- m_pEventHandler = pEventHandler;
+ typedef void (*EventCallback_t)(void);
+ void setOnTimeout(EventCallback_t callback) {
+ onTimeout = callback;
+ }
+ void setOnConnection(EventCallback_t callback) {
+ onConnection = callback;
+ }
+ void setOnDisconnection(EventCallback_t callback) {
+ onDisconnection = callback;
}
void handleEvent(GapEvents::gapEvent_e type) {
- if (NULL == m_pEventHandler) {
- return;
- }
switch (type) {
case GapEvents::GAP_EVENT_TIMEOUT:
state.advertising = 0;
- m_pEventHandler->onTimeout();
+ if (onTimeout) {
+ onTimeout();
+ }
break;
case GapEvents::GAP_EVENT_CONNECTED:
state.connected = 1;
- m_pEventHandler->onConnected();
+ if (onConnection) {
+ onConnection();
+ }
break;
case GapEvents::GAP_EVENT_DISCONNECTED:
state.connected = 0;
- m_pEventHandler->onDisconnected();
+ if (onDisconnection) {
+ onDisconnection();
+ }
break;
}
}
+protected:
+ Gap() :
+ state(),
+ onTimeout(NULL),
+ onConnection(NULL),
+ onDisconnection(NULL) {
+ /* empty */
+ }
+
+protected:
GapState_t state;
+
+private:
+ EventCallback_t onTimeout;
+ EventCallback_t onConnection;
+ EventCallback_t onDisconnection;
};
#endif // ifndef __GAP_H__
