Move Implementation of nRF5xCharacteristicDescriptorDiscoverer::Discovery

to cpp file.
This commit is contained in:
Vincent Coubard 2015-12-15 10:22:23 +00:00
parent c8d826ffd0
commit 15592642e1
2 changed files with 71 additions and 46 deletions

View file

@ -18,7 +18,6 @@
#include "mbed-drivers/mbed_error.h"
#include "ble/DiscoveredCharacteristicDescriptor.h"
nRF5xCharacteristicDescriptorDiscoverer::nRF5xCharacteristicDescriptorDiscoverer() :
discoveryRunning() {
// nothing to do
@ -73,7 +72,7 @@ ble_error_t nRF5xCharacteristicDescriptorDiscoverer::launch(
bool nRF5xCharacteristicDescriptorDiscoverer::isActive(const DiscoveredCharacteristic& characteristic) const {
for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
if(discoveryRunning[i].characteristic == characteristic) {
if(discoveryRunning[i].getCharacteristic() == characteristic) {
return true;
}
}
@ -103,7 +102,7 @@ void nRF5xCharacteristicDescriptorDiscoverer::process(uint16_t connectionHandle,
// prepare the next discovery request (if needed)
uint16_t startHandle = descriptors.descs[descriptors.count - 1].handle + 1;
uint16_t endHandle = discovery->characteristic.getLastHandle();
uint16_t endHandle = discovery->getCharacteristic().getLastHandle();
if(startHandle > endHandle) {
terminate(discovery, BLE_ERROR_NONE);
@ -135,12 +134,11 @@ void nRF5xCharacteristicDescriptorDiscoverer::terminate(Discovery* discovery, bl
tmp.terminate(err);
}
nRF5xCharacteristicDescriptorDiscoverer::Discovery*
nRF5xCharacteristicDescriptorDiscoverer::findRunningDiscovery(const DiscoveredCharacteristic& characteristic) {
for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
if(discoveryRunning[i].characteristic == characteristic && discoveryRunning[i].isEmpty() == false) {
if((discoveryRunning[i].getCharacteristic() == characteristic) &&
(discoveryRunning[i].isEmpty() == false)) {
return &discoveryRunning[i];
}
}
@ -150,15 +148,14 @@ nRF5xCharacteristicDescriptorDiscoverer::findRunningDiscovery(const DiscoveredCh
nRF5xCharacteristicDescriptorDiscoverer::Discovery*
nRF5xCharacteristicDescriptorDiscoverer::findRunningDiscovery(uint16_t handle) {
for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
if(discoveryRunning[i].characteristic.getConnectionHandle() == handle &&
discoveryRunning[i].isEmpty() == false) {
if((discoveryRunning[i].getCharacteristic().getConnectionHandle() == handle) &&
(discoveryRunning[i].isEmpty() == false)) {
return &discoveryRunning[i];
}
}
return NULL;
}
nRF5xCharacteristicDescriptorDiscoverer::Discovery*
nRF5xCharacteristicDescriptorDiscoverer::getAvailableDiscoverySlot() {
for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
@ -195,3 +192,45 @@ ble_error_t nRF5xCharacteristicDescriptorDiscoverer::gattc_descriptors_discover(
return BLE_ERROR_UNSPECIFIED;
}
}
// implementation of nRF5xCharacteristicDescriptorDiscoverer::Discovery
nRF5xCharacteristicDescriptorDiscoverer::Discovery::Discovery() :
characteristic(), onDiscovery(), onTerminate() {
}
nRF5xCharacteristicDescriptorDiscoverer::Discovery::Discovery(
const DiscoveredCharacteristic& c, const DiscoveryCallback_t& dCb, const TerminationCallback_t& tCb) :
characteristic(c), onDiscovery(dCb), onTerminate(tCb) {
}
void nRF5xCharacteristicDescriptorDiscoverer::Discovery::process(
GattAttribute::Handle_t handle, const UUID& uuid) {
CharacteristicDescriptorDiscovery::DiscoveryCallbackParams_t params = {
characteristic,
DiscoveredCharacteristicDescriptor(
characteristic.getGattClient(),
characteristic.getConnectionHandle(),
handle,
uuid
)
};
onDiscovery.call(&params);
}
void nRF5xCharacteristicDescriptorDiscoverer::Discovery::terminate(ble_error_t err) {
CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = {
characteristic,
err
};
onTerminate.call(&params);
}
bool nRF5xCharacteristicDescriptorDiscoverer::Discovery::isEmpty() const {
return *this == Discovery();
}
const DiscoveredCharacteristic& nRF5xCharacteristicDescriptorDiscoverer::Discovery::getCharacteristic() const {
return characteristic;
}

View file

@ -105,12 +105,13 @@ private:
* @brief Discovery process, it store the DiscoveredCharacteristic, the
* discovery callback and the termination callback.
*/
struct Discovery {
class Discovery {
public:
/**
* @brief Construct an empty discovery, such can be considerate as a not running discovery.
* @note #isEmpty function will return true
*/
Discovery() : characteristic(), onDiscovery(), onTerminate() { }
Discovery();
/**
* @brief Construct a valid discovery process.
@ -121,15 +122,7 @@ private:
*
* @note #isEmpty function will return false
*/
Discovery(const DiscoveredCharacteristic& c, const DiscoveryCallback_t& dCb, const TerminationCallback_t& tCb) :
characteristic(c),
onDiscovery(dCb),
onTerminate(tCb) {
}
DiscoveredCharacteristic characteristic;
DiscoveryCallback_t onDiscovery;
TerminationCallback_t onTerminate;
Discovery(const DiscoveredCharacteristic& c, const DiscoveryCallback_t& dCb, const TerminationCallback_t& tCb);
/**
* @brief Process the discovery of a descriptor.
@ -137,62 +130,50 @@ private:
* @param handle The attribute handle of the descriptor found
* @param uuid The UUID of the descriptor found.
*/
void process(GattAttribute::Handle_t handle, const UUID& uuid) {
CharacteristicDescriptorDiscovery::DiscoveryCallbackParams_t params = {
characteristic,
DiscoveredCharacteristicDescriptor(
characteristic.getGattClient(),
characteristic.getConnectionHandle(),
handle,
uuid
)
};
onDiscovery.call(&params);
}
void process(GattAttribute::Handle_t handle, const UUID& uuid);
/**
* @brief Terminate the discovery process.
*
* @param err Error associate with the termination
*
* @note after this call #isEmpty function will return true.
*/
void terminate(ble_error_t err) {
CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = {
characteristic,
err
};
onTerminate.call(&params);
}
void terminate(ble_error_t err);
/**
* @brief check if the discovery process is empty or not. Empty discovery are
* not running.
*
* @detail Discovery are empty after:
* - a default construction
* - a copy construction form a default constructed
* - an assignment from a default constructed Discovery
* @return true if the Discovery is empty and false otherwise.
*/
bool isEmpty() const {
return *this == Discovery();
}
bool isEmpty() const;
/**
* @brief return the characteristic from whom descriptors are discovered.
* @return the characteristic from whom descriptors are discovered.
*/
const DiscoveredCharacteristic& getCharacteristic() const;
/**
* @brief equal to operator, test if two discovery process are equal
*
* @param lhs left hand side of the expression
* @param rhs right hand side of the expression
* @return true if lhs == rhs
*/
friend bool operator==(const Discovery& lhs, const Discovery& rhs) {
return lhs.characteristic == rhs.characteristic &&
lhs.onDiscovery == rhs.onDiscovery &&
lhs.onTerminate == rhs.onTerminate;
lhs.onDiscovery == rhs.onDiscovery &&
lhs.onTerminate == rhs.onTerminate;
}
/**
* @brief not equal to operator, test if two discovery process are not equal
*
* @param lhs left hand side of the expression
* @param rhs right hand side of the expression
* @return true if lhs != rhs
@ -200,6 +181,11 @@ private:
friend bool operator!=(const Discovery& lhs, const Discovery& rhs) {
return !(lhs == rhs);
}
private:
DiscoveredCharacteristic characteristic;
DiscoveryCallback_t onDiscovery;
TerminationCallback_t onTerminate;
};
// find a running discovery process