Dependents:   SimpleLCDClock readCard2Twitter_http AnalogClock_StepperMotor_NTP ServoCamV1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers api_msg.h Source File

api_msg.h

00001 /*
00002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00003  * All rights reserved. 
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission. 
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  * 
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 #ifndef __LWIP_API_MSG_H__
00033 #define __LWIP_API_MSG_H__
00034 
00035 #include "lwip/opt.h"
00036 
00037 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
00038 
00039 #include <stddef.h> /* for size_t */
00040 
00041 #include "lwip/ip_addr.h"
00042 #include "lwip/err.h"
00043 #include "lwip/sys.h"
00044 #include "lwip/igmp.h"
00045 #include "lwip/api.h"
00046 
00047 #ifdef __cplusplus
00048 extern "C" {
00049 #endif
00050 
00051 /* IP addresses and port numbers are expected to be in
00052  * the same byte order as in the corresponding pcb.
00053  */
00054 /** This struct includes everything that is necessary to execute a function
00055     for a netconn in another thread context (mainly used to process netconns
00056     in the tcpip_thread context to be thread safe). */
00057 struct api_msg_msg {
00058   /** The netconn which to process - always needed: it includes the semaphore
00059       which is used to block the application thread until the function finished. */
00060   struct netconn *conn;
00061   /** The return value of the function executed in tcpip_thread. */
00062   err_t err;
00063   /** Depending on the executed function, one of these union members is used */
00064   union {
00065     /** used for do_send */
00066     struct netbuf *b;
00067     /** used for do_newconn */
00068     struct {
00069       u8_t proto;
00070     } n;
00071     /** used for do_bind and do_connect */
00072     struct {
00073       ip_addr_t *ipaddr;
00074       u16_t port;
00075     } bc;
00076     /** used for do_getaddr */
00077     struct {
00078       ip_addr_t *ipaddr;
00079       u16_t *port;
00080       u8_t local;
00081     } ad;
00082     /** used for do_write */
00083     struct {
00084       const void *dataptr;
00085       size_t len;
00086       u8_t apiflags;
00087     } w;
00088     /** used for do_recv */
00089     struct {
00090       u32_t len;
00091     } r;
00092 #if LWIP_IGMP
00093     /** used for do_join_leave_group */
00094     struct {
00095       ip_addr_t *multiaddr;
00096       ip_addr_t *netif_addr;
00097       enum netconn_igmp join_or_leave;
00098     } jl;
00099 #endif /* LWIP_IGMP */
00100 #if TCP_LISTEN_BACKLOG
00101     struct {
00102       u8_t backlog;
00103     } lb;
00104 #endif /* TCP_LISTEN_BACKLOG */
00105   } msg;
00106 };
00107 
00108 /** This struct contains a function to execute in another thread context and
00109     a struct api_msg_msg that serves as an argument for this function.
00110     This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */
00111 struct api_msg {
00112   /** function to execute in tcpip_thread context */
00113   void (* function)(struct api_msg_msg *msg);
00114   /** arguments for this function */
00115   struct api_msg_msg msg;
00116 };
00117 
00118 #if LWIP_DNS
00119 /** As do_gethostbyname requires more arguments but doesn't require a netconn,
00120     it has its own struct (to avoid struct api_msg getting bigger than necessary).
00121     do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
00122     (see netconn_gethostbyname). */
00123 struct dns_api_msg {
00124   /** Hostname to query or dotted IP address string */
00125   const char *name;
00126   /** Rhe resolved address is stored here */
00127   ip_addr_t *addr;
00128   /** This semaphore is posted when the name is resolved, the application thread
00129       should wait on it. */
00130   sys_sem_t *sem;
00131   /** Errors are given back here */
00132   err_t *err;
00133 };
00134 #endif /* LWIP_DNS */
00135 
00136 void do_newconn         ( struct api_msg_msg *msg);
00137 void do_delconn         ( struct api_msg_msg *msg);
00138 void do_bind            ( struct api_msg_msg *msg);
00139 void do_connect         ( struct api_msg_msg *msg);
00140 void do_disconnect      ( struct api_msg_msg *msg);
00141 void do_listen          ( struct api_msg_msg *msg);
00142 void do_send            ( struct api_msg_msg *msg);
00143 void do_recv            ( struct api_msg_msg *msg);
00144 void do_write           ( struct api_msg_msg *msg);
00145 void do_getaddr         ( struct api_msg_msg *msg);
00146 void do_close           ( struct api_msg_msg *msg);
00147 #if LWIP_IGMP
00148 void do_join_leave_group( struct api_msg_msg *msg);
00149 #endif /* LWIP_IGMP */
00150 
00151 #if LWIP_DNS
00152 void do_gethostbyname(void *arg);
00153 #endif /* LWIP_DNS */
00154 
00155 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
00156 void netconn_free(struct netconn *conn);
00157 
00158 #ifdef __cplusplus
00159 }
00160 #endif
00161 
00162 #endif /* LWIP_NETCONN */
00163 
00164 #endif /* __LWIP_API_MSG_H__ */