|
|
Jump to this file's LXR Page |
|
|
File: [CENS] / emstar / fusd / fusdd / fusdd_net_i.h
(download)
/
(as text)
Revision: 1.15, Tue Jan 18 02:59:41 2005 UTC (4 years, 10 months ago) by girod Branch: MAIN CVS Tags: rdd_alpha_version_1, pregeonet, mote, acoustic-05-18-06, PRE_TOSNIC_FIX, PRE_64BIT, MOTENIC_PRE_BUGFIX_20050415, LAURA_CALIBRATION_EXPERIMENTS, HEAD, ESS_RELEASE_3_5, ESS_RELEASE_3_4, ESS_RELEASE_3_3, ESS_RELEASE_3_2, ESS_RELEASE_3_1, ESS_RELEASE_3_0, ESS_RELEASE_2_0, ESS_CONNECTIVITY, ESS_CENTROUTE_TESTING, ESS2-CMS-V1_5_pretest, ESS2-CMS-V1_4cMergeSympathy_2, ESS2-CMS-V1_4c, ESS2-CMS-V1_4b, ESS2-CMS-V1_4a, ESS2-CMS-V1_3, ESS2-CMS-V1_2, ESS2-CMS-V1_1, ESS2-CMS-V1_0, EMSTAR_RELEASE_2_5, EMSTAR_RELEASE_2_1_BRANCH, EMSTAR_RELEASE_2_1, CYCLOPS_RELEASE_CANDIDATE_2_0, CYCLOPS_PRERELEASE_STABLE, CENTROUTE_EMSTAR_SOCKETS, BG_1_0, BANGLADESH_ARSENIC_1_2, BANGLADESH_ARSENIC_1_1, AMARSS_JR_DEPLOYMENT_6_05_07 Changes since 1.14: +2 -0 lines * moved fusdnet out of fusdd and into a separate process * added --enable-remote option into misc_init that waits for fusdnet * added fusdnet() macro for running fusdnet when desired * moved logging in fusdd_server over to elog * fixed bug in link.run |
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <time.h>
#include <sys/poll.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "fusd.h"
#include "fusd_msg.h"
#include "fusdd_net_fnsi_i.h"
#ifndef __FUSDD_NET_I_H__
#define __FUSDD_NET_I_H__
/*
* Networking
*/
#include <libdev/status_dev.h>
#include <libdev/command_dev.h>
#include <libdev/logring_dev.h>
typedef struct fusdnet_socket fn_socket_t;
typedef struct fusdnet_server_socket fns_socket_t;
typedef struct fusdnet_server fn_server_t;
typedef struct fusdnet fn_t;
typedef struct fusdnet_client fn_client_t;
typedef void (* message_arrived_cb_t)(fn_socket_t *fs, fusd_msg_t *msg);
typedef void (* closed_cb_t)(fn_socket_t *fs, int retval);
struct fusdnet_socket {
/* the socket to the client */
int socket_fd;
char *socket_name;
/* the input buffer, and a message ready indicator */
buf_t *input_buffer;
buf_t *output_buffer;
int message_ready:1;
/* socket event */
g_event_t *read_event;
g_event_t *write_event;
/* callback */
message_arrived_cb_t arrived; /* called on message arrival */
closed_cb_t closed; /* called on socket closed */
void *private_data;
};
/*
* NOTE: allocated fusd messages are always two separate
* buffers: the fusd_msg_t itself, and the data pointer
* (if present), separately allocated and freed.
*/
/*
* Socket API
*
* Initializes/destroys the events, etc.
* call this function with close, arrived, private_data,
* socket_fd and socket_name set
*
* Caller is responsible to free socket_name and private_data.
*/
int fn_socket_config(fn_socket_t *sock);
void fn_socket_destroy(fn_socket_t *sock);
/*
* read API
*
* NOTE: read callback passes an allocated fusd_msg
*/
void fn_socket_read_set_blocked(fn_socket_t *fs, int block);
/*
* write API
*/
int fn_socket_write(fn_socket_t *fs, fusd_msg_t *msg);
/*
* Server Data Structures
*/
typedef struct fns_client {
FNSI_DECL;
void *private_info;
void *remote_device_info;
fusd_msg_t sample;
} fns_client_t;
struct fusdnet_server_socket {
/* socket and address state */
fn_socket_t socket;
struct sockaddr_in from_addr;
/* per-open state, needed to keep
* private data and forge closes */
GArray *clients;
QUEUE_ELEMENT_DECL(_,struct fusdnet_server_socket);
fn_server_t *parent;
};
typedef struct fns_exp_msg {
fusd_msg_t *outgoing;
void *outgoing_data;
int datalen;
fns_socket_t *owner;
} fns_exp_msg_t;
struct fusdnet_server {
/* device name */
char *device_name;
int destroying;
/* active client sockets */
QUEUE_DECL(sockets, fns_socket_t);
/* pending messages */
/* outgoing.. broken out into two buffers */
GArray *outgoing_msgs;
/* incoming */
fusd_msg_t *incoming;
void *incoming_demux_token;
/* pending poll diff */
fusd_file_info_t *poll_diff;
/* queue pointers */
QUEUE_ELEMENT_DECL(_, struct fusdnet_server);
fn_t *parent;
};
struct fusdnet {
logring_context_t *log; /* log */
status_context_t *status; /* status */
/* server side state */
int incoming; /* bound socket */
fusd_context_t *server_channel; /* FUSD control channel to servers */
QUEUE_DECL(servers, fn_server_t);
fn_server_t unconnected; /* sockets that have registered */
};
/* use log not elog... we're below the pinit level! */
void nlog(int loglevel, char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
/* start funcs for client and server sides */
void fusdnet_server_init(fn_t *state);
void fusdnet_client_init(fn_t *state);
/* status report functions */
void fns_status_print(fn_t *fn, buf_t *buf);
void fnc_status_print(fn_t *fn, buf_t *buf);
void fn_status_notify(fn_t *fn);
void fusdnet_status_init(fn_t *state);
void fusd_msg_free(fusd_msg_t *msg);
#endif
| CENS CVS Mailing List |
Powered by ViewCVS 0.9.2 |