Lancaster University's fork of the mbed BLE API. Lives on github, https://github.com/lancaster-university/BLE_API

Dependents:   microbit-dal microbit-dal microbit-ble-open microbit-dal ... more

Fork of BLE_API by Bluetooth Low Energy

Files at this revision

API Documentation at this revision

Comitter:
LancasterUniversity
Date:
Wed Apr 06 18:40:40 2016 +0100
Parent:
1139:9af191d14c05
Commit message:
Synchronized with git rev bbc2dc58
Author: Joe Finney
microbit: Additional callback to indicate to applications when System
Attributes require initialisation from persistent storage.

Changed in this revision

ble/GattCallbackParamTypes.h Show annotated file Show diff for this revision Revisions of this file
ble/GattServer.h Show annotated file Show diff for this revision Revisions of this file
ble/GattServerEvents.h Show annotated file Show diff for this revision Revisions of this file
diff -r 9af191d14c05 -r dd2f69fad8c6 ble/GattCallbackParamTypes.h
--- a/ble/GattCallbackParamTypes.h	Wed Apr 06 18:40:39 2016 +0100
+++ b/ble/GattCallbackParamTypes.h	Wed Apr 06 18:40:40 2016 +0100
@@ -44,6 +44,10 @@
     const uint8_t           *data;    /* @note: Data might not persist beyond the callback; make a local copy if needed. */
 };
 
+struct GattSysAttrMissingCallbackParams {
+    Gap::Handle_t            connHandle;
+};
+
 enum GattAuthCallbackReply_t {
     AUTH_CALLBACK_REPLY_SUCCESS                       = 0x00,    /**< Success. */
     AUTH_CALLBACK_REPLY_ATTERR_INVALID_HANDLE         = 0x0101,  /**< ATT Error: Invalid attribute handle. */
diff -r 9af191d14c05 -r dd2f69fad8c6 ble/GattServer.h
--- a/ble/GattServer.h	Wed Apr 06 18:40:39 2016 +0100
+++ b/ble/GattServer.h	Wed Apr 06 18:40:40 2016 +0100
@@ -39,6 +39,9 @@
     typedef FunctionPointerWithContext<const GattServer *> GattServerShutdownCallback_t;
     typedef CallChainOfFunctionPointersWithContext<const GattServer *> GattServerShutdownCallbackChain_t;
 
+    typedef FunctionPointerWithContext<const GattSysAttrMissingCallbackParams*> SysAttrMissingCallback_t;
+    typedef CallChainOfFunctionPointersWithContext<const GattSysAttrMissingCallbackParams*> SysAttrMissingCallbackChain_t;
+
     typedef FunctionPointerWithContext<GattAttribute::Handle_t> EventCallback_t;
 
 protected:
@@ -48,6 +51,7 @@
         dataSentCallChain(),
         dataWrittenCallChain(),
         dataReadCallChain(),
+        sysAttrMissingCallChain(),
         updatesEnabledCallback(NULL),
         updatesDisabledCallback(NULL),
         confirmationReceivedCallback(NULL) {
@@ -317,6 +321,36 @@
     }
 
     /**
+     * Set up a callback for when asystem descriptor (CCCD) is missing.
+     * This may be raised in response to a BLE profile change om a bonded connection.
+     * This callback provides the opportunity for user applications to restore
+     * CCCD state at the appropriate time.
+     *
+     * @Note: It is possible to chain together multiple onSysAttrMissing callbacks
+     * (potentially from different modules of an application), although it is unlikely
+     * that this will be beneficial.
+     *
+     * @Note: It is also possible to set up a callback into a member function of
+     * some object.
+     *
+     * @Note It is possible to unregister a callback using onSysAttrMissing().detach(callback)
+     */
+    void onSysAttrMissing(const SysAttrMissingCallback_t& callback) {sysAttrMissingCallChain.add(callback);}
+    template <typename T>
+    void onSysAttrMissing(T *objPtr, void (T::*memberPtr)(const GattSysAttrMissingCallbackParams* connectionHandle)) {
+        sysAttrMissingCallChain.add(objPtr, memberPtr);
+    }
+
+    /**
+     * @brief provide access to the callchain of data written event callbacks
+     * It is possible to register callbacks using onDataWritten().add(callback);
+     * It is possible to unregister callbacks using onDataWritten().detach(callback)
+     * @return The data written event callbacks chain
+     */
+    SysAttrMissingCallbackChain_t& onSysAttrMissing() {
+        return sysAttrMissingCallChain;
+    }
+    /**
      * Setup a callback to be invoked on the peripheral when an attribute is
      * being read by a remote client.
      *
@@ -417,6 +451,10 @@
 
     /* Entry points for the underlying stack to report events back to the user. */
 protected:
+    void handleSysAttrMissingEvent(const GattSysAttrMissingCallbackParams *params) {
+        sysAttrMissingCallChain.call(params);
+    }
+
     void handleDataWrittenEvent(const GattWriteCallbackParams *params) {
         dataWrittenCallChain.call(params);
     }
@@ -476,6 +514,7 @@
         dataSentCallChain.clear();
         dataWrittenCallChain.clear();
         dataReadCallChain.clear();
+        sysAttrMissingCallChain.clear();
         updatesEnabledCallback       = NULL;
         updatesDisabledCallback      = NULL;
         confirmationReceivedCallback = NULL;
@@ -491,6 +530,7 @@
     DataSentCallbackChain_t           dataSentCallChain;
     DataWrittenCallbackChain_t        dataWrittenCallChain;
     DataReadCallbackChain_t           dataReadCallChain;
+    SysAttrMissingCallbackChain_t     sysAttrMissingCallChain;
     GattServerShutdownCallbackChain_t shutdownCallChain;
     EventCallback_t                   updatesEnabledCallback;
     EventCallback_t                   updatesDisabledCallback;
diff -r 9af191d14c05 -r dd2f69fad8c6 ble/GattServerEvents.h
--- a/ble/GattServerEvents.h	Wed Apr 06 18:40:39 2016 +0100
+++ b/ble/GattServerEvents.h	Wed Apr 06 18:40:40 2016 +0100
@@ -32,7 +32,7 @@
         GATT_EVENT_UPDATES_DISABLED        = 4,  /**< Notify/Indicate disabled in CCCD. */
         GATT_EVENT_CONFIRMATION_RECEIVED   = 5,  /**< Response received from Indicate message. */
         GATT_EVENT_READ_AUTHORIZATION_REQ  = 6,  /**< Request application to authorize read. */
-        GATT_EVENT_WRITE_AUTHORIZATION_REQ = 7,  /**< Request application to authorize write. */
+        GATT_EVENT_WRITE_AUTHORIZATION_REQ = 7  /**< Request application to authorize write. */
     } gattEvent_t;
 };