~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
cvs/emstar/fusd/fusdd/fusdd_net_i.h


  1 /*
  2  *
  3  * Copyright (c) 2003 The Regents of the University of California.  All 
  4  * rights reserved.
  5  *
  6  * Redistribution and use in source and binary forms, with or without
  7  * modification, are permitted provided that the following conditions
  8  * are met:
  9  *
 10  * - Redistributions of source code must retain the above copyright
 11  *   notice, this list of conditions and the following disclaimer.
 12  *
 13  * - Neither the name of the University nor the names of its
 14  *   contributors may be used to endorse or promote products derived
 15  *   from this software without specific prior written permission.
 16  *
 17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
 18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 19  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 20  * PARTICULAR  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
 21  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 23  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 24  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 25  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 27  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28  *
 29  */
 30  
 31 #include <stdio.h>
 32 #include <stdlib.h>
 33 #include <unistd.h>
 34 #include <sys/types.h>
 35 #include <sys/stat.h>
 36 #include <sys/time.h>
 37 #include <sys/uio.h>
 38 #include <sys/ioctl.h>
 39 #include <fcntl.h>
 40 #include <errno.h>
 41 #include <string.h>
 42 #include <time.h>
 43 #include <sys/poll.h>
 44 #include <sys/socket.h>
 45 #include <netinet/in.h>
 46 #include <arpa/inet.h>
 47 
 48 #include "fusd.h"
 49 #include "fusd_msg.h"
 50 #include "fusdd_net_fnsi_i.h"
 51 
 52 #ifndef __FUSDD_NET_I_H__
 53 #define __FUSDD_NET_I_H__
 54 
 55 /*
 56  *  Networking
 57  */
 58 
 59 #include <libdev/status_dev.h>
 60 #include <libdev/command_dev.h>
 61 #include <libdev/logring_dev.h>
 62 
 63 
 64 typedef struct fusdnet_socket fn_socket_t;
 65 typedef struct fusdnet_server_socket fns_socket_t;
 66 typedef struct fusdnet_server fn_server_t;
 67 typedef struct fusdnet fn_t;
 68 typedef struct fusdnet_client fn_client_t;
 69 
 70 
 71 typedef void (* message_arrived_cb_t)(fn_socket_t *fs, fusd_msg_t *msg);
 72 typedef void (* closed_cb_t)(fn_socket_t *fs, int retval);
 73 
 74 struct fusdnet_socket {
 75   /* the socket to the client */
 76   int socket_fd;
 77   char *socket_name;
 78 
 79   /* the input buffer, and a message ready indicator */
 80   buf_t *input_buffer;
 81   buf_t *output_buffer;
 82   int message_ready:1;
 83   
 84   /* socket event */
 85   g_event_t *read_event;
 86   g_event_t *write_event;
 87 
 88   /* callback */
 89   message_arrived_cb_t arrived;  /* called on message arrival */
 90   closed_cb_t closed;            /* called on socket closed */
 91   void *private_data;
 92 };
 93 
 94 /*
 95  *  NOTE: allocated fusd messages are always two separate
 96  *  buffers: the fusd_msg_t itself, and the data pointer
 97  *  (if present), separately allocated and freed.
 98  */
 99 
100 /*
101  *  Socket API
102  *
103  *  Initializes/destroys the events, etc.
104  *    call this function with close, arrived, private_data,
105  *    socket_fd and socket_name set
106  *
107  *  Caller is responsible to free socket_name and private_data.
108  */
109 int fn_socket_config(fn_socket_t *sock);
110 void fn_socket_destroy(fn_socket_t *sock);
111 
112 /* 
113  * read API 
114  *
115  * NOTE: read callback passes an allocated fusd_msg
116  */
117 void fn_socket_read_set_blocked(fn_socket_t *fs, int block);
118 
119 /* 
120  * write API 
121  */
122 int fn_socket_write(fn_socket_t *fs, fusd_msg_t *msg);
123 
124 
125 /*
126  *  Server Data Structures
127  */
128 
129 typedef struct fns_client {
130   FNSI_DECL;
131   void *private_info;
132   void *remote_device_info;
133   fusd_msg_t sample;
134 } fns_client_t;
135 
136 struct fusdnet_server_socket {
137   /* socket and address state */
138   fn_socket_t socket;
139   struct sockaddr_in from_addr; 
140 
141   /* per-open state, needed to keep 
142    * private data and forge closes */
143   GArray *clients;
144 
145   QUEUE_ELEMENT_DECL(_,struct fusdnet_server_socket);
146   fn_server_t *parent;
147 };
148 
149 typedef struct fns_exp_msg {
150   fusd_msg_t *outgoing;
151   void *outgoing_data;
152   int datalen;
153   fns_socket_t *owner;
154 } fns_exp_msg_t;
155 
156 struct fusdnet_server {
157   /* device name */
158   char *device_name;
159   int destroying;
160 
161   /* active client sockets */
162   QUEUE_DECL(sockets, fns_socket_t);
163 
164   /* pending messages */
165 
166   /* outgoing.. broken out into two buffers */
167   GArray *outgoing_msgs;
168 
169   /* incoming */
170   fusd_msg_t *incoming;
171   void *incoming_demux_token;
172 
173   /* pending poll diff */
174   fusd_file_info_t *poll_diff;
175   
176   /* queue pointers */
177   QUEUE_ELEMENT_DECL(_, struct fusdnet_server);
178   fn_t *parent;
179 };
180 
181 
182 
183 struct fusdnet {
184   logring_context_t *log;      /* log */
185   status_context_t *status;    /* status */
186 
187   /* server side state */
188   int incoming;                /* bound socket */
189   fusd_context_t *server_channel;   /* FUSD control channel to servers */ 
190   QUEUE_DECL(servers, fn_server_t);
191   fn_server_t unconnected;     /* sockets that have registered */
192 };
193 
194 
195 /* use log not elog... we're below the pinit level! */
196 void nlog(int loglevel, char *fmt, ...)  __attribute__ ((format (printf, 2, 3)));
197 
198 /* start funcs for client and server sides */
199 void fusdnet_server_init(fn_t *state);
200 void fusdnet_client_init(fn_t *state);
201 
202 /* status report functions */
203 void fns_status_print(fn_t *fn, buf_t *buf);
204 void fnc_status_print(fn_t *fn, buf_t *buf);
205 void fn_status_notify(fn_t *fn);
206 void fusdnet_status_init(fn_t *state);
207 
208 void fusd_msg_free(fusd_msg_t *msg);
209 
210 
211 #endif
212 
213 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.