Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef __CXUTILS_IPC_MAPPED_MESSAGE_BOX_H
00043 #define __CXUTILS_IPC_MAPPED_MESSAGE_BOX_H
00044
00045 #include "cxutils/ipc/mappedmemory.h"
00046
00047 namespace CxUtils
00048 {
00060 class CX_UTILS_DLL MappedMessageBox
00061 {
00062 public:
00063 static const unsigned int DefaultSize = 2097152;
00064 static const Time::Stamp DefaultTimeOut = 500;
00065 typedef MappedMemory::ID ID;
00066
00074 class CX_UTILS_DLL Header
00075 {
00076 public:
00077 static const unsigned int Size = 28;
00078 Header();
00079 Header(const Header& header);
00080 ~Header();
00081 Header& operator=(const Header& header);
00082 Time::Stamp mWriteTimeMs;
00083 Time::Stamp mReadTimeMs;
00084 unsigned int mCount;
00085 unsigned int mStartBytePos;
00086 unsigned int mEndBytePos;
00087 };
00088 MappedMessageBox();
00089 ~MappedMessageBox();
00090 bool OpenMessageBox(const ID id);
00091 bool OpenMessageBox(const std::string& name);
00092 bool CreateMessageBox(const ID id,
00093 const unsigned int size = 500000);
00094 bool CreateMessageBox(const std::string& name,
00095 const unsigned int size = 500000);
00096 void CloseMessageBox();
00097 bool IsOpen() const;
00098 bool IsEmpty() const;
00099 bool IsActive(const bool readTimeFlag,
00100 const unsigned int thresholdMilliseconds = DefaultTimeOut) const;
00101 bool Touch();
00102 bool WriteMessage(const Packet& message);
00103 bool WriteMessage(const std::string& message);
00104 bool ReadMessage(Packet& message) const;
00105 bool ReadMessage(std::string& message) const;
00106 unsigned int GetBufferSize() const;
00107 unsigned int GetNumMessages() const;
00108 unsigned int GetNumMessagesRead() const { return mMessagesRead; }
00109 private:
00110 static const unsigned int MessageHeaderSize = sizeof(unsigned int);
00111 Header ReadHeader() const;
00112 void WriteHeader(const Header& header) const;
00113 MappedMemory mMessageBox;
00114 unsigned int mMessagesRead;
00115 };
00116 }
00117
00118 #endif
00119