00001 // ===================================================================== 00021 // ===================================================================== 00022 #ifndef __TOBJECTSHAREDMEMORY_HH 00023 #define __TOBJECTSHAREDMEMORY_HH 00024 00025 #include "Tglobals.h" 00026 00027 //OutputしてるときはInputさせない 00028 00048 class TObjectSharedMemory 00049 { 00050 00051 protected: 00052 static TObjectSharedMemory* theObjectSharedMemory; 00053 00054 public: 00055 enum { tDefaultMaxEvent = 100 }; 00056 enum { tDefaultMemorySize = 1024 * 1024 }; 00057 00058 protected: 00059 Tint theSharedMemoryID; 00060 Tint theMemorySize; 00061 Tint theMaxEvent; 00062 Tint theCurrentPositionOfMemorySpace; 00063 Tbool* theReadable; 00064 Tvoid* theBaseAddress; 00065 Tvoid* theAddress; 00066 00067 public: 00068 TObjectSharedMemory( Tint memsize, Tint maxevt ); 00069 00070 protected: 00071 virtual ~TObjectSharedMemory(); 00072 00073 public: 00074 Tvoid* Attach( const Tvoid* shmaddr = 0, Tint shmflg = 0 ) const; 00075 Tint Detach(); 00076 Tint Remove( struct shmid_ds* buf = 0 ); 00077 00078 public: 00079 Tint GetSharedMemoryID() const; 00080 Tint GetMemorySize() const; 00081 Tvoid* GetBaseAddress() const; 00082 Tvoid* GetAddress() const; 00083 Tint GetMaxEvent() const; 00084 Tint GetCurrentPositionOfMemorySpace() const; 00085 Tvoid SetMaxEvent( Tint maxevt ); 00086 Tvoid SetCurrentPositionOfMemorySpace( Tint pos ); 00087 Tvoid SetSharedMemoryID( Tint memid ); 00088 Tvoid SetMemorySize( Tint memsize ); 00089 Tvoid SetAddress( Tvoid* shmaddr ); 00090 Tbool IsReadable() const; 00091 Tvoid SetReadable( Tbool permission ); 00092 00093 public: 00094 static TObjectSharedMemory* GetObjectSharedMemory(); 00095 00096 }; 00097 00098 inline TObjectSharedMemory* TObjectSharedMemory::GetObjectSharedMemory() 00099 { 00100 return theObjectSharedMemory; 00101 } 00102 00103 inline Tint TObjectSharedMemory::GetMaxEvent() const 00104 { 00105 return theMaxEvent; 00106 } 00107 00108 inline Tint TObjectSharedMemory::GetCurrentPositionOfMemorySpace() const 00109 { 00110 return theCurrentPositionOfMemorySpace; 00111 } 00112 00113 inline Tvoid TObjectSharedMemory::SetMaxEvent( Tint maxevt ) 00114 { 00115 theMaxEvent = maxevt; 00116 return; 00117 } 00118 00119 inline Tvoid TObjectSharedMemory::SetCurrentPositionOfMemorySpace( Tint pos ) 00120 { 00121 theCurrentPositionOfMemorySpace = pos; 00122 return; 00123 } 00124 00125 inline Tint TObjectSharedMemory::GetSharedMemoryID() const 00126 { 00127 return theSharedMemoryID; 00128 } 00129 00130 inline Tint TObjectSharedMemory::GetMemorySize() const 00131 { 00132 return theMemorySize; 00133 } 00134 00135 inline Tvoid* TObjectSharedMemory::GetBaseAddress() const 00136 { 00137 return theBaseAddress; 00138 } 00139 00140 inline Tvoid* TObjectSharedMemory::GetAddress() const 00141 { 00142 return theAddress; 00143 } 00144 00145 inline Tvoid TObjectSharedMemory::SetSharedMemoryID( Tint memid ) 00146 { 00147 theSharedMemoryID = memid; 00148 return; 00149 } 00150 00151 inline Tvoid TObjectSharedMemory::SetMemorySize( Tint memsize ) 00152 { 00153 theMemorySize = memsize; 00154 return; 00155 } 00156 00157 inline Tvoid TObjectSharedMemory::SetAddress( Tvoid* shmaddr ) 00158 { 00159 theAddress = shmaddr; 00160 return; 00161 } 00162 00163 inline Tvoid* TObjectSharedMemory::Attach( const Tvoid* shmaddr, Tint shmflg ) const 00164 { 00165 return shmat( theSharedMemoryID, shmaddr, shmflg ); 00166 } 00167 00168 inline Tint TObjectSharedMemory::Detach() 00169 { 00170 return shmdt( (Tvoid*)theReadable ); 00171 } 00172 00173 inline Tint TObjectSharedMemory::Remove( struct shmid_ds* buf ) 00174 { 00175 return shmctl( theSharedMemoryID, IPC_RMID, buf ); 00176 } 00177 00178 inline Tbool TObjectSharedMemory::IsReadable() const 00179 { 00180 return *theReadable; 00181 } 00182 00183 inline Tvoid TObjectSharedMemory::SetReadable( Tbool permission ) 00184 { 00185 *theReadable = permission; 00186 return; 00187 } 00188 00189 #endif