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  * All rights reserved.
7  *
8  * Author(s): Neil T. Dantam <ntd@rice.edu>
9  * Georgia Tech Humanoid Robotics Lab
10  * Under Direction of Prof. Mike Stilman <mstilman@cc.gatech.edu>
11  *
12  *
13  * This file is provided under the following "BSD-style" License:
14  *
15  *
16  * Redistribution and use in source and binary forms, with or
17  * without modification, are permitted provided that the following
18  * conditions are met:
19  *
20  * * Redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer.
22  *
23  * * Redistributions in binary form must reproduce the above
24  * copyright notice, this list of conditions and the following
25  * disclaimer in the documentation and/or other materials provided
26  * with the distribution.
27  *
28  * * Neither the name of the copyright holder the names of its
29  * contributors may be used to endorse or promote products derived
30  * from this software without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
33  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
34  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
35  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
36  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
37  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
38  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
40  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
41  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
42  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
43  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44  * POSSIBILITY OF SUCH DAMAGE.
45  *
46  */
47 
58 #ifndef ACH_GENERIC_H
59 #define ACH_GENERIC_H
60 
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 #ifdef __GNUC__
67 
68 #define ACH_WARN_UNUSED __attribute__((warn_unused_result))
69 #else
70 
71 #define ACH_WARN_UNUSED
72 #endif /* __GNUC__ */
73 
78 typedef enum ach_status {
79  ACH_OK = 0,
87  ACH_EEXIST = 8,
88  ACH_ENOENT = 9,
89  ACH_CLOSED = 10,
90  ACH_BUG = 11,
91  ACH_EINVAL = 12,
92  ACH_CORRUPT = 13,
94  ACH_EACCES = 15,
95  ACH_CANCELED = 16,
96  ACH_EFAULT = 17,
97  ACH_EINTR = 18,
101 } ach_status_t;
102 
103 
108 #define ACH_STATUS_MASK(r) (1<<(r))
109 
115 enum ach_mask {
116  ACH_MASK_OK = ACH_STATUS_MASK(ACH_OK),
117  ACH_MASK_OVERFLOW = ACH_STATUS_MASK(ACH_OVERFLOW),
118  ACH_MASK_INVALID_NAME = ACH_STATUS_MASK(ACH_INVALID_NAME),
119  ACH_MASK_BAD_SHM_FILE = ACH_STATUS_MASK(ACH_BAD_SHM_FILE),
120  ACH_MASK_FAILED_SYSCALL = ACH_STATUS_MASK(ACH_FAILED_SYSCALL),
121  ACH_MASK_STALE_FRAMES = ACH_STATUS_MASK(ACH_STALE_FRAMES),
122  ACH_MASK_MISSED_FRAME = ACH_STATUS_MASK(ACH_MISSED_FRAME),
123  ACH_MASK_TIMEOUT = ACH_STATUS_MASK(ACH_TIMEOUT),
124  ACH_MASK_EEXIST = ACH_STATUS_MASK(ACH_EEXIST),
125  ACH_MASK_ENOENT = ACH_STATUS_MASK(ACH_ENOENT),
126  ACH_MASK_CLOSED = ACH_STATUS_MASK(ACH_CLOSED),
127  ACH_MASK_BUG = ACH_STATUS_MASK(ACH_BUG),
128  ACH_MASK_EINVAL = ACH_STATUS_MASK(ACH_EINVAL),
129  ACH_MASK_CORRUPT = ACH_STATUS_MASK(ACH_CORRUPT),
130  ACH_MASK_BAD_HEADER = ACH_STATUS_MASK(ACH_BAD_HEADER),
131  ACH_MASK_EACCES = ACH_STATUS_MASK(ACH_EACCES),
132  ACH_MASK_CANCELED = ACH_STATUS_MASK(ACH_CANCELED),
133  ACH_MASK_EFAULT = ACH_STATUS_MASK(ACH_EFAULT),
134  ACH_MASK_EINTR = ACH_STATUS_MASK(ACH_EINTR),
135  ACH_MASK_ENOTSUP = ACH_STATUS_MASK(ACH_ENOTSUP),
136 
137  ACH_MASK_NONE = 0,
138  ACH_MASK_ALL = 0xffffffff
139 };
140 
142 typedef enum ach_mask ach_mask_t;
143 
145 static inline int
146 ach_status_mask( enum ach_status status )
147 {
148  return (enum ach_mask)ACH_STATUS_MASK(status);
149 }
150 
160 static inline int
161 ach_status_match( enum ach_status status, int mask )
162 {
163  return (ACH_STATUS_MASK(status) & mask) ? 1 : 0;
164 }
165 
171 typedef enum {
172  /* default options are zero */
173 
179 
184  ACH_O_FIRST = 0x00,
185 
195 
206  ACH_O_WAIT = 0x01,
207 
216  ACH_O_LAST = 0x02,
217 
222  ACH_O_COPY = 0x04,
223 
230 
232 #define ACH_CHAN_NAME_MAX 64ul
233 
234 
242 typedef enum ach_status
243 ach_get_fun(void *cx, void **obj_dst, const void *chan_src, size_t frame_size );
244 
245 
252 typedef enum ach_status
253 ach_put_fun(void *cx, void *chan_dst, const void *obj_src);
254 
257 typedef struct achk_opt {
258  int options;
259  struct timespec reltime;
260 } achk_opt_t;
261 
262 
263 #ifdef __cplusplus
264 }
265 #endif
266 
267 #endif
an invalid header was given
Definition: generic.h:93
int options
get options used by the kernel
Definition: generic.h:258
channel file already exists
Definition: generic.h:87
channel file didn't look right
Definition: generic.h:82
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:194
channel memory has been corrupted
Definition: generic.h:92
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:90
struct timespec reltime
kernel use relative time
Definition: generic.h:259
ach_get_opts_t
Option flags for ach_get().
Definition: generic.h:171
Do not block for a new messages.
Definition: generic.h:178
timeout before frame received
Definition: generic.h:86
invalid parameter
Definition: generic.h:91
ach_mask
Bit masks that correspond to members of enum ach_status.
Definition: generic.h:115
Struct containing 'cache' of kernel module data to avoid updating when no changes exist...
Definition: generic.h:257
Copy the message out of the channel, even if already seen.
Definition: generic.h:222
#define ACH_STATUS_MASK(r)
Generate a bit mask from an ach status type.
Definition: generic.h:108
permission denied
Definition: generic.h:94
no new data in the channel
Definition: generic.h:84
enum ach_mask ach_mask_t
Convenience typedef for enum ach_mask.
Definition: generic.h:142
enum ach_status ach_status_t
return status codes for ach functions.
not supported.
Definition: generic.h:100
Read the newest message out of the channel.
Definition: generic.h:216
invalid channel name
Definition: generic.h:81
unused
Definition: generic.h:89
operation canceled
Definition: generic.h:95
Retrieve the oldest unseen message.
Definition: generic.h:184
destination too small to hold frame
Definition: generic.h:80
operation interrupted.
Definition: generic.h:97
ach_status
return status codes for ach functions.
Definition: generic.h:78
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:96
channel file doesn't exist
Definition: generic.h:88
a system call failed
Definition: generic.h:83
Block until an unseen message arrives or timeout.
Definition: generic.h:206
we missed the next frame
Definition: generic.h:85
Timeout is a relative time.
Definition: generic.h:228
Call successful.
Definition: generic.h:79