/* * jlabROCSharedMemoryWrapper.hh * * Created on: June 16, 2014 * Author: * * This class provides a wrapper around accessing the shared memory on the ROCs */ #ifndef _jlabROCSharedMemoryWrapper_HH_ #define _jlabROCSharedMemoryWrapper_HH_ #include #include #include #include #include #include #include #include #include #include #include #include extern "C" { #include "shmem_roc.h" } using namespace std; class jlabBoard; class jlabROCSharedMemoryWrapper { public: jlabROCSharedMemoryWrapper( bool locDebugFlag = false ); virtual ~jlabROCSharedMemoryWrapper( void ); //! Return number of microseconds static suseconds_t GetTime() { struct timeval currTime; gettimeofday( &currTime, NULL ); return (1000000 * currTime.tv_sec + currTime.tv_usec); } void Loop_ReadingSharedMemory( void ); void Stop_SharedMemoryThread( void ); jlabBoard* GetBoard( uint32_t locSlot ) const; protected: // Prevent copying wrapper jlabROCSharedMemoryWrapper( const jlabROCSharedMemoryWrapper& chassis ); jlabROCSharedMemoryWrapper& operator=( const jlabROCSharedMemoryWrapper& chassis ); void Get_SharedMemoryPointer( void ); void Update_Discriminators( void ); void Update_FADC250s( void ); void Update_DIRCSCALERs( void ); void AlarmBoardsDIRC( bool updateStatus = false ); bool dDebugFlag; int semid; int shmid; roc_shmem* dROCSharedMemory; // These are set in the constructor and will not change from then on, so all reads are thread safe. // uint32_t is slot: 1 -> 21 set dDiscriminatorSlots; set dFADC250Slots; set dDIRCSlots; static const uint32_t dNumSlots = 21; static const long dMaxUpdateWaitTime = 60000000; bool dStopSharedMemoryThreadFlag; // Map with the boards that the chassis can see. The key is the slot number. map dBoardMap; }; inline void jlabROCSharedMemoryWrapper::Stop_SharedMemoryThread( void ) { dStopSharedMemoryThreadFlag = true; } inline jlabBoard* jlabROCSharedMemoryWrapper::GetBoard( uint32_t locSlot ) const { //Slot: 1 -> 21 map::const_iterator locIterator = dBoardMap.find( locSlot ); if ( locIterator == dBoardMap.end() ) return NULL; return locIterator->second; } #endif /* _jlabROCSharedMemoryWrapper_HH_ */