library for BLE_GAP_backpack

Dependencies:   nrf51-sdk

Fork of nRF51822 by Nordic Semiconductor

Revision:
561:613dbbdeed27
Parent:
553:2a413611e569
Child:
563:9c4b96f7be8d
--- a/source/nRF5xGattServer.cpp	Mon Jan 11 10:19:14 2016 +0000
+++ b/source/nRF5xGattServer.cpp	Mon Jan 11 10:19:15 2016 +0000
@@ -23,8 +23,10 @@
 #include "nRF5xGap.h"
 
 nRF5xGattServer &nRF5xGattServer::getInstance(void) {
-    static nRF5xGattServer m_instance;
-    return m_instance;
+    if (gattServerInstance == NULL) {
+        gattServerInstance = new nRF5xGattServer();
+    }
+    return (nRF5xGattServer &) *gattServerInstance;
 }
 
 /**************************************************************************/
@@ -312,6 +314,33 @@
 
 /**************************************************************************/
 /*!
+    @brief  Clear nRF5xGattServer's state.
+
+    @returns    ble_error_t
+
+    @retval     BLE_ERROR_NONE
+                Everything executed properly
+*/
+/**************************************************************************/
+ble_error_t nRF5xGattServer::cleanup(void)
+{
+    /* Clear all state that is from the parent, including private members */
+    if (GattServer::cleanup() != BLE_ERROR_NONE) {
+        return BLE_ERROR_INVALID_STATE;
+    }
+
+    /* Clear derived class members */
+    memset(p_characteristics,        0, sizeof(p_characteristics));
+    memset(p_descriptors,            0, sizeof(p_descriptors));
+    memset(nrfCharacteristicHandles, 0, sizeof(ble_gatts_char_handles_t));
+    memset(nrfDescriptorHandles,     0, sizeof(nrfDescriptorHandles));
+    descriptorCount = 0;
+
+    return BLE_ERROR_NONE;
+}
+
+/**************************************************************************/
+/*!
     @brief  Callback handler for events getting pushed up from the SD
 */
 /**************************************************************************/