387 lines
14 KiB
C
387 lines
14 KiB
C
#ifndef _MQUEUE_H
|
|
#define _MQUEUE_H
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#ifdef __XLT_OS__
|
|
#include "stdarg.h"
|
|
#include "stdlib.h"
|
|
#include "limits.h"
|
|
#include "time.h"
|
|
#else
|
|
#include <features.h>
|
|
|
|
#define __NEED_size_t
|
|
#define __NEED_ssize_t
|
|
#define __NEED_pthread_attr_t
|
|
#define __NEED_time_t
|
|
#define __NEED_struct_timespec
|
|
#include <bits/alltypes.h>
|
|
#endif
|
|
|
|
#ifdef __XLT_OS__
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
* Message queue attribute structure
|
|
*/
|
|
struct mq_attr {
|
|
long mq_flags; /**< Message queue flags */
|
|
long mq_maxmsg; /**< Maximum number of messages */
|
|
long mq_msgsize; /**< Maximum size of a message */
|
|
long mq_curmsgs; /**< Number of messages in the current message queue */
|
|
};
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
* Handle type of a message queue
|
|
*/
|
|
typedef UINTPTR mqd_t;
|
|
#else
|
|
typedef int mqd_t;
|
|
struct mq_attr {
|
|
long mq_flags, mq_maxmsg, mq_msgsize, mq_curmsgs, __unused[4];
|
|
};
|
|
struct sigevent;
|
|
#endif
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
*
|
|
* @par Description:
|
|
* This API is used to close a message queue that has a specified descriptor.
|
|
* @attention
|
|
* <ul>
|
|
* <li> If the message queue is empty, it will be reclaimed, which is similar to when mq_unlink is called.</li>
|
|
* </ul>
|
|
*
|
|
* @param personal [IN] Message queue descriptor.
|
|
*
|
|
* @retval 0 The message queue is successfully closed.
|
|
* @retval -1 The message queue fails to be closed, with either of the following error codes in errno.
|
|
*
|
|
* @par Errors
|
|
* <ul>
|
|
* <li><b>EBADF</b>: Invalid message queue descriptor.</li>
|
|
* <li><b>EAGAIN</b>: Failed to delete the message queue.</li>
|
|
* <li><b>EFAULT</b>: Failed to free the message queue.</li>
|
|
* <li><b>EINVAL</b>: Invalid parameter.</li>
|
|
* </ul>
|
|
*
|
|
* @par Dependency:
|
|
* <ul><li>mqueue.h</li></ul>
|
|
* @see mq_open
|
|
* @since Huawei LiteOS V100R001C00
|
|
*/
|
|
int mq_close(mqd_t);
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
*
|
|
* @par Description:
|
|
* This API is used to obtain attributes of the message queue that has a specified descriptor.
|
|
* @attention
|
|
* <ul>
|
|
* <li> None. </li>
|
|
* </ul>
|
|
*
|
|
* @param personal [IN] Message queue descriptor.
|
|
* @param mqAttr [OUT] Message queue attribute.
|
|
*
|
|
* @retval 0 The message queue attributes are successfully obtained.
|
|
* @retval -1 The message queue attributes fail to be obtained, with any of the following error codes in errno.
|
|
*
|
|
* @par Errors
|
|
* <ul>
|
|
* <li><b>EBADF</b>: Invalid message queue.</li>
|
|
* <li><b>EINVAL</b>: Invalid parameter.</li>
|
|
* </ul>
|
|
*
|
|
* @par Dependency:
|
|
* <ul><li>mqueue.h</li></ul>
|
|
* @see mq_setattr
|
|
* @since Huawei LiteOS V100R001C00
|
|
*/
|
|
int mq_getattr(mqd_t, struct mq_attr *);
|
|
int mq_notify(mqd_t, const struct sigevent *);
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
*
|
|
* @par Description:
|
|
* This API is used to open an existed message queue that has a specified name or create a new message queue.
|
|
* @attention
|
|
* <ul>
|
|
* <li>A message queue does not restrict the read and write permissions.</li>
|
|
* <li>The length of mqueue name must less than 256.</li>
|
|
* <li>This operation and closed mqueue scheduling must be used in coordination to release the resource.</li>
|
|
* <li>The parameter "mode" is not supported.</li>
|
|
* <li>The "mq_curmsgs" member of the mq_attr structure is not supported.</li>
|
|
* </ul>
|
|
*
|
|
* @param mqName [IN] Message queue name.
|
|
* @param openFlag [IN] Permission attributes of the message queue. The value range is
|
|
* [O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_EXCL, O_NONBLOCK].
|
|
* @param mode [IN] Message queue mode (variadic argument). When oflag is O_CREAT, it requires
|
|
* two additional arguments: mode, which shall be of type mode_t, and attr,
|
|
* which shall be a pointer to an mq_attr structure.
|
|
* @param attr [IN] Message queue attribute (variadic argument).
|
|
*
|
|
* @retval mqd_t The message queue is successfully opened or created.
|
|
* @retval (mqd_t)-1 The message queue fails to be opened or created, with any of the following error codes in errno.
|
|
* @par Errors
|
|
* <ul>
|
|
* <li><b>ENOENT</b>: O_CREAT flag is not set for oflag, and the message queue specified by name does not exist.</li>
|
|
* <li><b>EEXIST</b>: Both O_CREAT and O_EXCL are set for oflag, but the message queue
|
|
* specified by name already exists.</li>
|
|
* <li><b>EINVAL</b>: invalid parameter.</li>
|
|
* <li><b>ENFILE</b>: The number of opened message queues exceeds the maximum limit.</li>
|
|
* <li><b>ENOSPC</b>: insufficient memory.</li>
|
|
* <li><b>ENAMETOOLONG</b>: The message queue name specified by name is too long.</li>
|
|
* </ul>
|
|
*
|
|
* @par Dependency:
|
|
* <ul><li>mqueue.h</li></ul>
|
|
* @see mq_close
|
|
* @since Huawei LiteOS V100R001C00
|
|
*/
|
|
mqd_t mq_open(const char *, int, ...);
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
*
|
|
* @par Description:
|
|
* This API is used to remove the oldest message from the message queue that has a specified descriptor,
|
|
* and puts it in the buffer pointed to by msg_ptr.
|
|
* @attention
|
|
* <ul>
|
|
* <li> Priority-based message processing is not supported.</li>
|
|
* <li> The msg_len should be same to the length of string which msg_ptr point to.</li>
|
|
* </ul>
|
|
*
|
|
* @param personal [IN] Message queue descriptor.
|
|
* @param msg [IN] Pointer to the message content to be received.
|
|
* @param msgLen [IN] Length of the message to be received.
|
|
* @param msgPrio [OUT] Priority of the message to be received
|
|
* because priority-based message processing is not supported, this parameter is useless).
|
|
*
|
|
* @retval 0 The message is successfully received.
|
|
* @retval -1 The message fails to be received, with any of the following error codes in the errno.
|
|
*
|
|
* @par Errors
|
|
* <ul>
|
|
* <li><b>EINTR</b>: An interrupt is in progress while the message is being received.</li>
|
|
* <li><b>EBADF</b>: The message queue is invalid or not readable.</li>
|
|
* <li><b>EAGAIN</b>: The message queue is empty.</li>
|
|
* <li><b>EINVAL</b>: invalid parameter.</li>
|
|
* <li><b>EMSGSIZE</b>: The message to be received is too long.</li>
|
|
* <li><b>ETIMEDOUT</b>: The operaton times out.</li>
|
|
* </ul>
|
|
*
|
|
* @par Dependency:
|
|
* <ul><li>mqueue.h</li></ul>
|
|
* @see mq_send
|
|
* @since Huawei LiteOS V100R001C00
|
|
*/
|
|
ssize_t mq_receive(mqd_t, char *, size_t, unsigned *);
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
*
|
|
* @par Description:
|
|
* This API is used to put a message with specified message content and length into
|
|
* a message queue that has a specified descriptor.
|
|
* @attention
|
|
* <ul>
|
|
* <li> Priority-based message processing is not supported.</li>
|
|
* <li> The msg_len should be same to the length of string which msg_ptr point to.</li>
|
|
* </ul>
|
|
*
|
|
* @param personal [IN] Message queue descriptor.
|
|
* @param msg [IN] Pointer to the message content to be sent.
|
|
* @param msgLen [IN] Length of the message to be sent.
|
|
* @param msgPrio [IN] Priority of the message to be sent (the value of this parameter must
|
|
* be 0 because priority-based message sending is not supported. If the
|
|
* value is not 0, this API will cease to work.)
|
|
*
|
|
* @retval 0 The message is successfully sent.
|
|
* @retval -1 The message fails to be sent, with any of the following error codes in errno.
|
|
*
|
|
* @par Errors
|
|
* <ul>
|
|
* <li><b>EINTR</b>: An interrupt is in progress while the message is being sent.</li>
|
|
* <li><b>EBADF</b>: The message queue is invalid or not writable.</li>
|
|
* <li><b>EAGAIN</b>: The message queue is full.</li>
|
|
* <li><b>EINVAL</b>: Invalid parameter.</li>
|
|
* <li><b>ENOSPC</b>: Insufficient memory.</li>
|
|
* <li><b>EMSGSIZE</b>: The message to be sent is too long.</li>
|
|
* <li><b>EOPNOTSUPP</b>: The operation is not supported.</li>
|
|
* <li><b>ETIMEDOUT</b>: The operation times out.</li>
|
|
* </ul>
|
|
*
|
|
* @par Dependency:
|
|
* <ul><li>mqueue.h</li></ul>
|
|
* @see mq_receive
|
|
* @since Huawei LiteOS V100R001C00
|
|
*/
|
|
int mq_send(mqd_t, const char *, size_t, unsigned);
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
*
|
|
* @par Description:
|
|
* This API is used to modify attributes of the message queue that has a specified descriptor.
|
|
* @attention
|
|
* <ul>
|
|
* <li> The mq_maxmsg, mq_msgsize, and mq_curmsgs attributes are not modified
|
|
* in the message queue attribute setting.</li>
|
|
* </ul>
|
|
*
|
|
* @param personal [IN] Message queue descriptor.
|
|
* @param mqSetAttr [IN] New attribute of the message queue.
|
|
* @param MqOldAttr [OUT] Old attribute of the message queue.
|
|
*
|
|
* @retval 0 The message queue attributes are successfully set.
|
|
* @retval -1 The message queue attributes fail to be set, with either of the following error codes in the errno.
|
|
*
|
|
* @par Errors
|
|
* <ul>
|
|
* <li><b>EBADF</b>: Invalid message queue.</li>
|
|
* <li><b>EINVAL</b>: Invalid parameter.</li>
|
|
* </ul>
|
|
*
|
|
* @par Dependency:
|
|
* <ul><li>mqueue.h</li></ul>
|
|
* @see mq_getattr
|
|
* @since Huawei LiteOS V100R001C00
|
|
*/
|
|
int mq_setattr(mqd_t, const struct mq_attr *__restrict, struct mq_attr *__restrict);
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
*
|
|
* @par Description:
|
|
* This API is used to obtain a message with specified message content and length from
|
|
* a message queue message that has a specified descriptor.
|
|
* @attention
|
|
* <ul>
|
|
* <li> Priority-based message processing is not supported.</li>
|
|
* <li> The expiry time must be later than the current time.</li>
|
|
* <li> The wait time is a relative time.</li>
|
|
* <li> The msg_len should be same to the length of string which msg_ptr point to.</li>
|
|
* </ul>
|
|
*
|
|
* @param personal [IN] Message queue descriptor.
|
|
* @param msg [IN] Pointer to the message content to be received.
|
|
* @param msgLen [IN] Length of the message to be received.
|
|
* @param msgPrio [OUT] Priority of the message to be received (because priority-based message
|
|
* processing is not supported, this parameter is useless ).
|
|
* @param absTimeout [IN] Scheduled time at which the messagewill be received. If the value is 0,
|
|
* the message is an instant message.
|
|
*
|
|
* @retval 0 The message is successfully received.
|
|
* @retval -1 The message fails to be received, with any of the following error codes in errno.
|
|
*
|
|
* @par Errors
|
|
* <ul>
|
|
* <li><b>EINTR</b>: An interrupt is in progress while the message is being received.</li>
|
|
* <li><b>EBADF</b>: The message queue is invalid or not readable.</li>
|
|
* <li><b>EAGAIN</b>: The message queue is empty.</li>
|
|
* <li><b>EINVAL</b>: invalid parameter.</li>
|
|
* <li><b>EMSGSIZE</b>: The message to be received is too long.</li>
|
|
* <li><b>ETIMEDOUT</b>: The operation times out.</li>
|
|
* </ul>
|
|
*
|
|
* @par Dependency:
|
|
* <ul><li>mqueue.h</li></ul>
|
|
* @see mq_send
|
|
* @since Huawei LiteOS V100R001C00
|
|
*/
|
|
ssize_t mq_timedreceive(mqd_t, char *__restrict, size_t, unsigned *__restrict, const struct timespec *__restrict);
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
*
|
|
* @par Description:
|
|
* This API is used to put a message with specified message content and length into
|
|
* a message queue that has a descriptor at a scheduled time.
|
|
* @attention
|
|
* <ul>
|
|
* <li> Priority-based message processing is not supported.</li>
|
|
* <li> The expiry time must be later than the current time.</li>
|
|
* <li> The wait time is a relative time.</li>
|
|
* <li> The msg_len should be same to the length of string which msg_ptr point to.</li>
|
|
* </ul>
|
|
*
|
|
* @param mqdes [IN] Message queue descriptor.
|
|
* @param msg [IN] Pointer to the message content to be sent.
|
|
* @param msgLen [IN] Length of the message to be sent.
|
|
* @param msgPrio [IN] Priority of the message to be sent (the value of this parameter must be 0
|
|
* because priority-based message processing is not supported).
|
|
* @param absTimeout [IN] Scheduled time at which the message will be sent. If the value is 0,
|
|
* the message is an instant message.
|
|
*
|
|
* @retval 0 The message is successfully sent.
|
|
* @retval -1 The message fails to be sent, with any of the following error codes in errno.
|
|
*
|
|
* @par Errors
|
|
* <ul>
|
|
* <li><b>EINTR</b>: An interrupt is in progress while the message is being sent.</li>
|
|
* <li><b>EBADF</b>: The message queue is invalid or not writable.</li>
|
|
* <li><b>EAGAIN</b>: The message queue is full.</li>
|
|
* <li><b>EINVAL</b>: Invalid parameter.</li>
|
|
* <li><b>EMSGSIZE</b>: The message to be sent is too long.</li>
|
|
* <li><b>EOPNOTSUPP</b>: The operation is not supported.</li>
|
|
* <li><b>ETIMEDOUT</b>: The operation times out.</li>
|
|
* </ul>
|
|
*
|
|
* @par Dependency:
|
|
* <ul><li>mqueue.h</li></ul>
|
|
* @see mq_receive
|
|
* @since Huawei LiteOS V100R001C00
|
|
*/
|
|
int mq_timedsend(mqd_t, const char *, size_t, unsigned, const struct timespec *);
|
|
|
|
/**
|
|
* @ingroup mqueue
|
|
*
|
|
* @par Description:
|
|
* This API is used to remove a message queue that has a specified name.
|
|
* @attention
|
|
* <ul>
|
|
* <li> If the message queue is empty, it will be reclaimed, which is similar to when mq_close is called.</li>
|
|
* <li> The length of mqueue name must less than 256.</li>
|
|
* </ul>
|
|
*
|
|
* @param mqName [IN] Message queue name.
|
|
*
|
|
* @retval 0 The message queue is successfully removed.
|
|
* @retval -1 The message queue fails to be removed, with any of the following error codes in errno.
|
|
*
|
|
* @par Errors
|
|
* <ul>
|
|
* <li><b>ENOENT</b>: The message queue specified by name does not exist.</li>
|
|
* <li><b>EAGAIN</b>: Failed to delete the message queue.</li>
|
|
* <li><b>EBUSY</b>: The message queue to be removed is being used.</li>
|
|
* <li><b>EINVAL</b>: Invalid parameter.</li>
|
|
* <li><b>ENAMETOOLONG</b>: The name of mqueue is too long.</li>
|
|
* </ul>
|
|
*
|
|
* @par Dependency:
|
|
* <ul><li>mqueue.h</li></ul>
|
|
* @see mq_close
|
|
* @since Huawei LiteOS V100R001C00
|
|
*/
|
|
int mq_unlink(const char *);
|
|
|
|
#if _REDIR_TIME64
|
|
__REDIR(mq_timedreceive, __mq_timedreceive_time64);
|
|
__REDIR(mq_timedsend, __mq_timedsend_time64);
|
|
#endif
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
#endif
|