Bike service
Fork of BLE_API by
Diff: ble/GattServer.h
- Revision:
- 949:1902cbd0dd83
- Parent:
- 948:1bb402105289
- Child:
- 959:d99a4565f872
--- a/ble/GattServer.h Thu Nov 26 12:52:08 2015 +0000 +++ b/ble/GattServer.h Thu Nov 26 12:52:08 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. @@ -274,26 +258,14 @@ * * @Note: It is also possible to set up a callback into a member function of * some object. - * - * @Note It is possible to unregister a callback using onDataWritten().detach(callback) */ - 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); } /** - * @brief provide access to the callchain of data written event callbacks - * It is possible to register callbacks using onDataWritten().add(callback); - * It is possible to unregister callbacks using onDataWritten().detach(callback) - * @return The data written event callbacks chain - */ - DataWrittenCallbackChain_t& onDataWritten() { - return dataWrittenCallChain; - } - - /** * Setup a callback to be invoked on the peripheral when an attribute is * being read by a remote client. * @@ -309,12 +281,10 @@ * @Note: It is also possible to set up a callback into a member function of * some object. * - * @Note It is possible to unregister a callback using onDataRead().detach(callback) - * * @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; } @@ -333,16 +303,6 @@ } /** - * @brief provide access to the callchain of data read event callbacks - * It is possible to register callbacks using onDataRead().add(callback); - * It is possible to unregister callbacks using onDataRead().detach(callback) - * @return The data read event callbacks chain - */ - DataReadCallbackChain_t& onDataRead() { - return dataReadCallChain; - } - - /** * Set up a callback for when notifications or indications are enabled for a * characteristic on the local GATT server. */ @@ -363,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) { @@ -393,7 +357,9 @@ } void handleDataSentEvent(unsigned count) { - dataSentCallChain.call(count); + if (dataSentCallChain.hasCallbacksAttached()) { + dataSentCallChain.call(count); + } } protected: @@ -401,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. */