High level Bluetooth Low Energy API and radio abstraction layer

Fork of BLE_API by Bluetooth Low Energy

Revision:
986:5292837107a3
Parent:
976:043b3bd94ee0
Child:
990:53ac0ac3aa39
--- a/ble/Gap.h	Thu Nov 26 12:52:37 2015 +0000
+++ b/ble/Gap.h	Thu Nov 26 14:51:21 2015 +0000
@@ -140,15 +140,10 @@
         return (durationInMillis * 1000) / UNIT_1_25_MS;
     }
 
-    typedef FunctionPointerWithContext<TimeoutSource_t> TimeoutEventCallback_t;
-    typedef CallChainOfFunctionPointersWithContext<TimeoutSource_t> TimeoutEventCallbackChain_t;
 
-    typedef FunctionPointerWithContext<const ConnectionCallbackParams_t *> ConnectionEventCallback_t;
-    typedef CallChainOfFunctionPointersWithContext<const ConnectionCallbackParams_t *> ConnectionEventCallbackChain_t;
-
-    typedef FunctionPointerWithContext<const DisconnectionCallbackParams_t*> DisconnectionEventCallback_t;
-    typedef CallChainOfFunctionPointersWithContext<const DisconnectionCallbackParams_t*> DisconnectionEventCallbackChain_t;    
-
+    typedef void (*TimeoutEventCallback_t)(TimeoutSource_t source);
+    typedef void (*ConnectionEventCallback_t)(const ConnectionCallbackParams_t *params);
+    typedef void (*DisconnectionEventCallback_t)(const DisconnectionCallbackParams_t *params);
     typedef FunctionPointerWithContext<bool> RadioNotificationEventCallback_t;
 
     /*
@@ -897,25 +892,11 @@
     /**
      * Set up a callback for timeout events. Refer to TimeoutSource_t for
      * possible event types.
-     * @note It is possible to unregister callbacks using onTimeout().detach(callback)
      */
-    void onTimeout(TimeoutEventCallback_t callback) {
-        timeoutCallbackChain.add(callback);
-    }
-
-    /**
-     * @brief provide access to the callchain of timeout event callbacks
-     * It is possible to register callbacks using onTimeout().add(callback);
-     * It is possible to unregister callbacks using onTimeout().detach(callback) 
-     * @return The timeout event callbacks chain
-     */
-    TimeoutEventCallbackChain_t& onTimeout() {
-        return timeoutCallbackChain;
-    }
+    void onTimeout(TimeoutEventCallback_t callback) {timeoutCallback = callback;}
 
     /**
      * Append to a chain of callbacks to be invoked upon GAP connection.
-     * @note It is possible to unregister callbacks using onConnection().detach(callback)
      */
     void onConnection(ConnectionEventCallback_t callback) {connectionCallChain.add(callback);}
 
@@ -923,18 +904,7 @@
     void onConnection(T *tptr, void (T::*mptr)(const ConnectionCallbackParams_t*)) {connectionCallChain.add(tptr, mptr);}
 
     /**
-     * @brief provide access to the callchain of connection event callbacks
-     * It is possible to register callbacks using onConnection().add(callback);
-     * It is possible to unregister callbacks using onConnection().detach(callback) 
-     * @return The connection event callbacks chain
-     */
-    ConnectionEventCallbackChain_t& onconnection() { 
-        return connectionCallChain;
-    }
-
-    /**
      * Append to a chain of callbacks to be invoked upon GAP disconnection.
-     * @note It is possible to unregister callbacks using onDisconnection().detach(callback)
      */
     void onDisconnection(DisconnectionEventCallback_t callback) {disconnectionCallChain.add(callback);}
 
@@ -942,16 +912,6 @@
     void onDisconnection(T *tptr, void (T::*mptr)(const DisconnectionCallbackParams_t*)) {disconnectionCallChain.add(tptr, mptr);}
 
     /**
-     * @brief provide access to the callchain of disconnection event callbacks
-     * It is possible to register callbacks using onDisconnection().add(callback);
-     * It is possible to unregister callbacks using onDisconnection().detach(callback) 
-     * @return The disconnection event callbacks chain
-     */
-    DisconnectionEventCallbackChain_t& onDisconnection() {
-        return disconnectionCallChain;
-    }
-
-    /**
      * Set the application callback for radio-notification events.
      *
      * Radio Notification is a feature that enables ACTIVE and INACTIVE
@@ -980,10 +940,12 @@
      */
     void onRadioNotification(void (*callback)(bool param)) {
         radioNotificationCallback.attach(callback);
+        initRadioNotification();
     }
     template <typename T>
     void onRadioNotification(T *tptr, void (T::*mptr)(bool)) {
         radioNotificationCallback.attach(tptr, mptr);
+        initRadioNotification();
     }
 
 protected:
@@ -994,7 +956,7 @@
         _scanResponse(),
         state(),
         scanningActive(false),
-        timeoutCallbackChain(),
+        timeoutCallback(NULL),
         radioNotificationCallback(),
         onAdvertisementReport(),
         connectionCallChain(),
@@ -1040,8 +1002,8 @@
     }
 
     void processTimeoutEvent(TimeoutSource_t source) {
-        if (timeoutCallbackChain) {
-            timeoutCallbackChain(source);
+        if (timeoutCallback) {
+            timeoutCallback(source);
         }
     }
 
@@ -1055,11 +1017,11 @@
     bool                             scanningActive;
 
 protected:
-    TimeoutEventCallbackChain_t       timeoutCallbackChain;
-    RadioNotificationEventCallback_t  radioNotificationCallback;
-    AdvertisementReportCallback_t     onAdvertisementReport;
-    ConnectionEventCallbackChain_t    connectionCallChain;
-    DisconnectionEventCallbackChain_t disconnectionCallChain;
+    TimeoutEventCallback_t           timeoutCallback;
+    RadioNotificationEventCallback_t radioNotificationCallback;
+    AdvertisementReportCallback_t    onAdvertisementReport;
+    CallChainOfFunctionPointersWithContext<const ConnectionCallbackParams_t*>    connectionCallChain;
+    CallChainOfFunctionPointersWithContext<const DisconnectionCallbackParams_t*> disconnectionCallChain;
 
 private:
     /* Disallow copy and assignment. */