High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
Diff: ble/GattServer.h
- Revision:
- 1062:a3fd424b73ca
- Parent:
- 1052:b55e1ad3e1b3
- Child:
- 1063:187f9929cb60
--- a/ble/GattServer.h Mon Jan 11 08:51:36 2016 +0000 +++ b/ble/GattServer.h Mon Jan 11 08:51:37 2016 +0000 @@ -397,9 +397,59 @@ } protected: + /** + * Clear all GattServer 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 GattServer members. This shall be achieved + * by a call to GattServer::cleanup() from the sub-class' cleanup() + * implementation. + * + * @return BLE_ERROR_NONE on success. + */ + virtual ble_error_t cleanup(void) { + serviceCount = 0; + characteristicCount = 0; + + dataSentCallChain.clear(); + dataWrittenCallChain.clear(); + dataReadCallChain.clear(); + updatesEnabledCallback = NULL; + updatesDisabledCallback = NULL; + confirmationReceivedCallback = NULL; + + return BLE_ERROR_NONE; + } + +public: + /** + * Clear all GattServer state of the object pointed to by + * gattServerInstance. + * + * 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 gattServerInstance is NULL then it is assumed that Gap has not + * been instantiated and a call to GattServer::shutdown() will succeed. + */ + static ble_error_t shutdown(void) { + if (gattServerInstance) { + return gattServerInstance->cleanup(); + } + return BLE_ERROR_NONE; + } + +protected: uint8_t serviceCount; uint8_t characteristicCount; +protected: + static GattServer *gattServerInstance; /**< Pointer to the GattServer object instance. + * If NULL, then GattServer has not been initialized. */ + private: DataSentCallbackChain_t dataSentCallChain; DataWrittenCallbackChain_t dataWrittenCallChain;