prova invio BLE

Dependents:   BLE_HeartRate_IDB04A1

Fork of BLE_API by Bluetooth Low Energy

Revision:
1062:a3fd424b73ca
Parent:
1053:ec4a5b9b254e
Child:
1063:187f9929cb60
--- a/ble/GattClient.h	Mon Jan 11 08:51:36 2016 +0000
+++ b/ble/GattClient.h	Mon Jan 11 08:51:37 2016 +0000
@@ -326,6 +326,46 @@
     }
 
 protected:
+    /**
+     * Clear all GattClient state of the associated object.
+     *
+     * This function is meant to be overridden in the platform-specific
+     * sub-class. Nevertheless, the sub-class is only expected to clean up its
+     * state and not the data held in GattClient members. This shall be achieved
+     * by a call to GattClient::cleanup() from the sub-class' cleanup()
+     * implementation.
+     *
+     * @return BLE_ERROR_NONE on success.
+     */
+    virtual ble_error_t cleanup(void) {
+        onDataReadCallbackChain.clear();
+        onDataWriteCallbackChain.clear();
+        onHVXCallbackChain.clear();
+
+        return BLE_ERROR_NONE;
+    }
+
+public:
+    /**
+     * Clear all GattClient state of the object pointed to by
+     * gattClientInstance.
+     *
+     * This function is meant to be called by the overridden BLE::shutdown()
+     * in the platform-specific sub-class.
+     *
+     * @return BLE_ERROR_NONE on success.
+     *
+     * @note: If gattClientInstance is NULL then it is assumed that Gap has not
+     * been instantiated and a call to GattClient::shutdown() will succeed.
+     */
+    static ble_error_t shutdown(void) {
+        if (gattClientInstance) {
+            return gattClientInstance->cleanup();
+        }
+        return BLE_ERROR_NONE;
+    }
+
+protected:
     GattClient() {
         /* Empty */
     }
@@ -351,6 +391,10 @@
     WriteCallbackChain_t onDataWriteCallbackChain;
     HVXCallbackChain_t   onHVXCallbackChain;
 
+protected:
+    static GattClient *gattClientInstance;      /**< Pointer to the GattClient object instance.
+                                                 *   If NULL, then GattClient has not been initialized. */
+
 private:
     /* Disallow copy and assignment. */
     GattClient(const GattClient &);