pipe.h

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

Generated on Mon Dec 13 09:49:49 2004 for RTAI API by  doxygen 1.3.9.1