Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve API to facilitate full shutdown procedure #141

Merged
merged 2 commits into from
Dec 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions ble/Gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,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();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the callback states also be reset? similar to what you've done for GattClient.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I missed this ones. They should also be cleared.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it would be interesting to call clearAdvertisingPayload and clearScanResponse, it seems that these functions does more things.

/* 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