mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #5299 from pan-/ble-generic-event-filter
Ble: generic event filterpull/5526/head
commit
23408e40d1
|
@ -1776,6 +1776,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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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