pipe.h

00001 /*
00002  * Copyright (C) 2001,2002,2003 Philippe Gerum.
00003  *
00004  * RTAI/fusion is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published
00006  * by the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA
00007  * 02139, USA; either version 2 of the License, or (at your option)
00008  * any later version.
00009  *
00010  * RTAI/fusion is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018  */
00019 
00020 #ifndef _RTAI_NUCLEUS_PIPE_H
00021 #define _RTAI_NUCLEUS_PIPE_H
00022 
00023 #define XNPIPE_NDEVS      CONFIG_RTAI_OPT_PIPE_NRDEV
00024 #define XNPIPE_DEV_MAJOR  150
00025 
00026 #define XNPIPE_IOCTL_BASE     'p'
00027 #define XNPIPEIOC_GET_NRDEV   _IOW(XNPIPE_IOCTL_BASE,0,int)
00028 #define XNPIPEIOC_FLUSH       _IO(XNPIPE_IOCTL_BASE,1)
00029 
00030 #define XNPIPE_NORMAL 0x0
00031 #define XNPIPE_URGENT 0x1
00032 
00033 #ifdef __KERNEL__
00034 
00035 #include <nucleus/queue.h>
00036 #include <nucleus/synch.h>
00037 #include <nucleus/thread.h>
00038 #include <linux/types.h>
00039 #include <linux/poll.h>
00040 
00041 #define XNPIPE_WAIT   0x0
00042 #define XNPIPE_NOWAIT 0x1
00043 
00044 #define XNPIPE_KERN_CONN   0x1
00045 #define XNPIPE_USER_CONN   0x2
00046 #define XNPIPE_USER_SIGIO  0x4
00047 #define XNPIPE_USER_WREAD  0x08
00048 #define XNPIPE_USER_WREAD_READY  0x10
00049 
00050 #define XNPIPE_USER_WMASK \
00051 (XNPIPE_USER_WREAD)
00052 
00053 #define XNPIPE_USER_WREADY \
00054 (XNPIPE_USER_WREAD_READY)
00055 
00056 typedef struct xnpipe_mh {
00057 
00058     xnholder_t link;
00059     unsigned size;
00060     
00061 } xnpipe_mh_t;
00062 
00063 static inline xnpipe_mh_t *link2mh (xnholder_t *laddr)
00064 {
00065     return laddr ? ((xnpipe_mh_t *)(((char *)laddr) - (int)(&((xnpipe_mh_t *)0)->link))) : 0;
00066 }
00067 
00068 typedef int xnpipe_io_handler(int minor,
00069                               struct xnpipe_mh *mh,
00070                               int onerror,
00071                               void *cookie);
00072 
00073 typedef int xnpipe_session_handler(int minor,
00074                                    void *cookie);
00075 
00076 typedef void *xnpipe_alloc_handler(int minor,
00077                                    size_t size,
00078                                    void *cookie);
00079 typedef struct xnpipe_state {
00080 
00081     xnholder_t slink;   /* Link on sleep queue */
00082     xnholder_t alink;   /* Link on async queue */
00083 #define link2xnpipe(laddr,link) \
00084 ((struct xnpipe_state *)(((char *)laddr) - (int)(&((struct xnpipe_state *)0)->link)))
00085 
00086     xnqueue_t inq;      /* From user-space to kernel */
00087     xnqueue_t outq;     /* From kernel to user-space */
00088     xnpipe_io_handler *output_handler;
00089     xnpipe_io_handler *input_handler;
00090     xnpipe_alloc_handler *alloc_handler;
00091     xnsynch_t synchbase;
00092     void *cookie;
00093 
00094     /* Linux kernel part */
00095     xnflags_t status;
00096     struct fasync_struct *asyncq;
00097     wait_queue_head_t readq;            /* read waiters and an open waiter */
00098     unsigned int readw;
00099     size_t ionrd;
00100 
00101 } xnpipe_state_t;
00102 
00103 extern xnpipe_state_t xnpipe_states[];
00104 
00105 #define xnminor_from_state(s) (s - xnpipe_states)
00106 
00107 #ifdef __cplusplus
00108 extern "C" {
00109 #endif /* __cplusplus */
00110 
00111 int xnpipe_mount(void);
00112 
00113 void xnpipe_umount(void);
00114 
00115 /* Entry points of the kernel interface. */
00116 
00117 void xnpipe_setup(xnpipe_session_handler *open_handler,
00118                   xnpipe_session_handler *close_handler);
00119 
00120 int xnpipe_connect(int minor,
00121                    xnpipe_io_handler *output_handler,
00122                    xnpipe_io_handler *input_handler,
00123                    xnpipe_alloc_handler *alloc_handler,
00124                    void *cookie);
00125 
00126 int xnpipe_disconnect(int minor);
00127 
00128 ssize_t xnpipe_send(int minor,
00129                     struct xnpipe_mh *mh,
00130                     size_t size,
00131                     int flags);
00132 
00133 ssize_t xnpipe_recv(int minor,
00134                     struct xnpipe_mh **pmh,
00135                     xnticks_t timeout);
00136 
00137 int xnpipe_inquire(int minor);
00138 
00139 #ifdef __cplusplus
00140 }
00141 #endif /* __cplusplus */
00142 
00143 static inline xnholder_t *xnpipe_m_link(xnpipe_mh_t *mh)
00144 {
00145     return &mh->link;
00146 }
00147 
00148 static inline char *xnpipe_m_data(xnpipe_mh_t *mh)
00149 {
00150     return (char *)(mh + 1);
00151 }
00152 
00153 #define xnpipe_m_size(mh) ((mh)->size)
00154 
00155 #endif /* __KERNEL__ */
00156 
00157 #endif /* !_RTAI_NUCLEUS_PIPE_H */

Generated on Wed Jun 22 22:54:02 2005 for RTAI Fusion API by  doxygen 1.4.1