00001 // ===================================================================== 00031 // ===================================================================== 00032 #ifndef CLDAQ__TOBJECTSHAREDMEMORY_HH 00033 #define CLDAQ__TOBJECTSHAREDMEMORY_HH 00034 00035 #include "Tglobals.h" 00036 00037 //OutputしてるときはInputさせない 00038 00058 #ifdef __CLDAQ_ROOT_DLL 00059 #ifndef _SYS_SHM_H 00060 // from <bit/shm.h>, for rootcint 00061 typedef struct { 00062 struct ipc_perm shm_perm; /* operation perms */ 00063 int shm_segsz; /* size of segment (bytes) */ 00064 time_t shm_atime; /* last attach time */ 00065 time_t shm_dtime; /* last detach time */ 00066 time_t shm_ctime; /* last change time */ 00067 unsigned short shm_cpid; /* pid of creator */ 00068 unsigned short shm_lpid; /* pid of last operator */ 00069 short shm_nattch; /* no. of current attaches */ 00070 } shmid_ds; 00071 #endif 00072 #endif 00073 00074 class TObjectSharedMemory 00075 { 00076 00077 protected: 00078 static TObjectSharedMemory* theObjectSharedMemory; 00079 00080 public: 00081 enum { tDefaultMaxEvent = 100 }; 00082 enum { tDefaultMemorySize = 1024 * 1024 }; 00083 00084 protected: 00085 Tint theSharedMemoryID; 00086 Tint theMemorySize; 00087 Tint theMaxEvent; 00088 Tint theCurrentPositionOfMemorySpace; 00089 Tbool* theReadable; 00090 Tvoid* theBaseAddress; 00091 Tvoid* theAddress; 00092 00093 public: 00094 TObjectSharedMemory( Tint memsize, Tint maxevt ); 00095 00096 protected: 00097 virtual ~TObjectSharedMemory(); 00098 00099 public: 00100 Tvoid* Attach( const Tvoid* shmaddr = 0, Tint shmflg = 0 ) const; 00101 Tint Detach(); 00102 Tint Remove( struct shmid_ds* buf = 0 ); 00103 00104 public: 00105 Tint GetSharedMemoryID() const; 00106 Tint GetMemorySize() const; 00107 Tvoid* GetBaseAddress() const; 00108 Tvoid* GetAddress() const; 00109 Tint GetMaxEvent() const; 00110 Tint GetCurrentPositionOfMemorySpace() const; 00111 Tvoid SetMaxEvent( Tint maxevt ); 00112 Tvoid SetCurrentPositionOfMemorySpace( Tint pos ); 00113 Tvoid SetSharedMemoryID( Tint memid ); 00114 Tvoid SetMemorySize( Tint memsize ); 00115 Tvoid SetAddress( Tvoid* shmaddr ); 00116 Tbool IsReadable() const; 00117 Tvoid SetReadable( Tbool permission ); 00118 00119 public: 00120 static TObjectSharedMemory* GetObjectSharedMemory(); 00121 00122 #ifdef __CLDAQ_ROOT_DLL 00123 ClassDef(TObjectSharedMemory,0) 00124 #endif 00125 00126 }; 00127 00128 inline TObjectSharedMemory* TObjectSharedMemory::GetObjectSharedMemory() 00129 { 00130 return theObjectSharedMemory; 00131 } 00132 00133 inline Tint TObjectSharedMemory::GetMaxEvent() const 00134 { 00135 return theMaxEvent; 00136 } 00137 00138 inline Tint TObjectSharedMemory::GetCurrentPositionOfMemorySpace() const 00139 { 00140 return theCurrentPositionOfMemorySpace; 00141 } 00142 00143 inline Tvoid TObjectSharedMemory::SetMaxEvent( Tint maxevt ) 00144 { 00145 theMaxEvent = maxevt; 00146 return; 00147 } 00148 00149 inline Tvoid TObjectSharedMemory::SetCurrentPositionOfMemorySpace( Tint pos ) 00150 { 00151 theCurrentPositionOfMemorySpace = pos; 00152 return; 00153 } 00154 00155 inline Tint TObjectSharedMemory::GetSharedMemoryID() const 00156 { 00157 return theSharedMemoryID; 00158 } 00159 00160 inline Tint TObjectSharedMemory::GetMemorySize() const 00161 { 00162 return theMemorySize; 00163 } 00164 00165 inline Tvoid* TObjectSharedMemory::GetBaseAddress() const 00166 { 00167 return theBaseAddress; 00168 } 00169 00170 inline Tvoid* TObjectSharedMemory::GetAddress() const 00171 { 00172 return theAddress; 00173 } 00174 00175 inline Tvoid TObjectSharedMemory::SetSharedMemoryID( Tint memid ) 00176 { 00177 theSharedMemoryID = memid; 00178 return; 00179 } 00180 00181 inline Tvoid TObjectSharedMemory::SetMemorySize( Tint memsize ) 00182 { 00183 theMemorySize = memsize; 00184 return; 00185 } 00186 00187 inline Tvoid TObjectSharedMemory::SetAddress( Tvoid* shmaddr ) 00188 { 00189 theAddress = shmaddr; 00190 return; 00191 } 00192 00193 inline Tvoid* TObjectSharedMemory::Attach( const Tvoid* shmaddr, Tint shmflg ) const 00194 { 00195 return shmat( theSharedMemoryID, shmaddr, shmflg ); 00196 } 00197 00198 inline Tint TObjectSharedMemory::Detach() 00199 { 00200 return shmdt( (Tvoid*)theReadable ); 00201 } 00202 00203 inline Tint TObjectSharedMemory::Remove( struct shmid_ds* buf ) 00204 { 00205 return shmctl( theSharedMemoryID, IPC_RMID, buf ); 00206 } 00207 00208 inline Tbool TObjectSharedMemory::IsReadable() const 00209 { 00210 return *theReadable; 00211 } 00212 00213 inline Tvoid TObjectSharedMemory::SetReadable( Tbool permission ) 00214 { 00215 *theReadable = permission; 00216 return; 00217 } 00218 00219 #endif