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.
Dependents: microbit-dal microbit-dal microbit-ble-open microbit-dal ... more
Fork of BLE_API by
Revision 259:a95264ad705c, committed 2015-01-21
- Comitter:
- rgrover1
- Date:
- Wed Jan 21 09:32:48 2015 +0000
- Parent:
- 258:85de85adfac7
- Child:
- 260:ea7f9f14cc15
- Commit message:
- Synchronized with git rev 580f31d8
Author: marcuschang
Added chained callbacks for onDataSent.
Changed in this revision
| public/BLEDevice.h | Show annotated file Show diff for this revision Revisions of this file |
| public/GattServer.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/public/BLEDevice.h Wed Jan 21 09:32:48 2015 +0000
+++ b/public/BLEDevice.h Wed Jan 21 09:32:48 2015 +0000
@@ -225,8 +225,16 @@
/**
* Setup a callback for the GATT event DATA_SENT.
+ *
+ * @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(GattServer::ServerEventCallbackWithCount_t callback);
+ void onDataSent(void (*callback)(unsigned count));
+ template <typename T> void onDataSent(T * objPtr, void (T::*memberPtr)(unsigned count));
/**
* Setup a callback for when a characteristic has its value updated by a
@@ -525,11 +533,15 @@
}
inline void
-BLEDevice::onDataSent(GattServer::ServerEventCallbackWithCount_t callback)
-{
+BLEDevice::onDataSent(void (*callback)(unsigned count)) {
transport->getGattServer().setOnDataSent(callback);
}
+template <typename T> inline void
+BLEDevice::onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) {
+ transport->getGattServer().setOnDataSent(objPtr, memberPtr);
+}
+
inline void
BLEDevice::onDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)) {
transport->getGattServer().setOnDataWritten(callback);
--- a/public/GattServer.h Wed Jan 21 09:32:48 2015 +0000
+++ b/public/GattServer.h Wed Jan 21 09:32:48 2015 +0000
@@ -27,10 +27,9 @@
/* Event callback handlers. */
typedef void (*EventCallback_t)(uint16_t attributeHandle);
typedef void (*ServerEventCallback_t)(void); /**< independent of any particular attribute */
- typedef void (*ServerEventCallbackWithCount_t)(unsigned count); /**< independent of any particular attribute */
protected:
- GattServer() : serviceCount(0), characteristicCount(0), onDataSent(NULL), onDataWritten(), onUpdatesEnabled(NULL), onUpdatesDisabled(NULL), onConfirmationReceived(NULL) {
+ GattServer() : serviceCount(0), characteristicCount(0), onDataSent(), onDataWritten(), onUpdatesEnabled(NULL), onUpdatesDisabled(NULL), onConfirmationReceived(NULL) {
/* empty */
}
@@ -47,7 +46,11 @@
// be sure to call sd_ble_gatts_hvx() twice with notify then indicate!
// Strange use case, but valid and must be covered!
- void setOnDataSent(ServerEventCallbackWithCount_t callback) {onDataSent = callback;}
+ void setOnDataSent(void (*callback)(unsigned count)) {onDataSent.add(callback);}
+ template <typename T>
+ void setOnDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) {
+ onDataSent.add(objPtr, memberPtr);
+ }
void setOnDataWritten(void (*callback)(const GattCharacteristicWriteCBParams *eventDataP)) {onDataWritten.add(callback);}
template <typename T>
void setOnDataWritten(T *objPtr, void (T::*memberPtr)(const GattCharacteristicWriteCBParams *context)) {
@@ -85,8 +88,8 @@
}
void handleDataSentEvent(unsigned count) {
- if (onDataSent) {
- onDataSent(count);
+ if (onDataSent.hasCallbacksAttached()) {
+ onDataSent.call(count);
}
}
@@ -95,7 +98,7 @@
uint8_t characteristicCount;
private:
- ServerEventCallbackWithCount_t onDataSent;
+ CallChainOfFunctionPointersWithContext<unsigned> onDataSent;
CallChainOfFunctionPointersWithContext<const GattCharacteristicWriteCBParams *> onDataWritten;
EventCallback_t onUpdatesEnabled;
EventCallback_t onUpdatesDisabled;
