|
Serial-TCP/IPbridge
1.0
|
Message buffer that can be used in separate threads. More...
#include <shared_buffer.h>
Public Types | |
| typedef unsigned long | MessageId |
| Message ID. More... | |
| typedef std::pair< std::string, MessageId > | MessageWithId |
| Message with identification. More... | |
Public Member Functions | |
| SharedBuffer () | |
| Default constructor. More... | |
| ~SharedBuffer () | |
| Destructor. More... | |
| SharedBuffer (const SharedBuffer &other) | |
| Copy constructor. More... | |
| SharedBuffer & | operator= (const SharedBuffer &other) |
| Assignment operator. More... | |
| bool | operator== (const SharedBuffer &other) |
| Equality comparison. More... | |
| bool | operator== (const SharedBuffer &other) const |
| Equality comparison. More... | |
| bool | operator!= (const SharedBuffer &other) |
| Non-equality comparison. More... | |
| bool | operator!= (const SharedBuffer &other) const |
| Non-equality comparison. More... | |
| Buffer::size_type | size () |
| Returns the size of the buffer. More... | |
| Buffer::size_type | size () const |
| Returns the size of the buffer. More... | |
| MessageWithId | getMessage () |
| Returns the first message from the buffer. More... | |
| void | addMessage (const std::string &message) |
| Adds the selected message to the buffer. More... | |
| void | removeMessage (MessageId messageId) |
| Removes the selected message from the buffer. More... | |
| void | changeMessage (MessageId messageId, const std::string &newMessage) |
| Changes the selected message with a new one. More... | |
Static Public Attributes | |
| static const MessageWithId | INVALID_MESSAGE |
| Invalid message. More... | |
Private Types | |
| typedef std::list< MessageWithId > | Buffer |
| Buffer type. More... | |
Private Member Functions | |
| void | lockBufferMutex () |
| Locks the buffer mutex. More... | |
| void | unlockBufferMutex () |
| Locks the buffer mutex. More... | |
| MessageId | generateNewMessageId () |
| Generates and returns a new message ID. More... | |
| void | initializeBufferMutex () |
| Initializes the buffer mutex. More... | |
| void | swap (SharedBuffer &other) |
| Swap the contents of this object with the other object. More... | |
Private Attributes | |
| Buffer | _buffer |
| Buffer. More... | |
| MessageId | _lastMessageId |
| Last message ID. More... | |
| pthread_mutex_t | _bufferMutex |
| Buffer mutex. More... | |
Message buffer that can be used in separate threads.
All of the class operations are thread-safe. Each member function can throw ThreadingError in case of some threading-related problem.
It provides value semantics (objects copying and comparison is allowed).
|
private |
Buffer type.
| typedef unsigned long SharedBuffer::MessageId |
Message ID.
| typedef std::pair<std::string, MessageId> SharedBuffer::MessageWithId |
Message with identification.
| SharedBuffer::SharedBuffer | ( | ) |
Default constructor.
| SharedBuffer::~SharedBuffer | ( | ) |
Destructor.
| SharedBuffer::SharedBuffer | ( | const SharedBuffer & | other | ) |
Copy constructor.
| other | Object that will be used as a model in the object creation. |
Constructs a copy of the other object.
| void SharedBuffer::addMessage | ( | const std::string & | message | ) |
Adds the selected message to the buffer.
| message | The message to be added. |
| void SharedBuffer::changeMessage | ( | MessageId | messageId, |
| const std::string & | newMessage | ||
| ) |
Changes the selected message with a new one.
| messageId | The ID of the message to be changed. |
| newMessage | The new message. |
If there is no message with the selected ID, then this function does nothing.
|
private |
Generates and returns a new message ID.
| MessageWithId SharedBuffer::getMessage | ( | ) |
Returns the first message from the buffer.
If there are no messages in the buffer, it returns INVALID_MESSAGE.
|
private |
Initializes the buffer mutex.
|
private |
Locks the buffer mutex.
| bool SharedBuffer::operator!= | ( | const SharedBuffer & | other | ) |
Non-equality comparison.
| other | Object that will be compared with this object. |
| bool SharedBuffer::operator!= | ( | const SharedBuffer & | other | ) | const |
Non-equality comparison.
| other | Object that will be compared with this object. |
| SharedBuffer& SharedBuffer::operator= | ( | const SharedBuffer & | other | ) |
Assignment operator.
| other | Object that will be assigned to this object. |
Guarantees the strong exception safety.
| bool SharedBuffer::operator== | ( | const SharedBuffer & | other | ) |
Equality comparison.
| other | Object that will be compared with this object. |
| bool SharedBuffer::operator== | ( | const SharedBuffer & | other | ) | const |
Equality comparison.
| other | Object that will be compared with this object. |
| void SharedBuffer::removeMessage | ( | MessageId | messageId | ) |
Removes the selected message from the buffer.
| messageId | The ID of the message to be removed. |
If there is no message with the selected ID, then this function does nothing.
| Buffer::size_type SharedBuffer::size | ( | ) |
Returns the size of the buffer.
| Buffer::size_type SharedBuffer::size | ( | ) | const |
Returns the size of the buffer.
|
private |
Swap the contents of this object with the other object.
| other | Object that will be swapped with this object. |
Guarantees nothrow exception safety.
Preconditions:
|
private |
Locks the buffer mutex.
|
private |
Buffer.
|
private |
Buffer mutex.
|
private |
Last message ID.
|
static |
Invalid message.
Can be returned by getMessage() if there are no messages in the buffer.
1.8.6