Skip to content

iox::posix::MessageQueue🔗

Wrapper class for posix message queue. More...

#include <message_queue.hpp>

Inherits from DesignPattern::Creation< MessageQueue, IpcChannelError >

Public Functions🔗

Name
MessageQueue()
MessageQueue(const MessageQueue & other)
MessageQueue(MessageQueue && other)
MessageQueue & operator=(const MessageQueue & other)
MessageQueue & operator=(MessageQueue && other)
~MessageQueue()
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.
cxx::expected< std::string, IpcChannelError > receive() const
receive message from queue using std::string.
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.
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()
cxx::expected< bool, IpcChannelError > unlinkIfExists(const IpcChannelName_t & name)

Public Attributes🔗

Name
constexpr mqd_t INVALID_DESCRIPTOR
constexpr int32_t ERROR_CODE
constexpr size_t SHORTEST_VALID_QUEUE_NAME
constexpr size_t NULL_TERMINATOR_SIZE
constexpr size_t MAX_MESSAGE_SIZE

Friends🔗

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

Additional inherited members🔗

Public Types inherited from DesignPattern::Creation< MessageQueue, IpcChannelError >

Name
using Creation< DerivedClass, ErrorType > CreationPattern_t
using iox::cxx::expected< DerivedClass, ErrorType > result_t
using ErrorType errorType_t

Public Functions inherited from DesignPattern::Creation< MessageQueue, IpcChannelError >

Name
template \<typename... Targs>
result_t
create(Targs &&... args)
factory method which guarantees that either a working object is produced or an error value describing the error during construction
result_t verify(DerivedClass && newObject)
verifies if a class was created successfully
template \<typename... Targs>
iox::cxx::expected< ErrorType >
placementCreate(void *const memory, Targs &&... args)
factory method which guarantees that either a working object is produced or an error value describing the error during construction
Creation() =default
Creation(Creation && rhs)
Creation(const Creation & rhs) =default
bool isInitialized() const
returns true if the object was constructed successfully, otherwise false

Protected Attributes inherited from DesignPattern::Creation< MessageQueue, IpcChannelError >

Name
bool m_isInitialized
ErrorType m_errorValue

Detailed Description🔗

class iox::posix::MessageQueue;

Wrapper class for posix message queue.

Template Parameters:

  • NON_BLOCKING specifies 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);
}

Public Functions Documentation🔗

function MessageQueue🔗

MessageQueue()

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

function MessageQueue🔗

MessageQueue(
    const MessageQueue & other
)

function MessageQueue🔗

MessageQueue(
    MessageQueue && other
)

function operator=🔗

MessageQueue & operator=(
    const MessageQueue & other
)

function operator=🔗

MessageQueue & operator=(
    MessageQueue && other
)

function ~MessageQueue🔗

~MessageQueue()

function destroy🔗

cxx::expected< IpcChannelError > destroy()

close and remove message queue.

function send🔗

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

send a message to queue using std::string.

Return: true if sent without errors, false otherwise

function receive🔗

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

receive message from queue using std::string.

Return: number of characters received. In case of an error, returns -1 and msg is empty.

Todo: zero copy receive with receive(cxx::string&); cxx::string would be the buffer for mq_receive

function timedReceive🔗

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.

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

function timedSend🔗

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

function isOutdated🔗

cxx::expected< bool, IpcChannelError > isOutdated()

function unlinkIfExists🔗

static cxx::expected< bool, IpcChannelError > unlinkIfExists(
    const IpcChannelName_t & name
)

Public Attributes Documentation🔗

variable INVALID_DESCRIPTOR🔗

static constexpr mqd_t INVALID_DESCRIPTOR = -1;

variable ERROR_CODE🔗

static constexpr int32_t ERROR_CODE = -1;

variable SHORTEST_VALID_QUEUE_NAME🔗

static constexpr size_t SHORTEST_VALID_QUEUE_NAME = 2;

variable NULL_TERMINATOR_SIZE🔗

static constexpr size_t NULL_TERMINATOR_SIZE = 1;

variable MAX_MESSAGE_SIZE🔗

static constexpr size_t MAX_MESSAGE_SIZE = 4096;

Friends🔗

friend DesignPattern::Creation< MessageQueue, IpcChannelError >🔗

friend class DesignPattern::Creation< MessageQueue, IpcChannelError >;

for calling private constructor in create method


Updated on 31 May 2022 at 15:52:33 CEST