Skip to content

Commit

Permalink
Merge pull request #141 from andresag01/develop
Browse files Browse the repository at this point in the history
Improve API to facilitate full shutdown procedure
  • Loading branch information
rgrover committed Dec 16, 2015
2 parents b8fde92 + cd809e2 commit 1e448f8
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 1 deletion.
36 changes: 36 additions & 0 deletions ble/Gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,42 @@ class Gap {
radioNotificationCallback.attach(tptr, mptr);
}

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 reset its
* state and not the data held in Gap members. This shall be achieved by a
* call to Gap::reset() from the sub-class' reset() implementation.
*
* @return BLE_ERROR_NONE on success.
*
* @note: Currently a call to reset() does not reset the advertising and
* scan parameters to default values.
*/
virtual ble_error_t reset(void) {
/* Clear Gap state */
state.advertising = 0;
state.connected = 0;

/* Clear scanning state */
scanningActive = false;

/* Clear advertising and scanning data */
_advPayload.clear();
_scanResponse.clear();

/* Clear callbacks */
timeoutCallbackChain.clear();
connectionCallChain.clear();
disconnectionCallChain.clear();
radioNotificationCallback = NULL;
onAdvertisementReport = NULL;

return BLE_ERROR_NONE;
}

protected:
Gap() :
_advParams(),
Expand Down
20 changes: 20 additions & 0 deletions ble/GattClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,26 @@ class GattClient {
return onHVXCallbackChain;
}

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 reset its
* state and not the data held in GattClient members. This shall be achieved
* by a call to GattClient::reset() from the sub-class' reset()
* implementation.
*
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t reset(void) {
onDataReadCallbackChain.clear();
onDataWriteCallbackChain.clear();
onHVXCallbackChain.clear();

return BLE_ERROR_NONE;
}

protected:
GattClient() {
/* Empty */
Expand Down
26 changes: 26 additions & 0 deletions ble/GattServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,32 @@ class GattServer {
dataSentCallChain.call(count);
}

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 reset its
* state and not the data held in GattServer members. This shall be achieved
* by a call to GattServer::reset() from the sub-class' reset()
* implementation.
*
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t reset(void) {
serviceCount = 0;
characteristicCount = 0;

dataSentCallChain.clear();
dataWrittenCallChain.clear();
dataReadCallChain.clear();
updatesEnabledCallback = NULL;
updatesDisabledCallback = NULL;
confirmationReceivedCallback = NULL;

return BLE_ERROR_NONE;
}

protected:
uint8_t serviceCount;
uint8_t characteristicCount;
Expand Down
22 changes: 22 additions & 0 deletions ble/SecurityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,28 @@ class SecurityManager {
/* empty */
}

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 reset its
* state and not the data held in SecurityManager members. This shall be
* achieved by a call to SecurityManager::reset() from the sub-class'
* reset() implementation.
*
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t reset(void) {
securitySetupInitiatedCallback = NULL;
securitySetupCompletedCallback = NULL;
linkSecuredCallback = NULL;
securityContextStoredCallback = NULL;
passkeyDisplayCallback = NULL;

return BLE_ERROR_NONE;
}

protected:
SecuritySetupInitiatedCallback_t securitySetupInitiatedCallback;
SecuritySetupCompletedCallback_t securitySetupCompletedCallback;
Expand Down
21 changes: 21 additions & 0 deletions ble/ServiceDiscovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,27 @@ class ServiceDiscovery {
*/
virtual void onTermination(TerminationCallback_t callback) = 0;

/**
* 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 reset its
* state and not the data held in ServiceDiscovery members. This shall be
* achieved by a call to ServiceDiscovery::reset() from the sub-class'
* reset() implementation.
*
* @return BLE_ERROR_NONE on success.
*/
virtual ble_error_t reset(void) {
connHandle = 0;
matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN);
serviceCallback = NULL;
matchingCharacteristicUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN);
characteristicCallback = NULL;

return BLE_ERROR_NONE;
}

protected:
Gap::Handle_t connHandle; /**< Connection handle as provided by the SoftDevice. */
UUID matchingServiceUUID;
Expand Down
1 change: 0 additions & 1 deletion source/BLE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ bool BLE::hasInitialized(void) const

ble_error_t BLE::shutdown(void)
{
clearAdvertisingPayload();
if (!transport) {
error("bad handle to underlying transport");
}
Expand Down

0 comments on commit 1e448f8

Please sign in to comment.