TwitterExample with newer library (2012Aug)

Dependencies:   EthernetNetIf HTTPClient mbed

Committer:
nxpfan
Date:
Wed Aug 29 03:50:19 2012 +0000
Revision:
0:075157567b0c
simple twitter example with newer library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxpfan 0:075157567b0c 1 /*
nxpfan 0:075157567b0c 2 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
nxpfan 0:075157567b0c 3 * All rights reserved.
nxpfan 0:075157567b0c 4 *
nxpfan 0:075157567b0c 5 * Redistribution and use in source and binary forms, with or without modification,
nxpfan 0:075157567b0c 6 * are permitted provided that the following conditions are met:
nxpfan 0:075157567b0c 7 *
nxpfan 0:075157567b0c 8 * 1. Redistributions of source code must retain the above copyright notice,
nxpfan 0:075157567b0c 9 * this list of conditions and the following disclaimer.
nxpfan 0:075157567b0c 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
nxpfan 0:075157567b0c 11 * this list of conditions and the following disclaimer in the documentation
nxpfan 0:075157567b0c 12 * and/or other materials provided with the distribution.
nxpfan 0:075157567b0c 13 * 3. The name of the author may not be used to endorse or promote products
nxpfan 0:075157567b0c 14 * derived from this software without specific prior written permission.
nxpfan 0:075157567b0c 15 *
nxpfan 0:075157567b0c 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
nxpfan 0:075157567b0c 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
nxpfan 0:075157567b0c 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
nxpfan 0:075157567b0c 19 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
nxpfan 0:075157567b0c 20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
nxpfan 0:075157567b0c 21 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
nxpfan 0:075157567b0c 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
nxpfan 0:075157567b0c 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
nxpfan 0:075157567b0c 24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
nxpfan 0:075157567b0c 25 * OF SUCH DAMAGE.
nxpfan 0:075157567b0c 26 *
nxpfan 0:075157567b0c 27 * This file is part of the lwIP TCP/IP stack.
nxpfan 0:075157567b0c 28 *
nxpfan 0:075157567b0c 29 * Author: Adam Dunkels <adam@sics.se>
nxpfan 0:075157567b0c 30 *
nxpfan 0:075157567b0c 31 */
nxpfan 0:075157567b0c 32 #ifndef __LWIP_API_MSG_H__
nxpfan 0:075157567b0c 33 #define __LWIP_API_MSG_H__
nxpfan 0:075157567b0c 34
nxpfan 0:075157567b0c 35 #include "lwip/opt.h"
nxpfan 0:075157567b0c 36
nxpfan 0:075157567b0c 37 #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */
nxpfan 0:075157567b0c 38
nxpfan 0:075157567b0c 39 #include <stddef.h> /* for size_t */
nxpfan 0:075157567b0c 40
nxpfan 0:075157567b0c 41 #include "lwip/ip_addr.h"
nxpfan 0:075157567b0c 42 #include "lwip/err.h"
nxpfan 0:075157567b0c 43 #include "lwip/sys.h"
nxpfan 0:075157567b0c 44 #include "lwip/igmp.h"
nxpfan 0:075157567b0c 45 #include "lwip/api.h"
nxpfan 0:075157567b0c 46
nxpfan 0:075157567b0c 47 #ifdef __cplusplus
nxpfan 0:075157567b0c 48 extern "C" {
nxpfan 0:075157567b0c 49 #endif
nxpfan 0:075157567b0c 50
nxpfan 0:075157567b0c 51 #define NETCONN_SHUT_RD 1
nxpfan 0:075157567b0c 52 #define NETCONN_SHUT_WR 2
nxpfan 0:075157567b0c 53 #define NETCONN_SHUT_RDWR 3
nxpfan 0:075157567b0c 54
nxpfan 0:075157567b0c 55 /* IP addresses and port numbers are expected to be in
nxpfan 0:075157567b0c 56 * the same byte order as in the corresponding pcb.
nxpfan 0:075157567b0c 57 */
nxpfan 0:075157567b0c 58 /** This struct includes everything that is necessary to execute a function
nxpfan 0:075157567b0c 59 for a netconn in another thread context (mainly used to process netconns
nxpfan 0:075157567b0c 60 in the tcpip_thread context to be thread safe). */
nxpfan 0:075157567b0c 61 struct api_msg_msg {
nxpfan 0:075157567b0c 62 /** The netconn which to process - always needed: it includes the semaphore
nxpfan 0:075157567b0c 63 which is used to block the application thread until the function finished. */
nxpfan 0:075157567b0c 64 struct netconn *conn;
nxpfan 0:075157567b0c 65 /** The return value of the function executed in tcpip_thread. */
nxpfan 0:075157567b0c 66 err_t err;
nxpfan 0:075157567b0c 67 /** Depending on the executed function, one of these union members is used */
nxpfan 0:075157567b0c 68 union {
nxpfan 0:075157567b0c 69 /** used for do_send */
nxpfan 0:075157567b0c 70 struct netbuf *b;
nxpfan 0:075157567b0c 71 /** used for do_newconn */
nxpfan 0:075157567b0c 72 struct {
nxpfan 0:075157567b0c 73 u8_t proto;
nxpfan 0:075157567b0c 74 } n;
nxpfan 0:075157567b0c 75 /** used for do_bind and do_connect */
nxpfan 0:075157567b0c 76 struct {
nxpfan 0:075157567b0c 77 ip_addr_t *ipaddr;
nxpfan 0:075157567b0c 78 u16_t port;
nxpfan 0:075157567b0c 79 } bc;
nxpfan 0:075157567b0c 80 /** used for do_getaddr */
nxpfan 0:075157567b0c 81 struct {
nxpfan 0:075157567b0c 82 ip_addr_t *ipaddr;
nxpfan 0:075157567b0c 83 u16_t *port;
nxpfan 0:075157567b0c 84 u8_t local;
nxpfan 0:075157567b0c 85 } ad;
nxpfan 0:075157567b0c 86 /** used for do_write */
nxpfan 0:075157567b0c 87 struct {
nxpfan 0:075157567b0c 88 const void *dataptr;
nxpfan 0:075157567b0c 89 size_t len;
nxpfan 0:075157567b0c 90 u8_t apiflags;
nxpfan 0:075157567b0c 91 } w;
nxpfan 0:075157567b0c 92 /** used for do_recv */
nxpfan 0:075157567b0c 93 struct {
nxpfan 0:075157567b0c 94 u32_t len;
nxpfan 0:075157567b0c 95 } r;
nxpfan 0:075157567b0c 96 /** used for do_close (/shutdown) */
nxpfan 0:075157567b0c 97 struct {
nxpfan 0:075157567b0c 98 u8_t shut;
nxpfan 0:075157567b0c 99 } sd;
nxpfan 0:075157567b0c 100 #if LWIP_IGMP
nxpfan 0:075157567b0c 101 /** used for do_join_leave_group */
nxpfan 0:075157567b0c 102 struct {
nxpfan 0:075157567b0c 103 ip_addr_t *multiaddr;
nxpfan 0:075157567b0c 104 ip_addr_t *netif_addr;
nxpfan 0:075157567b0c 105 enum netconn_igmp join_or_leave;
nxpfan 0:075157567b0c 106 } jl;
nxpfan 0:075157567b0c 107 #endif /* LWIP_IGMP */
nxpfan 0:075157567b0c 108 #if TCP_LISTEN_BACKLOG
nxpfan 0:075157567b0c 109 struct {
nxpfan 0:075157567b0c 110 u8_t backlog;
nxpfan 0:075157567b0c 111 } lb;
nxpfan 0:075157567b0c 112 #endif /* TCP_LISTEN_BACKLOG */
nxpfan 0:075157567b0c 113 } msg;
nxpfan 0:075157567b0c 114 };
nxpfan 0:075157567b0c 115
nxpfan 0:075157567b0c 116 /** This struct contains a function to execute in another thread context and
nxpfan 0:075157567b0c 117 a struct api_msg_msg that serves as an argument for this function.
nxpfan 0:075157567b0c 118 This is passed to tcpip_apimsg to execute functions in tcpip_thread context. */
nxpfan 0:075157567b0c 119 struct api_msg {
nxpfan 0:075157567b0c 120 /** function to execute in tcpip_thread context */
nxpfan 0:075157567b0c 121 void (* function)(struct api_msg_msg *msg);
nxpfan 0:075157567b0c 122 /** arguments for this function */
nxpfan 0:075157567b0c 123 struct api_msg_msg msg;
nxpfan 0:075157567b0c 124 };
nxpfan 0:075157567b0c 125
nxpfan 0:075157567b0c 126 #if LWIP_DNS
nxpfan 0:075157567b0c 127 /** As do_gethostbyname requires more arguments but doesn't require a netconn,
nxpfan 0:075157567b0c 128 it has its own struct (to avoid struct api_msg getting bigger than necessary).
nxpfan 0:075157567b0c 129 do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
nxpfan 0:075157567b0c 130 (see netconn_gethostbyname). */
nxpfan 0:075157567b0c 131 struct dns_api_msg {
nxpfan 0:075157567b0c 132 /** Hostname to query or dotted IP address string */
nxpfan 0:075157567b0c 133 const char *name;
nxpfan 0:075157567b0c 134 /** Rhe resolved address is stored here */
nxpfan 0:075157567b0c 135 ip_addr_t *addr;
nxpfan 0:075157567b0c 136 /** This semaphore is posted when the name is resolved, the application thread
nxpfan 0:075157567b0c 137 should wait on it. */
nxpfan 0:075157567b0c 138 sys_sem_t *sem;
nxpfan 0:075157567b0c 139 /** Errors are given back here */
nxpfan 0:075157567b0c 140 err_t *err;
nxpfan 0:075157567b0c 141 };
nxpfan 0:075157567b0c 142 #endif /* LWIP_DNS */
nxpfan 0:075157567b0c 143
nxpfan 0:075157567b0c 144 void do_newconn ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 145 void do_delconn ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 146 void do_bind ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 147 void do_connect ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 148 void do_disconnect ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 149 void do_listen ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 150 void do_send ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 151 void do_recv ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 152 void do_write ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 153 void do_getaddr ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 154 void do_close ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 155 void do_shutdown ( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 156 #if LWIP_IGMP
nxpfan 0:075157567b0c 157 void do_join_leave_group( struct api_msg_msg *msg);
nxpfan 0:075157567b0c 158 #endif /* LWIP_IGMP */
nxpfan 0:075157567b0c 159
nxpfan 0:075157567b0c 160 #if LWIP_DNS
nxpfan 0:075157567b0c 161 void do_gethostbyname(void *arg);
nxpfan 0:075157567b0c 162 #endif /* LWIP_DNS */
nxpfan 0:075157567b0c 163
nxpfan 0:075157567b0c 164 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
nxpfan 0:075157567b0c 165 void netconn_free(struct netconn *conn);
nxpfan 0:075157567b0c 166
nxpfan 0:075157567b0c 167 #ifdef __cplusplus
nxpfan 0:075157567b0c 168 }
nxpfan 0:075157567b0c 169 #endif
nxpfan 0:075157567b0c 170
nxpfan 0:075157567b0c 171 #endif /* LWIP_NETCONN */
nxpfan 0:075157567b0c 172
nxpfan 0:075157567b0c 173 #endif /* __LWIP_API_MSG_H__ */