High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
Revision 953:f6eb43f524b2, committed 2015-11-26
- Comitter:
- rgrover1
- Date:
- Thu Nov 26 12:52:33 2015 +0000
- Parent:
- 952:8a6c287de1be
- Child:
- 954:8b33ea639a1f
- Commit message:
- Synchronized with git rev dfc03ce0
Author: Vincent Coubard
Convert Gap::timeout callback to a callback chain. Add 'boolean'
conversion and function operator syntax to
CallChainOfFunctionPointerWithContext
Changed in this revision
--- a/ble/CallChainOfFunctionPointersWithContext.h Thu Nov 26 12:52:33 2015 +0000 +++ b/ble/CallChainOfFunctionPointersWithContext.h Thu Nov 26 12:52:33 2015 +0000 @@ -97,6 +97,14 @@ return common_add(new FunctionPointerWithContext<ContextType>(tptr, mptr)); } + /** Add a function at the front of the chain. + * + * @param func The FunctionPointerWithContext to add. + */ + void add(const FunctionPointerWithContext<ContextType>& func) { + common_add(new FunctionPointerWithContext<ContextType>(func)); + } + /** * Detach a function pointer from a callchain * @@ -153,6 +161,29 @@ } } + /** + * @brief same as above but const + */ + void call(ContextType context) const { + if (chainHead) { + chainHead->call(context); + } + } + + /** + * @brief same as above but with function call operator + */ + void operator()(ContextType context) const { + call(context); + } + + typedef void (CallChainOfFunctionPointersWithContext::*bool_type)() const; + void True() const {} + + operator bool_type() const { + return chainHead == NULL ? 0 : &CallChainOfFunctionPointersWithContext::True; + } + private: pFunctionPointerWithContext_t common_add(pFunctionPointerWithContext_t pf) { if (chainHead == NULL) {
--- a/ble/FunctionPointerWithContext.h Thu Nov 26 12:52:33 2015 +0000 +++ b/ble/FunctionPointerWithContext.h Thu Nov 26 12:52:33 2015 +0000 @@ -94,6 +94,13 @@ } } + /** + * @brief Same as above + */ + void operator()(ContextType context) const { + call(context); + } + /** Same as above, workaround for mbed os FunctionPointer implementation. */ void call(ContextType context) { _caller(this, context);
--- a/ble/Gap.h Thu Nov 26 12:52:33 2015 +0000 +++ b/ble/Gap.h Thu Nov 26 12:52:33 2015 +0000 @@ -140,8 +140,9 @@ return (durationInMillis * 1000) / UNIT_1_25_MS; } + typedef FunctionPointerWithContext<TimeoutSource_t> TimeoutEventCallback_t; + typedef CallChainOfFunctionPointersWithContext<TimeoutSource_t> TimeoutEventCallbackChain_t; - typedef void (*TimeoutEventCallback_t)(TimeoutSource_t source); typedef void (*ConnectionEventCallback_t)(const ConnectionCallbackParams_t *params); typedef void (*DisconnectionEventCallback_t)(const DisconnectionCallbackParams_t *params); typedef FunctionPointerWithContext<bool> RadioNotificationEventCallback_t; @@ -893,7 +894,13 @@ * Set up a callback for timeout events. Refer to TimeoutSource_t for * possible event types. */ - void onTimeout(TimeoutEventCallback_t callback) {timeoutCallback = callback;} + void onTimeout(TimeoutEventCallback_t callback) { + timeoutCallbackChain.add(callback); + } + + TimeoutEventCallbackChain_t& onTimeout() { + return timeoutCallbackChain; + } /** * Append to a chain of callbacks to be invoked upon GAP connection. @@ -956,7 +963,7 @@ _scanResponse(), state(), scanningActive(false), - timeoutCallback(NULL), + timeoutCallbackChain(), radioNotificationCallback(), onAdvertisementReport(), connectionCallChain(), @@ -1002,8 +1009,8 @@ } void processTimeoutEvent(TimeoutSource_t source) { - if (timeoutCallback) { - timeoutCallback(source); + if (timeoutCallbackChain) { + timeoutCallbackChain(source); } } @@ -1017,7 +1024,7 @@ bool scanningActive; protected: - TimeoutEventCallback_t timeoutCallback; + TimeoutEventCallbackChain_t timeoutCallbackChain; RadioNotificationEventCallback_t radioNotificationCallback; AdvertisementReportCallback_t onAdvertisementReport; CallChainOfFunctionPointersWithContext<const ConnectionCallbackParams_t*> connectionCallChain;