Diana Software
QProcessStatus.hh
Go to the documentation of this file.
1 
2 #ifndef _QPROCESS_STATUS_HH_
3 #define _QPROCESS_STATUS_HH_
4 
5 #include <string>
6 #include <deque>
7 #include <map>
8 #include <signal.h>
9 
10 #include "QDiana.hh"
11 #include "QNamed.hh"
12 #include "QDaqCommonDefs.hh"
13 #include "QId.hh"
14 
31 class QProcessStatus : public QNamed, QId
32 {
33 public:
34 
36  static QProcessStatus& GetInstance();
38  virtual ~QProcessStatus() {}
39 
46  void Associate(int signalId, ProcessStatus_t pStatus);
48  void Disable(int signalId);
50  bool Ignore(int signalId);
51 
53  bool HasChanged() const { return !fStatusQueue.empty(); }
55  ProcessStatus_t GetState() const { return fState; }
58 
65  { if(HasChanged()) return fStatusQueue.front(); else return fState; }
73  void SetState(ProcessStatus_t state);
75  void Notify();
76 
78  bool isRunning() const { return (QRunning_s == fState);}
80  bool isPaused() const { return (QPaused_s == fState);}
82  bool isIdle() const { return (QIdle_s == fState);}
84  bool isReady() const { return (QReady_s == fState);}
86  bool isExiting() const { return (QExiting_s == fState);}
88  bool isWaiting() const { return (QWaiting_s == fState);}
89 
91  const std::string& GetError() const {return fError;}
93  void SetError(const std::string& errMsg) {fError=errMsg;}
95  bool isError() const {return (fError != "");}
96 
98  bool TrgCtrlEnabled() const { return fTrgCtrl; }
100  void SetTrgCtrlEnabled(bool enabled) {fTrgCtrl = enabled; }
101 
108  void InformServer();
109 
115  void SetName(const std::string& name) { QNamed::SetName(name); }
116 
117  void EnableInformServer(bool enabled) { fInformEnabled = enabled; }
118 private:
120  QProcessStatus();
121 
127  bool fTrgCtrl;
131  const size_t kMaxQueued;
133  std::deque<ProcessStatus_t> fStatusQueue;
135  std::string fError;
137  std::map<int,ProcessStatus_t> fSigMap;
138 
139 
153  void HandleSignal(int signalId);
154 
164  void AddToQueue(ProcessStatus_t state);
165 
171 
172  friend void SigHandler(int);
173 };
174 
182 void SigHandler(int signalId);
183 
184 #endif // _QPROCESS_STATUS_HH_
@ QIdle_s
@ QPaused_s
@ QExiting_s
@ QWaiting_s
@ QRunning_s
@ QReady_s
void SigHandler(int signalId)
signal handler function
wrapper for ProcessStatus_ enum
base class for anything having an id
Definition: QId.hh:13
base class for anything that has a name
Definition: QNamed.hh:14
void SetName(const std::string &name)
Definition: QNamed.hh:20
process status and signal handler
bool isWaiting() const
check wether current process status is QWaiting_s
std::map< int, ProcessStatus_t > fSigMap
void Notify()
acknowledge oldest process status contained in staus queue
ProcessStatus_t fState
current process status
bool isPaused() const
check wether current process status is QPaused_s
bool TrgCtrlEnabled() const
check wether trigger control signals are enabled
void SetTrgCtrlEnabled(bool enabled)
enable or disable trigger status control
friend void SigHandler(int)
signal handler function
bool isError() const
check wether an error occurred
void SetError(const std::string &errMsg)
set error string
const size_t kMaxQueued
const std::string & GetError() const
get error string
ProcessStatus_t GetLastStatus() const
get last status that have been added to status queue. If queue is empty current process status is ret...
std::string fError
error string
virtual ~QProcessStatus()
dtor
bool HasChanged() const
tell wehter process status has changed
void SetName(const std::string &name)
set process name that will be used for communication with message logger server
ProcessStatus_t GetNextState() const
get the status the process will go into the next time that Notify() will be called....
ProcessStatus_t GetPreviousState() const
get previous state
bool isIdle() const
check wether current process status is QIdle_s
void EnableInformServer(bool enabled)
static QProcessStatus & GetInstance()
get singleton Instance
void AddToQueue(ProcessStatus_t state)
add state to process status queue.
void InformServer()
inform MsgServer about current process status
bool Ignore(int signalId)
ignore signal
bool isRunning() const
check wether current process status is QRunning_s
std::deque< ProcessStatus_t > fStatusQueue
ProcessStatus_t GetState() const
get current state
void HandleSignal(int signalId)
this method is called each time a registered signal is caught. It updates the status queue and inform...
void Associate(int signalId, ProcessStatus_t pStatus)
associate a signal to a given process status
bool isReady() const
check wether current process status is QReady_s
void SetState(ProcessStatus_t state)
change current process status bypassing status queue vector
ProcessStatus_t fPreviousState
previous process status
void Disable(int signalId)
disable handling of a signal (use defauls system handler)
bool isExiting() const
check wether current process status is QExiting_s