Terminate pending discoveries when a connection end.

Add accessor for ServiceDiscovery and CharacteristicDescriptorDiscover in
GattClient.

Remove friend relationship with bleGattcEventHandler
This commit is contained in:
Vincent Coubard 2015-11-19 08:31:43 +00:00
parent c778aa8aa3
commit b795c29150
5 changed files with 35 additions and 14 deletions

View file

@ -40,6 +40,10 @@
#include "ble_hci.h"
#include "btle_discovery.h"
#include "nRF5xGattClient.h"
#include "nRF5xServiceDiscovery.h"
#include "nRF5xCharacteristicDescriptorDiscoverer.h"
extern "C" void assert_nrf_callback(uint16_t line_num, const uint8_t *p_file_name);
void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t *p_file_name);
@ -182,8 +186,13 @@ static void btle_handler(ble_evt_t *p_ble_evt)
reason = static_cast<Gap::DisconnectionReason_t>(p_ble_evt->evt.gap_evt.params.disconnected.reason);
break;
}
// Close all pending discoveries for this connection
nRF5xGattClient& gattClient = nRF5xGattClient::getInstance();
gattClient.characteristicDescriptorDiscoverer().terminate(handle, BLE_ERROR_INVALID_STATE);
gattClient.discovery().terminate(handle);
nRF5xGap::getInstance().processDisconnectionEvent(handle, reason);
// TODO: close pending discoveries
break;
}

View file

@ -21,9 +21,9 @@
#if !defined(TARGET_MCU_NRF51_16K_S110) && !defined(TARGET_MCU_NRF51_32K_S110)
void bleGattcEventHandler(const ble_evt_t *p_ble_evt)
{
nRF5xServiceDiscovery &sdSingleton = nRF5xGattClient::getInstance().discovery;
nRF5xServiceDiscovery &sdSingleton = nRF5xGattClient::getInstance().discovery();
nRF5xCharacteristicDescriptorDiscoverer &characteristicDescriptorDiscoverer =
nRF5xGattClient::getInstance().characteristicDescriptorDiscoverer;
nRF5xGattClient::getInstance().characteristicDescriptorDiscoverer();
switch (p_ble_evt->header.evt_id) {
case BLE_GATTC_EVT_PRIM_SRVC_DISC_RSP:

View file

@ -33,7 +33,7 @@ nRF5xGattClient::launchServiceDiscovery(Gap::Handle_t
const UUID &matchingServiceUUIDIn,
const UUID &matchingCharacteristicUUIDIn)
{
return discovery.launch(connectionHandle, sc, cc, matchingServiceUUIDIn, matchingCharacteristicUUIDIn);
return _discovery.launch(connectionHandle, sc, cc, matchingServiceUUIDIn, matchingCharacteristicUUIDIn);
}
ble_error_t nRF5xGattClient::discoverCharacteristicDescriptors(
@ -41,7 +41,7 @@ ble_error_t nRF5xGattClient::discoverCharacteristicDescriptors(
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback)
{
return characteristicDescriptorDiscoverer.launch(
return _characteristicDescriptorDiscoverer.launch(
characteristic,
discoveryCallback,
terminationCallback
@ -49,11 +49,11 @@ ble_error_t nRF5xGattClient::discoverCharacteristicDescriptors(
}
bool nRF5xGattClient::isCharacteristicDescriptorsDiscoveryActive(const DiscoveredCharacteristic& characteristic) const {
return characteristicDescriptorDiscoverer.isActive(characteristic);
return _characteristicDescriptorDiscoverer.isActive(characteristic);
}
void nRF5xGattClient::terminateCharacteristicDescriptorsDiscovery(const DiscoveredCharacteristic& characteristic) {
return characteristicDescriptorDiscoverer.requestTerminate(characteristic);
return _characteristicDescriptorDiscoverer.requestTerminate(characteristic);
}
#endif

View file

@ -88,14 +88,14 @@ public:
const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN));
virtual void onServiceDiscoveryTermination(ServiceDiscovery::TerminationCallback_t callback) {
discovery.onTermination(callback);
_discovery.onTermination(callback);
}
/**
* Is service-discovery currently active?
*/
virtual bool isServiceDiscoveryActive(void) const {
return discovery.isActive();
return _discovery.isActive();
}
/**
@ -103,7 +103,7 @@ public:
* invocation of the TerminationCallback if service-discovery is active.
*/
virtual void terminateServiceDiscovery(void) {
discovery.terminate();
_discovery.terminate();
}
/**
@ -171,19 +171,25 @@ public:
}
public:
nRF5xGattClient() : discovery(this) {
nRF5xGattClient() : _discovery(this) {
/* empty */
}
friend void bleGattcEventHandler(const ble_evt_t *p_ble_evt);
nRF5xServiceDiscovery& discovery() {
return _discovery;
}
nRF5xCharacteristicDescriptorDiscoverer& characteristicDescriptorDiscoverer() {
return _characteristicDescriptorDiscoverer;
}
private:
nRF5xGattClient(const nRF5xGattClient &);
const nRF5xGattClient& operator=(const nRF5xGattClient &);
private:
nRF5xServiceDiscovery discovery;
nRF5xCharacteristicDescriptorDiscoverer characteristicDescriptorDiscoverer;
nRF5xServiceDiscovery _discovery;
nRF5xCharacteristicDescriptorDiscoverer _characteristicDescriptorDiscoverer;
#endif // if !S110
};

View file

@ -94,6 +94,12 @@ public:
terminateServiceDiscovery();
}
void terminate(Gap::Handle_t connectionHandle) {
if(connHandle == connectionHandle) {
terminate();
}
}
virtual void onTermination(ServiceDiscovery::TerminationCallback_t callback) {
onTerminationCallback = callback;
}