Skip to content

Commit 6d2592a

Browse files
committed
BLE - Devirtualize ::GattServer.
The interface is defined in ::ble::interface::GattServer and an implementation must export the implementation type ::ble::impl::GattServer.
1 parent e56fd68 commit 6d2592a

File tree

2 files changed

+304
-120
lines changed

2 files changed

+304
-120
lines changed

features/FEATURE_BLE/ble/GattServer.h

Lines changed: 95 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@
1717
#ifndef MBED_GATT_SERVER_H__
1818
#define MBED_GATT_SERVER_H__
1919

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
2632

2733
/**
2834
* @addtogroup ble
@@ -85,7 +91,15 @@
8591
* Characteristic Value Notification and Characteristic Value Indication when
8692
* the nature of the server initiated is not relevant.
8793
*/
94+
#if !defined(DOXYGEN_ONLY)
95+
template <class Impl>
96+
class GattServer : public StaticInterface<Impl, GattServer> {
97+
#else
8898
class GattServer {
99+
#endif
100+
101+
using StaticInterface<Impl, ::ble::interface::GattServer>::impl;
102+
89103
public:
90104

91105
/**
@@ -195,17 +209,7 @@ class GattServer {
195209
/**
196210
* Construct a GattServer instance.
197211
*/
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();
209213

210214
/*
211215
* The following functions are meant to be overridden in the platform
@@ -237,15 +241,7 @@ class GattServer {
237241
*
238242
* @return BLE_ERROR_NONE if the service was successfully added.
239243
*/
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);
249245

250246
/**
251247
* Read the value of an attribute present in the local GATT server.
@@ -260,24 +256,15 @@ class GattServer {
260256
*
261257
* @return BLE_ERROR_NONE if a value was read successfully into the buffer.
262258
*
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 *)
264260
* must be used to read Client Characteristic Configuration Descriptor (CCCD)
265261
* because the value of this type of attribute depends on the connection.
266262
*/
267-
virtual ble_error_t read(
263+
ble_error_t read(
268264
GattAttribute::Handle_t attributeHandle,
269265
uint8_t buffer[],
270266
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+
);
281268

282269
/**
283270
* Read the value of an attribute present in the local GATT server.
@@ -297,22 +284,12 @@ class GattServer {
297284
*
298285
* @return BLE_ERROR_NONE if a value was read successfully into the buffer.
299286
*/
300-
virtual ble_error_t read(
301-
Gap::Handle_t connectionHandle,
287+
ble_error_t read(
288+
ble::connection_handle_t connectionHandle,
302289
GattAttribute::Handle_t attributeHandle,
303290
uint8_t *buffer,
304291
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+
);
316293

317294
/**
318295
* Update the value of an attribute present in the local GATT server.
@@ -329,22 +306,12 @@ class GattServer {
329306
* @return BLE_ERROR_NONE if the attribute value has been successfully
330307
* updated.
331308
*/
332-
virtual ble_error_t write(
309+
ble_error_t write(
333310
GattAttribute::Handle_t attributeHandle,
334311
const uint8_t *value,
335312
uint16_t size,
336313
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+
);
348315

349316
/**
350317
* Update the value of an attribute present in the local GATT server.
@@ -367,24 +334,13 @@ class GattServer {
367334
* @return BLE_ERROR_NONE if the attribute value has been successfully
368335
* updated.
369336
*/
370-
virtual ble_error_t write(
371-
Gap::Handle_t connectionHandle,
337+
ble_error_t write(
338+
ble::connection_handle_t connectionHandle,
372339
GattAttribute::Handle_t attributeHandle,
373340
const uint8_t *value,
374341
uint16_t size,
375342
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+
);
388344

389345
/**
390346
* Determine if one of the connected clients has subscribed to notifications
@@ -397,18 +353,10 @@ class GattServer {
397353
* @return BLE_ERROR_NONE if the connection and handle are found. False
398354
* otherwise.
399355
*/
400-
virtual ble_error_t areUpdatesEnabled(
356+
ble_error_t areUpdatesEnabled(
401357
const GattCharacteristic &characteristic,
402358
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+
);
412360

413361
/**
414362
* Determine if an identified client has subscribed to notifications or
@@ -423,20 +371,11 @@ class GattServer {
423371
* @return BLE_ERROR_NONE if the connection and handle are found. False
424372
* otherwise.
425373
*/
426-
virtual ble_error_t areUpdatesEnabled(
427-
Gap::Handle_t connectionHandle,
374+
ble_error_t areUpdatesEnabled(
375+
ble::connection_handle_t connectionHandle,
428376
const GattCharacteristic &characteristic,
429377
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+
);
440379

441380
/**
442381
* Indicate if the underlying stack emit events when an attribute is read by
@@ -447,12 +386,7 @@ class GattServer {
447386
*
448387
* @return true if onDataRead is supported; false otherwise.
449388
*/
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;
456390

457391
/*
458392
* APIs with nonvirtual implementations.
@@ -791,24 +725,56 @@ class GattServer {
791725
*
792726
* @return BLE_ERROR_NONE on success.
793727
*/
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 --- */
799732

800-
serviceCount = 0;
801-
characteristicCount = 0;
733+
/* Derived implementation must call the base reset_ */
734+
ble_error_t reset_(void);
802735

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);
809737

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;
812778

813779
protected:
814780
/**
@@ -878,4 +844,13 @@ class GattServer {
878844
* @}
879845
*/
880846

847+
#if !defined(DOXYGEN_ONLY)
848+
} // interface
849+
} // ble
850+
851+
typedef ble::impl::GattServer GattServer;
852+
853+
#endif
854+
855+
881856
#endif /* ifndef MBED_GATT_SERVER_H__ */

0 commit comments

Comments
 (0)