Message storage class for sharing packet or string data between threads/processes using shared memory. This MappedMessageBox class is only compatible with other programs using the same from CxUtils. More...
#include <mappedmessagebox.h>
Classes | |
class | Header |
Class for storing MappedMessageBox header information that is stored at the beginning of shared memory used in MappedMessageBox. More... | |
Public Types | |
typedef MappedMemory::ID | ID |
ID Field. | |
Public Member Functions | |
MappedMessageBox () | |
Constructor. | |
~MappedMessageBox () | |
Destructor. | |
bool | OpenMessageBox (const ID id) |
Opens a view to a message box that is already created. Once open you may read/write to the message box. | |
bool | OpenMessageBox (const std::string &name) |
Opens a view to a message box that is already created. Once open you may read/write to the message box. | |
bool | CreateMessageBox (const ID id, const unsigned int size=500000) |
Attempts to create a shared memory message box with a specific unique name and size in bytes. If a message box with the same name and size already exists, this method will open a view of, otherwise it will fail. | |
bool | CreateMessageBox (const std::string &name, const unsigned int size=500000) |
Attempts to create a shared memory message box with a specific unique name and size in bytes. If a message box with the same name and size already exists, this method will open a view of, otherwise it will fail. | |
void | CloseMessageBox () |
Closes the view of the message box. Once the last process exits, the shared memory is released. | |
bool | IsOpen () const |
bool | IsEmpty () const |
Method checks to see if there are no message in the box, or if there are no new messages to read. | |
bool | IsActive (const bool readTimeFlag, const unsigned int thresholdMilliseconds=DefaultTimeOut) const |
Method checks to see if there are threads/processes writing messages by checking to see if a thread/process touched/wrote to the message box within a threshold. | |
bool | Touch () |
Performs a "touch" of shared memory by only updating the write time value of shared memory header used for MappedMessageBox. This is used to let other processes know that someone is still writing to shared memory even if they have not written any new messages. | |
bool | WriteMessage (const Packet &message) |
Writes the message/packet data to the MappedMessageBox. | |
bool | WriteMessage (const std::string &message) |
Writes the message/packet data to the MappedMessageBox. | |
bool | ReadMessage (Packet &message) const |
Reads a message out of the message box. | |
bool | ReadMessage (std::string &message) const |
Reads a message out of the message box. | |
unsigned int | GetBufferSize () const |
unsigned int | GetNumMessages () const |
unsigned int | GetNumMessagesRead () const |
Static Public Attributes | |
static const unsigned int | DefaultSize = 2097152 |
static const Time::Stamp | DefaultTimeOut = 500 |
Message storage class for sharing packet or string data between threads/processes using shared memory. This MappedMessageBox class is only compatible with other programs using the same from CxUtils.
Ass the MappedMessageBox gets full old messages are automatically deleted (buffer overflow) to make room for new messages.
Definition at line 60 of file mappedmessagebox.h.
ID Field.
Definition at line 65 of file mappedmessagebox.h.
MappedMessageBox::MappedMessageBox | ( | ) |
Constructor.
Definition at line 118 of file mappedmessagebox.cpp.
MappedMessageBox::~MappedMessageBox | ( | ) |
Destructor.
Definition at line 128 of file mappedmessagebox.cpp.
void MappedMessageBox::CloseMessageBox | ( | ) |
Closes the view of the message box. Once the last process exits, the shared memory is released.
Definition at line 323 of file mappedmessagebox.cpp.
bool MappedMessageBox::CreateMessageBox | ( | const ID | id, |
const unsigned int | size = 500000 |
||
) |
Attempts to create a shared memory message box with a specific unique name and size in bytes. If a message box with the same name and size already exists, this method will open a view of, otherwise it will fail.
[in] | id | ID number of the shared memory location. |
[in] | size | Size available for storage of your messages in bytes. |
Definition at line 209 of file mappedmessagebox.cpp.
bool MappedMessageBox::CreateMessageBox | ( | const std::string & | name, |
const unsigned int | size = 500000 |
||
) |
Attempts to create a shared memory message box with a specific unique name and size in bytes. If a message box with the same name and size already exists, this method will open a view of, otherwise it will fail.
[in] | name | The name used to reference the shared memory. Must be less than 20 characters in width. To maximize portability between windows and linux, this should be an integer number. |
[in] | size | Size available for storage of your messages in bytes. |
Definition at line 234 of file mappedmessagebox.cpp.
unsigned int MappedMessageBox::GetBufferSize | ( | ) | const |
Definition at line 623 of file mappedmessagebox.cpp.
unsigned int MappedMessageBox::GetNumMessages | ( | ) | const |
Definition at line 638 of file mappedmessagebox.cpp.
unsigned int CxUtils::MappedMessageBox::GetNumMessagesRead | ( | ) | const [inline] |
Definition at line 108 of file mappedmessagebox.h.
bool MappedMessageBox::IsActive | ( | const bool | readTimeFlag, |
const unsigned int | thresholdMilliseconds = DefaultTimeOut |
||
) | const |
Method checks to see if there are threads/processes writing messages by checking to see if a thread/process touched/wrote to the message box within a threshold.
[in] | readTimeFlag | If true, the read time is checked for activity, if false, the write time to mssage box is checkd for activity. |
[in] | thresholdMilliseconds | The threshold for determining if there is an active writer to shared memory. |
Definition at line 387 of file mappedmessagebox.cpp.
bool MappedMessageBox::IsEmpty | ( | ) | const |
Method checks to see if there are no message in the box, or if there are no new messages to read.
Definition at line 353 of file mappedmessagebox.cpp.
bool MappedMessageBox::IsOpen | ( | ) | const |
Definition at line 335 of file mappedmessagebox.cpp.
bool MappedMessageBox::OpenMessageBox | ( | const std::string & | name ) |
Opens a view to a message box that is already created. Once open you may read/write to the message box.
[in] | name | The name used to reference the shared memory. Must be less than 20 characters in width. To maximize portability between windows and linux, this should be an integer number. |
Definition at line 176 of file mappedmessagebox.cpp.
bool MappedMessageBox::OpenMessageBox | ( | const ID | id ) |
Opens a view to a message box that is already created. Once open you may read/write to the message box.
[in] | id | ID number of the shared memory location. |
Definition at line 144 of file mappedmessagebox.cpp.
bool MappedMessageBox::ReadMessage | ( | Packet & | message ) | const |
Reads a message out of the message box.
This method will read the first message that has not been read yet by this instance of the MappedMessageBox.
[in] | message | Packet data to read from message box. |
Definition at line 534 of file mappedmessagebox.cpp.
bool MappedMessageBox::ReadMessage | ( | std::string & | message ) | const |
Reads a message out of the message box.
This method will read the first message that has not been read yet by this instance of the MappedMessageBox.
[in] | message | String data to read from message box. |
Definition at line 602 of file mappedmessagebox.cpp.
bool MappedMessageBox::Touch | ( | ) |
Performs a "touch" of shared memory by only updating the write time value of shared memory header used for MappedMessageBox. This is used to let other processes know that someone is still writing to shared memory even if they have not written any new messages.
Definition at line 426 of file mappedmessagebox.cpp.
bool MappedMessageBox::WriteMessage | ( | const Packet & | message ) |
Writes the message/packet data to the MappedMessageBox.
The message will be inserted at the end of the message box.
[in] | message | Packet data to write into message box for others to read. |
Definition at line 456 of file mappedmessagebox.cpp.
bool MappedMessageBox::WriteMessage | ( | const std::string & | message ) |
Writes the message/packet data to the MappedMessageBox.
The message will be inserted at the end of the message box.
[in] | message | String data to write into message box for others to read. |
Definition at line 514 of file mappedmessagebox.cpp.
const unsigned int CxUtils::MappedMessageBox::DefaultSize = 2097152 [static] |
Definition at line 63 of file mappedmessagebox.h.
const Time::Stamp CxUtils::MappedMessageBox::DefaultTimeOut = 500 [static] |
Definition at line 64 of file mappedmessagebox.h.