summaryrefslogtreecommitdiff
path: root/FreeRTOS-Labs/Demo/FreeRTOS_Plus_POSIX_with_actor_Windows_Simulator/lib/include/FreeRTOS_POSIX/mqueue.h
blob: 5acfd01e8715f27a669210825c573c919ac323da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
 * Amazon FreeRTOS POSIX V1.1.0
 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates.  All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 * http://aws.amazon.com/freertos
 * http://www.FreeRTOS.org
 */

/**
 * @file mqueue.h
 * @brief Message queues.
 *
 * http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/mqueue.h.html
 */

#ifndef _FREERTOS_POSIX_MQUEUE_H_
#define _FREERTOS_POSIX_MQUEUE_H_

/* FreeRTOS+POSIX includes. */
#include "FreeRTOS_POSIX/time.h"

/**
 * @brief Message queue descriptor.
 */
typedef void * mqd_t;

/**
 * @brief Message queue attributes.
 */
struct mq_attr
{
    long mq_flags;   /**< Message queue flags. */
    long mq_maxmsg;  /**< Maximum number of messages. */
    long mq_msgsize; /**< Maximum message size. */
    long mq_curmsgs; /**< Number of messages currently queued. */
};

/**
 * @brief Close a message queue.
 *
 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_close.html
 *
 * @retval 0 - Upon successful completion
 * @retval -1 - A error occurred. errno is also set.
 *
 * @sideeffect Possible errno values
 * <br>
 * EBADF - The mqdes argument is not a valid message queue descriptor.
 */
int mq_close( mqd_t mqdes );

/**
 * @brief Get message queue attributes.
 *
 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_getattr.html
 *
 * @retval 0 - Upon successful completion
 * @retval -1 - A error occurred. errno is also set.
 *
 * @sideeffect Possible errno values
 * <br>
 * DBADF - The mqdes argument is not a valid message queue descriptor.
 */
int mq_getattr( mqd_t mqdes,
                struct mq_attr * mqstat );

/**
 * @brief Open a message queue.
 *
 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html
 *
 * @note Supported name pattern: leading &lt;slash&gt; character in name is always required;
 * the maximum length (excluding null-terminator) of the name argument can be NAME_MAX.
 * The default value of NAME_MAX in FreeRTOS_POSIX_portable_default.h is 64, which can be
 * overwritten by user.
 * @note mode argument is not supported.
 * @note Supported oflags: O_RDWR, O_CREAT, O_EXCL, and O_NONBLOCK.
 *
 * @retval Message queue descriptor -- Upon successful completion
 * @retval (mqd_t) - 1 -- An error occurred. errno is also set.
 *
 * @sideeffect Possible errno values
 * <br>
 * EINVAL - name argument is invalid (not following name pattern),
 * OR if O_CREAT is specified in oflag with attr argument not NULL and either mq_maxmsg or mq_msgsize is equal to or less than zero,
 * OR either O_CREAT or O_EXCL is not set and a queue with the same name is unlinked but pending to be removed.
 * <br>
 * EEXIST - O_CREAT and O_EXCL are set and the named message queue already exists.
 * <br>
 * ENOSPC - There is insufficient space for the creation of the new message queue.
 * <br>
 * ENOENT - O_CREAT is not set and the named message queue does not exist.
 */
mqd_t mq_open( const char * name,
               int oflag,
               mode_t mode,
               struct mq_attr * attr );

/**
 * @brief Receive a message from a message queue.
 *
 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html
 *
 * @note msg_prio argument is not supported. Messages are not checked for corruption.
 *
 * @retval The length of the selected message in bytes - Upon successful completion.
 * The message is removed from the queue
 * @retval -1 - An error occurred. errno is also set.
 *
 * @sideeffect Possible errno values
 * <br>
 * EBADF - The mqdes argument is not a valid message queue descriptor open for reading.
 * <br>
 * EMSGSIZE - The specified message buffer size, msg_len, is less than the message size attribute of the message queue.
 * <br>
 * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
 * but no message arrived on the queue before the specified timeout expired.
 * <br>
 * EAGAIN - O_NONBLOCK was set in the message description associated with mqdes, and the specified message queue is empty.
 */
ssize_t mq_receive( mqd_t mqdes,
                    char * msg_ptr,
                    size_t msg_len,
                    unsigned int * msg_prio );

/**
 * @brief Send a message to a message queue.
 *
 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html
 *
 * @note msg_prio argument is not supported.
 *
 * @retval 0 - Upon successful completion.
 * @retval -1 - An error occurred. errno is also set.
 *
 * @sideeffect Possible errno values
 * <br>
 * EBADF - The mqdes argument is not a valid message queue descriptor open for writing.
 * <br>
 * EMSGSIZE - The specified message length, msg_len, exceeds the message size attribute of the message queue,
 * OR insufficient memory for the message to be sent.
 * <br>
 * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
 * but the timeout expired before the message could be added to the queue.
 * <br>
 * EAGAIN - The O_NONBLOCK flag is set in the message queue description associated with mqdes,
 * and the specified message queue is full.
 */
int mq_send( mqd_t mqdes,
             const char * msg_ptr,
             size_t msg_len,
             unsigned msg_prio );

/**
 * @brief Receive a message from a message queue with timeout.
 *
 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_timedreceive.html
 *
 * @note msg_prio argument is not supported. Messages are not checked for corruption.
 *
 * @retval The length of the selected message in bytes - Upon successful completion.
 * The message is removed from the queue
 * @retval -1 - An error occurred. errno is also set.
 *
 * @sideeffect Possible errno values
 * <br>
 * EBADF - The mqdes argument is not a valid message queue descriptor open for reading.
 * <br>
 * EMSGSIZE - The specified message buffer size, msg_len, is less than the message size attribute of the message queue.
 * <br>
 * EINVAL - The process or thread would have blocked, and the abstime parameter specified a nanoseconds field value
 * less than zero or greater than or equal to 1000 million.
 * <br>
 * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
 * but no message arrived on the queue before the specified timeout expired.
 * <br>
 * EAGAIN - O_NONBLOCK was set in the message description associated with mqdes, and the specified message queue is empty.
 */
ssize_t mq_timedreceive( mqd_t mqdes,
                         char * msg_ptr,
                         size_t msg_len,
                         unsigned * msg_prio,
                         const struct timespec * abstime );

/**
 * @brief Send a message to a message queue with timeout.
 *
 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_timedsend.html
 *
 * @note msg_prio argument is not supported.
 *
 * @retval 0 - Upon successful completion.
 * @retval -1 - An error occurred. errno is also set.
 *
 * @sideeffect Possible errno values
 * <br>
 * EBADF - The mqdes argument is not a valid message queue descriptor open for writing.
 * <br>
 * EMSGSIZE - The specified message length, msg_len, exceeds the message size attribute of the message queue,
 * OR insufficient memory for the message to be sent.
 * <br>
 * EINVAL - The process or thread would have blocked, and the abstime parameter specified a nanoseconds field
 * value less than zero or greater than or equal to 1000 million.
 * <br>
 * ETIMEDOUT - The O_NONBLOCK flag was not set when the message queue was opened,
 * but the timeout expired before the message could be added to the queue.
 * <br>
 * EAGAIN - The O_NONBLOCK flag is set in the message queue description associated with mqdes,
 * and the specified message queue is full.
 */
int mq_timedsend( mqd_t mqdes,
                  const char * msg_ptr,
                  size_t msg_len,
                  unsigned msg_prio,
                  const struct timespec * abstime );

/**
 * @brief Remove a message queue.
 *
 * http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_unlink.html
 *
 * @retval 0 - Upon successful completion.
 * @retval -1 - An error occurred. errno is also set.
 *
 * @sideeffect Possible errno values
 * <br>
 * EINVAL - name argument is invalid. Refer to requirements on name argument in mq_open().
 * <br>
 * ENOENT - The named message queue does not exist.
 */
int mq_unlink( const char * name );

#endif /* ifndef _FREERTOS_POSIX_MQUEUE_H_ */