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.
*
*
* $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
@ -107,14 +107,42 @@ enum {
/* Called on IP packet output. */
#if UIP_CONF_IPV6
u8_t (* tcpip_output)(uip_lladdr_t *);
#else
static u8_t dummy_tcpip_output_function(void)
static u8_t (* outputfunc)(uip_lladdr_t *a);
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;
}
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
#if UIP_CONF_IP_FORWARD
@ -685,7 +713,7 @@ PROCESS_THREAD(tcpip_process, ev, data)
s.p = PROCESS_CURRENT();
}
#endif
tcpip_event = process_alloc_event();
etimer_set(&periodic, CLOCK_SECOND/2);

View File

@ -62,7 +62,7 @@
*
* 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__
#define __TCPIP_H__
@ -288,11 +288,11 @@ CCIF void tcpip_poll_udp(struct uip_udp_conn *conn);
*
* This function just registers a process to be polled when
* an ICMPv6 message is received.
* If no application registers, some ICMPv6 packets will be
* If no application registers, some ICMPv6 packets will be
* processed by the "kernel" as usual (NS, NA, RS, RA, Echo request),
* others will be dropped.
* If an appplication registers here, it will be polled with a
* process_post_synch everytime an ICMPv6 packet is received.
* process_post_synch everytime an ICMPv6 packet is received.
*/
u8_t icmp6_new(void *appstate);
@ -333,9 +333,11 @@ CCIF void tcpip_input(void);
* The eventual parameter is the MAC address of the destination.
*/
#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
extern u8_t (* tcpip_output)(void);
void tcpip_set_outputfunc(u8_t (* f)(void));
u8_t tcpip_output(void);
#endif
/**
@ -355,7 +357,7 @@ extern unsigned char tcpip_do_forwarding;
*/
extern unsigned char tcpip_is_forwarding;
#define tcpip_set_outputfunc(outputfunc) tcpip_output = (outputfunc)
#define tcpip_set_forwarding(forwarding) tcpip_do_forwarding = (forwarding)
/** @} */