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 551:d79a7933a6d1, committed 2015-06-19
- Comitter:
- rgrover1
- Date:
- Fri Jun 19 15:52:10 2015 +0100
- Parent:
- 550:35b3962903af
- Child:
- 552:9bf985a8a49b
- Commit message:
- Synchronized with git rev dd7bbc97
Author: Rohit Grover
fix GattServer::onDataRead()
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:10 2015 +0100
+++ b/public/BLE.h Fri Jun 19 15:52:10 2015 +0100
@@ -1172,7 +1172,8 @@
}
/**
- * Setup a callback for when a characteristic is being read by a client.
+ * Setup a callback to be invoked on the peripheral when an attribute is
+ * being read by a remote client.
*
* @Note: this functionality may not be available on all underlying stacks.
* You could use GattCharacteristic::setReadAuthorizationCallback() as an
@@ -1188,9 +1189,18 @@
*
* @return BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available;
* else BLE_ERROR_NONE.
+ *
+ * @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.onDataRead(...) should be replaced with
+ * ble.gattServer().onDataRead(...).
*/
- ble_error_t onDataRead(void (*callback)(const GattReadCallbackParams *eventDataP));
- template <typename T> ble_error_t onDataRead(T * objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context));
+ ble_error_t onDataRead(void (*callback)(const GattReadCallbackParams *eventDataP)) {
+ return gattServer().onDataRead(callback);
+ }
+ template <typename T> ble_error_t onDataRead(T * objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context)) {
+ return gattServer().onDataRead(objPtr, memberPtr);
+ }
/**
* Setup a callback for when notifications/indications are enabled for a
@@ -1300,16 +1310,6 @@
/* BLE methods. Most of these simply forward the calls to the underlying
* transport.*/
-inline ble_error_t
-BLE::onDataRead(void (*callback)(const GattReadCallbackParams *eventDataP)) {
- return transport->getGattServer().setOnDataRead(callback);
-}
-
-template <typename T> inline ble_error_t
-BLE::onDataRead(T *objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context)) {
- return transport->getGattServer().setOnDataRead(objPtr, memberPtr);
-}
-
inline void
BLE::onUpdatesDisabled(GattServer::EventCallback_t callback)
{
--- a/public/GattServer.h Fri Jun 19 15:52:10 2015 +0100
+++ b/public/GattServer.h Fri Jun 19 15:52:10 2015 +0100
@@ -36,7 +36,7 @@
characteristicCount(0),
dataSentCallChain(),
dataWrittenCallChain(),
- onDataRead(),
+ dataReadCallChain(),
updatesEnabledCallback(NULL),
onUpdatesDisabled(NULL),
onConfirmationReceived(NULL) {
@@ -188,21 +188,41 @@
virtual bool isOnDataReadAvailable() const {
return false;
}
- ble_error_t setOnDataRead(void (*callback)(const GattReadCallbackParams *eventDataP)) {
+
+ /**
+ * Setup a callback to be invoked on the peripheral when an attribute is
+ * being read by a remote client.
+ *
+ * @Note: this functionality may not be available on all underlying stacks.
+ * You could use GattCharacteristic::setReadAuthorizationCallback() as an
+ * alternative.
+ *
+ * @Note: it is possible to chain together multiple onDataRead callbacks
+ * (potentially from different modules of an application) to receive updates
+ * to characteristics. Services may add their own onDataRead callbacks
+ * behind the scenes to trap interesting events.
+ *
+ * @Note: it is also possible to setup a callback into a member function of
+ * some object.
+ *
+ * @return BLE_ERROR_NOT_IMPLEMENTED if this functionality isn't available;
+ * else BLE_ERROR_NONE.
+ */
+ ble_error_t onDataRead(void (*callback)(const GattReadCallbackParams *eventDataP)) {
if (!isOnDataReadAvailable()) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
- onDataRead.add(callback);
+ dataReadCallChain.add(callback);
return BLE_ERROR_NONE;
}
template <typename T>
- ble_error_t setOnDataRead(T *objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context)) {
+ ble_error_t onDataRead(T *objPtr, void (T::*memberPtr)(const GattReadCallbackParams *context)) {
if (!isOnDataReadAvailable()) {
return BLE_ERROR_NOT_IMPLEMENTED;
}
- onDataRead.add(objPtr, memberPtr);
+ dataReadCallChain.add(objPtr, memberPtr);
return BLE_ERROR_NONE;
}
@@ -223,8 +243,8 @@
}
void handleDataReadEvent(const GattReadCallbackParams *params) {
- if (onDataRead.hasCallbacksAttached()) {
- onDataRead.call(params);
+ if (dataReadCallChain.hasCallbacksAttached()) {
+ dataReadCallChain.call(params);
}
}
@@ -263,7 +283,7 @@
private:
CallChainOfFunctionPointersWithContext<unsigned> dataSentCallChain;
CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams *> dataWrittenCallChain;
- CallChainOfFunctionPointersWithContext<const GattReadCallbackParams *> onDataRead;
+ CallChainOfFunctionPointersWithContext<const GattReadCallbackParams *> dataReadCallChain;
EventCallback_t updatesEnabledCallback;
EventCallback_t onUpdatesDisabled;
EventCallback_t onConfirmationReceived;
