fixed GattServer::onDataSent()

master
Rohit Grover 2015-06-19 08:24:54 +01:00
parent ebd6bbceb5
commit 0553e6f440
2 changed files with 30 additions and 19 deletions

View File

@ -1131,9 +1131,18 @@ public:
*
* @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
@ -1267,16 +1276,6 @@ typedef BLE BLEDevice; /* DEPRECATED. This type alias is retained for the sake o
/* BLE methods. Most of these simply forward the calls to the underlying
* 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);

View File

@ -34,7 +34,7 @@ protected:
GattServer() :
serviceCount(0),
characteristicCount(0),
onDataSent(),
dataSentCallChain(),
onDataWritten(),
onDataRead(),
onUpdatesEnabled(NULL),
@ -143,11 +143,23 @@ public:
// 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 @@ protected:
}
void handleDataSentEvent(unsigned count) {
if (onDataSent.hasCallbacksAttached()) {
onDataSent.call(count);
if (dataSentCallChain.hasCallbacksAttached()) {
dataSentCallChain.call(count);
}
}
@ -228,7 +240,7 @@ protected:
uint8_t characteristicCount;
private:
CallChainOfFunctionPointersWithContext<unsigned> onDataSent;
CallChainOfFunctionPointersWithContext<unsigned> dataSentCallChain;
CallChainOfFunctionPointersWithContext<const GattWriteCallbackParams *> onDataWritten;
CallChainOfFunctionPointersWithContext<const GattReadCallbackParams *> onDataRead;
EventCallback_t onUpdatesEnabled;