BLE: Put generic gattclient procedures inside the GattClient class

pull/5739/head
Vincent Coubard 2018-01-10 14:15:08 +00:00
parent c5bc247217
commit 3061db271d
2 changed files with 13 additions and 22 deletions

View File

@ -26,27 +26,12 @@
namespace ble { namespace ble {
namespace generic { namespace generic {
// forward declarations
struct procedure_control_block_t;
struct discovery_control_block_t;
struct read_control_block_t;
struct write_control_block_t;
struct descriptor_discovery_control_block_t;
/** /**
* Generic implementation of the GattClient. * Generic implementation of the GattClient.
* It requires a pal::GattClient injected at construction site. * It requires a pal::GattClient injected at construction site.
* @important: Not part of the public interface of BLE API. * @important: Not part of the public interface of BLE API.
*/ */
class GenericGattClient : public GattClient { class GenericGattClient : public GattClient {
// give access to control block classes
friend struct procedure_control_block_t;
friend struct discovery_control_block_t;
friend struct read_control_block_t;
friend struct write_control_block_t;
friend struct descriptor_discovery_control_block_t;
public: public:
/** /**
* Create a GenericGattClient from a pal::GattClient * Create a GenericGattClient from a pal::GattClient
@ -130,6 +115,12 @@ public:
virtual ble_error_t reset(void); virtual ble_error_t reset(void);
private: private:
struct procedure_control_block_t;
struct discovery_control_block_t;
struct read_control_block_t;
struct write_control_block_t;
struct descriptor_discovery_control_block_t;
procedure_control_block_t* get_control_block(Gap::Handle_t connection); procedure_control_block_t* get_control_block(Gap::Handle_t connection);
const procedure_control_block_t* get_control_block(Gap::Handle_t connection) const; const procedure_control_block_t* get_control_block(Gap::Handle_t connection) const;
void insert_control_block(procedure_control_block_t* cb) const; void insert_control_block(procedure_control_block_t* cb) const;

View File

@ -55,7 +55,7 @@ enum procedure_type_t {
/* /*
* Base class for a procedure control block * Base class for a procedure control block
*/ */
struct procedure_control_block_t { struct GenericGattClient::procedure_control_block_t {
/* /*
* Base constructor for procedure control block. * Base constructor for procedure control block.
*/ */
@ -83,7 +83,7 @@ struct procedure_control_block_t {
/* /*
* Procedure control block for the discovery process. * Procedure control block for the discovery process.
*/ */
struct discovery_control_block_t : public procedure_control_block_t { struct GenericGattClient::discovery_control_block_t : public procedure_control_block_t {
discovery_control_block_t( discovery_control_block_t(
Gap::Handle_t handle, Gap::Handle_t handle,
ServiceDiscovery::ServiceCallback_t service_callback, ServiceDiscovery::ServiceCallback_t service_callback,
@ -409,7 +409,7 @@ struct discovery_control_block_t : public procedure_control_block_t {
}; };
struct read_control_block_t : public procedure_control_block_t { struct GenericGattClient::read_control_block_t : public procedure_control_block_t {
read_control_block_t( read_control_block_t(
Gap::Handle_t connection_handle, uint16_t attribute_handle, uint16_t offset Gap::Handle_t connection_handle, uint16_t attribute_handle, uint16_t offset
) : procedure_control_block_t(READ_PROCEDURE, connection_handle), ) : procedure_control_block_t(READ_PROCEDURE, connection_handle),
@ -593,7 +593,7 @@ struct read_control_block_t : public procedure_control_block_t {
/* /*
* Control block for the write process * Control block for the write process
*/ */
struct write_control_block_t : public procedure_control_block_t { struct GenericGattClient::write_control_block_t : public procedure_control_block_t {
write_control_block_t( write_control_block_t(
Gap::Handle_t connection_handle, uint16_t attribute_handle, Gap::Handle_t connection_handle, uint16_t attribute_handle,
uint8_t* data, uint16_t len uint8_t* data, uint16_t len
@ -785,7 +785,7 @@ struct write_control_block_t : public procedure_control_block_t {
/* /*
* Control block for the descriptor discovery process * Control block for the descriptor discovery process
*/ */
struct descriptor_discovery_control_block_t : public procedure_control_block_t { struct GenericGattClient::descriptor_discovery_control_block_t : public procedure_control_block_t {
descriptor_discovery_control_block_t( descriptor_discovery_control_block_t(
const DiscoveredCharacteristic& characteristic, const DiscoveredCharacteristic& characteristic,
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback, const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
@ -1278,7 +1278,7 @@ void GenericGattClient::on_transaction_timeout(connection_handle_t connection) {
pcb->handle_timeout_error(this); pcb->handle_timeout_error(this);
} }
procedure_control_block_t* GenericGattClient::get_control_block(Gap::Handle_t connection) { GenericGattClient::procedure_control_block_t* GenericGattClient::get_control_block(Gap::Handle_t connection) {
procedure_control_block_t* it = control_blocks; procedure_control_block_t* it = control_blocks;
while (it && it->connection_handle != connection) { while (it && it->connection_handle != connection) {
it = it->next; it = it->next;
@ -1286,7 +1286,7 @@ procedure_control_block_t* GenericGattClient::get_control_block(Gap::Handle_t co
return it; return it;
} }
const procedure_control_block_t* GenericGattClient::get_control_block(Gap::Handle_t connection) const { const GenericGattClient::procedure_control_block_t* GenericGattClient::get_control_block(Gap::Handle_t connection) const {
procedure_control_block_t* it = control_blocks; procedure_control_block_t* it = control_blocks;
while (it && it->connection_handle != connection) { while (it && it->connection_handle != connection) {
it = it->next; it = it->next;