17
17
#ifndef MBED_GATT_CLIENT_H__
18
18
#define MBED_GATT_CLIENT_H__
19
19
20
- #include " ble/Gap.h"
21
- #include " GattAttribute.h"
22
- #include " ServiceDiscovery.h"
23
- #include " CharacteristicDescriptorDiscovery.h"
24
-
25
- #include " GattCallbackParamTypes.h"
26
-
27
- #include " CallChainOfFunctionPointersWithContext.h"
20
+ #include " ble/common/StaticInterface.h"
21
+ #include " ble/GattAttribute.h"
22
+ #include " ble/ServiceDiscovery.h"
23
+ #include " ble/CharacteristicDescriptorDiscovery.h"
24
+ #include " ble/GattCallbackParamTypes.h"
25
+ #include " ble/CallChainOfFunctionPointersWithContext.h"
26
+ #include " BleImplementationForward.h"
27
+
28
+ #if !defined(DOXYGEN_ONLY)
29
+ namespace ble {
30
+ namespace interface {
31
+ #endif
28
32
29
33
/* *
30
34
* @addtogroup ble
81
85
* indicate properties are set. The client discovers that descriptor
82
86
* if it intends to register to server initiated events.
83
87
*/
88
+ #if defined(DOXYGEN_ONLY)
84
89
class GattClient {
90
+ #else
91
+ template <class Impl >
92
+ class GattClient : public StaticInterface <Impl, GattClient> {
93
+ #endif
94
+
95
+ using StaticInterface<Impl, ::ble::interface::GattClient>::impl;
96
+
85
97
public:
86
98
87
99
/* *
@@ -214,7 +226,7 @@ class GattClient {
214
226
*/
215
227
public:
216
228
217
- virtual ~GattClient () { }
229
+ ~GattClient () { }
218
230
219
231
/* *
220
232
* Launch the service and characteristic discovery procedure of a GATT server
@@ -266,24 +278,13 @@ class GattClient {
266
278
* @return BLE_ERROR_NONE if the discovery procedure has been successfully
267
279
* started and an appropriate error otherwise.
268
280
*/
269
- virtual ble_error_t launchServiceDiscovery (
270
- Gap::Handle_t connectionHandle,
281
+ ble_error_t launchServiceDiscovery (
282
+ ble:: connection_handle_t connectionHandle,
271
283
ServiceDiscovery::ServiceCallback_t sc = NULL ,
272
284
ServiceDiscovery::CharacteristicCallback_t cc = NULL ,
273
285
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN),
274
286
const UUID &matchingCharacteristicUUIDIn = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)
275
- ) {
276
- /* Avoid compiler warnings about unused variables. */
277
- (void )connectionHandle;
278
- (void )sc;
279
- (void )cc;
280
- (void )matchingServiceUUID;
281
- (void )matchingCharacteristicUUIDIn;
282
-
283
- /* Requesting action from porters: override this API if this capability
284
- is supported. */
285
- return BLE_ERROR_NOT_IMPLEMENTED;
286
- }
287
+ );
287
288
288
289
/* *
289
290
* Launch the service discovery procedure of a GATT server peer.
@@ -314,8 +315,8 @@ class GattClient {
314
315
* @return BLE_ERROR_NONE if the discovery procedure has been successfully
315
316
* started and an appropriate error otherwise.
316
317
*/
317
- virtual ble_error_t discoverServices (
318
- Gap::Handle_t connectionHandle,
318
+ ble_error_t discoverServices (
319
+ ble:: connection_handle_t connectionHandle,
319
320
ServiceDiscovery::ServiceCallback_t callback,
320
321
const UUID &matchingServiceUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)
321
322
) {
@@ -355,46 +356,27 @@ class GattClient {
355
356
* @return BLE_ERROR_NONE if the discovery procedure has been successfully
356
357
* started and an appropriate error otherwise.
357
358
*/
358
- virtual ble_error_t discoverServices (
359
- Gap::Handle_t connectionHandle,
359
+ ble_error_t discoverServices (
360
+ ble:: connection_handle_t connectionHandle,
360
361
ServiceDiscovery::ServiceCallback_t callback,
361
362
GattAttribute::Handle_t startHandle,
362
363
GattAttribute::Handle_t endHandle
363
- ) {
364
- /* Avoid compiler warnings about unused variables. */
365
- (void )connectionHandle;
366
- (void )callback;
367
- (void )startHandle;
368
- (void )endHandle;
369
-
370
- /* Requesting action from porters: override this API if this capability
371
- is supported. */
372
- return BLE_ERROR_NOT_IMPLEMENTED;
373
- }
364
+ );
374
365
375
366
/* *
376
367
* Check if the service discovery procedure is currently active.
377
368
*
378
369
* @return true if service discovery procedure is active and false otherwise.
379
370
*/
380
- virtual bool isServiceDiscoveryActive (void ) const
381
- {
382
- /* Requesting action from porters: override this API if this capability
383
- is supported. */
384
- return false ;
385
- }
371
+ bool isServiceDiscoveryActive (void ) const ;
386
372
387
373
/* *
388
374
* Terminate all ongoing service discovery procedures.
389
375
*
390
376
* It results in an invocation of the service discovery termination handler
391
377
* registered with onServiceDiscoveryTermination().
392
378
*/
393
- virtual void terminateServiceDiscovery (void )
394
- {
395
- /* Requesting action from porters: override this API if this capability
396
- is supported. */
397
- }
379
+ void terminateServiceDiscovery (void );
398
380
399
381
/* *
400
382
* Initiate the read procedure of an attribute handle.
@@ -428,20 +410,11 @@ class GattClient {
428
410
* Finally, concat the last response with the value containing all the
429
411
* previous responses and forward that value to the event handlers.
430
412
*/
431
- virtual ble_error_t read (
432
- Gap::Handle_t connHandle,
413
+ ble_error_t read (
414
+ ble:: connection_handle_t connHandle,
433
415
GattAttribute::Handle_t attributeHandle,
434
416
uint16_t offset
435
- ) const {
436
- /* Avoid compiler warnings about unused variables. */
437
- (void )connHandle;
438
- (void )attributeHandle;
439
- (void )offset;
440
-
441
- /* Requesting action from porters: override this API if this capability
442
- is supported. */
443
- return BLE_ERROR_NOT_IMPLEMENTED;
444
- }
417
+ ) const ;
445
418
446
419
/* *
447
420
* Initiate a write procedure on an attribute value.
@@ -480,24 +453,13 @@ class GattClient {
480
453
* by sending an execute write request to the peer. The peer response is
481
454
* forwarded to the application handlers.
482
455
*/
483
- virtual ble_error_t write (
456
+ ble_error_t write (
484
457
GattClient::WriteOp_t cmd,
485
- Gap::Handle_t connHandle,
458
+ ble:: connection_handle_t connHandle,
486
459
GattAttribute::Handle_t attributeHandle,
487
460
size_t length,
488
461
const uint8_t *value
489
- ) const {
490
- /* Avoid compiler warnings about unused variables. */
491
- (void )cmd;
492
- (void )connHandle;
493
- (void )attributeHandle;
494
- (void )length;
495
- (void )value;
496
-
497
- /* Requesting action from porters: override this API if this capability
498
- is supported. */
499
- return BLE_ERROR_NOT_IMPLEMENTED;
500
- }
462
+ ) const ;
501
463
502
464
/* Event callback handlers. */
503
465
public:
@@ -587,14 +549,9 @@ class GattClient {
587
549
*
588
550
* @param[in] callback Event handler being registered.
589
551
*/
590
- virtual void onServiceDiscoveryTermination (
552
+ void onServiceDiscoveryTermination (
591
553
ServiceDiscovery::TerminationCallback_t callback
592
- ) {
593
- (void )callback; /* Avoid compiler warnings about ununsed variables. */
594
-
595
- /* Requesting action from porters: override this API if this capability
596
- is supported. */
597
- }
554
+ );
598
555
599
556
/* *
600
557
* Initiate the descriptor discovery procedure for a given characteristic.
@@ -618,18 +575,11 @@ class GattClient {
618
575
* @return BLE_ERROR_NONE if the characteristic descriptor discovery
619
576
* procedure has been launched successfully otherwise an appropriate error.
620
577
*/
621
- virtual ble_error_t discoverCharacteristicDescriptors (
578
+ ble_error_t discoverCharacteristicDescriptors (
622
579
const DiscoveredCharacteristic& characteristic,
623
580
const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
624
581
const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
625
- ) {
626
- (void ) characteristic;
627
- (void ) discoveryCallback;
628
- (void ) terminationCallback;
629
- /* Requesting action from porter(s): override this API if this
630
- capability is supported. */
631
- return BLE_ERROR_NOT_IMPLEMENTED;
632
- }
582
+ );
633
583
634
584
/* *
635
585
* Query status of the descriptor discovery procedure for a given
@@ -641,14 +591,9 @@ class GattClient {
641
591
* @return true if a descriptors discovery is active for the characteristic
642
592
* in input otherwise false.
643
593
*/
644
- virtual bool isCharacteristicDescriptorDiscoveryActive (
594
+ bool isCharacteristicDescriptorDiscoveryActive (
645
595
const DiscoveredCharacteristic& characteristic
646
- ) const {
647
- (void ) characteristic;
648
- /* Requesting action from porter(s): override this API if this
649
- capability is supported. */
650
- return false ;
651
- }
596
+ ) const ;
652
597
653
598
/* *
654
599
* @brief Terminate an ongoing characteristic descriptor discovery procedure.
@@ -659,13 +604,9 @@ class GattClient {
659
604
* @param[in] characteristic The characteristic containing the descriptors
660
605
* being discovered.
661
606
*/
662
- virtual void terminateCharacteristicDescriptorDiscovery (
607
+ void terminateCharacteristicDescriptorDiscovery (
663
608
const DiscoveredCharacteristic& characteristic
664
- ) {
665
- /* Requesting action from porter(s): override this API if this
666
- capability is supported. */
667
- (void ) characteristic;
668
- }
609
+ );
669
610
670
611
/* *
671
612
* Trigger MTU negotiation. This might result in a Gap event onAttMtuChange
@@ -679,14 +620,7 @@ class GattClient {
679
620
* @return BLE_ERROR_NONE if the procedure has been launched successfully
680
621
* otherwise an appropriate error.
681
622
*/
682
- virtual ble_error_t negotiateAttMtu (
683
- ble::connection_handle_t connection
684
- ) {
685
- /* Requesting action from porter(s): override this API if this
686
- capability is supported. */
687
- (void ) connection;
688
- return BLE_ERROR_NOT_IMPLEMENTED;
689
- }
623
+ ble_error_t negotiateAttMtu (ble::connection_handle_t connection);
690
624
691
625
/* *
692
626
* Register an handler for Handle Value Notification/Indication events.
@@ -781,18 +715,67 @@ class GattClient {
781
715
*
782
716
* @return BLE_ERROR_NONE on success.
783
717
*/
784
- virtual ble_error_t reset (void )
785
- {
786
- /* Notify that the instance is about to shut down. */
787
- shutdownCallChain.call (this );
788
- shutdownCallChain.clear ();
718
+ ble_error_t reset (void );
789
719
790
- onDataReadCallbackChain.clear ();
791
- onDataWriteCallbackChain.clear ();
792
- onHVXCallbackChain.clear ();
720
+ protected:
793
721
794
- return BLE_ERROR_NONE;
795
- }
722
+ /* --- Abstract calls to override --- */
723
+
724
+ /* Derived implementation must call the base class implementation */
725
+ ble_error_t reset_ (void );
726
+
727
+ ble_error_t discoverServices_ (
728
+ ble::connection_handle_t connectionHandle,
729
+ ServiceDiscovery::ServiceCallback_t callback,
730
+ GattAttribute::Handle_t startHandle,
731
+ GattAttribute::Handle_t endHandle
732
+ );
733
+
734
+ ble_error_t launchServiceDiscovery_ (
735
+ ble::connection_handle_t connectionHandle,
736
+ ServiceDiscovery::ServiceCallback_t sc,
737
+ ServiceDiscovery::CharacteristicCallback_t cc,
738
+ const UUID &matchingServiceUUID,
739
+ const UUID &matchingCharacteristicUUIDIn
740
+ );
741
+
742
+ bool isServiceDiscoveryActive_ (void ) const ;
743
+
744
+ void terminateServiceDiscovery_ (void );
745
+
746
+ ble_error_t negotiateAttMtu_ (ble::connection_handle_t connection);
747
+
748
+ ble_error_t read_ (
749
+ ble::connection_handle_t connHandle,
750
+ GattAttribute::Handle_t attributeHandle,
751
+ uint16_t offset
752
+ ) const ;
753
+
754
+ ble_error_t write_ (
755
+ GattClient::WriteOp_t cmd,
756
+ ble::connection_handle_t connHandle,
757
+ GattAttribute::Handle_t attributeHandle,
758
+ size_t length,
759
+ const uint8_t *value
760
+ ) const ;
761
+
762
+ void onServiceDiscoveryTermination_ (
763
+ ServiceDiscovery::TerminationCallback_t callback
764
+ );
765
+
766
+ ble_error_t discoverCharacteristicDescriptors_ (
767
+ const DiscoveredCharacteristic& characteristic,
768
+ const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
769
+ const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
770
+ );
771
+
772
+ bool isCharacteristicDescriptorDiscoveryActive_ (
773
+ const DiscoveredCharacteristic& characteristic
774
+ ) const ;
775
+
776
+ void terminateCharacteristicDescriptorDiscovery_ (
777
+ const DiscoveredCharacteristic& characteristic
778
+ );
796
779
797
780
protected:
798
781
GattClient () : eventHandler(NULL )
@@ -888,4 +871,12 @@ class GattClient {
888
871
* @}
889
872
*/
890
873
874
+ #if !defined(DOXYGEN_ONLY)
875
+ } // namespace interface
876
+ } // namespace ble
877
+
878
+ using ble::impl::GattClient;
879
+ #endif
880
+
881
+
891
882
#endif /* ifndef MBED_GATT_CLIENT_H__ */
0 commit comments