Modify shutdown API and functionality
Modify the shutdown API to remove the static shutdown function in Gap, SecurityManager, GattClient and GattServer. Futhermore, remove the static references to Gap, SecurityManager, GattClient and GattServer objects inside their own classes. The cleanup method is renamed to `reset()` and made public. Finally, additional functionality is added to the reset implementation in Gap.
This commit is contained in:
parent
b817cf3e57
commit
cd809e2a2c
10 changed files with 28 additions and 194 deletions
38
ble/Gap.h
38
ble/Gap.h
|
@ -983,21 +983,21 @@ public:
|
|||
radioNotificationCallback.attach(tptr, mptr);
|
||||
}
|
||||
|
||||
protected:
|
||||
public:
|
||||
/**
|
||||
* Clear all Gap 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
|
||||
* sub-class. Nevertheless, the sub-class is only expected to reset its
|
||||
* state and not the data held in Gap members. This shall be achieved by a
|
||||
* call to Gap::cleanup() from the sub-class' cleanup() implementation.
|
||||
* call to Gap::reset() from the sub-class' reset() implementation.
|
||||
*
|
||||
* @return BLE_ERROR_NONE on success.
|
||||
*
|
||||
* @note: Currently a call to cleanup() does not reset the advertising and
|
||||
* @note: Currently a call to reset() does not reset the advertising and
|
||||
* scan parameters to default values.
|
||||
*/
|
||||
virtual ble_error_t cleanup(void) {
|
||||
virtual ble_error_t reset(void) {
|
||||
/* Clear Gap state */
|
||||
state.advertising = 0;
|
||||
state.connected = 0;
|
||||
|
@ -1009,25 +1009,13 @@ protected:
|
|||
_advPayload.clear();
|
||||
_scanResponse.clear();
|
||||
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
/* Clear callbacks */
|
||||
timeoutCallbackChain.clear();
|
||||
connectionCallChain.clear();
|
||||
disconnectionCallChain.clear();
|
||||
radioNotificationCallback = NULL;
|
||||
onAdvertisementReport = NULL;
|
||||
|
||||
public:
|
||||
/**
|
||||
* Clear all Gap state of the object pointed to by gapInstance.
|
||||
*
|
||||
* 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 gapInstance is NULL then it is assumed that Gap has not been
|
||||
* instantiated and a call to Gap::shutdown() will succeed.
|
||||
*/
|
||||
static ble_error_t shutdown(void) {
|
||||
if (gapInstance) {
|
||||
return gapInstance->cleanup();
|
||||
}
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
@ -1099,10 +1087,6 @@ protected:
|
|||
GapState_t state;
|
||||
bool scanningActive;
|
||||
|
||||
protected:
|
||||
static Gap *gapInstance; /**< Pointer to the Gap object instance.
|
||||
* If NULL, then Gap has not been initialized. */
|
||||
|
||||
protected:
|
||||
TimeoutEventCallbackChain_t timeoutCallbackChain;
|
||||
RadioNotificationEventCallback_t radioNotificationCallback;
|
||||
|
|
|
@ -325,19 +325,19 @@ public:
|
|||
return onHVXCallbackChain;
|
||||
}
|
||||
|
||||
protected:
|
||||
public:
|
||||
/**
|
||||
* 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
|
||||
* sub-class. Nevertheless, the sub-class is only expected to reset 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()
|
||||
* by a call to GattClient::reset() from the sub-class' reset()
|
||||
* implementation.
|
||||
*
|
||||
* @return BLE_ERROR_NONE on success.
|
||||
*/
|
||||
virtual ble_error_t cleanup(void) {
|
||||
virtual ble_error_t reset(void) {
|
||||
onDataReadCallbackChain.clear();
|
||||
onDataWriteCallbackChain.clear();
|
||||
onHVXCallbackChain.clear();
|
||||
|
@ -345,26 +345,6 @@ protected:
|
|||
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 */
|
||||
|
@ -391,10 +371,6 @@ protected:
|
|||
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 &);
|
||||
|
|
|
@ -396,19 +396,19 @@ protected:
|
|||
dataSentCallChain.call(count);
|
||||
}
|
||||
|
||||
protected:
|
||||
public:
|
||||
/**
|
||||
* 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
|
||||
* sub-class. Nevertheless, the sub-class is only expected to reset 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()
|
||||
* by a call to GattServer::reset() from the sub-class' reset()
|
||||
* implementation.
|
||||
*
|
||||
* @return BLE_ERROR_NONE on success.
|
||||
*/
|
||||
virtual ble_error_t cleanup(void) {
|
||||
virtual ble_error_t reset(void) {
|
||||
serviceCount = 0;
|
||||
characteristicCount = 0;
|
||||
|
||||
|
@ -422,34 +422,10 @@ protected:
|
|||
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;
|
||||
|
|
|
@ -231,19 +231,19 @@ protected:
|
|||
/* empty */
|
||||
}
|
||||
|
||||
protected:
|
||||
public:
|
||||
/**
|
||||
* Clear all SecurityManager 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
|
||||
* sub-class. Nevertheless, the sub-class is only expected to reset its
|
||||
* state and not the data held in SecurityManager members. This shall be
|
||||
* achieved by a call to SecurityManager::cleanup() from the sub-class'
|
||||
* cleanup() implementation.
|
||||
* achieved by a call to SecurityManager::reset() from the sub-class'
|
||||
* reset() implementation.
|
||||
*
|
||||
* @return BLE_ERROR_NONE on success.
|
||||
*/
|
||||
virtual ble_error_t cleanup(void) {
|
||||
virtual ble_error_t reset(void) {
|
||||
securitySetupInitiatedCallback = NULL;
|
||||
securitySetupCompletedCallback = NULL;
|
||||
linkSecuredCallback = NULL;
|
||||
|
@ -253,31 +253,6 @@ protected:
|
|||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* Clear all SecurityManager state of the object pointed to by
|
||||
* securityManagerInstance.
|
||||
*
|
||||
* 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 securityManagerInstance is NULL then it is assumed that Gap has
|
||||
* not been instantiated and a call to SecurityManager::shutdown() will
|
||||
* succeed.
|
||||
*/
|
||||
static ble_error_t shutdown(void) {
|
||||
if (securityManagerInstance) {
|
||||
return securityManagerInstance->cleanup();
|
||||
}
|
||||
return BLE_ERROR_NONE;
|
||||
}
|
||||
|
||||
protected:
|
||||
static SecurityManager *securityManagerInstance; /**< Pointer to the SecurityManager object instance.
|
||||
* If NULL, then SecurityManager has not been initialized. */
|
||||
|
||||
protected:
|
||||
SecuritySetupInitiatedCallback_t securitySetupInitiatedCallback;
|
||||
SecuritySetupCompletedCallback_t securitySetupCompletedCallback;
|
||||
|
|
|
@ -136,14 +136,14 @@ public:
|
|||
* Clear all ServiceDiscovery 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
|
||||
* sub-class. Nevertheless, the sub-class is only expected to reset its
|
||||
* state and not the data held in ServiceDiscovery members. This shall be
|
||||
* achieved by a call to ServiceDiscovery::cleanup() from the sub-class'
|
||||
* cleanup() implementation.
|
||||
* achieved by a call to ServiceDiscovery::reset() from the sub-class'
|
||||
* reset() implementation.
|
||||
*
|
||||
* @return BLE_ERROR_NONE on success.
|
||||
*/
|
||||
virtual ble_error_t cleanup(void) {
|
||||
virtual ble_error_t reset(void) {
|
||||
connHandle = 0;
|
||||
matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN);
|
||||
serviceCallback = NULL;
|
||||
|
|
|
@ -131,7 +131,6 @@ bool BLE::hasInitialized(void) const
|
|||
|
||||
ble_error_t BLE::shutdown(void)
|
||||
{
|
||||
clearAdvertisingPayload();
|
||||
if (!transport) {
|
||||
error("bad handle to underlying transport");
|
||||
}
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ble/Gap.h"
|
||||
|
||||
Gap *Gap::gapInstance = NULL;
|
|
@ -1,19 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ble/GattClient.h"
|
||||
|
||||
GattClient *GattClient::gattClientInstance = NULL;
|
|
@ -1,19 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ble/GattServer.h"
|
||||
|
||||
GattServer *GattServer::gattServerInstance = NULL;
|
|
@ -1,19 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "ble/SecurityManager.h"
|
||||
|
||||
SecurityManager *SecurityManager::securityManagerInstance = NULL;
|
Loading…
Reference in a new issue