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
Revision 547:f84c514eee35, committed 2015-06-19
- Comitter:
- rgrover1
- Date:
- Fri Jun 19 15:52:09 2015 +0100
- Parent:
- 546:9fdf3d960d12
- Child:
- 548:623e4c0f0b6e
- Commit message:
- Synchronized with git rev 0553e6f4
Author: Rohit Grover
fixed GattServer::onDataSent()
Changed in this revision
| public/BLE.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/BLE.h Fri Jun 19 15:52:09 2015 +0100
+++ b/public/BLE.h Fri Jun 19 15:52:09 2015 +0100
@@ -1131,9 +1131,18 @@
*
* @Note: it is also possible to setup a callback into a member function of
* some object.
+ *
+ * @note: This API is now *deprecated* and will be dropped in the future.
+ * You should use the parallel API from GattServer directly. A former call
+ * to ble.onDataSent(...) should be replaced with
+ * ble.gap().onDataSent(...).
*/
- void onDataSent(void (*callback)(unsigned count));
- template <typename T> void onDataSent(T * objPtr, void (T::*memberPtr)(unsigned count));
+ void onDataSent(void (*callback)(unsigned count)) {
+ gattServer().onDataSent(callback);
+ }
+ template <typename T> void onDataSent(T * objPtr, void (T::*memberPtr)(unsigned count)) {
+ gattServer().onDataSent(objPtr, memberPtr);
+ }
/**
* Setup a callback for when a characteristic has its value updated by a
@@ -1268,16 +1277,6 @@
* transport.*/
inline void
-BLE::onDataSent(void (*callback)(unsigned count)) {
- transport->getGattServer().setOnDataSent(callback);
-}
-
-template <typename T> inline void
-BLE::onDataSent(T *objPtr, void (T::*memberPtr)(unsigned count)) {
- transport->getGattServer().setOnDataSent(objPtr, memberPtr);
-}
-
-inline void
BLE::onDataWritten(void (*callback)(const GattWriteCallbackParams *eventDataP)) {
transport->getGattServer().setOnDataWritten(callback);
}
--- a/public/GattServer.h Fri Jun 19 15:52:09 2015 +0100
+++ b/public/GattServer.h Fri Jun 19 15:52:09 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;
