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.
Diff: ble/GattServer.h
- Revision:
- 966:9451b90bbb66
- Parent:
- 959:d99a4565f872
- Child:
- 969:61f13bc8edbf
diff -r 212c16f6247f -r 9451b90bbb66 ble/GattServer.h
--- a/ble/GattServer.h Thu Nov 26 12:52:34 2015 +0000
+++ b/ble/GattServer.h Thu Nov 26 12:52:34 2015 +0000
@@ -26,18 +26,9 @@
class GattServer {
public:
-
/* Event callback handlers. */
- typedef FunctionPointerWithContext<unsigned> DataSentCallback_t;
- typedef CallChainOfFunctionPointersWithContext<unsigned> DataSentCallbackChain_t;
-
- typedef FunctionPointerWithContext<const GattWriteCallbackParams*> DataWrittenCallback_t;
- typedef CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams*> DataWrittenCallbackChain_t;
-
- typedef FunctionPointerWithContext<const GattReadCallbackParams*> DataReadCallback_t;
- typedef CallChainOfFunctionPointersWithContext<const GattReadCallbackParams *> DataReadCallbackChain_t;
-
- typedef FunctionPointerWithContext<GattAttribute::Handle_t> EventCallback_t;
+ typedef void (*EventCallback_t)(GattAttribute::Handle_t attributeHandle);
+ typedef void (*ServerEventCallback_t)(void); /**< Independent of any particular attribute. */
protected:
GattServer() :
@@ -247,20 +238,13 @@
* @Note: It is also possible to set up a callback into a member function of
* some object.
*/
- void onDataSent(const DataSentCallback_t& callback) {dataSentCallChain.add(callback);}
+ void onDataSent(void (*callback)(unsigned count)) {dataSentCallChain.add(callback);}
template <typename T>
void onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) {
dataSentCallChain.add(objPtr, memberPtr);
}
/**
- * @brief get the callback chain called when the event DATA_EVENT is triggered.
- */
- DataSentCallbackChain_t& onDataSent() {
- return dataSentCallChain;
- }
-
- /**
* Set up a callback for when an attribute has its value updated by or at the
* connected peer. For a peripheral, this callback is triggered when the local
* GATT server has an attribute updated by a write command from the peer.
@@ -275,16 +259,12 @@
* @Note: It is also possible to set up a callback into a member function of
* some object.
*/
- void onDataWritten(const DataWrittenCallback_t& callback) {dataWrittenCallChain.add(callback);}
+ void onDataWritten(void (*callback)(const GattWriteCallbackParams *eventDataP)) {dataWrittenCallChain.add(callback);}
template <typename T>
void onDataWritten(T *objPtr, void (T::*memberPtr)(const GattWriteCallbackParams *context)) {
dataWrittenCallChain.add(objPtr, memberPtr);
}
- DataWrittenCallbackChain_t& onDataWritten() {
- return dataWrittenCallChain;
- }
-
/**
* Setup a callback to be invoked on the peripheral when an attribute is
* being read by a remote client.
@@ -304,7 +284,7 @@
* @return BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available;
* else BLE_ERROR_NONE.
*/
- ble_error_t onDataRead(const DataReadCallback_t& callback) {
+ ble_error_t onDataRead(void (*callback)(const GattReadCallbackParams *eventDataP)) {
if (!isOnDataReadAvailable()) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
@@ -322,10 +302,6 @@
return BLE_ERROR_NONE;
}
- DataReadCallbackChain_t& onDataRead() {
- return dataReadCallChain;
- }
-
/**
* Set up a callback for when notifications or indications are enabled for a
* characteristic on the local GATT server.
@@ -347,11 +323,15 @@
/* Entry points for the underlying stack to report events back to the user. */
protected:
void handleDataWrittenEvent(const GattWriteCallbackParams *params) {
- dataWrittenCallChain.call(params);
+ if (dataWrittenCallChain.hasCallbacksAttached()) {
+ dataWrittenCallChain.call(params);
+ }
}
void handleDataReadEvent(const GattReadCallbackParams *params) {
- dataReadCallChain.call(params);
+ if (dataReadCallChain.hasCallbacksAttached()) {
+ dataReadCallChain.call(params);
+ }
}
void handleEvent(GattServerEvents::gattEvent_e type, GattAttribute::Handle_t attributeHandle) {
@@ -377,7 +357,9 @@
}
void handleDataSentEvent(unsigned count) {
- dataSentCallChain.call(count);
+ if (dataSentCallChain.hasCallbacksAttached()) {
+ dataSentCallChain.call(count);
+ }
}
protected:
@@ -385,12 +367,12 @@
uint8_t characteristicCount;
private:
- DataSentCallbackChain_t dataSentCallChain;
- DataWrittenCallbackChain_t dataWrittenCallChain;
- DataReadCallbackChain_t dataReadCallChain;
- EventCallback_t updatesEnabledCallback;
- EventCallback_t updatesDisabledCallback;
- EventCallback_t confirmationReceivedCallback;
+ CallChainOfFunctionPointersWithContext<unsigned> dataSentCallChain;
+ CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams *> dataWrittenCallChain;
+ CallChainOfFunctionPointersWithContext<const GattReadCallbackParams *> dataReadCallChain;
+ EventCallback_t updatesEnabledCallback;
+ EventCallback_t updatesDisabledCallback;
+ EventCallback_t confirmationReceivedCallback;
private:
/* Disallow copy and assignment. */