Xenomai API  2.6.5
pipe.h
Go to the documentation of this file.
1 
22 #ifndef _XENO_PIPE_H
23 #define _XENO_PIPE_H
24 
25 #include <nucleus/pipe.h>
26 #include <nucleus/heap.h>
27 #include <native/types.h>
28 
29 /* Operation flags. */
30 #define P_NORMAL XNPIPE_NORMAL
31 #define P_URGENT XNPIPE_URGENT
32 
33 #define P_MINOR_AUTO XNPIPE_MINOR_AUTO
34 
35 #define P_EVENT_INPUT 1
36 #define P_EVENT_OUTPUT 2
37 #define P_EVENT_CLOSE 3
38 #define P_EVENT_NOBUF 4
39 
40 typedef struct rt_pipe_placeholder {
41  xnhandle_t opaque;
42 } RT_PIPE_PLACEHOLDER;
43 
44 #ifdef __KERNEL__
45 
46 #include <native/ppd.h>
47 
48 #define XENO_PIPE_MAGIC 0x55550202
49 
50 #define P_SYNCWAIT 0
51 #define P_ATOMIC 1
52 
53 typedef xnpipe_mh_t RT_PIPE_MSG;
54 
55 #define P_MSGPTR(msg) xnpipe_m_data(msg)
56 #define P_MSGSIZE(msg) xnpipe_m_size(msg)
57 
58 typedef struct rt_pipe {
59 
60  unsigned magic; /* !< Magic code -- must be first. */
61 
62  xnholder_t link; /* !< Link in flush queue. */
63 
64 #define link2rtpipe(ln) container_of(ln, RT_PIPE, link)
65 
66  int minor; /* !< Device minor number. */
67 
68  RT_PIPE_MSG *buffer; /* !< Buffer used in byte stream mode. */
69 
70  xnheap_t *bufpool; /* !< Current buffer pool. */
71 
72  int (*monitor)(struct rt_pipe *pipe, int event, long arg);
73 
74  xnheap_t privpool; /* !< Private buffer pool. */
75 
76  size_t fillsz; /* !< Bytes written to the buffer. */
77 
78  u_long status; /* !< Status information. */
79 
80  xnhandle_t handle; /* !< Handle in registry -- zero if unregistered. */
81 
82  char name[XNOBJECT_NAME_LEN]; /* !< Symbolic name. */
83 
84 #ifdef CONFIG_XENO_OPT_PERVASIVE
85  pid_t cpid; /* !< Creator's pid. */
86 #endif /* CONFIG_XENO_OPT_PERVASIVE */
87 
88  xnholder_t rlink; /* !< Link in resource queue. */
89 
90 #define rlink2pipe(ln) container_of(ln, RT_PIPE, rlink)
91 
92  xnqueue_t *rqueue; /* !< Backpointer to resource queue. */
93 
94 } RT_PIPE;
95 
96 #else /* !__KERNEL__ */
97 
98 typedef RT_PIPE_PLACEHOLDER RT_PIPE;
99 
100 #endif /* __KERNEL__ */
101 
102 #ifdef __cplusplus
103 extern "C" {
104 #endif
105 
106 /* Public interface. */
107 
108 int rt_pipe_create(RT_PIPE *pipe,
109  const char *name,
110  int minor,
111  size_t poolsize);
112 
113 int rt_pipe_delete(RT_PIPE *pipe);
114 
115 ssize_t rt_pipe_read(RT_PIPE *pipe,
116  void *buf,
117  size_t size,
118  RTIME timeout);
119 
120 ssize_t rt_pipe_write(RT_PIPE *pipe,
121  const void *buf,
122  size_t size,
123  int mode);
124 
125 ssize_t rt_pipe_stream(RT_PIPE *pipe,
126  const void *buf,
127  size_t size);
128 
129 #ifdef __KERNEL__
130 
131 ssize_t rt_pipe_receive(RT_PIPE *pipe,
132  RT_PIPE_MSG **msg,
133  RTIME timeout);
134 
135 ssize_t rt_pipe_send(RT_PIPE *pipe,
136  RT_PIPE_MSG *msg,
137  size_t size,
138  int mode);
139 
140 RT_PIPE_MSG *rt_pipe_alloc(RT_PIPE *pipe,
141  size_t size);
142 
143 int rt_pipe_free(RT_PIPE *pipe,
144  RT_PIPE_MSG *msg);
145 
146 int rt_pipe_flush(RT_PIPE *pipe,
147  int mode);
148 
149 int rt_pipe_monitor(RT_PIPE *pipe,
150  int (*fn)(RT_PIPE *pipe, int event, long arg));
151 
152 #else /* !__KERNEL__ */
153 
154 int rt_pipe_bind(RT_PIPE *pipe,
155  const char *name,
156  RTIME timeout);
157 
158 static inline int rt_pipe_unbind(RT_PIPE *pipe)
159 {
160  pipe->opaque = XN_NO_HANDLE;
161  return 0;
162 }
163 
164 #endif /* __KERNEL__ */
165 
166 #ifdef CONFIG_XENO_OPT_NATIVE_PIPE
167 
168 int __native_pipe_pkg_init(void);
169 
170 void __native_pipe_pkg_cleanup(void);
171 
172 static inline void __native_pipe_flush_rq(xnqueue_t *rq)
173 {
174  xeno_flush_rq_norelease(RT_PIPE, rq, pipe);
175 }
176 
177 #else /* !CONFIG_XENO_OPT_NATIVE_PIPE */
178 
179 #define __native_pipe_pkg_init() ({ 0; })
180 #define __native_pipe_pkg_cleanup() do { } while(0)
181 #define __native_pipe_flush_rq(rq) do { } while(0)
182 
183 #endif /* !CONFIG_XENO_OPT_NATIVE_PIPE */
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif /* !_XENO_PIPE_H */
int rt_pipe_flush(RT_PIPE *pipe, int mode)
Flush the i/o queues associated with the kernel endpoint of a message pipe.
Definition: pipe.c:1083
int rt_pipe_monitor(RT_PIPE *pipe, int(*fn)(RT_PIPE *pipe, int event, long arg))
Monitor a message pipe asynchronously.
Definition: pipe.c:1165
int rt_pipe_delete(RT_PIPE *pipe)
Delete a message pipe.
Definition: pipe.c:37
This file is part of the Xenomai project.
ssize_t rt_pipe_stream(RT_PIPE *pipe, const void *buf, size_t size)
Stream bytes to a pipe.
Definition: pipe.c:54
int rt_pipe_free(RT_PIPE *pipe, RT_PIPE_MSG *msg)
Free a message pipe buffer.
Definition: pipe.c:1032
RT_PIPE_MSG * rt_pipe_alloc(RT_PIPE *pipe, size_t size)
Allocate a message pipe buffer.
Definition: pipe.c:992
int rt_pipe_create(RT_PIPE *pipe, const char *name, int minor, size_t poolsize)
Create a message pipe.
Definition: pipe.c:24
ssize_t rt_pipe_send(RT_PIPE *pipe, RT_PIPE_MSG *msg, size_t size, int mode)
Send a message through a pipe.
Definition: pipe.c:734
ssize_t rt_pipe_write(RT_PIPE *pipe, const void *buf, size_t size, int mode)
Write a message to a pipe.
Definition: pipe.c:48
ssize_t rt_pipe_read(RT_PIPE *pipe, void *buf, size_t size, RTIME timeout)
Read a message from a pipe.
Definition: pipe.c:42
This file is part of the Xenomai project.
ssize_t rt_pipe_receive(RT_PIPE *pipe, RT_PIPE_MSG **msg, RTIME timeout)
Receive a message from a pipe.
Definition: pipe.c:520