include/nucleus/pipe.h

00001 /*
00002  * Copyright (C) 2001,2002,2003 Philippe Gerum.
00003  *
00004  * Xenomai 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  * Xenomai 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 _XENO_NUCLEUS_PIPE_H
00021 #define _XENO_NUCLEUS_PIPE_H
00022 
00023 #define XNPIPE_NDEVS      CONFIG_XENO_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 #define XNPIPEIOC_SETSIG      _IO(XNPIPE_IOCTL_BASE,2)
00030 
00031 #define XNPIPE_NORMAL  0x0
00032 #define XNPIPE_URGENT  0x1
00033 
00034 #define XNPIPE_MINOR_AUTO  -1
00035 
00036 #ifdef __KERNEL__
00037 
00038 #include <nucleus/queue.h>
00039 #include <nucleus/synch.h>
00040 #include <nucleus/thread.h>
00041 #include <linux/types.h>
00042 #include <linux/poll.h>
00043 
00044 #define XNPIPE_KERN_CONN         0x1
00045 #define XNPIPE_USER_CONN         0x2
00046 #define XNPIPE_USER_SIGIO        0x4
00047 #define XNPIPE_USER_WREAD        0x8
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     unsigned rdoff;
00061     
00062 } xnpipe_mh_t;
00063 
00064 static inline xnpipe_mh_t *link2mh (xnholder_t *laddr)
00065 {
00066     return laddr ? ((xnpipe_mh_t *)(((char *)laddr) - (int)(&((xnpipe_mh_t *)0)->link))) : 0;
00067 }
00068 
00069 typedef int xnpipe_io_handler(int minor,
00070                               struct xnpipe_mh *mh,
00071                               int retval,
00072                               void *cookie);
00073 
00074 typedef int xnpipe_session_handler(int minor,
00075                                    void *cookie);
00076 
00077 typedef void *xnpipe_alloc_handler(int minor,
00078                                    size_t size,
00079                                    void *cookie);
00080 typedef struct xnpipe_state {
00081 
00082     xnholder_t slink;   /* Link on sleep queue */
00083     xnholder_t alink;   /* Link on async queue */
00084 #define link2xnpipe(laddr,link) \
00085 ((struct xnpipe_state *)(((char *)laddr) - (int)(&((struct xnpipe_state *)0)->link)))
00086 
00087     xnqueue_t inq;      /* From user-space to kernel */
00088     xnqueue_t outq;     /* From kernel to user-space */
00089     xnpipe_io_handler *output_handler;
00090     xnpipe_io_handler *input_handler;
00091     xnpipe_alloc_handler *alloc_handler;
00092     xnsynch_t synchbase;
00093     void *cookie;
00094 
00095     /* Linux kernel part */
00096     xnflags_t status;
00097     struct fasync_struct *asyncq;
00098     wait_queue_head_t readq;            /* read waiters and an open waiter */
00099     unsigned int readw;
00100     size_t ionrd;
00101 
00102 } xnpipe_state_t;
00103 
00104 extern xnpipe_state_t xnpipe_states[];
00105 
00106 #define xnminor_from_state(s) (s - xnpipe_states)
00107 
00108 #ifdef __cplusplus
00109 extern "C" {
00110 #endif /* __cplusplus */
00111 
00112 int xnpipe_mount(void);
00113 
00114 void xnpipe_umount(void);
00115 
00116 /* Entry points of the kernel interface. */
00117 
00118 void xnpipe_setup(xnpipe_session_handler *open_handler,
00119                   xnpipe_session_handler *close_handler);
00120 
00121 int xnpipe_connect(int minor,
00122                    xnpipe_io_handler *output_handler,
00123                    xnpipe_io_handler *input_handler,
00124                    xnpipe_alloc_handler *alloc_handler,
00125                    void *cookie);
00126 
00127 int xnpipe_disconnect(int minor);
00128 
00129 ssize_t xnpipe_send(int minor,
00130                     struct xnpipe_mh *mh,
00131                     size_t size,
00132                     int flags);
00133 
00134 ssize_t xnpipe_mfixup(int minor,
00135                       struct xnpipe_mh *mh,
00136                       ssize_t size);
00137 
00138 ssize_t xnpipe_recv(int minor,
00139                     struct xnpipe_mh **pmh,
00140                     xnticks_t timeout);
00141 
00142 int xnpipe_inquire(int minor);
00143 
00144 #ifdef __cplusplus
00145 }
00146 #endif /* __cplusplus */
00147 
00148 static inline xnholder_t *xnpipe_m_link(xnpipe_mh_t *mh)
00149 {
00150     return &mh->link;
00151 }
00152 
00153 static inline char *xnpipe_m_data(xnpipe_mh_t *mh)
00154 {
00155     return (char *)(mh + 1);
00156 }
00157 
00158 #define xnpipe_m_size(mh) ((mh)->size)
00159 
00160 #define xnpipe_m_rdoff(mh) ((mh)->rdoff)
00161 
00162 #endif /* __KERNEL__ */
00163 
00164 #endif /* !_XENO_NUCLEUS_PIPE_H */

Generated on Mon Dec 25 13:57:10 2006 for Xenomai API by  doxygen 1.4.6