/* * BufferSubscriber.hh * * Created on: Dec 14, 2017 * Author: Hovanes Egiyan */ #ifndef BUFFERSUBSCRIBER_HH_ #define BUFFERSUBSCRIBER_HH_ #include #include #include #include #include #include #include #include #include #include #include #include namespace VETROC { void decodeData( unsigned int data ); template class BufferSubscriber { protected: BUFFER* m_container; boost::mutex m_mutex; bool exitThreadFlagIsRaised; bool accessingIsRequested; unsigned activeSleepTime; unsigned passiveSleepTime; public: typedef typename BUFFER::value_type value_type; BufferSubscriber( BUFFER* buffer ) : m_container( buffer ), m_mutex(), exitThreadFlagIsRaised( false ), accessingIsRequested( false ), activeSleepTime( 10 ), passiveSleepTime( 1000 ) { } virtual ~BufferSubscriber() { } void operator()() { std::cerr << "BufferSubscriber: method operator()() for this class should not be used, it should be overridden" << std::endl; return; } BUFFER* getContainer() { boost::mutex::scoped_lock lock( m_mutex ); return m_container; } void setContainer( BUFFER* container ) { boost::mutex::scoped_lock lock( m_mutex ); m_container = container; } unsigned getActiveSleepTime() { boost::mutex::scoped_lock lock( m_mutex ); return activeSleepTime; } void setActiveSleepTime( unsigned activeSleepTime ) { boost::mutex::scoped_lock lock( this->m_mutex ); this->activeSleepTime = activeSleepTime; } bool isExitThreadFlagRaised() { boost::mutex::scoped_lock lock( m_mutex ); return exitThreadFlagIsRaised; } void setExitThreadFlagRaised( bool exitLoopFlagIsRaised = true ) { boost::mutex::scoped_lock lock( this->m_mutex ); this->exitThreadFlagIsRaised = exitLoopFlagIsRaised; } bool isAccessingRequested() { boost::mutex::scoped_lock lock( m_mutex ); return accessingIsRequested; } void setAccessingRequested( bool fillingIsRequested = true ) { boost::mutex::scoped_lock lock( this->m_mutex ); this->accessingIsRequested = fillingIsRequested; } unsigned getPassiveSleepTime() { boost::mutex::scoped_lock lock( m_mutex ); return passiveSleepTime; } void setPassiveSleepTime( unsigned passiveSleepTime ) { boost::mutex::scoped_lock lock( this->m_mutex ); this->passiveSleepTime = passiveSleepTime; } }; } /* namespace VETROC */ #endif /* BUFFERSUBSCRIBER_HH_ */