Merge pull request #14525 from jarlamsa/no_duplicate_status_cb_feature_wisun

Check for duplicate status callbacks before adding to the list
pull/14586/head feature-wisun-1.6.0
Arto Kinnunen 2021-04-20 11:40:34 +03:00 committed by GitHub
commit b1796dedeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -149,6 +149,11 @@ static void call_all_event_listeners(NetworkInterface *iface, nsapi_event_t even
void NetworkInterface::add_event_listener(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb)
{
iface_eventlist_t *event_list = get_interface_event_list_head();
ns_list_foreach_safe(iface_eventlist_entry_t, entry, event_list) {
if (entry->status_cb == status_cb && entry->iface == this) {
return;
}
}
iface_eventlist_entry_t *entry = new iface_eventlist_entry_t;
entry->iface = this;
entry->status_cb = status_cb;
@ -163,7 +168,6 @@ void NetworkInterface::remove_event_listener(mbed::Callback<void(nsapi_event_t,
if (entry->status_cb == status_cb && entry->iface == this) {
ns_list_remove(event_list, entry);
delete entry;
return;
}
}
}