From 7e9f9a05302d1ca90654af7fdd57883a08fba0c8 Mon Sep 17 00:00:00 2001 From: Rohit Grover Date: Wed, 3 Dec 2014 11:44:10 +0000 Subject: [PATCH] add API BLEDevice::shutdown() to purge the BLE stack of GATT and GAP state. init() should be called before restoring state. fixes #15. --- common/BLEDeviceInstanceBase.h | 1 + public/BLEDevice.h | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/common/BLEDeviceInstanceBase.h b/common/BLEDeviceInstanceBase.h index b6a7432..20f1dc0 100644 --- a/common/BLEDeviceInstanceBase.h +++ b/common/BLEDeviceInstanceBase.h @@ -28,6 +28,7 @@ public: virtual Gap& getGap() = 0; virtual GattServer& getGattServer() = 0; virtual ble_error_t init(void) = 0; + virtual ble_error_t shutdown(void) = 0; virtual ble_error_t reset(void) = 0; virtual ble_error_t setTxPower(int8_t txPower) = 0; virtual void waitForEvent(void) = 0; diff --git a/public/BLEDevice.h b/public/BLEDevice.h index 98b56a7..67f26b5 100644 --- a/public/BLEDevice.h +++ b/public/BLEDevice.h @@ -36,6 +36,11 @@ public: ble_error_t init(); ble_error_t reset(void); + /** + * Purge the BLE stack of GATT and GAP state. init() must be called afterwards to re-instate services and GAP state. + */ + ble_error_t shutdown(void); + /* GAP specific APIs */ public: /** @@ -364,6 +369,13 @@ BLEDevice::reset(void) return transport->reset(); } +inline ble_error_t +BLEDevice::shutdown(void) +{ + clearAdvertisingPayload(); + return transport->shutdown(); +} + inline ble_error_t BLEDevice::setAddress(Gap::addr_type_t type, const Gap::address_t address) {