Skip to content

Commit b42abd0

Browse files
committed
BLE: cleanup PalEvent queue and implementation
1 parent 52b132e commit b42abd0

File tree

6 files changed

+32
-30
lines changed

6 files changed

+32
-30
lines changed

connectivity/FEATURE_BLE/source/cordio/include/ble/internal/BLEInstanceBaseImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "source/generic/GattClientImpl.h"
4141
#include "source/GattServerImpl.h"
4242
#include "source/generic/SecurityManagerImpl.h"
43+
#include "internal/PalEventQueueImpl.h"
4344

4445
namespace ble {
4546

@@ -176,7 +177,7 @@ class BLEInstanceBase : public interface::BLEInstanceBase {
176177
INITIALIZED
177178
} initialization_status;
178179

179-
mutable ble::PalEventQueue _event_queue;
180+
mutable ble::impl::PalEventQueue _event_queue;
180181
mbed::LowPowerTimer _timer;
181182
uint64_t _last_update_us;
182183
};

connectivity/FEATURE_BLE/source/cordio/include/ble/internal/PalEventQueueImpl.h

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ namespace ble {
2828

2929
class BLEInstanceBase;
3030

31+
namespace impl {
32+
3133
/**
3234
* Simple implementation of the EventQueue.
3335
*/
34-
class PalEventQueue : interface::PalEventQueue {
36+
class PalEventQueue final : public ble::PalEventQueue {
3537
public:
3638
typedef mbed::Callback<void()> event_t;
3739

@@ -41,15 +43,17 @@ class PalEventQueue : interface::PalEventQueue {
4143
* @attention a call to initialize is mandatory before any other call.
4244
*/
4345
PalEventQueue() :
44-
_ble_base(NULL), _events(NULL) { }
46+
_ble_base(nullptr), _events(nullptr)
47+
{
48+
}
4549

4650
/**
4751
* Initialize the event queue with a BLEInstanceBase and a ble id.
4852
*
4953
* @param ble_base the instance which will be used to signal the presence
5054
* of new events.
5155
*/
52-
void initialize(BLEInstanceBase* ble_base)
56+
void initialize(ble::BLEInstanceBase *ble_base)
5357
{
5458
_ble_base = ble_base;
5559
}
@@ -65,25 +69,22 @@ class PalEventQueue : interface::PalEventQueue {
6569
/**
6670
* @see ble::post
6771
*/
68-
virtual bool post(const mbed::Callback<void()>& event)
72+
bool post(const mbed::Callback<void()> &event) final
6973
{
70-
if (_ble_base == NULL) {
74+
if (_ble_base == nullptr) {
7175
return false;
7276
}
73-
void* event_buf = WsfBufAlloc(sizeof(EventNode));
74-
MBED_ASSERT(event_buf != NULL);
75-
if (event_buf == NULL) {
76-
return false;
77-
}
78-
EventNode* next = new(event_buf) EventNode(event);
79-
if (next == NULL) {
77+
void *event_buf = WsfBufAlloc(sizeof(EventNode));
78+
MBED_ASSERT(event_buf != nullptr);
79+
if (event_buf == nullptr) {
8080
return false;
8181
}
82+
auto *next = new(event_buf) EventNode(event);
8283

83-
if (_events == NULL) {
84+
if (_events == nullptr) {
8485
_events = next;
8586
} else {
86-
EventNode* previous = _events;
87+
EventNode *previous = _events;
8788
while (previous->next) {
8889
previous = previous->next;
8990
}
@@ -102,7 +103,7 @@ class PalEventQueue : interface::PalEventQueue {
102103
void clear()
103104
{
104105
while (_events) {
105-
EventNode* next = _events->next;
106+
EventNode *next = _events->next;
106107
_events->~EventNode();
107108
WsfBufFree(_events);
108109
_events = next;
@@ -115,7 +116,7 @@ class PalEventQueue : interface::PalEventQueue {
115116
void process()
116117
{
117118
while (_events) {
118-
EventNode* next = _events->next;
119+
EventNode *next = _events->next;
119120
_events->event();
120121
_events->~EventNode();
121122
WsfBufFree(_events);
@@ -125,17 +126,21 @@ class PalEventQueue : interface::PalEventQueue {
125126

126127
private:
127128
struct EventNode {
128-
EventNode(const event_t event) : event(event), next(NULL) { }
129+
EventNode(const event_t event) : event(event), next(nullptr)
130+
{
131+
}
132+
129133
event_t event;
130-
EventNode* next;
134+
EventNode *next;
131135
};
132136

133137
void signal_event();
134138

135-
BLEInstanceBase* _ble_base;
136-
EventNode* _events;
139+
ble::BLEInstanceBase *_ble_base;
140+
EventNode *_events;
137141
};
138142

143+
} // namespace impl
139144
} // namespace ble
140145

141146
#endif /* BLE_PAL_SIMPLE_EVENT_QUEUE_H_ */

connectivity/FEATURE_BLE/source/cordio/source/PalEventQueueImpl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
* limitations under the License.
1717
*/
1818

19-
#include "source/pal/PalEventQueue.h"
19+
#include "internal/PalEventQueueImpl.h"
2020
#include "source/BLEInstanceBase.h"
2121

2222
namespace ble {
23+
namespace impl {
2324

2425
void PalEventQueue::signal_event()
2526
{
2627
_ble_base->signalEventsToProcess();
2728
}
2829

30+
} // namespace impl
2931
} // namespace ble

connectivity/FEATURE_BLE/source/generic/GapImpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ const central_privacy_configuration_t Gap::default_central_privacy_configuration
318318
};
319319

320320
Gap::Gap(
321-
PalEventQueue &event_queue,
321+
ble::PalEventQueue &event_queue,
322322
PalGap &pal_gap,
323323
PalGenericAccessService &generic_access_service,
324324
PalSecurityManager &pal_sm

connectivity/FEATURE_BLE/source/generic/GapImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class Gap :
357357
Gap &operator=(const Gap &);
358358

359359
Gap(
360-
PalEventQueue &event_queue,
360+
ble::PalEventQueue &event_queue,
361361
PalGap &pal_gap,
362362
PalGenericAccessService &generic_access_service,
363363
PalSecurityManager &pal_sm

connectivity/FEATURE_BLE/source/pal/PalEventQueue.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "platform/Callback.h"
2323

2424
namespace ble {
25-
namespace interface {
2625

2726
/**
2827
* Simple interface which allow upper layer to post an event into the event
@@ -55,11 +54,6 @@ class PalEventQueue {
5554
virtual bool post(const mbed::Callback<void()>& event) = 0;
5655
};
5756

58-
} // namespace interface
5957
} // namespace ble
6058

61-
/* This includes the concrete class implementation, to provide a an alternative BLE PAL implementation
62-
* disable Cordio and place your header in a path with the same structure */
63-
#include "ble/internal/PalEventQueueImpl.h"
64-
6559
#endif /* BLE_PAL_EVENT_QUEUE_H_ */

0 commit comments

Comments
 (0)