Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
Diff: public/GattServer.h
- Revision:
- 558:f5d517505e85
- Parent:
- 556:34fa32a420f9
- Child:
- 567:e4b38e43de7c
--- a/public/GattServer.h Fri Jun 19 15:52:10 2015 +0100
+++ b/public/GattServer.h Fri Jun 19 15:52:10 2015 +0100
@@ -43,14 +43,18 @@
/* empty */
}
+ /*
+ * The following functions are meant to be overridden in the platform-specific sub-class.
+ */
public:
- /* These functions must be defined in the sub-class */
/**
* Add a service declaration to the local server ATT table. Also add the
* characteristics contained within.
*/
- virtual ble_error_t addService(GattService &) = 0;
+ virtual ble_error_t addService(GattService &) {
+ return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
+ }
/**
* Read the value of a characteristic from the local GattServer
@@ -67,7 +71,9 @@
*
* @return BLE_ERROR_NONE if a value was read successfully into the buffer.
*/
- virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP) = 0;
+ virtual ble_error_t read(GattAttribute::Handle_t attributeHandle, uint8_t buffer[], uint16_t *lengthP) {
+ return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
+ }
/**
* Read the value of a characteristic from the local GattServer
@@ -90,7 +96,9 @@
* parameter to allow fetches for connection-specific multivalued
* attribtues (such as the CCCDs).
*/
- virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP) = 0;
+ virtual ble_error_t read(Gap::Handle_t connectionHandle, GattAttribute::Handle_t attributeHandle, uint8_t *buffer, uint16_t *lengthP) {
+ return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
+ }
/**
* Update the value of a characteristic on the local GattServer.
@@ -110,7 +118,9 @@
*
* @return BLE_ERROR_NONE if we have successfully set the value of the attribute.
*/
- virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t *, uint16_t, bool localOnly = false) = 0;
+ virtual ble_error_t write(GattAttribute::Handle_t, const uint8_t *, uint16_t, bool localOnly = false) {
+ return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
+ }
/**
* Update the value of a characteristic on the local GattServer. A version
@@ -134,9 +144,23 @@
*
* @return BLE_ERROR_NONE if we have successfully set the value of the attribute.
*/
- virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t *, uint16_t, bool localOnly = false) = 0;
+ virtual ble_error_t write(Gap::Handle_t connectionHandle, GattAttribute::Handle_t, const uint8_t *, uint16_t, bool localOnly = false) {
+ return BLE_ERROR_NOT_IMPLEMENTED; /* default implementation; override this API if this capability is supported. */
+ }
/**
+ * A virtual function to allow underlying stacks to indicate if they support
+ * onDataRead(). It should be overridden to return true as applicable.
+ */
+ virtual bool isOnDataReadAvailable() const {
+ return false; /* default implementation; override this API if this capability is supported. */
+ }
+
+ /*
+ * APIs with non-virtual implementations.
+ */
+public:
+ /**
* Add a callback for the GATT event DATA_SENT (which is triggered when
* updates are sent out by GATT in the form of notifications).
*
@@ -175,14 +199,6 @@
}
/**
- * A virtual function to allow underlying stacks to indicate if they support
- * onDataRead(). It should be overridden to return true as applicable.
- */
- virtual bool isOnDataReadAvailable() const {
- return false;
- }
-
- /**
* Setup a callback to be invoked on the peripheral when an attribute is
* being read by a remote client.
*
@@ -237,6 +253,7 @@
*/
void onConfirmationReceived(EventCallback_t callback) {confirmationReceivedCallback = callback;}
+ /* Entry points for the underlying stack to report events back to the user. */
protected:
void handleDataWrittenEvent(const GattWriteCallbackParams *params) {
if (dataWrittenCallChain.hasCallbacksAttached()) {
