iceoryx_doc  1.0.1
Public Member Functions | Static Public Member Functions | Static Public Attributes | Friends | List of all members
iox::posix::MessageQueue Class Reference

Wrapper class for posix message queue. More...

#include <message_queue.hpp>

Inheritance diagram for iox::posix::MessageQueue:
Inheritance graph
[legend]
Collaboration diagram for iox::posix::MessageQueue:
Collaboration graph
[legend]

Public Member Functions

 MessageQueue ()
 
 MessageQueue (const MessageQueue &other)=delete
 
 MessageQueue (MessageQueue &&other)
 
MessageQueueoperator= (const MessageQueue &other)=delete
 
MessageQueueoperator= (MessageQueue &&other)
 
cxx::expected< IpcChannelError > destroy ()
 close and remove message queue.
 
cxx::expected< IpcChannelError > send (const std::string &msg) const
 send a message to queue using std::string. More...
 
cxx::expected< std::string, IpcChannelError > receive () const
 receive message from queue using std::string. More...
 
cxx::expected< std::string, IpcChannelError > timedReceive (const units::Duration &timeout) const
 try to receive message from queue for a given timeout duration using std::string. Only defined for NON_BLOCKING == false. More...
 
cxx::expected< IpcChannelError > timedSend (const std::string &msg, const units::Duration &timeout) const
 try to send a message to the queue for a given timeout duration using std::string
 
cxx::expected< bool, IpcChannelError > isOutdated ()
 
- Public Member Functions inherited from DesignPattern::Creation< MessageQueue, IpcChannelError >
 Creation (Creation &&rhs) noexcept
 
 Creation (const Creation &rhs) noexcept=default
 
Creationoperator= (Creation &&rhs) noexcept
 
Creationoperator= (const Creation &rhs) noexcept=default
 
bool isInitialized () const noexcept
 returns true if the object was constructed successfully, otherwise false
 

Static Public Member Functions

static cxx::expected< bool, IpcChannelError > unlinkIfExists (const IpcChannelName_t &name)
 
- Static Public Member Functions inherited from DesignPattern::Creation< MessageQueue, IpcChannelError >
static result_t create (Targs &&... args) noexcept
 factory method which guarantees that either a working object is produced or an error value describing the error during construction More...
 
static result_t verify (MessageQueue &&newObject) noexcept
 verifies if a class was created successfully More...
 
static iox::cxx::expected< IpcChannelError > placementCreate (void *const memory, Targs &&... args) noexcept
 factory method which guarantees that either a working object is produced or an error value describing the error during construction More...
 

Static Public Attributes

static constexpr mqd_t INVALID_DESCRIPTOR = -1
 
static constexpr int32_t ERROR_CODE = -1
 
static constexpr size_t SHORTEST_VALID_QUEUE_NAME = 2
 
static constexpr size_t NULL_TERMINATOR_SIZE = 1
 
static constexpr size_t MAX_MESSAGE_SIZE = 4096
 

Friends

class DesignPattern::Creation< MessageQueue, IpcChannelError >
 for calling private constructor in create method
 

Additional Inherited Members

- Public Types inherited from DesignPattern::Creation< MessageQueue, IpcChannelError >
using CreationPattern_t = Creation< MessageQueue, IpcChannelError >
 
using result_t = iox::cxx::expected< MessageQueue, IpcChannelError >
 
using errorType_t = IpcChannelError
 
- Protected Attributes inherited from DesignPattern::Creation< MessageQueue, IpcChannelError >
bool m_isInitialized
 
IpcChannelError m_errorValue
 

Detailed Description

Wrapper class for posix message queue.

Template Parameters
NON_BLOCKINGspecifies the type of message queue. A non-blocking message queue will immediately return from a send/receive call if the queue is full/empty. A blocking message has member functions timedSend and timedReceive which allow to specify a maximum timeout duration.
auto mq = posix::MessageQueue<true>::CreateMessageQueue("/MqName123");
if (mq.has_value())
{
mq->send("important message, bla.");
// ...
std::string str;
mq->receive(str);
}

Constructor & Destructor Documentation

◆ MessageQueue()

iox::posix::MessageQueue::MessageQueue ( )

default constructor. The result is an invalid MessageQueue object which can be reassigned later by using the move constructor.

Member Function Documentation

◆ receive()

cxx::expected<std::string, IpcChannelError> iox::posix::MessageQueue::receive ( ) const

receive message from queue using std::string.

Todo:
zero copy receive with receive(cxx::string&); cxx::string would be the buffer for mq_receive
Returns
number of characters received. In case of an error, returns -1 and msg is empty.

◆ send()

cxx::expected<IpcChannelError> iox::posix::MessageQueue::send ( const std::string &  msg) const

send a message to queue using std::string.

Returns
true if sent without errors, false otherwise

◆ timedReceive()

cxx::expected<std::string, IpcChannelError> iox::posix::MessageQueue::timedReceive ( const units::Duration timeout) const

try to receive message from queue for a given timeout duration using std::string. Only defined for NON_BLOCKING == false.

Returns
optional containing the received string. In case of an error, nullopt type is returned.

The documentation for this class was generated from the following file: