00001 00052 #ifndef _QPROCESS_STATUS_HH_ 00053 #define _QPROCESS_STATUS_HH_ 00054 00055 // C/C++ Includes 00056 #include <string> 00057 #include <deque> 00058 #include <map> 00059 #include <signal.h> 00060 00061 // Apollo Includes 00062 #include "QCuore.hh" 00063 #include "QNamed.hh" 00064 #include "QId.hh" 00065 #include "QDaqCommonDefs.hh" 00066 00067 class QProcessStatus : public QNamed, QId 00068 { 00069 public: 00070 00072 static QProcessStatus& GetInstance(); 00073 00075 virtual ~QProcessStatus() {} 00076 00086 bool Associate(int signalId,ProcessStatus_t pStatus); 00087 00094 bool Enable(int signalId); 00095 00097 bool Disable(int signalId); 00098 00100 bool Ignore(int signalId); 00101 00103 bool HasChanged() const { return !fStatusQueue.empty(); } 00104 00106 volatile ProcessStatus_t GetState() const { return fState; } 00107 00109 volatile ProcessStatus_t GetPreviousState() const 00110 { return fPreviousState; } 00111 00117 volatile ProcessStatus_t GetNextState() const 00118 { if(HasChanged()) return fStatusQueue.front(); else return fState; } 00119 00127 void SetState(ProcessStatus_t state); 00128 00133 void Notify(); 00134 00139 volatile bool isRunning() const { return (QRunning_s == fState);} 00140 00145 volatile bool isPaused() const { return (QPaused_s == fState);} 00146 00151 volatile bool isIdle() const { return (QIdle_s == fState);} 00152 00157 volatile bool isReady() const { return (QReady_s == fState);} 00158 00163 volatile bool TrgCtrlEnabled() const { return fTrgCtrl; } 00164 00170 const std::string& GetError() const {return fError;} 00171 00176 void SetError(const std::string& errMsg) {fError=errMsg;} 00177 00179 bool isError() const {return (fError != "");} 00180 00185 void SetTrgCtrlEnabled(bool enabled) {fTrgCtrl = enabled; } 00186 00193 void InformServer(); 00194 00200 void SetName(const std::string& name) { QNamed::SetName(name); } 00201 00202 00203 private: 00204 00209 QProcessStatus(); 00210 00212 mutable ProcessStatus_t fState; 00214 mutable ProcessStatus_t fPreviousState; 00215 00220 bool fTrgCtrl; 00221 00223 bool fInformEnabled; 00224 00228 const size_t kMaxQueued; 00229 00234 std::deque<ProcessStatus_t> fStatusQueue; 00235 00237 std::string fError; 00238 00240 std::map<int,ProcessStatus_t> fSigMap; 00241 00242 00256 void HandleSignal(int signalId); 00257 00259 void AssociateDefaults(); 00260 00270 void AddToQueue(ProcessStatus_t state); 00271 00276 ProcessStatus_t GetLastStatus() const; 00277 00279 bool CanBeHandled(int signalId) const; 00280 00282 bool CanBeDisabled(int signalId) const; 00283 00284 friend void SigHandler(int); 00285 }; 00286 00287 00295 void SigHandler(int signalId); 00296 00297 #endif // _QPROCESS_STATUS_HH_