Skip to content

Commit 63668cb

Browse files
committed
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.
1 parent 0025b68 commit 63668cb

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

features/FEATURE_BLE/ble/BLE.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,6 +1560,7 @@ class BLE
15601560
InstanceID_t instanceID;
15611561
BLEInstanceBase *transport; /* The device-specific backend */
15621562
OnEventsToProcessCallback_t whenEventsToProcess;
1563+
bool event_signaled;
15631564
};
15641565

15651566
typedef BLE BLEDevice; /**< @deprecated This type alias is retained for the

features/FEATURE_BLE/source/BLE.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
#include <stdio.h>
1718
#include "ble/BLE.h"
1819
#include "ble/BLEInstanceBase.h"
1920

@@ -139,7 +140,8 @@ void defaultSchedulingCallback(BLE::OnEventsToProcessCallbackContext* params) {
139140

140141

141142
BLE::BLE(InstanceID_t instanceIDIn) : instanceID(instanceIDIn), transport(),
142-
whenEventsToProcess(defaultSchedulingCallback)
143+
whenEventsToProcess(defaultSchedulingCallback),
144+
event_signaled(false)
143145
{
144146
static BLEInstanceBase *transportInstances[NUM_INSTANCES];
145147

@@ -168,6 +170,7 @@ ble_error_t BLE::shutdown(void)
168170
error("bad handle to underlying transport");
169171
}
170172

173+
event_signaled = false;
171174
return transport->shutdown();
172175
}
173176

@@ -263,20 +266,41 @@ void BLE::waitForEvent(void)
263266

264267
void BLE::processEvents()
265268
{
269+
if (event_signaled == false) {
270+
return;
271+
}
272+
266273
if (!transport) {
267274
error("bad handle to underlying transport");
268275
}
269276

277+
event_signaled = false;
278+
270279
transport->processEvents();
271280
}
272281

273282
void BLE::onEventsToProcess(const BLE::OnEventsToProcessCallback_t& callback)
274283
{
275284
whenEventsToProcess = callback;
285+
286+
// If events were previously signaled but the handler was not in place then
287+
// signal immediately events availability
288+
if (event_signaled && whenEventsToProcess) {
289+
OnEventsToProcessCallbackContext params = {
290+
*this
291+
};
292+
whenEventsToProcess(&params);
293+
}
276294
}
277295

278296
void BLE::signalEventsToProcess()
279297
{
298+
if (event_signaled == true) {
299+
return;
300+
}
301+
302+
event_signaled = true;
303+
280304
if (whenEventsToProcess) {
281305
OnEventsToProcessCallbackContext params = {
282306
*this

0 commit comments

Comments
 (0)