QProcessStatus Class Reference

Inheritance diagram for QProcessStatus:

List of all members.


Detailed Description

apollo process status and signal handler

Author:
Marco Pallavicini

sergio.didomizio@ge.infn.it update process status according to received signal

Handled signals are: SIGINT, SIGABRT, SIGFPE, SIGSEGV, SIGTERM, SIGUSR1, SIGUSR2, SIGTTIN, SIGTTOU. Each signal can be associated to a value of QDaqCommonDefs::ProcessStatus_t. More than one signal can be associated to the same process status. Several signals are enabled by default and serveral are not. Moreover, the association between a signal and the corresponding QDaqCommonDefs::ProcessStatus_t is not modifiable for all signals, as for the enabled/disabled state, which can be toggled only for several signals. When a signal is not enabled, the default signal handler is called. In order for a signal to be ignored, the Ignore() method must be called with the signal as argument. All signals that can be disabled can be also ignored. Follows a detailed list of the possibilities the user has to control each signal:

Public Member Functions

virtual ~QProcessStatus ()
 dtor
bool Associate (int signalId, QDaqCommonDefs::ProcessStatus_t pStatus)
 associate a signal to a given process status
bool Enable (int signalId)
 associate signal to cuore signal handler
bool Disable (int signalId)
 enable handling of a signal
bool Ignore (int signalId)
 ignore signal
bool HasChanged () const
 tell wehter process status has changed
volatile
QDaqCommonDefs::ProcessStatus_t 
GetState () const
 get current state
volatile
QDaqCommonDefs::ProcessStatus_t 
GetPreviousState () const
 get previous state
volatile
QDaqCommonDefs::ProcessStatus_t 
GetNextState () const
 get the status the process will go into the next time that Notify() will be called. Returns current state if hasChanged() returns false
void SetState (QDaqCommonDefs::ProcessStatus_t state)
 change current process status bypassing status queue vector
void Notify ()
 acknowledge oldest process status contained in staus queue vector
volatile bool isRunning () const
 check wether current process status is QRunning_s
volatile bool isPaused () const
 check wether current process status is QPaused_s
volatile bool isIdle () const
 check wether current process status is QIdle_s
volatile bool isReady () const
 check wether current process status is QReady_s
volatile bool TrgCtrlEnabled () const
 check wether trigger control signals are enabled
const std::string & GetError () const
 get error string
void SetError (const std::string &errMsg)
 set error string
bool isError () const
 check wether an error occurred
void SetTrgCtrlEnabled (bool enabled)
 enable or disable trigger status control
void InformServer ()
 inform Daq Server about current process status
void SetName (const std::string &name)
 set process name that will be used for communication with message logger server

Static Public Member Functions

static QProcessStatusGetInstance ()
 get singleton Instance

Private Member Functions

 QProcessStatus ()
 declare signal handler for handled signals, set error string to an empty string and disable by default trigger control signals
void HandleSignal (int signalId)
 this method is called each time a registered signal is caught. It updates the status queue and inform message logger if necessary.
void AssociateDefaults ()
 associate default signals to be caught
void AddToQueue (QDaqCommonDefs::ProcessStatus_t state)
 add state to process status queue.
QDaqCommonDefs::ProcessStatus_t GetLastStatus () const
 get last status that have been added to status queue. If queue is empty current process status is returned.
bool CanBeHandled (int signalId) const
 check wether requested signal can be handled
bool CanBeDisabled (int signalId) const
 check wether requested signal can be disabled

Private Attributes

QDaqCommonDefs::ProcessStatus_t fState
 current process status
QDaqCommonDefs::ProcessStatus_t fPreviousState
 previous process status
bool fTrgCtrl
 determine wether trigger control signals are enabled (default is disabled)
bool fInformEnabled
 determine wether to inform server about changes of state
const size_t kMaxQueued
 maximum number of not-notified process statuses. If process queue exceeds this size a warning is sent to stderr.
std::deque
< QDaqCommonDefs::ProcessStatus_t
fStatusQueue
 vector containing stauts evolution for current process contains all status changes that are newer than current state
std::string fError
 error string
std::map< int,
QDaqCommonDefs::ProcessStatus_t
fSigMap
 map of system signal and associated process status

Friends

void SigHandler (int)
 signal handler function

Member Function Documentation

bool QProcessStatus::Associate ( int  signalId,
QDaqCommonDefs::ProcessStatus_t  pStatus 
)

associate a signal to a given process status

Parameters:
signalId system signal to be associated to status pStatus
pStatus process status to be associated to signal signalId
Returns:
true if association succeeded, false otherwise
See the documentation at the beginning of this class to understand what signal can be associated to which status

References Enable(), and fSigMap.

bool QProcessStatus::Enable ( int  signalId  ) 

associate signal to cuore signal handler

Parameters:
signalId signal to be enabled. This signal must be already associated to a value of QDaqCommonDefs::ProcessStatus_t.
Returns:
true unless

References CanBeHandled(), fInformEnabled, and SigHandler.

Referenced by Associate(), and AssociateDefaults().

void QProcessStatus::SetState ( QDaqCommonDefs::ProcessStatus_t  state  ) 

change current process status bypassing status queue vector

Parameters:
state new process status
Previous state is updated, status queue is flushed and InformServer() is called

References fPreviousState, fState, fStatusQueue, InformServer(), and QDaqCommonDefs::ProcessStatusEnumToString().

Referenced by QNiDigitalController::HandleNiError(), QPulserGuiInterface::Start(), and QPulserGuiInterface::Stop().

volatile bool QProcessStatus::isRunning (  )  const [inline]

check wether current process status is QRunning_s

Returns:
true if current status is QRunning_s, false otherwise

References fState, and QDaqCommonDefs::QRunning_s.

Referenced by QBasePulserController::Run().

volatile bool QProcessStatus::isPaused (  )  const [inline]

check wether current process status is QPaused_s

Returns:
true if current status is QPaused_s, false otherwise

References fState, and QDaqCommonDefs::QPaused_s.

volatile bool QProcessStatus::isIdle (  )  const [inline]

check wether current process status is QIdle_s

Returns:
true if current status is QIdle_s, false otherwise

References fState, and QDaqCommonDefs::QIdle_s.

volatile bool QProcessStatus::isReady (  )  const [inline]

check wether current process status is QReady_s

Returns:
true if current status is QReady_s, false otherwise

References fState, and QDaqCommonDefs::QReady_s.

volatile bool QProcessStatus::TrgCtrlEnabled (  )  const [inline]

check wether trigger control signals are enabled

Returns:
true if trigger control signals are enabled, false otherwise

References fTrgCtrl.

Referenced by HandleSignal().

const std::string& QProcessStatus::GetError (  )  const [inline]

get error string

Returns:
error string associated to last error, or empty string if no error occurred

References fError.

void QProcessStatus::SetError ( const std::string &  errMsg  )  [inline]

set error string

Parameters:
errMsg error message

References fError.

Referenced by HandleSignal().

void QProcessStatus::SetTrgCtrlEnabled ( bool  enabled  )  [inline]

enable or disable trigger status control

Parameters:
enable if true, trigger control is enabled (default is disabled)

References fTrgCtrl.

void QProcessStatus::InformServer (  ) 

inform Daq Server about current process status

Msg Server is informed by mean of a socket client. If error string is not empty, it is sent to Daq Server together with process status Id.

References fInformEnabled, QApolloMessenger::GetInstance(), GetState(), QApolloMessenger::SendStatus(), and QApolloMessenger::SetName().

Referenced by HandleSignal(), Notify(), and SetState().

void QProcessStatus::SetName ( const std::string &  name  )  [inline]

set process name that will be used for communication with message logger server

Parameters:
name process name

void QProcessStatus::HandleSignal ( int  signalId  )  [private]

this method is called each time a registered signal is caught. It updates the status queue and inform message logger if necessary.

Parameters:
signalId system signal to be handled
Add status associated to signal signalId to process status queue. If signal is SIGSEGV or SIGFPE and process queue already contains another error, exit is forced calling exit(1). Detected signal is added to queue only if it is consistent with last status that is in queue (or with current status in case queue is empty). In case of inconistent state, an error is set by mean of SetError(). For example stop signal is not considered if process is not running.

References AddToQueue(), fSigMap, fStatusQueue, GetLastStatus(), InformServer(), QDaqCommonDefs::QAskStatus_s, QDaqCommonDefs::QError_s, QDaqCommonDefs::QExiting_s, QDaqCommonDefs::QIdle_s, QDaqCommonDefs::QPaused_s, QDaqCommonDefs::QReady_s, QDaqCommonDefs::QRunning_s, QDaqCommonDefs::QStopped_s, QDaqCommonDefs::QTriggerOff_s, QDaqCommonDefs::QTriggerOn_s, SetError(), and TrgCtrlEnabled().

Referenced by SigHandler().

void QProcessStatus::AddToQueue ( QDaqCommonDefs::ProcessStatus_t  state  )  [private]

add state to process status queue.

Parameters:
state status to be added to queue
If state is QTriggerOn_s or QTriggerOff_s, the queue is populated with 2 new elements: the requested state and then the current one. If process queue has more than kMaxQueued elements a warning is sent to stderr.

References fStatusQueue, GetLastStatus(), kMaxQueued, QDaqCommonDefs::QTriggerOff_s, and QDaqCommonDefs::QTriggerOn_s.

Referenced by HandleSignal().


Friends And Related Function Documentation

void SigHandler ( int   )  [friend]

signal handler function

Parameters:
signalId signal to be handled
When a registered system signal is detected, this function simply calls the QProcessStatus::HandleSignal() method.

Referenced by Enable().


The documentation for this class was generated from the following files:

Generated on Tue Nov 16 10:50:08 2010 for CUORE Software by  doxygen 1.5.6