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 *ln)
00065 {
00066     return ln ? container_of(ln, xnpipe_mh_t, link) : NULL;
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(ln, fld)    container_of(ln, xnpipe_state_t, fld)
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     size_t ionrd;
00099 
00100 } xnpipe_state_t;
00101 
00102 extern xnpipe_state_t xnpipe_states[];
00103 
00104 #define xnminor_from_state(s) (s - xnpipe_states)
00105 
00106 #ifdef __cplusplus
00107 extern "C" {
00108 #endif /* __cplusplus */
00109 
00110 int xnpipe_mount(void);
00111 
00112 void xnpipe_umount(void);
00113 
00114 /* Entry points of the kernel interface. */
00115 
00116 void xnpipe_setup(xnpipe_session_handler *open_handler,
00117                   xnpipe_session_handler *close_handler);
00118 
00119 int xnpipe_connect(int minor,
00120                    xnpipe_io_handler *output_handler,
00121                    xnpipe_io_handler *input_handler,
00122                    xnpipe_alloc_handler *alloc_handler,
00123                    void *cookie);
00124 
00125 int xnpipe_disconnect(int minor);
00126 
00127 ssize_t xnpipe_send(int minor,
00128                     struct xnpipe_mh *mh,
00129                     size_t size,
00130                     int flags);
00131 
00132 ssize_t xnpipe_mfixup(int minor,
00133                       struct xnpipe_mh *mh,
00134                       ssize_t size);
00135 
00136 ssize_t xnpipe_recv(int minor,
00137                     struct xnpipe_mh **pmh,
00138                     xnticks_t timeout);
00139 
00140 int xnpipe_inquire(int minor);
00141 
00142 #ifdef __cplusplus
00143 }
00144 #endif /* __cplusplus */
00145 
00146 static inline xnholder_t *xnpipe_m_link(xnpipe_mh_t *mh)
00147 {
00148     return &mh->link;
00149 }
00150 
00151 static inline char *xnpipe_m_data(xnpipe_mh_t *mh)
00152 {
00153     return (char *)(mh + 1);
00154 }
00155 
00156 #define xnpipe_m_size(mh) ((mh)->size)
00157 
00158 #define xnpipe_m_rdoff(mh) ((mh)->rdoff)
00159 
00160 #endif /* __KERNEL__ */
00161 
00162 #endif /* !_XENO_NUCLEUS_PIPE_H */

Generated on Sun Dec 9 10:37:17 2007 for Xenomai API by  doxygen 1.5.3