Skip to content

Commit b135074

Browse files
committed
BLE - Devirtualize ble::generic::GattClient
GenericGattClient is parametized by two types: - The template of the PalGattClient - The SigningMonitorEventHandler Note that the PalGattClient template must be of the form PalGattClient<EventHandler>. The event handler being the GenericGattClient.
1 parent 39e938b commit b135074

File tree

2 files changed

+125
-77
lines changed

2 files changed

+125
-77
lines changed

features/FEATURE_BLE/ble/generic/GenericGattClient.h

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,29 @@ namespace generic {
3232
* It requires a pal::GattClient injected at construction site.
3333
* @attention: Not part of the public interface of BLE API.
3434
*/
35-
class GenericGattClient : public GattClient,
36-
public pal::SigningEventMonitor,
37-
public pal::GattClient::EventHandler {
35+
template<template<class> class TPalGattClient, class SigningMonitorEventHandler>
36+
class GenericGattClient :
37+
public interface::GattClient<GenericGattClient<TPalGattClient, SigningMonitorEventHandler> >,
38+
public pal::SigningEventMonitor<GenericGattClient<TPalGattClient, SigningMonitorEventHandler>, SigningMonitorEventHandler>,
39+
public pal::GattClientEventHandler<GenericGattClient<TPalGattClient, SigningMonitorEventHandler> > {
40+
41+
using interface::GattClient<GenericGattClient<TPalGattClient, SigningMonitorEventHandler> >::eventHandler;
42+
3843
public:
3944

40-
/**
41-
* @see pal::GattClient::EventHandler::on_att_mtu_change
42-
*/
43-
virtual void on_att_mtu_change(
44-
ble::connection_handle_t connection_handle,
45-
uint16_t att_mtu_size
46-
)
47-
{
48-
if (eventHandler) {
49-
eventHandler->onAttMtuChange(connection_handle, att_mtu_size);
50-
}
51-
}
45+
typedef interface::GattClient<GenericGattClient<TPalGattClient, SigningMonitorEventHandler> > Base;
46+
typedef TPalGattClient<GenericGattClient> PalGattClient;
47+
typedef typename Base::WriteOp_t WriteOp_t;
5248

5349
/**
5450
* Create a GenericGattClient from a pal::GattClient
5551
*/
56-
GenericGattClient(pal::GattClient* pal_client);
52+
GenericGattClient(PalGattClient* pal_client);
5753

5854
/**
5955
* @see GattClient::launchServiceDiscovery
6056
*/
61-
virtual ble_error_t launchServiceDiscovery(
57+
ble_error_t launchServiceDiscovery_(
6258
connection_handle_t connection_handle,
6359
ServiceDiscovery::ServiceCallback_t service_callback,
6460
ServiceDiscovery::CharacteristicCallback_t characteristic_callback,
@@ -69,17 +65,17 @@ class GenericGattClient : public GattClient,
6965
/**
7066
* @see GattClient::isServiceDiscoveryActive
7167
*/
72-
virtual bool isServiceDiscoveryActive() const;
68+
bool isServiceDiscoveryActive_() const;
7369

7470
/**
7571
* @see GattClient::terminateServiceDiscovery
7672
*/
77-
virtual void terminateServiceDiscovery();
73+
void terminateServiceDiscovery_();
7874

7975
/**
8076
* @see GattClient::read
8177
*/
82-
virtual ble_error_t read(
78+
ble_error_t read_(
8379
connection_handle_t connection_handle,
8480
GattAttribute::Handle_t attribute_handle,
8581
uint16_t offset
@@ -88,8 +84,8 @@ class GenericGattClient : public GattClient,
8884
/**
8985
* @see GattClient::write
9086
*/
91-
virtual ble_error_t write(
92-
GattClient::WriteOp_t cmd,
87+
ble_error_t write_(
88+
WriteOp_t cmd,
9389
connection_handle_t connection_handle,
9490
GattAttribute::Handle_t attribute_handle,
9591
size_t length,
@@ -99,14 +95,14 @@ class GenericGattClient : public GattClient,
9995
/**
10096
* @see GattClient::onServiceDiscoveryTermination
10197
*/
102-
virtual void onServiceDiscoveryTermination(
98+
void onServiceDiscoveryTermination_(
10399
ServiceDiscovery::TerminationCallback_t callback
104100
);
105101

106102
/**
107103
* @see GattClient::discoverCharacteristicDescriptors
108104
*/
109-
virtual ble_error_t discoverCharacteristicDescriptors(
105+
ble_error_t discoverCharacteristicDescriptors_(
110106
const DiscoveredCharacteristic& characteristic,
111107
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
112108
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
@@ -115,41 +111,41 @@ class GenericGattClient : public GattClient,
115111
/**
116112
* @see GattClient::isCharacteristicDescriptorDiscoveryActive
117113
*/
118-
virtual bool isCharacteristicDescriptorDiscoveryActive(
114+
bool isCharacteristicDescriptorDiscoveryActive_(
119115
const DiscoveredCharacteristic& characteristic
120116
) const;
121117

122118
/**
123119
* @see GattClient::terminateCharacteristicDescriptorDiscovery
124120
*/
125-
virtual void terminateCharacteristicDescriptorDiscovery(
121+
void terminateCharacteristicDescriptorDiscovery_(
126122
const DiscoveredCharacteristic& characteristic
127123
);
128124

129125
/**
130126
* @see GattClient::negotiateAttMtu
131127
*/
132-
virtual ble_error_t negotiateAttMtu(
128+
ble_error_t negotiateAttMtu_(
133129
connection_handle_t connection
134130
);
135131

136132
/**
137133
* @see GattClient::reset
138134
*/
139-
virtual ble_error_t reset(void);
135+
ble_error_t reset_(void);
140136

141137
/**
142138
* @see ble::pal::SigningEventMonitor::set_signing_event_handler
143139
*/
144-
virtual void set_signing_event_handler(pal::SigningEventMonitor::EventHandler *signing_event_handler);
140+
void set_signing_event_handler_(SigningMonitorEventHandler *signing_event_handler);
145141

146142
/**
147-
* Return the user registered event handler.
148-
* @return User registered event handler or NULL if none is present.
143+
* @see pal::GattClient::EventHandler::on_att_mtu_change
149144
*/
150-
::GattClient::EventHandler* getEventHandler() {
151-
return eventHandler;
152-
}
145+
void on_att_mtu_change_(
146+
ble::connection_handle_t connection_handle,
147+
uint16_t att_mtu_size
148+
);
153149

154150
private:
155151
struct ProcedureControlBlock;
@@ -171,14 +167,14 @@ class GenericGattClient : public GattClient,
171167

172168
uint16_t get_mtu(connection_handle_t connection) const;
173169

174-
pal::GattClient* const _pal_client;
170+
PalGattClient* const _pal_client;
175171
ServiceDiscovery::TerminationCallback_t _termination_callback;
176-
pal::SigningEventMonitor::EventHandler* _signing_event_handler;
172+
SigningMonitorEventHandler* _signing_event_handler;
177173
mutable ProcedureControlBlock* control_blocks;
178174
bool _is_reseting;
179175
};
180176

181-
}
182-
}
177+
} // generic
178+
} // ble
183179

184180
#endif /* MBED_BLE_GENERIC_GATT_CLIENT */

0 commit comments

Comments
 (0)