QProcessStatus.hh

Go to the documentation of this file.
00001 
00054 #ifndef _QPROCESS_STATUS_HH_
00055 #define _QPROCESS_STATUS_HH_
00056 
00057 // C/C++ Includes
00058 #include <string>
00059 #include <deque>
00060 #include <map>
00061 #include <signal.h>
00062 
00063 // Apollo Includes
00064 #include "QCuore.hh"
00065 #include "QNamed.hh"
00066 #include "QId.hh"
00067 #include "QDaqCommonDefs.hh"
00068 
00069 class QProcessStatus : public QNamed, QId 
00070 {
00071 public:
00072    
00074    static QProcessStatus& GetInstance();
00075    
00077    virtual ~QProcessStatus() {}
00078 
00088    bool Associate(int signalId,QDaqCommonDefs::ProcessStatus_t pStatus);
00089 
00096    bool Enable(int signalId);
00097 
00099    bool Disable(int signalId);
00100 
00102    bool Ignore(int signalId);
00103 
00105    bool HasChanged() const { return !fStatusQueue.empty(); }
00106 
00108    volatile QDaqCommonDefs::ProcessStatus_t GetState() const { return fState; }
00109    
00111    volatile QDaqCommonDefs::ProcessStatus_t GetPreviousState() const 
00112    { return fPreviousState; }
00113 
00119    volatile QDaqCommonDefs::ProcessStatus_t GetNextState() const
00120    { if(HasChanged()) return fStatusQueue.front(); else return fState; }
00121 
00129    void SetState(QDaqCommonDefs::ProcessStatus_t state);
00130   
00135    void Notify();
00136 
00141    volatile bool isRunning() const
00142    { return (QDaqCommonDefs::QRunning_s == fState);}
00143 
00148    volatile bool isPaused() const
00149    { return (QDaqCommonDefs::QPaused_s  == fState);}
00150 
00155    volatile bool isIdle() const
00156    { return (QDaqCommonDefs::QIdle_s == fState);}
00157 
00162    volatile bool isReady() const
00163    { return (QDaqCommonDefs::QReady_s   == fState);}
00164 
00169    volatile bool TrgCtrlEnabled() const { return fTrgCtrl; }
00170    
00176    const std::string& GetError() const {return fError;}
00177 
00182    void SetError(const std::string& errMsg) {fError=errMsg;}
00183 
00185    bool isError() const {return (fError != "");}
00186    
00191    void SetTrgCtrlEnabled(bool enabled) {fTrgCtrl = enabled; }
00192    
00199    void InformServer();
00200    
00206    void SetName(const std::string& name) { QNamed::SetName(name); }
00207 
00208 
00209 private:
00210 
00215    QProcessStatus();
00216 
00218    mutable QDaqCommonDefs::ProcessStatus_t fState;
00220    mutable QDaqCommonDefs::ProcessStatus_t fPreviousState;
00221    
00226    bool fTrgCtrl;
00227 
00229    bool fInformEnabled;
00230 
00234    const size_t kMaxQueued;
00235 
00240    std::deque<QDaqCommonDefs::ProcessStatus_t> fStatusQueue;
00241 
00243    std::string fError;
00244 
00246    std::map<int,QDaqCommonDefs::ProcessStatus_t> fSigMap;
00247 
00248 
00262    void HandleSignal(int signalId);
00263 
00265    void AssociateDefaults();
00266 
00276    void AddToQueue(QDaqCommonDefs::ProcessStatus_t state);
00277    
00282    QDaqCommonDefs::ProcessStatus_t GetLastStatus() const;
00283 
00285    bool CanBeHandled(int signalId) const;
00286 
00288    bool CanBeDisabled(int signalId) const;
00289 
00290    friend void SigHandler(int);
00291 };
00292 
00293 
00301 void SigHandler(int signalId);
00302 
00303 #endif // _QPROCESS_STATUS_HH_

Generated on Tue Nov 16 10:49:55 2010 for CUORE Software by  doxygen 1.5.6