#ifndef _Brooks0254Module_ #define _Brooks0254Module_ #include #include #include #define _OPEN_THREADS #include #include #include #include #include using namespace std; #include "MtxLock.hh" #include "Brooks0254Port.hh" class Brooks0254Card; class Brooks0254Module { protected: //! Address of the chassis unsigned bmAddr; //! Serial port object pointer Brooks0254Port* bmPort; //! Mutex for an object pthread_mutex_t bmMutex; //! Mutex attributes for an object pthread_mutexattr_t bmMtxAttr; //! Initilize the mutex for the object void InitMutex(); //! Destroy the mutex for the object void CloseMutex(); //! Check communications with the module virtual bool CommIsOK() = 0; //! Default constructor is disabled Brooks0254Module(); public: //! Dummy static variable for initialization static int bmDummyInt; static unsigned bmDebFlag; //! Debug level indicator static pthread_mutex_t bmGlobMutex; //! Global mutex for this class static pthread_mutexattr_t bmGlobMtxAttr; //! Global mutex attributes //! Constructor. Initially serial port pointer is set to null Brooks0254Module( unsigned addr ) : bmAddr(addr), bmPort(0) { InitMutex(); } //! Copy constructor Brooks0254Module( Brooks0254Module& module ) : bmAddr(module.GetAddress()), bmPort(module.GetPort()) { InitMutex(); } //! Destructor ~Brooks0254Module() { CloseMutex();} //! Copy constructor Brooks0254Module& operator=( Brooks0254Module& module ); //! Function to synchronize modules virtual void Sync( bool dir = 0 ) = 0; //! Initialize global mutex static int InitGlobalMutex(); //! Get the address for the Brooks module inline unsigned GetAddress() { MtxLock scopeLock(bmMutex); return bmAddr; } //! Get the pointer to the serial port object fot this object inline Brooks0254Port* GetPort() { MtxLock scopeLock(bmMutex); return bmPort; } //! Set the address for the Brooks module inline unsigned SetAddress( unsigned addr ) { MtxLock scopeLock(bmMutex); return (bmAddr = addr); } //! Set the pointer to the serial port object inline Brooks0254Port* SetPort( Brooks0254Port* portPtr ) { MtxLock scopeLock(bmMutex); return (bmPort = portPtr); } //! Lock the Global mutex for this class inline static int GlobLock() // Lock static structures access { return pthread_mutex_lock( &bmGlobMutex ); } //! Unlock the global mutex for this class inline static int GlobUnlock() // Unlock static structures access { return pthread_mutex_unlock( &bmGlobMutex ); } }; #endif