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