Skip to content

Commit

Permalink
remember state for searching
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-szczepanek-arm committed Sep 18, 2020
1 parent c37a593 commit 5cf3b08
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
6 changes: 4 additions & 2 deletions connectivity/FEATURE_BLE/source/generic/GapImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3055,11 +3055,13 @@ void Gap::on_address_resolution_completed(
#endif //BLE_FEATURE_CONNECTABLE

#if BLE_ROLE_OBSERVER
uint8_t items_searched = 0;
while(true) {
PendingAdvertisingReportEvent *event = _reports_pending_address_resolution.pop(
PendingAdvertisingReportEvent *event = _reports_pending_address_resolution.continue_pop(
[peer_resolvable_address](PendingAdvertisingReportEvent &event){
return (event.get_pending_event().getPeerAddress() == peer_resolvable_address);
}
},
&items_searched
);

if (!event) {
Expand Down
21 changes: 21 additions & 0 deletions connectivity/FEATURE_BLE/source/generic/GapImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,26 @@ class Gap :
return nullptr;
}

/** Return pointer to the first element that fulfills the passed in condition and remove the entry
* that was pointing to the item. Transfers ownership to caller.
*
* @param compare_func The condition that is checked for all the items start from last put in.
* @param elements_searched Pointer to the number of items already searched. This is updated in the method.
* @return First element that fulfills the passed in condition or nullptr if no such item found.
*/
EventType* continue_pop(mbed::Callback<bool(EventType&)> compare_func, IndexType *events_searched)
{
for (IndexType i = *events_searched; i < _current_size ; ++i) {
(*events_searched)++;
if (compare_func(*_pointers[_current_index])) {
return pop();
}
increment_current_index();
}

return nullptr;
}

/** Return pointer to the first element that fulfills the passed in condition. Does not remove item from list.
*
* @param compare_func The condition that is checked for all the items start from last put in.
Expand Down Expand Up @@ -462,6 +482,7 @@ class Gap :
private:
EventType* _pointers[MAX_EVENTS];
IndexType _current_size = 0;
/* this helps us find the event faster */
IndexType _current_index = 0;
};

Expand Down

0 comments on commit 5cf3b08

Please sign in to comment.