From 79c00be5168e58ea55f5a0ed9c44651b540b52db Mon Sep 17 00:00:00 2001 From: fbernon Date: Fri, 5 Oct 2007 13:34:48 +0000 Subject: [PATCH] netifapi.h, netifapi.c: add function netifapi_netif_set_default. Change the common function to reduce a little bit the footprint (for all functions using only the "netif" parameter). --- CHANGELOG | 5 ++ src/api/netifapi.c | 156 ++++++++++++------------------------ src/include/lwip/netifapi.h | 41 ++++------ 3 files changed, 71 insertions(+), 131 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index baef5d00..2a60fd46 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,11 @@ HISTORY ++ New features: + 2007-10-05 Frédéric Bernon + * netifapi.h, netifapi.c: add function netifapi_netif_set_default. Change the + common function to reduce a little bit the footprint (for all functions using + only the "netif" parameter). + 2007-10-03 Frédéric Bernon * netifapi.h, netifapi.c: add functions netifapi_netif_set_up, netifapi_netif_set_down, netifapi_autoip_start and netifapi_autoip_stop. Use a common function to reduce diff --git a/src/api/netifapi.c b/src/api/netifapi.c index ad8916ef..49183737 100644 --- a/src/api/netifapi.c +++ b/src/api/netifapi.c @@ -39,19 +39,40 @@ #include "lwip/tcpip.h" /** - * call the "do_function" in a thread-safe way by running that function inside the - * tcpip_thread context. - * - * @note use only for "do_netifapi" functions where there is only netif parameter. + * Call netif_add() inside the tcpip_thread context. */ -err_t -netifapi_netif_common(struct netif *netif, void (* function)(struct netifapi_msg_msg *msg)) +void +do_netifapi_netif_add( struct netifapi_msg_msg *msg) { - struct netifapi_msg msg; - msg.function = function; - msg.msg.netif = netif; - TCPIP_NETIFAPI(&msg); - return msg.msg.err; + if (!netif_add( msg->netif, + msg->msg.add.ipaddr, + msg->msg.add.netmask, + msg->msg.add.gw, + msg->msg.add.state, + msg->msg.add.init, + msg->msg.add.input)) { + msg->err = ERR_IF; + } else { + msg->err = ERR_OK; + } + TCPIP_NETIFAPI_ACK(msg); +} + +/** + * Call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) inside the + * tcpip_thread context. + */ +void +do_netifapi_netif_common( struct netifapi_msg_msg *msg) +{ + if (msg->msg.common.errtfunc!=NULL) { + msg->err = + msg->msg.common.errtfunc(msg->netif); + } else { + msg->err = ERR_OK; + msg->msg.common.voidfunc(msg->netif); + } + TCPIP_NETIFAPI_ACK(msg); } /** @@ -70,8 +91,8 @@ netifapi_netif_add(struct netif *netif, err_t (* input)(struct pbuf *p, struct netif *netif)) { struct netifapi_msg msg; - msg.function = do_netifapi_netif_add; - msg.msg.netif = netif; + msg.function = do_netifapi_netif_add; + msg.msg.netif = netif; msg.msg.msg.add.ipaddr = ipaddr; msg.msg.msg.add.netmask = netmask; msg.msg.msg.add.gw = gw; @@ -83,100 +104,23 @@ netifapi_netif_add(struct netif *netif, } /** - * @todo comment + * call the "errtfunc" (or the "voidfunc" if "errtfunc" is NULL) in a thread-safe + * way by running that function inside the tcpip_thread context. + * + * @note use only for functions where there is only "netif" parameter. */ -void -do_netifapi_netif_add( struct netifapi_msg_msg *msg) -{ - msg->err = ERR_OK; - if (!netif_add( msg->netif, - msg->msg.add.ipaddr, - msg->msg.add.netmask, - msg->msg.add.gw, - msg->msg.add.state, - msg->msg.add.init, - msg->msg.add.input)) { - msg->err = ERR_IF; - } - TCPIP_NETIFAPI_ACK(msg); -} - -/** - * @todo comment - */ -void -do_netifapi_netif_remove( struct netifapi_msg_msg *msg) -{ - msg->err = ERR_OK; - netif_remove(msg->netif); - TCPIP_NETIFAPI_ACK(msg); +err_t +netifapi_netif_common( struct netif *netif, + void (* voidfunc)(struct netif *netif), + err_t (* errtfunc)(struct netif *netif) ) +{ + struct netifapi_msg msg; + msg.function = do_netifapi_netif_common; + msg.msg.netif = netif; + msg.msg.msg.common.voidfunc = voidfunc; + msg.msg.msg.common.errtfunc = errtfunc; + TCPIP_NETIFAPI(&msg); + return msg.msg.err; } -/** - * @todo comment - */ -void -do_netifapi_netif_set_up( struct netifapi_msg_msg *msg) -{ - msg->err = ERR_OK; - netif_set_up(msg->netif); - TCPIP_NETIFAPI_ACK(msg); -} - -/** - * @todo comment - */ -void -do_netifapi_netif_set_down( struct netifapi_msg_msg *msg) -{ - msg->err = ERR_OK; - netif_set_down(msg->netif); - TCPIP_NETIFAPI_ACK(msg); -} - -#if LWIP_DHCP -/** - * @todo comment - */ -void -do_netifapi_dhcp_start( struct netifapi_msg_msg *msg) -{ - msg->err = dhcp_start(msg->netif); - TCPIP_NETIFAPI_ACK(msg); -} - -/** - * @todo comment - */ -void -do_netifapi_dhcp_stop( struct netifapi_msg_msg *msg) -{ - msg->err = ERR_OK; - dhcp_stop(msg->netif); - TCPIP_NETIFAPI_ACK(msg); -} -#endif /* LWIP_DHCP */ - -#if LWIP_AUTOIP -/** - * @todo comment - */ -void -do_netifapi_autoip_start( struct netifapi_msg_msg *msg) -{ - msg->err = autoip_start(msg->netif); - TCPIP_NETIFAPI_ACK(msg); -} - -/** - * @todo comment - */ -void -do_netifapi_autoip_stop( struct netifapi_msg_msg *msg) -{ - msg->err = autoip_stop(msg->netif); - TCPIP_NETIFAPI_ACK(msg); -} -#endif /* LWIP_AUTOIP */ - #endif /* LWIP_NETIF_API */ diff --git a/src/include/lwip/netifapi.h b/src/include/lwip/netifapi.h index 063441ad..36c6bd0a 100644 --- a/src/include/lwip/netifapi.h +++ b/src/include/lwip/netifapi.h @@ -53,9 +53,13 @@ struct netifapi_msg_msg { struct ip_addr *netmask; struct ip_addr *gw; void *state; - err_t (* init)(struct netif *netif); + err_t (* init) (struct netif *netif); err_t (* input)(struct pbuf *p, struct netif *netif); } add; + struct { + void (* voidfunc)(struct netif *netif); + err_t (* errtfunc)(struct netif *netif); + } common; } msg; }; @@ -66,8 +70,6 @@ struct netifapi_msg { /* API for application */ -err_t netifapi_netif_common ( struct netif *netif, void (* function)(struct netifapi_msg_msg *msg)); - err_t netifapi_netif_add ( struct netif *netif, struct ip_addr *ipaddr, struct ip_addr *netmask, @@ -76,29 +78,18 @@ err_t netifapi_netif_add ( struct netif *netif, err_t (* init)(struct netif *netif), err_t (* input)(struct pbuf *p, struct netif *netif) ); -#define netifapi_netif_remove(n) netifapi_netif_common(n, do_netifapi_netif_remove) -#define netifapi_netif_set_up(n) netifapi_netif_common(n, do_netifapi_netif_set_up) -#define netifapi_netif_set_down(n) netifapi_netif_common(n, do_netifapi_netif_set_down) -#define netifapi_dhcp_start(n) netifapi_netif_common(n, do_netifapi_dhcp_start) -#define netifapi_dhcp_stop(n) netifapi_netif_common(n, do_netifapi_dhcp_stop) -#define netifapi_autoip_start(n) netifapi_netif_common(n, do_netifapi_autoip_start) -#define netifapi_autoip_stop(n) netifapi_netif_common(n, do_netifapi_autoip_stop) - - -/* API for tcpip_thread */ -void do_netifapi_netif_add ( struct netifapi_msg_msg *msg); -void do_netifapi_netif_remove ( struct netifapi_msg_msg *msg); -void do_netifapi_netif_set_up ( struct netifapi_msg_msg *msg); -void do_netifapi_netif_set_down( struct netifapi_msg_msg *msg); -#if LWIP_DHCP -void do_netifapi_dhcp_start ( struct netifapi_msg_msg *msg); -void do_netifapi_dhcp_stop ( struct netifapi_msg_msg *msg); -#endif /* LWIP_DHCP */ -#if LWIP_AUTOIP -void do_netifapi_autoip_start ( struct netifapi_msg_msg *msg); -void do_netifapi_autoip_stop ( struct netifapi_msg_msg *msg); -#endif /* LWIP_AUTOIP */ +err_t netifapi_netif_common ( struct netif *netif, + void (* voidfunc)(struct netif *netif), + err_t (* errtfunc)(struct netif *netif) ); +#define netifapi_netif_remove(n) netifapi_netif_common(n, netif_remove, NULL) +#define netifapi_netif_set_up(n) netifapi_netif_common(n, netif_set_up, NULL) +#define netifapi_netif_set_down(n) netifapi_netif_common(n, netif_set_down, NULL) +#define netifapi_netif_set_default(n) netifapi_netif_common(n, netif_set_default, NULL) +#define netifapi_dhcp_start(n) netifapi_netif_common(n, NULL, dhcp_start) +#define netifapi_dhcp_stop(n) netifapi_netif_common(n, dhcp_stop, NULL) +#define netifapi_autoip_start(n) netifapi_netif_common(n, NULL, autoip_start) +#define netifapi_autoip_stop(n) netifapi_netif_common(n, NULL, autoip_stop) #ifdef __cplusplus }