netif: add netif_remove_ext_callback() (counterpart to netif_add_ext_callback())

This commit is contained in:
goldsimon 2018-01-12 22:25:34 +01:00
parent d115b28057
commit 452c6a5378
2 changed files with 38 additions and 2 deletions

View File

@ -1637,7 +1637,8 @@ netif_find(const char *name)
* @param callback pointer to listener structure
* @param fn callback function
*/
void netif_add_ext_callback(netif_ext_callback_t *callback, netif_ext_callback_fn fn)
void
netif_add_ext_callback(netif_ext_callback_t *callback, netif_ext_callback_fn fn)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("callback must be != NULL", callback != NULL);
@ -1648,13 +1649,46 @@ void netif_add_ext_callback(netif_ext_callback_t *callback, netif_ext_callback_f
ext_callback = callback;
}
/**
* @ingroup netif
* Remove extended netif events listener
* @param callback pointer to listener structure
*/
void
netif_remove_ext_callback(netif_ext_callback_t* callback)
{
netif_ext_callback_t *last, *iter;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("callback must be != NULL", callback != NULL);
if (ext_callback == NULL) {
return;
}
if (callback == ext_callback) {
ext_callback = ext_callback->next;
} else {
last = ext_callback;
for (iter = ext_callback->next; iter != NULL; last = iter, iter = iter->next) {
if (iter == callback) {
LWIP_ASSERT("last != NULL", last != NULL);
last->next = callback->next;
callback->next = NULL;
return;
}
}
}
}
/**
* Invoke extended netif status event
* @param netif netif that is affected by change
* @param reason change reason
* @param args depends on reason, see reason description
*/
void netif_invoke_ext_callback(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
void
netif_invoke_ext_callback(struct netif *netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t *args)
{
netif_ext_callback_t *callback = ext_callback;

View File

@ -633,10 +633,12 @@ typedef struct netif_ext_callback
#define NETIF_DECLARE_EXT_CALLBACK(name) static netif_ext_callback_t name;
void netif_add_ext_callback(netif_ext_callback_t* callback, netif_ext_callback_fn fn);
void netif_remove_ext_callback(netif_ext_callback_t* callback);
void netif_invoke_ext_callback(struct netif* netif, netif_nsc_reason_t reason, const netif_ext_callback_args_t* args);
#else
#define NETIF_DECLARE_EXT_CALLBACK(name)
#define netif_add_ext_callback(callback, fn)
#define netif_remove_ext_callback(callback)
#define netif_invoke_ext_callback(netif, reason, args)
#endif