/* * BaseIUTimeoutable.hh * * Class for objects whos communication can time-out and * alarm would need to be set when it happens. * Created on: Nov 6, 2015 * Author: Hovanes Egiyan */ #ifndef BASEIUTIMEOUTABLE_HH_ #define BASEIUTIMEOUTABLE_HH_ #include #include #include #include #include #include #include #include "BaseIUAlarmable.hh" class BaseIUTimeoutable: public BaseIUAlarmable { protected: // Time during which there was no communication double btSilentTime; // Time after which an alarm level is set double btTimoutLimit; public: // Constructor BaseIUTimeoutable( const double timeLimit = 60000000 ) : BaseIUAlarmable(), btSilentTime( 0 ), btTimoutLimit( timeLimit ) { CheckAlarm(); return; } // Destructor virtual ~BaseIUTimeoutable() { return; } // Copy constructor BaseIUTimeoutable( const BaseIUTimeoutable& o ) : BaseIUAlarmable( o ), btSilentTime( o.btSilentTime ), btTimoutLimit( o.btTimoutLimit ) { CheckAlarm(); return; } // Assignment operator BaseIUTimeoutable& operator=( const BaseIUTimeoutable& o ) { BaseIUAlarmable::operator=( o ); btSilentTime = o.btSilentTime; btTimoutLimit = o.btTimoutLimit; CheckAlarm(); return *this; } // virtual std::string GetName() = 0; // Check if there is a timeout condition, and if there is set // the alarm status to COMM alarm. inline virtual void CheckAlarm() { if ( btSilentTime > btTimoutLimit ) { // std::cout << "Will alarm for " << GetName() << std::endl; std::cout << "Will alarm" << std::endl; this->SetStatus( epicsAlarmComm ); this->SetSeverity( epicsSevInvalid ); } else { this->SetStatus( epicsAlarmNone ); this->SetSeverity( epicsSevNone ); } } inline virtual double IncrementSilentTime( const double incTime ) { btSilentTime += incTime; this->CheckAlarm(); return btSilentTime; } inline virtual double GetSilentTime() const { return btSilentTime; } inline virtual void SetSilentTime( const double btSilentTime ) { this->btSilentTime = btSilentTime; this->CheckAlarm(); } inline virtual double GetTimoutLimit() const { return btTimoutLimit; } inline virtual void SetTimoutLimit( const double btTimoutLimit ) { this->btTimoutLimit = btTimoutLimit; this->CheckAlarm(); } }; #endif /* BASEIUTIMEOUTABLE_HH_ */