fdsf
Fork of nRF51822 by
Revision 569:9e72aa06ec32, committed 2016-01-11
- Comitter:
- vcoubard
- Date:
- Mon Jan 11 10:19:20 2016 +0000
- Parent:
- 568:13b23a4b1f58
- Child:
- 570:f162898cb6c4
- Commit message:
- Synchronized with git rev 15592642
Author: Vincent Coubard
Move Implementation of nRF5xCharacteristicDescriptorDiscoverer::Discovery
to cpp file.
Changed in this revision
--- a/source/nRF5xCharacteristicDescriptorDiscoverer.cpp Mon Jan 11 10:19:20 2016 +0000 +++ b/source/nRF5xCharacteristicDescriptorDiscoverer.cpp Mon Jan 11 10:19:20 2016 +0000 @@ -18,7 +18,6 @@ #include "mbed-drivers/mbed_error.h" #include "ble/DiscoveredCharacteristicDescriptor.h" - nRF5xCharacteristicDescriptorDiscoverer::nRF5xCharacteristicDescriptorDiscoverer() : discoveryRunning() { // nothing to do @@ -73,7 +72,7 @@ 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 @@ // 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 @@ 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::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) { @@ -194,4 +191,46 @@ default: 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(¶ms); +} + +void nRF5xCharacteristicDescriptorDiscoverer::Discovery::terminate(ble_error_t err) { + CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = { + characteristic, + err + }; + + onTerminate.call(¶ms); +} + +bool nRF5xCharacteristicDescriptorDiscoverer::Discovery::isEmpty() const { + return *this == Discovery(); +} + +const DiscoveredCharacteristic& nRF5xCharacteristicDescriptorDiscoverer::Discovery::getCharacteristic() const { + return characteristic; } \ No newline at end of file
--- a/source/nRF5xCharacteristicDescriptorDiscoverer.h Mon Jan 11 10:19:20 2016 +0000 +++ b/source/nRF5xCharacteristicDescriptorDiscoverer.h Mon Jan 11 10:19:20 2016 +0000 @@ -105,12 +105,13 @@ * @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 @@ * * @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 @@ * @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(¶ms); - } + 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(¶ms); - } + 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 @@ 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