Merge pull request #5299 from pan-/ble-generic-event-filter

Ble: generic event filter
pull/5526/head
Jimmy Brisson 2017-11-22 10:14:13 -06:00 committed by GitHub
commit 23408e40d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View File

@ -1776,6 +1776,7 @@ private:
InstanceID_t instanceID;
BLEInstanceBase *transport; /* The device-specific backend */
OnEventsToProcessCallback_t whenEventsToProcess;
bool event_signaled;
};
/**

View File

@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <stdio.h>
#include "ble/BLE.h"
#include "ble/BLEInstanceBase.h"
@ -139,7 +140,8 @@ void defaultSchedulingCallback(BLE::OnEventsToProcessCallbackContext* params) {
BLE::BLE(InstanceID_t instanceIDIn) : instanceID(instanceIDIn), transport(),
whenEventsToProcess(defaultSchedulingCallback)
whenEventsToProcess(defaultSchedulingCallback),
event_signaled(false)
{
static BLEInstanceBase *transportInstances[NUM_INSTANCES];
@ -168,6 +170,7 @@ ble_error_t BLE::shutdown(void)
error("bad handle to underlying transport");
}
event_signaled = false;
return transport->shutdown();
}
@ -263,20 +266,41 @@ void BLE::waitForEvent(void)
void BLE::processEvents()
{
if (event_signaled == false) {
return;
}
if (!transport) {
error("bad handle to underlying transport");
}
event_signaled = false;
transport->processEvents();
}
void BLE::onEventsToProcess(const BLE::OnEventsToProcessCallback_t& 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(&params);
}
}
void BLE::signalEventsToProcess()
{
if (event_signaled == true) {
return;
}
event_signaled = true;
if (whenEventsToProcess) {
OnEventsToProcessCallbackContext params = {
*this