Class MessageQueue
Defined in File message_queue.hpp
Inheritance Relationships
Base Type
public DesignPattern::Creation< MessageQueue, IpcChannelError >(Template Class Creation)
Class Documentation
-
class MessageQueue : public DesignPattern::Creation<MessageQueue, IpcChannelError>
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
-
MessageQueue() noexcept
default constructor. The result is an invalid MessageQueue object which can be reassigned later by using the move constructor.
-
MessageQueue(const MessageQueue &other) = delete
-
MessageQueue(MessageQueue &&other) noexcept
-
MessageQueue &operator=(const MessageQueue &other) = delete
-
MessageQueue &operator=(MessageQueue &&other) noexcept
-
~MessageQueue() noexcept
-
cxx::expected<IpcChannelError> destroy() noexcept
close and remove message queue.
-
cxx::expected<IpcChannelError> send(const std::string &msg) const noexcept
send a message to queue using std::string.
- Returns:
true if sent without errors, false otherwise
-
cxx::expected<std::string, IpcChannelError> receive() const noexcept
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.
-
cxx::expected<std::string, IpcChannelError> timedReceive(const units::Duration &timeout) const noexcept
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.
-
cxx::expected<IpcChannelError> timedSend(const std::string &msg, const units::Duration &timeout) const noexcept
try to send a message to the queue for a given timeout duration using std::string
-
cxx::expected<bool, IpcChannelError> isOutdated() noexcept
Public Static Functions
-
static cxx::expected<bool, IpcChannelError> unlinkIfExists(const IpcChannelName_t &name) noexcept
Public Static Attributes
-
static constexpr mqd_t INVALID_DESCRIPTOR = std::numeric_limits<mqd_t>::max()
-
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
- friend class DesignPattern::Creation< MessageQueue, IpcChannelError >