Classes | Public Types | Public Member Functions | Static Public Attributes

CxUtils::MappedMessageBox Class Reference

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>

List of all members.

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

Detailed Description

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.


Member Typedef Documentation

ID Field.

Definition at line 65 of file mappedmessagebox.h.


Constructor & Destructor Documentation

MappedMessageBox::MappedMessageBox (  )

Constructor.

Definition at line 118 of file mappedmessagebox.cpp.

MappedMessageBox::~MappedMessageBox (  )

Destructor.

Definition at line 128 of file mappedmessagebox.cpp.


Member Function Documentation

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.

Parameters:
[in]idID number of the shared memory location.
[in]sizeSize available for storage of your messages in bytes.
Returns:
True on success, false on failure.

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.

Parameters:
[in]nameThe 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]sizeSize available for storage of your messages in bytes.
Returns:
True on success, false on failure.

Definition at line 234 of file mappedmessagebox.cpp.

unsigned int MappedMessageBox::GetBufferSize (  ) const
Returns:
Total amount of memory available for storing messages in bytes.

Definition at line 623 of file mappedmessagebox.cpp.

unsigned int MappedMessageBox::GetNumMessages (  ) const
Returns:
Number of messages inside of the shared memory queue/box.

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.

Parameters:
[in]readTimeFlagIf true, the read time is checked for activity, if false, the write time to mssage box is checkd for activity.
[in]thresholdMillisecondsThe threshold for determining if there is an active writer to shared memory.
Returns:
True if active, otherwise false.

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.

Returns:
True if box is empty or has no new messages, false otherwise.

Definition at line 353 of file mappedmessagebox.cpp.

bool MappedMessageBox::IsOpen (  ) const
Returns:
True if messsage box is open, otherwise false.

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.

Parameters:
[in]nameThe 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.
Returns:
True on success, false on failure.

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.

Parameters:
[in]idID number of the shared memory location.
Returns:
True on success, false on failure.

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.

Parameters:
[in]messagePacket data to read from message box.
Returns:
True on success, false on failure.

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.

Parameters:
[in]messageString data to read from message box.
Returns:
True on success, false on failure.

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.

Returns:
True on success, false on failure.

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.

Parameters:
[in]messagePacket data to write into message box for others to read.
Returns:
True on success, false on failure.

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.

Parameters:
[in]messageString data to write into message box for others to read.
Returns:
True on success, false on failure.

Definition at line 514 of file mappedmessagebox.cpp.


Member Data Documentation

const unsigned int CxUtils::MappedMessageBox::DefaultSize = 2097152 [static]

Definition at line 63 of file mappedmessagebox.h.

Definition at line 64 of file mappedmessagebox.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines