Skip to content

Commit e2b87c6

Browse files
pending events for connections and adv reports
1 parent ff74525 commit e2b87c6

File tree

1 file changed

+65
-0
lines changed
  • connectivity/FEATURE_BLE/source/generic

1 file changed

+65
-0
lines changed

connectivity/FEATURE_BLE/source/generic/GapImpl.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,68 @@ class Gap :
506506
EventList<T>::Entry *_head;
507507
};
508508

509+
class PendingAdvertisingReportEvent {
510+
public:
511+
PendingAdvertisingReportEvent(
512+
const AdvertisingReportEvent& event_to_copy
513+
)
514+
{
515+
bool allocation_error = false;
516+
517+
/* copy the data to the buffer */
518+
const mbed::Span<const uint8_t> payload = event_to_copy.getPayload();
519+
if (payload.size()) {
520+
advertising_data_buffer = new(std::nothrow) uint8_t[payload.size()];
521+
if (advertising_data_buffer) {
522+
memcpy(advertising_data_buffer, payload.data(), payload.size());
523+
} else {
524+
allocation_error = true;
525+
}
526+
}
527+
528+
if (!allocation_error) {
529+
/* create a copy of the event */
530+
event = new(std::nothrow) AdvertisingReportEvent(event_to_copy);
531+
532+
if (event && payload.size()) {
533+
/* set the payload to our local copy of the data */
534+
event->setAdvertisingData(mbed::make_Span(advertising_data_buffer, payload.size()));
535+
}
536+
}
537+
};
538+
539+
~PendingAdvertisingReportEvent()
540+
{
541+
delete event;
542+
delete[] advertising_data_buffer;
543+
}
544+
545+
public:
546+
AdvertisingReportEvent *event = nullptr;
547+
548+
private:
549+
uint8_t *advertising_data_buffer = nullptr;
550+
};
551+
552+
class PendingConnectionCompleteEvent {
553+
public:
554+
PendingConnectionCompleteEvent(
555+
const ConnectionCompleteEvent& event_to_copy
556+
)
557+
{
558+
/* create a copy of the event */
559+
event = new(std::nothrow) ConnectionCompleteEvent(event_to_copy);
560+
};
561+
562+
~PendingConnectionCompleteEvent()
563+
{
564+
delete event;
565+
}
566+
567+
public:
568+
ConnectionCompleteEvent *event = nullptr;
569+
};
570+
509571
private:
510572
/* Disallow copy and assignment. */
511573
Gap(const Gap &);
@@ -731,6 +793,9 @@ class Gap :
731793
*/
732794
ble::Gap::EventHandler *_event_handler;
733795

796+
EventList<PendingAdvertisingReportEvent> _reports_pending_address_resolution;
797+
EventList<PendingConnectionCompleteEvent> _connections_pending_address_resolution;
798+
734799
PalEventQueue &_event_queue;
735800
PalGap &_pal_gap;
736801
PalGenericAccessService &_gap_service;

0 commit comments

Comments
 (0)