Improve readability with getHandle inline

Fork of BLE_API by Bluetooth Low Energy

Revision:
257:6be2b4b0cd71
Parent:
246:aa639ef2f290
diff -r e14bc27b224f -r 6be2b4b0cd71 public/Gap.h
--- a/public/Gap.h	Tue Dec 02 02:51:52 2014 +0000
+++ b/public/Gap.h	Mon Jan 12 14:49:53 2015 -0800
@@ -20,6 +20,9 @@
 #include "GapAdvertisingData.h"
 #include "GapAdvertisingParams.h"
 #include "GapEvents.h"
+#include "CallChain.h"
+
+using namespace mbed;
 
 class Gap {
 public:
@@ -96,14 +99,36 @@
     /* Event callback handlers */
     void setOnTimeout(EventCallback_t callback) {onTimeout = callback;}
     void setOnConnection(ConnectionEventCallback_t callback) {onConnection = callback;}
+
+    /**
+     * Set the application callback for disconnection events.
+     * @param callback
+     *        Pointer to the unique callback.
+     */
     void setOnDisconnection(DisconnectionEventCallback_t callback) {onDisconnection = callback;}
 
+    /**
+     * Append to a chain of callbacks to be invoked upon disconnection; these
+     * callbacks receive no context and are therefore different from the
+     * onDisconnection callback.
+     * @param callback
+     *        function pointer to be invoked upon disconnection; receives no context.
+     *
+     * @note the disconnection CallChain should have been merged with
+     *     onDisconnctionCallback; but this was not possible because
+     *     FunctionPointer (which is a building block for CallChain) doesn't
+     *     accept variadic templates.
+     */
+    template<typename T>
+    void addToDisconnectionCallChain(T *tptr, void (T::*mptr)(void)) {disconnectionCallChain.add(tptr, mptr);}
+
     GapState_t getState(void) const {
         return state;
     }
 
 protected:
-    Gap() : state(), onTimeout(NULL), onConnection(NULL), onDisconnection(NULL) {
+    /* Default constructor. */
+    Gap() : state(), onTimeout(NULL), onConnection(NULL), onDisconnection(NULL), disconnectionCallChain() {
         /* empty */
     }
 
@@ -120,6 +145,7 @@
         if (onDisconnection) {
             onDisconnection(handle, reason);
         }
+        disconnectionCallChain.call();
     }
 
     void processEvent(GapEvents::gapEvent_e type) {
@@ -140,6 +166,7 @@
     EventCallback_t              onTimeout;
     ConnectionEventCallback_t    onConnection;
     DisconnectionEventCallback_t onDisconnection;
+    CallChain                    disconnectionCallChain;
 
 private:
     /* disallow copy and assignment */