17
17
#ifndef MBED_GATT_SERVER_H__
18
18
#define MBED_GATT_SERVER_H__
19
19
20
- #include " ble/Gap.h"
21
- #include " GattService.h"
22
- #include " GattAttribute.h"
23
- #include " GattServerEvents.h"
24
- #include " GattCallbackParamTypes.h"
25
- #include " CallChainOfFunctionPointersWithContext.h"
20
+ #include " ble/common/StaticInterface.h"
21
+ #include " ble/GattService.h"
22
+ #include " ble/GattAttribute.h"
23
+ #include " ble/GattServerEvents.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
26
32
27
33
/* *
28
34
* @addtogroup ble
85
91
* Characteristic Value Notification and Characteristic Value Indication when
86
92
* the nature of the server initiated is not relevant.
87
93
*/
94
+ #if !defined(DOXYGEN_ONLY)
95
+ template <class Impl >
96
+ class GattServer : public StaticInterface <Impl, GattServer> {
97
+ #else
88
98
class GattServer {
99
+ #endif
100
+
101
+ using StaticInterface<Impl, ::ble::interface::GattServer>::impl;
102
+
89
103
public:
90
104
91
105
/* *
@@ -195,17 +209,7 @@ class GattServer {
195
209
/* *
196
210
* Construct a GattServer instance.
197
211
*/
198
- GattServer () :
199
- eventHandler (NULL ),
200
- serviceCount (0 ),
201
- characteristicCount (0 ),
202
- dataSentCallChain (),
203
- dataWrittenCallChain (),
204
- dataReadCallChain (),
205
- updatesEnabledCallback (NULL ),
206
- updatesDisabledCallback (NULL ),
207
- confirmationReceivedCallback (NULL ) {
208
- }
212
+ GattServer ();
209
213
210
214
/*
211
215
* The following functions are meant to be overridden in the platform
@@ -237,15 +241,7 @@ class GattServer {
237
241
*
238
242
* @return BLE_ERROR_NONE if the service was successfully added.
239
243
*/
240
- virtual ble_error_t addService (GattService &service)
241
- {
242
- /* Avoid compiler warnings about unused variables. */
243
- (void )service;
244
-
245
- /* Requesting action from porters: override this API if this capability
246
- is supported. */
247
- return BLE_ERROR_NOT_IMPLEMENTED;
248
- }
244
+ ble_error_t addService (GattService &service);
249
245
250
246
/* *
251
247
* Read the value of an attribute present in the local GATT server.
@@ -260,24 +256,15 @@ class GattServer {
260
256
*
261
257
* @return BLE_ERROR_NONE if a value was read successfully into the buffer.
262
258
*
263
- * @attention read(Gap::Handle_t , GattAttribute::Handle_t, uint8_t *, uint16_t *)
259
+ * @attention read(ble::connection_handle_t , GattAttribute::Handle_t, uint8_t *, uint16_t *)
264
260
* must be used to read Client Characteristic Configuration Descriptor (CCCD)
265
261
* because the value of this type of attribute depends on the connection.
266
262
*/
267
- virtual ble_error_t read (
263
+ ble_error_t read (
268
264
GattAttribute::Handle_t attributeHandle,
269
265
uint8_t buffer[],
270
266
uint16_t *lengthP
271
- ) {
272
- /* Avoid compiler warnings about unused variables. */
273
- (void )attributeHandle;
274
- (void )buffer;
275
- (void )lengthP;
276
-
277
- /* Requesting action from porters: override this API if this capability
278
- is supported. */
279
- return BLE_ERROR_NOT_IMPLEMENTED;
280
- }
267
+ );
281
268
282
269
/* *
283
270
* Read the value of an attribute present in the local GATT server.
@@ -297,22 +284,12 @@ class GattServer {
297
284
*
298
285
* @return BLE_ERROR_NONE if a value was read successfully into the buffer.
299
286
*/
300
- virtual ble_error_t read (
301
- Gap::Handle_t connectionHandle,
287
+ ble_error_t read (
288
+ ble:: connection_handle_t connectionHandle,
302
289
GattAttribute::Handle_t attributeHandle,
303
290
uint8_t *buffer,
304
291
uint16_t *lengthP
305
- ) {
306
- /* Avoid compiler warnings about unused variables. */
307
- (void )connectionHandle;
308
- (void )attributeHandle;
309
- (void )buffer;
310
- (void )lengthP;
311
-
312
- /* Requesting action from porters: override this API if this capability
313
- is supported. */
314
- return BLE_ERROR_NOT_IMPLEMENTED;
315
- }
292
+ );
316
293
317
294
/* *
318
295
* Update the value of an attribute present in the local GATT server.
@@ -329,22 +306,12 @@ class GattServer {
329
306
* @return BLE_ERROR_NONE if the attribute value has been successfully
330
307
* updated.
331
308
*/
332
- virtual ble_error_t write (
309
+ ble_error_t write (
333
310
GattAttribute::Handle_t attributeHandle,
334
311
const uint8_t *value,
335
312
uint16_t size,
336
313
bool localOnly = false
337
- ) {
338
- /* Avoid compiler warnings about unused variables. */
339
- (void )attributeHandle;
340
- (void )value;
341
- (void )size;
342
- (void )localOnly;
343
-
344
- /* Requesting action from porters: override this API if this capability
345
- is supported. */
346
- return BLE_ERROR_NOT_IMPLEMENTED;
347
- }
314
+ );
348
315
349
316
/* *
350
317
* Update the value of an attribute present in the local GATT server.
@@ -367,24 +334,13 @@ class GattServer {
367
334
* @return BLE_ERROR_NONE if the attribute value has been successfully
368
335
* updated.
369
336
*/
370
- virtual ble_error_t write (
371
- Gap::Handle_t connectionHandle,
337
+ ble_error_t write (
338
+ ble:: connection_handle_t connectionHandle,
372
339
GattAttribute::Handle_t attributeHandle,
373
340
const uint8_t *value,
374
341
uint16_t size,
375
342
bool localOnly = false
376
- ) {
377
- /* Avoid compiler warnings about unused variables. */
378
- (void )connectionHandle;
379
- (void )attributeHandle;
380
- (void )value;
381
- (void )size;
382
- (void )localOnly;
383
-
384
- /* Requesting action from porters: override this API if this capability
385
- is supported. */
386
- return BLE_ERROR_NOT_IMPLEMENTED;
387
- }
343
+ );
388
344
389
345
/* *
390
346
* Determine if one of the connected clients has subscribed to notifications
@@ -397,18 +353,10 @@ class GattServer {
397
353
* @return BLE_ERROR_NONE if the connection and handle are found. False
398
354
* otherwise.
399
355
*/
400
- virtual ble_error_t areUpdatesEnabled (
356
+ ble_error_t areUpdatesEnabled (
401
357
const GattCharacteristic &characteristic,
402
358
bool *enabledP
403
- ) {
404
- /* Avoid compiler warnings about unused variables. */
405
- (void )characteristic;
406
- (void )enabledP;
407
-
408
- /* Requesting action from porters: override this API if this capability
409
- is supported. */
410
- return BLE_ERROR_NOT_IMPLEMENTED;
411
- }
359
+ );
412
360
413
361
/* *
414
362
* Determine if an identified client has subscribed to notifications or
@@ -423,20 +371,11 @@ class GattServer {
423
371
* @return BLE_ERROR_NONE if the connection and handle are found. False
424
372
* otherwise.
425
373
*/
426
- virtual ble_error_t areUpdatesEnabled (
427
- Gap::Handle_t connectionHandle,
374
+ ble_error_t areUpdatesEnabled (
375
+ ble:: connection_handle_t connectionHandle,
428
376
const GattCharacteristic &characteristic,
429
377
bool *enabledP
430
- ) {
431
- /* Avoid compiler warnings about unused variables. */
432
- (void )connectionHandle;
433
- (void )characteristic;
434
- (void )enabledP;
435
-
436
- /* Requesting action from porters: override this API if this capability
437
- is supported. */
438
- return BLE_ERROR_NOT_IMPLEMENTED;
439
- }
378
+ );
440
379
441
380
/* *
442
381
* Indicate if the underlying stack emit events when an attribute is read by
@@ -447,12 +386,7 @@ class GattServer {
447
386
*
448
387
* @return true if onDataRead is supported; false otherwise.
449
388
*/
450
- virtual bool isOnDataReadAvailable () const
451
- {
452
- /* Requesting action from porters: override this API if this capability
453
- is supported. */
454
- return false ;
455
- }
389
+ bool isOnDataReadAvailable () const ;
456
390
457
391
/*
458
392
* APIs with nonvirtual implementations.
@@ -791,24 +725,56 @@ class GattServer {
791
725
*
792
726
* @return BLE_ERROR_NONE on success.
793
727
*/
794
- virtual ble_error_t reset (void )
795
- {
796
- /* Notify that the instance is about to shutdown */
797
- shutdownCallChain.call (this );
798
- shutdownCallChain.clear ();
728
+ ble_error_t reset (void );
729
+
730
+ protected:
731
+ /* --- Abstract calls to override --- */
799
732
800
- serviceCount = 0 ;
801
- characteristicCount = 0 ;
733
+ /* Derived implementation must call the base reset_ */
734
+ ble_error_t reset_ ( void ) ;
802
735
803
- dataSentCallChain.clear ();
804
- dataWrittenCallChain.clear ();
805
- dataReadCallChain.clear ();
806
- updatesEnabledCallback = NULL ;
807
- updatesDisabledCallback = NULL ;
808
- confirmationReceivedCallback = NULL ;
736
+ ble_error_t addService_ (GattService &service);
809
737
810
- return BLE_ERROR_NONE;
811
- }
738
+ ble_error_t read_ (
739
+ GattAttribute::Handle_t attributeHandle,
740
+ uint8_t buffer[],
741
+ uint16_t *lengthP
742
+ );
743
+
744
+ ble_error_t read_ (
745
+ ble::connection_handle_t connectionHandle,
746
+ GattAttribute::Handle_t attributeHandle,
747
+ uint8_t *buffer,
748
+ uint16_t *lengthP
749
+ );
750
+
751
+ ble_error_t write_ (
752
+ GattAttribute::Handle_t attributeHandle,
753
+ const uint8_t *value,
754
+ uint16_t size,
755
+ bool localOnly
756
+ );
757
+
758
+ ble_error_t write_ (
759
+ ble::connection_handle_t connectionHandle,
760
+ GattAttribute::Handle_t attributeHandle,
761
+ const uint8_t *value,
762
+ uint16_t size,
763
+ bool localOnly
764
+ );
765
+
766
+ ble_error_t areUpdatesEnabled_ (
767
+ const GattCharacteristic &characteristic,
768
+ bool *enabledP
769
+ );
770
+
771
+ ble_error_t areUpdatesEnabled_ (
772
+ ble::connection_handle_t connectionHandle,
773
+ const GattCharacteristic &characteristic,
774
+ bool *enabledP
775
+ );
776
+
777
+ bool isOnDataReadAvailable_ () const ;
812
778
813
779
protected:
814
780
/* *
@@ -878,4 +844,13 @@ class GattServer {
878
844
* @}
879
845
*/
880
846
847
+ #if !defined(DOXYGEN_ONLY)
848
+ } // interface
849
+ } // ble
850
+
851
+ typedef ble::impl::GattServer GattServer;
852
+
853
+ #endif
854
+
855
+
881
856
#endif /* ifndef MBED_GATT_SERVER_H__ */
0 commit comments