High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
Diff: public/GattServer.h
- Revision:
- 690:4d850ccf9f96
- Parent:
- 682:c36be4ee7c01
- Child:
- 691:02b4a4b632e1
diff -r 08b9c561c62f -r 4d850ccf9f96 public/GattServer.h --- a/public/GattServer.h Fri Jun 19 15:53:04 2015 +0100 +++ b/public/GattServer.h Fri Jun 19 15:53:04 2015 +0100 @@ -34,7 +34,7 @@ GattServer() : serviceCount(0), characteristicCount(0), - onDataSent(), + dataSentCallChain(), onDataWritten(), onDataRead(), onUpdatesEnabled(NULL), @@ -143,11 +143,23 @@ // be sure to call sd_ble_gatts_hvx() twice with notify then indicate! // Strange use case, but valid and must be covered! - void setOnDataSent(void (*callback)(unsigned count)) {onDataSent.add(callback);} + /** + * Add a callback for the GATT event DATA_SENT (which is triggered when + * updates are sent out by GATT in the form of notifications). + * + * @Note: it is possible to chain together multiple onDataSent callbacks + * (potentially from different modules of an application) to receive updates + * to characteristics. + * + * @Note: it is also possible to setup a callback into a member function of + * some object. + */ + void onDataSent(void (*callback)(unsigned count)) {dataSentCallChain.add(callback);} template <typename T> - void setOnDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) { - onDataSent.add(objPtr, memberPtr); + void onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) { + dataSentCallChain.add(objPtr, memberPtr); } + void setOnDataWritten(void (*callback)(const GattWriteCallbackParams *eventDataP)) {onDataWritten.add(callback);} template <typename T> void setOnDataWritten(T *objPtr, void (T::*memberPtr)(const GattWriteCallbackParams *context)) { @@ -218,8 +230,8 @@ } void handleDataSentEvent(unsigned count) { - if (onDataSent.hasCallbacksAttached()) { - onDataSent.call(count); + if (dataSentCallChain.hasCallbacksAttached()) { + dataSentCallChain.call(count); } } @@ -228,7 +240,7 @@ uint8_t characteristicCount; private: - CallChainOfFunctionPointersWithContext<unsigned> onDataSent; + CallChainOfFunctionPointersWithContext<unsigned> dataSentCallChain; CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams *> onDataWritten; CallChainOfFunctionPointersWithContext<const GattReadCallbackParams *> onDataRead; EventCallback_t onUpdatesEnabled;