5#ifdef TGT_OS_TYPE_VXWORKS
9#ifdef TGT_OS_TYPE_LINUX
10 #include <sys/types.h>
24#define IPC_QUEUE_TIMEOUT_SEC (1)
36 (void) mq_close(this->
handle);
49#ifndef TGT_OS_TYPE_VXWORKS
51 (void)snprintf(pid,
sizeof(pid),
".%d",getpid());
52 pid[
sizeof(pid)-1] = 0;
58 memset(&att,0,
sizeof(att));
59 att.mq_maxmsg = depth;
60 att.mq_msgsize = msgSize;
68 handle = mq_open(this->m_name.toChar(), O_RDWR | O_CREAT | O_EXCL, 0666, &att);
74 (void)mq_unlink(this->m_name.toChar());
80 handle = mq_open(this->m_name.toChar(), O_RDWR | O_CREAT | O_EXCL, 0666, &att);
88 QueueHandle* queueHandle =
new(std::nothrow) QueueHandle(handle);
89 if (
nullptr == queueHandle) {
101 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
102 if (
nullptr != queueHandle) {
106 (void) mq_unlink(this->m_name.toChar());
111 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
112 mqd_t handle = queueHandle->handle;
118 if (
nullptr == buffer) {
122 bool keepTrying =
true;
125 gettimeofday(&now,
nullptr);
126 struct timespec wait;
127 wait.tv_sec = now.tv_sec;
128 wait.tv_nsec = now.tv_usec * 1000;
133 NATIVE_INT_TYPE stat = mq_timedsend(handle,
reinterpret_cast<const char*
>(buffer), size, priority, &wait);
167 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
168 mqd_t handle = queueHandle->handle;
175 bool notFinished =
true;
176 while (notFinished) {
178 gettimeofday(&now,
nullptr);
179 struct timespec wait;
180 wait.tv_sec = now.tv_sec;
181 wait.tv_nsec = now.tv_usec * 1000;
186 size = mq_timedreceive(handle,
reinterpret_cast<char*
>(buffer),
static_cast<size_t>(capacity),
187#ifdef TGT_OS_TYPE_VXWORKS
188 reinterpret_cast<int*
>(&priority), &wait);
190 reinterpret_cast<unsigned int*
>(&priority), &wait);
226 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
227 mqd_t handle = queueHandle->handle;
230 int status = mq_getattr(handle, &attr);
232 return static_cast<U32
>(attr.mq_curmsgs);
241 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
242 mqd_t handle = queueHandle->handle;
245 int status = mq_getattr(handle, &attr);
247 return static_cast<U32
>(attr.mq_maxmsg);
251 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
252 mqd_t handle = queueHandle->handle;
255 int status = mq_getattr(handle, &attr);
257 return static_cast<U32
>(attr.mq_msgsize);
PlatformPointerCastType POINTER_CAST
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
#define IPC_QUEUE_TIMEOUT_SEC
NATIVE_INT_TYPE getQueueSize() const
get the queue depth (maximum number of messages queue can hold)
NATIVE_INT_TYPE getMsgSize() const
get the message size (maximum message size queue can hold)
QueueStatus create(const Fw::StringBase &name, NATIVE_INT_TYPE depth, NATIVE_INT_TYPE msgSize)
create a message queue
QueueStatus send(const Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE priority, QueueBlocking block)
send a message
NATIVE_INT_TYPE getNumMsgs() const
get the number of messages in the queue
QueueStatus receive(Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE &priority, QueueBlocking block)
receive a message
NATIVE_INT_TYPE getMaxMsgs() const
get the maximum number of messages (high watermark)
QueueHandle(mqd_t m_handle)
QueueString m_name
queue name
@ QUEUE_SIZE_MISMATCH
attempted to send or receive with buffer too large, too small
@ QUEUE_UNINITIALIZED
Queue wasn't initialized successfully.
@ QUEUE_NO_MORE_MSGS
If non-blocking, all the messages have been drained.
@ QUEUE_INVALID_PRIORITY
invalid priority requested
@ QUEUE_EMPTY_BUFFER
supplied buffer is empty
@ QUEUE_UNKNOWN_ERROR
Unexpected error; can't match with returns.
@ QUEUE_OK
message sent/received okay
@ QUEUE_FULL
queue was full when attempting to send a message
@ QUEUE_BLOCKING
Queue receive blocks until a message arrives.
@ QUEUE_NONBLOCKING
Queue receive always returns even if there is no message.
static NATIVE_INT_TYPE s_numQueues
tracks number of queues in the system
POINTER_CAST m_handle
handle for implementation specific queue