17
17
#ifndef BLE_PAL_GATT_CLIENT_H_
18
18
#define BLE_PAL_GATT_CLIENT_H_
19
19
20
+ #include " ble/common/StaticInterface.h"
20
21
#include " ble/UUID.h"
21
22
#include " ble/BLETypes.h"
22
23
#include " ble/ArrayView.h"
29
30
namespace ble {
30
31
namespace pal {
31
32
33
+ /* *
34
+ * Definition of the general handler of GattClient related events.
35
+ */
36
+ template <class Impl >
37
+ struct GattClientEventHandler : StaticInterface<Impl, GattClientEventHandler> {
38
+
39
+ using StaticInterface<Impl, ble::pal::GattClientEventHandler>::impl;
40
+
41
+ /* *
42
+ * Function invoked when the connections changes the ATT_MTU which controls
43
+ * the maximum size of an attribute that can be read in a single L2CAP packet
44
+ * which might be fragmented across multiple packets.
45
+ *
46
+ * @param connectionHandle The handle of the connection that changed the size.
47
+ * @param attMtuSize
48
+ */
49
+ void on_att_mtu_change (
50
+ ble::connection_handle_t connection_handle,
51
+ uint16_t att_mtu_size
52
+ ) {
53
+ impl ()->on_att_mtu_change_ (connection_handle, att_mtu_size);
54
+ }
55
+ };
56
+
57
+
32
58
/* *
33
59
* Adaptation layer for a GATT client.
34
60
*
@@ -54,25 +80,14 @@ namespace pal {
54
80
* implementation for GattClient by subclassing the AttClient class and use
55
81
* the class AttClientToGattClientAdapter
56
82
*/
83
+ template <class Impl , class EventHandler >
57
84
class GattClient {
85
+
86
+ Impl* self () {
87
+ return static_cast <Impl*>(this );
88
+ }
89
+
58
90
public:
59
- /* *
60
- * Definition of the general handler of GattClient related events.
61
- */
62
- struct EventHandler {
63
- /* *
64
- * Function invoked when the connections changes the ATT_MTU which controls
65
- * the maximum size of an attribute that can be read in a single L2CAP packet
66
- * which might be fragmented across multiple packets.
67
- *
68
- * @param connectionHandle The handle of the connection that changed the size.
69
- * @param attMtuSize
70
- */
71
- virtual void on_att_mtu_change (
72
- ble::connection_handle_t connection_handle,
73
- uint16_t att_mtu_size
74
- ) = 0;
75
- };
76
91
77
92
/* *
78
93
* Initialisation of the instance. An implementation can use this function
@@ -84,7 +99,9 @@ class GattClient {
84
99
* @return BLE_ERROR_NONE if the request has been successfully sent or the
85
100
* appropriate error otherwise.
86
101
*/
87
- virtual ble_error_t initialize () = 0;
102
+ ble_error_t initialize () {
103
+ return self ()->initialize_ ();
104
+ }
88
105
89
106
/* *
90
107
* Termination of the instance. An implementation can use this function
@@ -97,7 +114,9 @@ class GattClient {
97
114
* @return BLE_ERROR_NONE if the request has been successfully sent or the
98
115
* appropriate error otherwise.
99
116
*/
100
- virtual ble_error_t terminate () = 0;
117
+ ble_error_t terminate () {
118
+ return self ()->terminate_ ();
119
+ }
101
120
102
121
/* *
103
122
* Negotiate the mtu to use by this connection.
@@ -116,7 +135,9 @@ class GattClient {
116
135
* @param connection The handle of the connection to send this request to.
117
136
* @return BLE_ERROR_NONE or an appropriate error.
118
137
*/
119
- virtual ble_error_t exchange_mtu (connection_handle_t connection) = 0;
138
+ ble_error_t exchange_mtu (connection_handle_t connection) {
139
+ return self ()->exchange_mtu_ (connection);
140
+ }
120
141
121
142
/* *
122
143
* Acquire the size of the mtu for a given connection.
@@ -129,10 +150,12 @@ class GattClient {
129
150
* @return BLE_ERROR_NONE if the MTU size has been acquired or the
130
151
* appropriate error otherwise.
131
152
*/
132
- virtual ble_error_t get_mtu_size (
153
+ ble_error_t get_mtu_size (
133
154
connection_handle_t connection_handle,
134
155
uint16_t & mtu_size
135
- ) = 0;
156
+ ) {
157
+ return self ()->get_mtu_size_ (connection_handle, mtu_size);
158
+ }
136
159
137
160
/* *
138
161
* Discover primary services in the range [begin - 0xFFFF].
@@ -165,10 +188,15 @@ class GattClient {
165
188
*
166
189
* @return BLE_ERROR_NONE or an appropriate error.
167
190
*/
168
- virtual ble_error_t discover_primary_service (
191
+ ble_error_t discover_primary_service (
169
192
connection_handle_t connection,
170
193
attribute_handle_t discovery_range_begining
171
- ) = 0;
194
+ ) {
195
+ return self ()->discover_primary_service_ (
196
+ connection,
197
+ discovery_range_begining
198
+ );
199
+ }
172
200
173
201
/* *
174
202
* Discover primary services by UUID in the range [discovery_range_begining - 0xFFFF].
@@ -200,11 +228,17 @@ class GattClient {
200
228
*
201
229
* @return BLE_ERROR_NONE or an appropriate error.
202
230
*/
203
- virtual ble_error_t discover_primary_service_by_service_uuid (
231
+ ble_error_t discover_primary_service_by_service_uuid (
204
232
connection_handle_t connection_handle,
205
233
attribute_handle_t discovery_range_beginning,
206
234
const UUID& uuid
207
- ) = 0;
235
+ ) {
236
+ return self ()->discover_primary_service_by_service_uuid_ (
237
+ connection_handle,
238
+ discovery_range_beginning,
239
+ uuid
240
+ );
241
+ }
208
242
209
243
/* *
210
244
* Find included services within a service.
@@ -242,10 +276,15 @@ class GattClient {
242
276
*
243
277
* @return BLE_ERROR_NONE or an appropriate error.
244
278
*/
245
- virtual ble_error_t find_included_service (
279
+ ble_error_t find_included_service (
246
280
connection_handle_t connection_handle,
247
281
attribute_handle_range_t service_range
248
- ) = 0;
282
+ ) {
283
+ return self ()->find_included_service_ (
284
+ connection_handle,
285
+ service_range
286
+ );
287
+ }
249
288
250
289
/* *
251
290
* Find characteristic declarations within a service definition.
@@ -283,10 +322,15 @@ class GattClient {
283
322
*
284
323
* @return BLE_ERROR_NONE or an appropriate error.
285
324
*/
286
- virtual ble_error_t discover_characteristics_of_a_service (
325
+ ble_error_t discover_characteristics_of_a_service (
287
326
connection_handle_t connection_handle,
288
327
attribute_handle_range_t discovery_range
289
- ) = 0;
328
+ ) {
329
+ return self ()->discover_characteristics_of_a_service_ (
330
+ connection_handle,
331
+ discovery_range
332
+ );
333
+ }
290
334
291
335
/* *
292
336
* Discover characteristic descriptors of a characteristic.
@@ -317,10 +361,15 @@ class GattClient {
317
361
*
318
362
* @return BLE_ERROR_NONE or an appropriate error.
319
363
*/
320
- virtual ble_error_t discover_characteristics_descriptors (
364
+ ble_error_t discover_characteristics_descriptors (
321
365
connection_handle_t connection_handle,
322
366
attribute_handle_range_t descriptors_discovery_range
323
- ) = 0;
367
+ ) {
368
+ return self ()->discover_characteristics_descriptors_ (
369
+ connection_handle,
370
+ descriptors_discovery_range
371
+ );
372
+ }
324
373
325
374
/* *
326
375
* Read the value of an attribute.
@@ -343,10 +392,12 @@ class GattClient {
343
392
*
344
393
* @return BLE_ERROR_NONE or an appropriate error.
345
394
*/
346
- virtual ble_error_t read_attribute_value (
395
+ ble_error_t read_attribute_value (
347
396
connection_handle_t connection_handle,
348
397
attribute_handle_t attribute_handle
349
- ) = 0;
398
+ ) {
399
+ return self ()->read_attribute_value_ (connection_handle, attribute_handle);
400
+ }
350
401
351
402
/* *
352
403
* Read a characteristic value using its UUID (type).
@@ -377,11 +428,17 @@ class GattClient {
377
428
*
378
429
* @return BLE_ERROR_NONE or an appropriate error.
379
430
*/
380
- virtual ble_error_t read_using_characteristic_uuid (
431
+ ble_error_t read_using_characteristic_uuid (
381
432
connection_handle_t connection_handle,
382
433
attribute_handle_range_t read_range,
383
434
const UUID& uuid
384
- ) = 0;
435
+ ) {
436
+ return self ()->read_using_characteristic_uuid_ (
437
+ connection_handle,
438
+ read_range,
439
+ uuid
440
+ );
441
+ }
385
442
386
443
/* *
387
444
* Read a partial value of an attribute.
@@ -409,11 +466,13 @@ class GattClient {
409
466
*
410
467
* @return BLE_ERROR_NONE or an appropriate error.
411
468
*/
412
- virtual ble_error_t read_attribute_blob (
469
+ ble_error_t read_attribute_blob (
413
470
connection_handle_t connection_handle,
414
471
attribute_handle_t attribute_handle,
415
472
uint16_t offset
416
- ) = 0;
473
+ ) {
474
+ return self ()->read_attribute_blob_ (connection_handle, attribute_handle, offset);
475
+ }
417
476
418
477
/* *
419
478
* Read atomically multiple characteristics values.
@@ -435,10 +494,15 @@ class GattClient {
435
494
*
436
495
* @return BLE_ERROR_NONE or an appropriate error.
437
496
*/
438
- virtual ble_error_t read_multiple_characteristic_values (
497
+ ble_error_t read_multiple_characteristic_values (
439
498
connection_handle_t connection_handle,
440
499
const ArrayView<const attribute_handle_t >& characteristic_value_handles
441
- ) = 0;
500
+ ) {
501
+ return self ()->read_multiple_characteristic_values_ (
502
+ connection_handle,
503
+ characteristic_value_handles
504
+ );
505
+ }
442
506
443
507
/* *
444
508
* Send a write command to the server.
@@ -453,11 +517,17 @@ class GattClient {
453
517
*
454
518
* @return BLE_ERROR_NONE or an appropriate error.
455
519
*/
456
- virtual ble_error_t write_without_response (
520
+ ble_error_t write_without_response (
457
521
connection_handle_t connection_handle,
458
522
attribute_handle_t characteristic_value_handle,
459
523
const ArrayView<const uint8_t >& value
460
- ) = 0;
524
+ ) {
525
+ return self ()->write_without_response_ (
526
+ connection_handle,
527
+ characteristic_value_handle,
528
+ value
529
+ );
530
+ }
461
531
462
532
/* *
463
533
* Send a Signed Write without Response command to the server.
@@ -475,11 +545,17 @@ class GattClient {
475
545
*
476
546
* @return BLE_ERROR_NONE or an appropriate error.
477
547
*/
478
- virtual ble_error_t signed_write_without_response (
548
+ ble_error_t signed_write_without_response (
479
549
connection_handle_t connection_handle,
480
550
attribute_handle_t characteristic_value_handle,
481
551
const ArrayView<const uint8_t >& value
482
- ) = 0;
552
+ ) {
553
+ return self ()->signed_write_without_response_ (
554
+ connection_handle,
555
+ characteristic_value_handle,
556
+ value
557
+ );
558
+ }
483
559
484
560
/* *
485
561
* Send a write request to the server.
@@ -501,11 +577,13 @@ class GattClient {
501
577
*
502
578
* @return BLE_ERROR_NONE or an appropriate error.
503
579
*/
504
- virtual ble_error_t write_attribute (
580
+ ble_error_t write_attribute (
505
581
connection_handle_t connection_handle,
506
582
attribute_handle_t attribute_handle,
507
583
const ArrayView<const uint8_t >& value
508
- ) = 0;
584
+ ) {
585
+ return self ()->write_attribute_ (connection_handle, attribute_handle, value);
586
+ }
509
587
510
588
/* *
511
589
* Send a prepare write request to the server.
@@ -536,12 +614,19 @@ class GattClient {
536
614
*
537
615
* @return BLE_ERROR_NONE or an appropriate error.
538
616
*/
539
- virtual ble_error_t queue_prepare_write (
617
+ ble_error_t queue_prepare_write (
540
618
connection_handle_t connection_handle,
541
619
attribute_handle_t characteristic_value_handle,
542
620
const ArrayView<const uint8_t >& value,
543
621
uint16_t offset
544
- ) = 0;
622
+ ) {
623
+ return self ()->queue_prepare_write_ (
624
+ connection_handle,
625
+ characteristic_value_handle,
626
+ value,
627
+ offset
628
+ );
629
+ }
545
630
546
631
/* *
547
632
* Send a request to the server to execute the queue of prepared write
@@ -563,10 +648,12 @@ class GattClient {
563
648
*
564
649
* @return BLE_ERROR_NONE or an appropriate error.
565
650
*/
566
- virtual ble_error_t execute_write_queue (
651
+ ble_error_t execute_write_queue (
567
652
connection_handle_t connection_handle,
568
653
bool execute
569
- ) = 0;
654
+ ) {
655
+ return self ()->execute_write_queue_ (connection_handle, execute);
656
+ }
570
657
571
658
/* *
572
659
* Register a callback which will handle messages from the server.
@@ -621,7 +708,7 @@ class GattClient {
621
708
protected:
622
709
GattClient () : _event_handler(NULL ) { }
623
710
624
- virtual ~GattClient () { }
711
+ ~GattClient () { }
625
712
626
713
/* *
627
714
* Upon server message reception an implementation shall call this function.
0 commit comments