This class implements a message queue.
More...
|
typedef unsigned int | Id |
| Definition of a message id. More...
|
|
|
| MessageQueue ()=default |
| Creates a new message queue. More...
|
|
| MessageQueue (MessageQueue &&messageQueue) |
| Move constructor. More...
|
|
| MessageQueue (const unsigned int oldMessageAge) |
| Creates a new message queue. More...
|
|
| ~MessageQueue () |
| Destructs a message queue. More...
|
|
bool | push (const Id id, const std::string &message, const std::string &value) |
| Pushes a new message. More...
|
|
bool | front (const Id id, std::string &message, std::string &value) |
| Gets the front message for a given message id. More...
|
|
bool | front (const Id id, const double timeout, std::string &message, std::string &value) |
| Gets the front message for a given message id and waits a specified time if no message is available. More...
|
|
void | pop (const Id id) |
| Pops the front message with a specified message id from the queue. More...
|
|
std::string | pop (const Id id, const double timeout) |
| Returns and pops the front message for a given message id and waits a specified time if no message is available. More...
|
|
bool | pop (const Id id, const double timeout, std::string &message, std::string &value) |
| Returns and pops the front message for a given message id and waits a specified time if no message is available. More...
|
|
void | clear () |
| Clears the entire message queue. More...
|
|
void | clear (const Id id) |
| Clears all messages with a specified message id. More...
|
|
Id | uniqueId () |
| Returns a unique message id within this message queue. More...
|
|
Id | lastUniqueId () |
| Returns the last unique message id again. More...
|
|
MessageQueue & | operator= (MessageQueue &&messageQueue) |
| Move operator. More...
|
|
|
typedef std::pair< std::string, std::string > | Message |
| Definition of a message pair. More...
|
|
typedef std::queue< Message > | Queue |
| Definition of a queue holding message pairs. More...
|
|
typedef std::unordered_map< Id, Queue > | MessageMap |
| Definition of a map mapping message ids to message queues. More...
|
|
This class implements a message queue.
◆ Id
Definition of a message id.
◆ Message
Definition of a message pair.
◆ MessageMap
Definition of a map mapping message ids to message queues.
◆ Queue
Definition of a queue holding message pairs.
◆ MessageQueue() [1/3]
Ocean::Network::MessageQueue::MessageQueue |
( |
| ) |
|
|
default |
Creates a new message queue.
◆ MessageQueue() [2/3]
Ocean::Network::MessageQueue::MessageQueue |
( |
MessageQueue && |
messageQueue | ) |
|
Move constructor.
- Parameters
-
messageQueue | The message queue object to be moved |
◆ MessageQueue() [3/3]
Ocean::Network::MessageQueue::MessageQueue |
( |
const unsigned int |
oldMessageAge | ) |
|
|
explicit |
Creates a new message queue.
- Parameters
-
oldMessageAge | The capacity of the queue, with range [1, infinity) |
◆ ~MessageQueue()
Ocean::Network::MessageQueue::~MessageQueue |
( |
| ) |
|
Destructs a message queue.
◆ clear() [1/2]
void Ocean::Network::MessageQueue::clear |
( |
| ) |
|
Clears the entire message queue.
◆ clear() [2/2]
void Ocean::Network::MessageQueue::clear |
( |
const Id |
id | ) |
|
Clears all messages with a specified message id.
- Parameters
-
id | Message id to clear all messages for |
◆ front() [1/2]
bool Ocean::Network::MessageQueue::front |
( |
const Id |
id, |
|
|
const double |
timeout, |
|
|
std::string & |
message, |
|
|
std::string & |
value |
|
) |
| |
Gets the front message for a given message id and waits a specified time if no message is available.
- Parameters
-
id | Message id to get the front message for |
timeout | Time to wait in seconds |
message | Resulting message |
value | Resulting optional value |
- Returns
- True, if a message could be returned within the specified wait time
◆ front() [2/2]
bool Ocean::Network::MessageQueue::front |
( |
const Id |
id, |
|
|
std::string & |
message, |
|
|
std::string & |
value |
|
) |
| |
Gets the front message for a given message id.
- Parameters
-
id | Message id to get the front message for |
message | Resulting message |
value | Resulting optional value |
- Returns
- True, if succeeded
◆ invalidId()
Returns an invalid message id.
- Returns
- Invalid message id
◆ lastUniqueId()
Id Ocean::Network::MessageQueue::lastUniqueId |
( |
| ) |
|
Returns the last unique message id again.
Beware: Do no use this id directly, use it for control purpose only!
- Returns
- Last unique id
◆ operator=()
Move operator.
- Parameters
-
messageQueue | The message queue to be moved |
- Returns
- Reference to this object
◆ pop() [1/3]
void Ocean::Network::MessageQueue::pop |
( |
const Id |
id | ) |
|
Pops the front message with a specified message id from the queue.
- Parameters
-
id | Message id to pop the front message for |
◆ pop() [2/3]
std::string Ocean::Network::MessageQueue::pop |
( |
const Id |
id, |
|
|
const double |
timeout |
|
) |
| |
Returns and pops the front message for a given message id and waits a specified time if no message is available.
- Parameters
-
id | Message id to get the front message for |
timeout | Time to wait in seconds |
- Returns
- Resulting message, if any
◆ pop() [3/3]
bool Ocean::Network::MessageQueue::pop |
( |
const Id |
id, |
|
|
const double |
timeout, |
|
|
std::string & |
message, |
|
|
std::string & |
value |
|
) |
| |
Returns and pops the front message for a given message id and waits a specified time if no message is available.
- Parameters
-
id | Message id to get the front message for |
timeout | Time to wait in seconds |
message | Resulting message |
value | Resulting optional value |
- Returns
- True, if a message could be popped within the specified wait time
◆ push()
bool Ocean::Network::MessageQueue::push |
( |
const Id |
id, |
|
|
const std::string & |
message, |
|
|
const std::string & |
value |
|
) |
| |
Pushes a new message.
Beware: To avoid a message overflow all messages older than the defined 'age' will be released.
- Parameters
-
id | Message id |
message | The message to push |
value | Optional message value to push |
- Returns
- True, if succeeded
◆ uniqueId()
Id Ocean::Network::MessageQueue::uniqueId |
( |
| ) |
|
Returns a unique message id within this message queue.
- Returns
- Unique message id
◆ idCounter_
Id Ocean::Network::MessageQueue::idCounter_ = invalidId() |
|
protected |
◆ lock_
Lock Ocean::Network::MessageQueue::lock_ |
|
protected |
◆ messageMap_
MessageMap Ocean::Network::MessageQueue::messageMap_ |
|
protected |
Map holding all messages.
◆ oldMessageAge_
unsigned int Ocean::Network::MessageQueue::oldMessageAge_ = 500u |
|
protected |
Definition of an message age of old and therefore unused messages.
The documentation for this class was generated from the following file: