ach
Real-Time IPC Library
generic.h
Go to the documentation of this file.
1 /* -*- mode: C; c-basic-offset: 4 -*- */
2 /* ex: set shiftwidth=4 tabstop=4 expandtab: */
3 /*
4  * Copyright (c) 2008-2014, Georgia Tech Research Corporation
5  * Copyright (c) 2015, Rice University
6  * Copyright (c) 2015, Atlas Copco Rock Drills AB
7  * All rights reserved.
8  *
9  * Author(s): Neil T. Dantam <ntd@rice.edu>
10  * Mattias <matjo75@gmail.com>
11  * Georgia Tech Humanoid Robotics Lab
12  * Under Direction of Prof. Mike Stilman <mstilman@cc.gatech.edu>
13  *
14  *
15  * This file is provided under the following "BSD-style" License:
16  *
17  *
18  * Redistribution and use in source and binary forms, with or
19  * without modification, are permitted provided that the following
20  * conditions are met:
21  *
22  * * Redistributions of source code must retain the above copyright
23  * notice, this list of conditions and the following disclaimer.
24  *
25  * * Redistributions in binary form must reproduce the above
26  * copyright notice, this list of conditions and the following
27  * disclaimer in the documentation and/or other materials provided
28  * with the distribution.
29  *
30  * * Neither the name of the copyright holder the names of its
31  * contributors may be used to endorse or promote products derived
32  * from this software without specific prior written permission.
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
35  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
36  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
37  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
39  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
43  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
44  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
45  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46  * POSSIBILITY OF SUCH DAMAGE.
47  *
48  */
49 
60 #ifndef ACH_GENERIC_H
61 #define ACH_GENERIC_H
62 
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 #ifdef __GNUC__
69 
70 #define ACH_WARN_UNUSED __attribute__((warn_unused_result))
71 #else
72 
73 #define ACH_WARN_UNUSED
74 #endif /* __GNUC__ */
75 
76 #ifdef CONFIG_COMPAT
77 #include <linux/compat.h>
78 #endif /* CONFIG_COMPAT */
79 
84 typedef enum ach_status {
85  ACH_OK = 0,
90  ACH_EAGAIN = 5,
93  ACH_EEXIST = 8,
94  ACH_ENOENT = 9,
95  ACH_CLOSED = 10,
96  ACH_BUG = 11,
97  ACH_EINVAL = 12,
98  ACH_CORRUPT = 13,
100  ACH_EACCES = 15,
102  ACH_EFAULT = 17,
103  ACH_EINTR = 18,
106  ACH_ENOTSUP = 19,
107 } ach_status_t;
108 
109 #define ACH_STALE_FRAMES ACH_EAGAIN
110 #define ACH_LOCKED ACH_EAGAIN
111 
116 #define ACH_STATUS_MASK(r) (1<<(r))
117 
123 enum ach_mask {
124  ACH_MASK_OK = ACH_STATUS_MASK(ACH_OK),
125  ACH_MASK_OVERFLOW = ACH_STATUS_MASK(ACH_OVERFLOW),
126  ACH_MASK_INVALID_NAME = ACH_STATUS_MASK(ACH_INVALID_NAME),
127  ACH_MASK_BAD_SHM_FILE = ACH_STATUS_MASK(ACH_BAD_SHM_FILE),
128  ACH_MASK_FAILED_SYSCALL = ACH_STATUS_MASK(ACH_FAILED_SYSCALL),
129  ACH_MASK_EAGAIN = ACH_STATUS_MASK(ACH_EAGAIN),
130  ACH_MASK_MISSED_FRAME = ACH_STATUS_MASK(ACH_MISSED_FRAME),
131  ACH_MASK_TIMEOUT = ACH_STATUS_MASK(ACH_TIMEOUT),
132  ACH_MASK_EEXIST = ACH_STATUS_MASK(ACH_EEXIST),
133  ACH_MASK_ENOENT = ACH_STATUS_MASK(ACH_ENOENT),
134  ACH_MASK_CLOSED = ACH_STATUS_MASK(ACH_CLOSED),
135  ACH_MASK_BUG = ACH_STATUS_MASK(ACH_BUG),
136  ACH_MASK_EINVAL = ACH_STATUS_MASK(ACH_EINVAL),
137  ACH_MASK_CORRUPT = ACH_STATUS_MASK(ACH_CORRUPT),
138  ACH_MASK_BAD_HEADER = ACH_STATUS_MASK(ACH_BAD_HEADER),
139  ACH_MASK_EACCES = ACH_STATUS_MASK(ACH_EACCES),
140  ACH_MASK_CANCELED = ACH_STATUS_MASK(ACH_CANCELED),
141  ACH_MASK_EFAULT = ACH_STATUS_MASK(ACH_EFAULT),
142  ACH_MASK_EINTR = ACH_STATUS_MASK(ACH_EINTR),
143  ACH_MASK_ENOTSUP = ACH_STATUS_MASK(ACH_ENOTSUP),
144  ACH_MASK_LOCKED = ACH_STATUS_MASK(ACH_LOCKED),
145 
146  ACH_MASK_NONE = 0,
147  ACH_MASK_ALL = 0xffffffff
148 };
149 
150 #define ACH_MASK_STALE_FRAMES ACH_MASK_EAGAIN
151 #define ACH_MASK_LOCKED ACH_MASK_EAGAIN
152 
154 typedef enum ach_mask ach_mask_t;
155 
157 static inline int
158 ach_status_mask( enum ach_status status )
159 {
160  return ACH_STATUS_MASK(status);
161 }
162 
172 static inline int
173 ach_status_match( enum ach_status status, int mask )
174 {
175  return (ACH_STATUS_MASK(status) & mask) ? 1 : 0;
176 }
177 
183 typedef enum {
184  /* default options are zero */
185 
191 
196  ACH_O_FIRST = 0x00,
197 
207 
218  ACH_O_WAIT = 0x01,
219 
228  ACH_O_LAST = 0x02,
229 
234  ACH_O_COPY = 0x04,
235 
242 
244 #define ACH_CHAN_NAME_MAX 64ul
245 
246 
254 typedef enum ach_status
255 ach_get_fun(void *cx, void **obj_dst, const void *chan_src, size_t frame_size );
256 
257 
264 typedef enum ach_status
265 ach_put_fun(void *cx, void *chan_dst, const void *obj_src);
266 
269 typedef struct achk_opt {
270  int options;
271  struct timespec reltime;
272 } achk_opt_t;
273 
274 #ifdef CONFIG_COMPAT
275 
277 typedef struct achk_opt_32 {
278  int options;
279  struct compat_timespec reltime;
280 } achk_opt_t_32;
281 
282 #endif /* CONFIG_COMPAT */
283 
284 #ifdef __cplusplus
285 }
286 #endif
287 
288 #endif
an invalid header was given
Definition: generic.h:99
int options
get options used by the kernel
Definition: generic.h:270
channel file already exists
Definition: generic.h:93
channel file didn't look right
Definition: generic.h:88
no new data in the channel
Definition: generic.h:90
enum ach_status ach_put_fun(void *cx, void *chan_dst, const void *obj_src)
Function type to transfer data into the channel.
Timeout is an absolute time.
Definition: generic.h:206
channel memory has been corrupted
Definition: generic.h:98
struct achk_opt achk_opt_t
Struct containing 'cache' of kernel module data to avoid updating when no changes exist...
internal ach error
Definition: generic.h:96
struct timespec reltime
kernel use relative time
Definition: generic.h:271
ach_get_opts_t
Option flags for ach_get().
Definition: generic.h:183
Do not block for a new messages.
Definition: generic.h:190
timeout before frame received
Definition: generic.h:92
invalid parameter
Definition: generic.h:97
ach_mask
Bit masks that correspond to members of enum ach_status.
Definition: generic.h:123
Struct containing 'cache' of kernel module data to avoid updating when no changes exist...
Definition: generic.h:269
Copy the message out of the channel, even if already seen.
Definition: generic.h:234
#define ACH_STATUS_MASK(r)
Generate a bit mask from an ach status type.
Definition: generic.h:116
permission denied
Definition: generic.h:100
enum ach_mask ach_mask_t
Convenience typedef for enum ach_mask.
Definition: generic.h:154
enum ach_status ach_status_t
return status codes for ach functions.
not supported.
Definition: generic.h:106
Read the newest message out of the channel.
Definition: generic.h:228
invalid channel name
Definition: generic.h:87
unused
Definition: generic.h:95
operation canceled
Definition: generic.h:101
Retrieve the oldest unseen message.
Definition: generic.h:196
destination too small to hold frame
Definition: generic.h:86
operation interrupted.
Definition: generic.h:103
ach_status
return status codes for ach functions.
Definition: generic.h:84
enum ach_status ach_get_fun(void *cx, void **obj_dst, const void *chan_src, size_t frame_size)
Function type to transfer data out of the channel.
bad address for data copy
Definition: generic.h:102
channel file doesn't exist
Definition: generic.h:94
a system call failed
Definition: generic.h:89
Block until an unseen message arrives or timeout.
Definition: generic.h:218
we missed the next frame
Definition: generic.h:91
Timeout is a relative time.
Definition: generic.h:240
Call successful.
Definition: generic.h:85