mirror of https://github.com/ARMmbed/mbed-os.git
BLE: Add generic event filter.
This filter prevent events to be signaled multiple times to the upper layer. It also signal events to a newly set event processor hook.pull/5299/head
parent
0025b685ea
commit
63668cb7d2
|
@ -1560,6 +1560,7 @@ private:
|
||||||
InstanceID_t instanceID;
|
InstanceID_t instanceID;
|
||||||
BLEInstanceBase *transport; /* The device-specific backend */
|
BLEInstanceBase *transport; /* The device-specific backend */
|
||||||
OnEventsToProcessCallback_t whenEventsToProcess;
|
OnEventsToProcessCallback_t whenEventsToProcess;
|
||||||
|
bool event_signaled;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef BLE BLEDevice; /**< @deprecated This type alias is retained for the
|
typedef BLE BLEDevice; /**< @deprecated This type alias is retained for the
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include "ble/BLE.h"
|
#include "ble/BLE.h"
|
||||||
#include "ble/BLEInstanceBase.h"
|
#include "ble/BLEInstanceBase.h"
|
||||||
|
|
||||||
|
@ -139,7 +140,8 @@ void defaultSchedulingCallback(BLE::OnEventsToProcessCallbackContext* params) {
|
||||||
|
|
||||||
|
|
||||||
BLE::BLE(InstanceID_t instanceIDIn) : instanceID(instanceIDIn), transport(),
|
BLE::BLE(InstanceID_t instanceIDIn) : instanceID(instanceIDIn), transport(),
|
||||||
whenEventsToProcess(defaultSchedulingCallback)
|
whenEventsToProcess(defaultSchedulingCallback),
|
||||||
|
event_signaled(false)
|
||||||
{
|
{
|
||||||
static BLEInstanceBase *transportInstances[NUM_INSTANCES];
|
static BLEInstanceBase *transportInstances[NUM_INSTANCES];
|
||||||
|
|
||||||
|
@ -168,6 +170,7 @@ ble_error_t BLE::shutdown(void)
|
||||||
error("bad handle to underlying transport");
|
error("bad handle to underlying transport");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event_signaled = false;
|
||||||
return transport->shutdown();
|
return transport->shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,20 +266,41 @@ void BLE::waitForEvent(void)
|
||||||
|
|
||||||
void BLE::processEvents()
|
void BLE::processEvents()
|
||||||
{
|
{
|
||||||
|
if (event_signaled == false) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!transport) {
|
if (!transport) {
|
||||||
error("bad handle to underlying transport");
|
error("bad handle to underlying transport");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
event_signaled = false;
|
||||||
|
|
||||||
transport->processEvents();
|
transport->processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BLE::onEventsToProcess(const BLE::OnEventsToProcessCallback_t& callback)
|
void BLE::onEventsToProcess(const BLE::OnEventsToProcessCallback_t& callback)
|
||||||
{
|
{
|
||||||
whenEventsToProcess = callback;
|
whenEventsToProcess = callback;
|
||||||
|
|
||||||
|
// If events were previously signaled but the handler was not in place then
|
||||||
|
// signal immediately events availability
|
||||||
|
if (event_signaled && whenEventsToProcess) {
|
||||||
|
OnEventsToProcessCallbackContext params = {
|
||||||
|
*this
|
||||||
|
};
|
||||||
|
whenEventsToProcess(¶ms);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BLE::signalEventsToProcess()
|
void BLE::signalEventsToProcess()
|
||||||
{
|
{
|
||||||
|
if (event_signaled == true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event_signaled = true;
|
||||||
|
|
||||||
if (whenEventsToProcess) {
|
if (whenEventsToProcess) {
|
||||||
OnEventsToProcessCallbackContext params = {
|
OnEventsToProcessCallbackContext params = {
|
||||||
*this
|
*this
|
||||||
|
|
Loading…
Reference in New Issue