Skip to content

Commit 333a315

Browse files
committed
BLE - devirtualize pal::AttClient
1 parent 7e78433 commit 333a315

File tree

1 file changed

+82
-31
lines changed

1 file changed

+82
-31
lines changed

features/FEATURE_BLE/ble/pal/AttClient.h

Lines changed: 82 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef BLE_PAL_ATTCLIENT_H_
1818
#define BLE_PAL_ATTCLIENT_H_
1919

20+
#include "ble/common/StaticInterface.h"
2021
#include "ble/UUID.h"
2122
#include "ble/BLETypes.h"
2223
#include "ble/ArrayView.h"
@@ -39,7 +40,15 @@ namespace pal {
3940
*
4041
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F
4142
*/
42-
struct AttClient {
43+
template<class Impl>
44+
struct AttClient : public StaticInterface<Impl, AttClient> {
45+
private:
46+
47+
using StaticInterface<Impl, ble::pal::AttClient>::impl;
48+
49+
public:
50+
51+
4352
/**
4453
* Initialization of the instance. An implementation can use this function
4554
* to initialise the subsystems needed to realize the ATT operations of this
@@ -50,7 +59,9 @@ struct AttClient {
5059
* @return BLE_ERROR_NONE if the request has been successfully sent or the
5160
* appropriate error otherwise.
5261
*/
53-
virtual ble_error_t initialize() = 0;
62+
ble_error_t initialize() {
63+
return impl()->initialize_();
64+
}
5465

5566
/**
5667
* Termination of the instance. An implementation can use this function
@@ -63,7 +74,9 @@ struct AttClient {
6374
* @return BLE_ERROR_NONE if the request has been successfully sent or the
6475
* appropriate error otherwise.
6576
*/
66-
virtual ble_error_t terminate() = 0;
77+
ble_error_t terminate() {
78+
return impl()->terminate_();
79+
}
6780

6881
/**
6982
* Send an exchange MTU request which negotiate the size of the MTU used by
@@ -89,7 +102,9 @@ struct AttClient {
89102
*
90103
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.2.1
91104
*/
92-
virtual ble_error_t exchange_mtu_request(connection_handle_t connection) = 0;
105+
ble_error_t exchange_mtu_request(connection_handle_t connection) {
106+
return impl()->exchange_mtu_request_(connection);
107+
}
93108

94109
/**
95110
* Acquire the size of the mtu for a given connection.
@@ -102,10 +117,12 @@ struct AttClient {
102117
* @return BLE_ERROR_NONE if the MTU size has been acquired or the
103118
* appropriate error otherwise.
104119
*/
105-
virtual ble_error_t get_mtu_size(
120+
ble_error_t get_mtu_size(
106121
connection_handle_t connection_handle,
107122
uint16_t& mtu_size
108-
) = 0;
123+
) {
124+
return impl()->get_mtu_size_(connection_handle, mtu_size);
125+
}
109126

110127
/**
111128
* Send a find information request to a server in order to obtain the
@@ -138,10 +155,12 @@ struct AttClient {
138155
*
139156
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.3.1
140157
*/
141-
virtual ble_error_t find_information_request(
158+
ble_error_t find_information_request(
142159
connection_handle_t connection_handle,
143160
attribute_handle_range_t discovery_range
144-
) = 0;
161+
) {
162+
return impl()->find_information_request_(connection_handle, discovery_range);
163+
}
145164

146165
/**
147166
* Send a Find By Type Value Request which retrieve the handles of attributes
@@ -174,12 +193,19 @@ struct AttClient {
174193
*
175194
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.3.3
176195
*/
177-
virtual ble_error_t find_by_type_value_request(
196+
ble_error_t find_by_type_value_request(
178197
connection_handle_t connection_handle,
179198
attribute_handle_range_t discovery_range,
180199
uint16_t type,
181200
const ArrayView<const uint8_t>& value
182-
) = 0;
201+
) {
202+
return impl()->find_by_type_value_request_(
203+
connection_handle,
204+
discovery_range,
205+
type,
206+
value
207+
);
208+
}
183209

184210
/**
185211
* Send a Read By Type Request used to obtain the values of attributes where
@@ -218,11 +244,13 @@ struct AttClient {
218244
*
219245
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.4.1
220246
*/
221-
virtual ble_error_t read_by_type_request(
247+
ble_error_t read_by_type_request(
222248
connection_handle_t connection_handle,
223249
attribute_handle_range_t read_range,
224250
const UUID& type
225-
) = 0;
251+
) {
252+
return impl()->read_by_type_request_(connection_handle, read_range, type);
253+
}
226254

227255
/**
228256
* Send a Read Request to read the value of an attribute in the server.
@@ -257,10 +285,12 @@ struct AttClient {
257285
*
258286
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.4.3
259287
*/
260-
virtual ble_error_t read_request(
288+
ble_error_t read_request(
261289
connection_handle_t connection_handle,
262290
attribute_handle_t attribute_handle
263-
) = 0;
291+
) {
292+
return impl()->read_request_(connection_handle, attribute_handle);
293+
}
264294

265295
/**
266296
* Send a read blob request to a server to read a part of the value of an
@@ -303,11 +333,13 @@ struct AttClient {
303333
*
304334
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.4.5
305335
*/
306-
virtual ble_error_t read_blob_request(
336+
ble_error_t read_blob_request(
307337
connection_handle_t connection_handle,
308338
attribute_handle_t attribute_handle,
309339
uint16_t offset
310-
) = 0;
340+
) {
341+
return impl()->read_blob_request_(connection_handle, attribute_handle, offset);
342+
}
311343

312344
/**
313345
* Send a read multiple request to the server. It is used to read two or more
@@ -347,10 +379,12 @@ struct AttClient {
347379
*
348380
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.4.7
349381
*/
350-
virtual ble_error_t read_multiple_request(
382+
ble_error_t read_multiple_request(
351383
connection_handle_t connection_handle,
352384
const ArrayView<const attribute_handle_t>& attribute_handles
353-
) = 0;
385+
) {
386+
return impl()->read_multiple_request_(connection_handle, attribute_handles);
387+
}
354388

355389
/**
356390
* Send a read by group type request to the server. It is used to get
@@ -397,11 +431,13 @@ struct AttClient {
397431
*
398432
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.4.9
399433
*/
400-
virtual ble_error_t read_by_group_type_request(
434+
ble_error_t read_by_group_type_request(
401435
connection_handle_t connection_handle,
402436
attribute_handle_range_t read_range,
403437
const UUID& group_type
404-
) = 0;
438+
) {
439+
return impl()->read_by_group_type_request_(connection_handle, read_range, group_type);
440+
}
405441

406442
/**
407443
* Send a write request to the server to write the value of an attribute.
@@ -450,11 +486,13 @@ struct AttClient {
450486
*
451487
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.5.1
452488
*/
453-
virtual ble_error_t write_request(
489+
ble_error_t write_request(
454490
connection_handle_t connection_handle,
455491
attribute_handle_t attribute_handle,
456492
const ArrayView<const uint8_t>& value
457-
) = 0;
493+
) {
494+
return impl()->write_request_(connection_handle, attribute_handle, value);
495+
}
458496

459497
/**
460498
* Send a write command to the server. A write command is similar to a write
@@ -470,11 +508,13 @@ struct AttClient {
470508
*
471509
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.5.3
472510
*/
473-
virtual ble_error_t write_command(
511+
ble_error_t write_command(
474512
connection_handle_t connection_handle,
475513
attribute_handle_t attribute_handle,
476514
const ArrayView<const uint8_t>& value
477-
) = 0;
515+
) {
516+
return impl()->write_command_(connection_handle, attribute_handle, value);
517+
}
478518

479519
/**
480520
* Send a signed write command to the server. Behaviour is similar to a write
@@ -495,11 +535,13 @@ struct AttClient {
495535
*
496536
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.5.4
497537
*/
498-
virtual ble_error_t signed_write_command(
538+
ble_error_t signed_write_command(
499539
connection_handle_t connection_handle,
500540
attribute_handle_t attribute_handle,
501541
const ArrayView<const uint8_t>& value
502-
) = 0;
542+
) {
543+
return impl()->signed_write_command_(connection_handle, attribute_handle, value);
544+
}
503545

504546
/**
505547
* The Prepare Write Request is used to request the server to prepare to
@@ -547,12 +589,19 @@ struct AttClient {
547589
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.6.1
548590
*
549591
*/
550-
virtual ble_error_t prepare_write_request(
592+
ble_error_t prepare_write_request(
551593
connection_handle_t connection_handle,
552594
attribute_handle_t attribute_handle,
553595
uint16_t offset,
554596
const ArrayView<const uint8_t>& value
555-
) = 0;
597+
) {
598+
return impl()->prepare_write_request_(
599+
connection_handle,
600+
attribute_handle,
601+
offset,
602+
value
603+
);
604+
}
556605

557606
/**
558607
* Send an Execute Write Request to the server. This request will instruct
@@ -591,10 +640,12 @@ struct AttClient {
591640
*
592641
* @note see BLUETOOTH SPECIFICATION Version 5.0 | Vol 3, Part F Section 3.4.6.3
593642
*/
594-
virtual ble_error_t execute_write_request(
643+
ble_error_t execute_write_request(
595644
connection_handle_t connection_handle,
596645
bool execute
597-
) = 0;
646+
) {
647+
return impl()->execute_write_request_(connection_handle, execute);
648+
}
598649

599650
/**
600651
* Register a callback which will handle messages from the server.
@@ -630,7 +681,7 @@ struct AttClient {
630681
protected:
631682
AttClient() { }
632683

633-
virtual ~AttClient() { }
684+
~AttClient() { }
634685

635686
/**
636687
* Upon server message reception an implementation shall call this function.

0 commit comments

Comments
 (0)