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 #ifndef _CXUTILS_IPC_MAPPED_MEMORY_H
00042 #define _CXUTILS_IPC_MAPPED_MEMORY_H
00043
00044 #include <limits.h>
00045 #include <assert.h>
00046
00047 #include "cxutils/cxbase.h"
00048 #include "cxutils/packet.h"
00049 #include "cxutils/mutex.h"
00050 #include "cxutils/time.h"
00051
00052 namespace CxUtils
00053 {
00066 class CX_UTILS_DLL MappedMemory
00067 {
00068 public:
00069 static const unsigned ReadAccess = 1;
00070 static const unsigned int ReadWriteAccess = 2;
00071 static const unsigned int MemoryNameSize = 128;
00072 typedef unsigned long long int ID;
00073 MappedMemory();
00074 virtual ~MappedMemory();
00075 int OpenMappedMemory(const ID id,
00076 const unsigned int access = ReadWriteAccess,
00077 const unsigned int expectedSize = 0);
00078 int OpenMappedMemory(const std::string& name,
00079 const unsigned int access = ReadWriteAccess,
00080 const unsigned int expectedSize = 0);
00081 int CreateMappedMemory(const ID id,
00082 const unsigned int size);
00083 int CreateMappedMemory(const std::string& name,
00084 const unsigned int size);
00085 int CloseMappedMemory();
00086 static int DeleteMappedMemory(const std::string& name);
00087 int Lock(unsigned long wait = INFINITE) const;
00088 int Unlock() const;
00089 Packet* operator->();
00090 const Packet* operator->() const;
00091 Packet* GetData();
00092 const Packet* GetData() const;
00093 int Copy(const unsigned int p1, const unsigned int p2);
00094 bool IsOpen() const;
00095 static bool IsMemOpen(const std::string& name);
00096 unsigned char* GetMemory();
00097 const unsigned char* GetMemory() const;
00098 const std::string GetMappedName() const { return std::string(mMappedName); }
00099 unsigned int Length() const;
00100 private:
00101 #ifdef WIN32
00102 void* mFileMapping;
00103 void* mFileSizeMapping;
00104 unsigned char* mpMemorySizePtr;
00105 #else
00106 int mFileMapping;
00107 bool mCreatedFlag;
00108 #endif
00109 Mutex* mpMemMutex;
00110 char mMappedName[MemoryNameSize];
00111 unsigned int mWriteAccess;
00112 unsigned char* mpMemory;
00113 unsigned int mLength;
00114 Packet::Wrapper mPacket;
00115 };
00116 }
00117
00118 #endif
00119
00120