Code Search for Developers
 
 
  

libusfusd_i.h from EmStar at Krugle


Show libusfusd_i.h syntax highlighted

/*
 *
 * 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.
 *
 */
 

/*
 * ufusd library: overloads system calls for fun and profit
 * 
 * PLEASE NOTE: intended for use only in synergy stadium
 *
 * author: girod
 *
 * $Id: libusfusd_i.h,v 1.1 2003/09/05 21:41:22 girod Exp $
 */

#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/types.h>
#include <sys/socket.h>
#include <unistd.h>
#include <signal.h>
#include <varargs.h>
#include <sys/poll.h>

#include <fusd/fusd.h>
#include <fusd/fusd_msg.h>

#include <libmisc/misc.h>

#define __USE_GNU
# include <pthread.h>
#undef __USE_GNU

#ifndef __LIBUSFUSD_I_H__
#define __LIBUSFUSD_I_H__

typedef struct usfusd_conn usfusd_conn_t;
typedef struct usfusd_thread usfusd_thread_t;
typedef struct usfusd usfusd_t;

/* per-thread state */
struct usfusd_thread {
  /* this pid */
  int pid;

  /* virtual poll request state for fusd sockets, if present */
  struct pollfd *sfds;
  int sfd_count;
  
  /* pipe wakeup from poll/select */
  int pipe[2];

  /* state for blocked or pending calls */
  fusd_msg_t *pending_msg;    /* pending request */
  fusd_msg_t *reply_msg;      /* response */
  usfusd_conn_t *curr_conn;   /* connection this applies to */

  /* parent struct */
  usfusd_t *parent;
};


/* connection info, per device connection */
struct usfusd_conn {
  /* connection identity (for debug) */
  struct sockaddr_in dest;    /* sockaddr */
  char *path;                 /* path to request */
  int socket;                 /* the socket */

  /* prevents interleaved writes to socket */
  pthread_mutex_t write_mutex;       /* any thread can write */

  /* blocked call conditions (of main mutex) */
  int read_call;
  int write_call;
  int ioctl_call;
  pthread_cond_t call_block;

  /* emulated connection state */
  int pos;                    /* position of file pointer */
  int flags;                  /* flags, e.g. O_RDWR, O_NONBLOCK */
  int poll_state;             /* current assumed poll state */
  int transaction;            /* next transaction ID */

  /* read state */
  buf_t *incoming;
  
  /* destruction */
  int destroyed;              /* flag indicates connection is closed */
  int refcount;               /* count of threads blocked on this conn */
  int read_active;            /* true when this is in a reader poll */
  
  usfusd_t *parent;
};


/* usfusd global state */
struct usfusd {
  /* mutex protecting usfusd global state */
  pthread_mutex_t mutex;
  
  /* per connection info */
  usfusd_conn_t *conns[FD_SETSIZE];
  pthread_mutex_t read_mutex;        /* one thread reads */

  /* per-thread state */
  usfusd_thread_t **threads;
  int thread_count;

  /* the reader thread -- this thread is in a poll */
  usfusd_thread_t *reader;

};


/* libusfusd_socket.c */
void usfusd_process_sockets(usfusd_thread_t *t, struct pollfd *fds, int fd_count);
void usfusd_process_wakeup(usfusd_thread_t *thread, struct pollfd *pfd);
int usfusd_update_poll_state(usfusd_thread_t *thread, struct pollfd *fds, int fd_count, int *v_errno);
void usfusd_thread_wake(usfusd_thread_t *thread);
usfusd_thread_t *usfusd_thread_lookup(usfusd_t *state);
void usfusd_conn_destroy(usfusd_conn_t *c);
int usfusd_conn_destroyed(usfusd_conn_t *c);
int usfusd_poll_request(usfusd_conn_t *conn);
void usfusd_lock_type(usfusd_thread_t *thread, usfusd_conn_t *conn, fusd_msg_t *msg);
void usfusd_thread_release_conn(usfusd_thread_t *t);
void usfusd_thread_release_read_mutex(usfusd_thread_t *t);

/* libusfusd_fops.c */
int usfusd_open(const char *path, mode_t mode);
int usfusd_poll(struct pollfd *ufds, unsigned int nfds, int timeout);

/* libusfusd_overload.c */
int pthread_is_linked();

/* libusfusd_rw.c */
int usfusd_write_msg(int socket, fusd_msg_t *msg, char *data_buf);
int usfusd_read_msg(int socket, fusd_msg_t *msg, char *data_buf, int max_data_len);
int usfusd_connect(struct sockaddr_in *dest);

/* libusfusd_util.c */
void usfusd_fill_msg(fusd_msg_t *msg, usfusd_conn_t *conn);
int usfusd_parse_path(usfusd_conn_t *conn, const char *path);

/* libc */
int __open(const char *path, int oflag, ...);
int __close(int fd);
int __poll(struct pollfd *ufds, unsigned int nfds, int timeout);

#endif




See more files for this project here

EmStar

EmStar is a software system for developing and deploying wireless sensor networks involving Linux-based platforms. As the wireless sensor network community has attempted to deploy more complex designs---large-scale, long-lived systems that need self-organization and adaptivity---a number of difficult software design issues have arisen. Advances in software design have not kept pace with the capabilities of hardware. This is because designing for an adaptive, efficient, and useful sensor network has turned out to be surprisingly complex and difficult. EmStar is a Linux-based software framework, whose goal is to dramatically reduce this complexity, enabling work to be shared and reused, and simplifying and speeding the design of new sensor network applications.

Project homepage: http://cvs.cens.ucla.edu/emstar/
Programming language(s): C,Shell Script
License: other

  libusfusd_fops.c
  libusfusd_g.c
  libusfusd_i.h
  libusfusd_overload.c
  libusfusd_rw.c
  libusfusd_socket.c
  libusfusd_util.c