Rewrote the tcpip_output() and tcpip_set_outputfunc() so that the latter is a proper function (which simplifies debugging) and so that tcpip_output() checks if the output callback function is NULL before calling it

This commit is contained in:
adamdunkels 2009-02-20 21:21:56 +00:00
parent 7c86f70573
commit 4ec5167276
2 changed files with 43 additions and 13 deletions

View file

@ -29,7 +29,7 @@
* This file is part of the Contiki operating system. * This file is part of the Contiki operating system.
* *
* *
* $Id: tcpip.c,v 1.18 2009/02/20 07:59:36 julienabeille Exp $ * $Id: tcpip.c,v 1.19 2009/02/20 21:21:56 adamdunkels Exp $
*/ */
/** /**
* \file * \file
@ -107,14 +107,42 @@ enum {
/* Called on IP packet output. */ /* Called on IP packet output. */
#if UIP_CONF_IPV6 #if UIP_CONF_IPV6
u8_t (* tcpip_output)(uip_lladdr_t *);
#else static u8_t (* outputfunc)(uip_lladdr_t *a);
static u8_t dummy_tcpip_output_function(void)
u8_t
tcpip_output(uip_lladdr_t *a)
{ {
UIP_LOG("dummy_tcpip_output_function: Use tcpip_set_outputfunc() to replace this dummy"); if(outputfunc != NULL) {
return outputfunc(a);
}
UIP_LOG("tcpip_output: Use tcpip_set_outputfunc() to set an output function");
return 0; return 0;
} }
u8_t (* tcpip_output)(void) = dummy_tcpip_output_function;
void
tcpip_set_outputfunc(u8_t (*f)(uip_lladdr_t *))
{
outputfunc = f;
}
#else
static u8_t (* outputfunc)(void);
u8_t
tcpip_output(void)
{
if(outputfunc != NULL) {
return outputfunc();
}
UIP_LOG("tcpip_output: Use tcpip_set_outputfunc() to set an output function");
return 0;
}
void
tcpip_set_outputfunc(u8_t (*f)(void))
{
outputfunc = f;
}
#endif #endif
#if UIP_CONF_IP_FORWARD #if UIP_CONF_IP_FORWARD

View file

@ -62,7 +62,7 @@
* *
* Author: Adam Dunkels <adam@sics.se> * Author: Adam Dunkels <adam@sics.se>
* *
* $Id: tcpip.h,v 1.12 2008/10/14 09:40:56 julienabeille Exp $ * $Id: tcpip.h,v 1.13 2009/02/20 21:21:57 adamdunkels Exp $
*/ */
#ifndef __TCPIP_H__ #ifndef __TCPIP_H__
#define __TCPIP_H__ #define __TCPIP_H__
@ -333,9 +333,11 @@ CCIF void tcpip_input(void);
* The eventual parameter is the MAC address of the destination. * The eventual parameter is the MAC address of the destination.
*/ */
#if UIP_CONF_IPV6 #if UIP_CONF_IPV6
extern u8_t (* tcpip_output)(uip_lladdr_t *); u8_t tcpip_output(uip_lladdr_t *);
void tcpip_set_outputfunc(u8_t (* f)(uip_lladdr_t *));
#else #else
extern u8_t (* tcpip_output)(void); void tcpip_set_outputfunc(u8_t (* f)(void));
u8_t tcpip_output(void);
#endif #endif
/** /**
@ -355,7 +357,7 @@ extern unsigned char tcpip_do_forwarding;
*/ */
extern unsigned char tcpip_is_forwarding; extern unsigned char tcpip_is_forwarding;
#define tcpip_set_outputfunc(outputfunc) tcpip_output = (outputfunc)
#define tcpip_set_forwarding(forwarding) tcpip_do_forwarding = (forwarding) #define tcpip_set_forwarding(forwarding) tcpip_do_forwarding = (forwarding)
/** @} */ /** @} */