Diana Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
QProcessStatus Class Reference

process status and signal handler More...

Inheritance diagram for QProcessStatus:
QNamed QId

Public Member Functions

virtual ~QProcessStatus ()
 dtor More...
 
void Associate (int signalId, ProcessStatus_t pStatus)
 associate a signal to a given process status More...
 
void Disable (int signalId)
 disable handling of a signal (use defauls system handler) More...
 
bool Ignore (int signalId)
 ignore signal More...
 
bool HasChanged () const
 tell wehter process status has changed More...
 
ProcessStatus_t GetState () const
 get current state More...
 
ProcessStatus_t GetPreviousState () const
 get previous state More...
 
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 More...
 
void SetState (ProcessStatus_t state)
 change current process status bypassing status queue vector More...
 
void Notify ()
 acknowledge oldest process status contained in staus queue More...
 
bool isRunning () const
 check wether current process status is QRunning_s More...
 
bool isPaused () const
 check wether current process status is QPaused_s More...
 
bool isIdle () const
 check wether current process status is QIdle_s More...
 
bool isReady () const
 check wether current process status is QReady_s More...
 
bool isExiting () const
 check wether current process status is QExiting_s More...
 
bool isWaiting () const
 check wether current process status is QWaiting_s More...
 
const std::string & GetError () const
 get error string More...
 
void SetError (const std::string &errMsg)
 set error string More...
 
bool isError () const
 check wether an error occurred More...
 
bool TrgCtrlEnabled () const
 check wether trigger control signals are enabled More...
 
void SetTrgCtrlEnabled (bool enabled)
 enable or disable trigger status control More...
 
void InformServer ()
 inform MsgServer about current process status More...
 
void SetName (const std::string &name)
 set process name that will be used for communication with message logger server More...
 
void EnableInformServer (bool enabled)
 
- Public Member Functions inherited from QNamed
 QNamed ()
 
 QNamed (const std::string &Name)
 
virtual ~QNamed ()
 
const std::string & GetName () const
 
void SetName (const std::string &name)
 

Static Public Member Functions

static QProcessStatusGetInstance ()
 get singleton Instance More...
 

Private Member Functions

 QProcessStatus ()
 ctor More...
 
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. More...
 
void AddToQueue (ProcessStatus_t state)
 add state to process status queue. More...
 
ProcessStatus_t GetLastStatus () const
 get last status that have been added to status queue. If queue is empty current process status is returned. More...
 
- Private Member Functions inherited from QId
 QId ()
 
 QId (int id)
 
virtual ~QId ()
 
void SetId (int id)
 
int GetId () const
 

Private Attributes

ProcessStatus_t fState
 current process status More...
 
ProcessStatus_t fPreviousState
 previous process status More...
 
bool fTrgCtrl
 
bool fInformEnabled
 
const size_t kMaxQueued
 
std::deque< ProcessStatus_tfStatusQueue
 
std::string fError
 error string More...
 
std::map< int, ProcessStatus_tfSigMap
 

Friends

void SigHandler (int)
 signal handler function More...
 

Detailed Description

process status and signal handler

Author
Marco Pallavicini
sergi.nosp@m.o.di.nosp@m.domiz.nosp@m.io@g.nosp@m.e.inf.nosp@m.n.it

Each signal can be associated to a value of ProcessStatus_t. More than one signal can be associated to the same process status.
By default no signal is handled.
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.
The behavior for SIGFPE and SIGSEGV is different from that of other signals: if the handling of these signals is enabled, they are automatically associated to QError_s state. Moreover these signals cannot be ignored.

Definition at line 31 of file QProcessStatus.hh.

Constructor & Destructor Documentation

◆ ~QProcessStatus()

virtual QProcessStatus::~QProcessStatus ( )
inlinevirtual

dtor

Definition at line 38 of file QProcessStatus.hh.

◆ QProcessStatus()

QProcessStatus::QProcessStatus ( )
private

ctor

Definition at line 20 of file QProcessStatus.cc.

References fSigMap, and fStatusQueue.

Member Function Documentation

◆ AddToQueue()

void QProcessStatus::AddToQueue ( ProcessStatus_t  state)
private

add state to process status queue.

Parameters
statestatus 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.

Definition at line 258 of file QProcessStatus.cc.

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

Referenced by HandleSignal(), and SigHandler().

◆ Associate()

void QProcessStatus::Associate ( int  signalId,
ProcessStatus_t  pStatus 
)

associate a signal to a given process status

If signalId is SIGSEGV or SIGFPE, pStatus is ignored, and signal is associated to QError_s

Definition at line 57 of file QProcessStatus.cc.

References fSigMap, QError_s, and SigHandler.

Referenced by main().

◆ Disable()

void QProcessStatus::Disable ( int  signalId)

disable handling of a signal (use defauls system handler)

Definition at line 37 of file QProcessStatus.cc.

References fSigMap.

◆ EnableInformServer()

void QProcessStatus::EnableInformServer ( bool  enabled)
inline

Definition at line 117 of file QProcessStatus.hh.

References fInformEnabled.

◆ GetError()

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

get error string

Definition at line 91 of file QProcessStatus.hh.

References fError.

Referenced by QSequence::Run().

◆ GetInstance()

QProcessStatus & QProcessStatus::GetInstance ( )
static

get singleton Instance

Definition at line 12 of file QProcessStatus.cc.

Referenced by main(), QFrameWork::Run(), and QSequence::Run().

◆ GetLastStatus()

ProcessStatus_t QProcessStatus::GetLastStatus ( ) const
private

get last status that have been added to status queue. If queue is empty current process status is returned.

Definition at line 278 of file QProcessStatus.cc.

References fState, and fStatusQueue.

Referenced by AddToQueue(), and HandleSignal().

◆ GetNextState()

ProcessStatus_t QProcessStatus::GetNextState ( ) const
inline

get the status the process will go into the next time that Notify() will be called. Returns current state if hasChanged() returns false

Definition at line 64 of file QProcessStatus.hh.

References fState, fStatusQueue, and HasChanged().

◆ GetPreviousState()

ProcessStatus_t QProcessStatus::GetPreviousState ( ) const
inline

get previous state

Definition at line 57 of file QProcessStatus.hh.

References fPreviousState.

◆ GetState()

ProcessStatus_t QProcessStatus::GetState ( ) const
inline

get current state

Definition at line 55 of file QProcessStatus.hh.

References fState.

◆ HandleSignal()

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
signalIdsystem 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.

Definition at line 68 of file QProcessStatus.cc.

References AddToQueue(), fSigMap, fStatusQueue, GetLastStatus(), InformServer(), QAskStatus_s, QError_s, QExiting_s, QIdle_s, QPaused_s, QReady_s, QRunning_s, QStopped_s, QWaiting_s, and SetError().

◆ HasChanged()

bool QProcessStatus::HasChanged ( ) const
inline

tell wehter process status has changed

Definition at line 53 of file QProcessStatus.hh.

References fStatusQueue.

Referenced by GetNextState(), QFrameWork::Run(), and QSequence::Run().

◆ Ignore()

bool QProcessStatus::Ignore ( int  signalId)

ignore signal

Definition at line 45 of file QProcessStatus.cc.

References fSigMap, and QIgnore_s.

◆ InformServer()

void QProcessStatus::InformServer ( )

inform MsgServer 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.

Definition at line 213 of file QProcessStatus.cc.

References err, fInformEnabled, and QERR_SUCCESS.

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

◆ isError()

bool QProcessStatus::isError ( ) const
inline

check wether an error occurred

Definition at line 95 of file QProcessStatus.hh.

References fError.

Referenced by QSequence::Run().

◆ isExiting()

bool QProcessStatus::isExiting ( ) const
inline

check wether current process status is QExiting_s

Definition at line 86 of file QProcessStatus.hh.

References fState, and QExiting_s.

Referenced by QSequence::Run().

◆ isIdle()

bool QProcessStatus::isIdle ( ) const
inline

check wether current process status is QIdle_s

Definition at line 82 of file QProcessStatus.hh.

References fState, and QIdle_s.

◆ isPaused()

bool QProcessStatus::isPaused ( ) const
inline

check wether current process status is QPaused_s

Definition at line 80 of file QProcessStatus.hh.

References fState, and QPaused_s.

◆ isReady()

bool QProcessStatus::isReady ( ) const
inline

check wether current process status is QReady_s

Definition at line 84 of file QProcessStatus.hh.

References fState, and QReady_s.

◆ isRunning()

bool QProcessStatus::isRunning ( ) const
inline

check wether current process status is QRunning_s

Definition at line 78 of file QProcessStatus.hh.

References fState, and QRunning_s.

Referenced by QFrameWork::Run(), and QSequence::Run().

◆ isWaiting()

bool QProcessStatus::isWaiting ( ) const
inline

check wether current process status is QWaiting_s

Definition at line 88 of file QProcessStatus.hh.

References fState, and QWaiting_s.

◆ Notify()

void QProcessStatus::Notify ( )

acknowledge oldest process status contained in staus queue

Definition at line 243 of file QProcessStatus.cc.

References fPreviousState, fState, fStatusQueue, and InformServer().

Referenced by QFrameWork::Run(), and QSequence::Run().

◆ SetError()

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

set error string

Definition at line 93 of file QProcessStatus.hh.

References fError.

Referenced by HandleSignal(), and SigHandler().

◆ SetName()

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

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

Parameters
nameprocess name

Definition at line 115 of file QProcessStatus.hh.

References QNamed::SetName().

◆ SetState()

void QProcessStatus::SetState ( ProcessStatus_t  state)

change current process status bypassing status queue vector

Parameters
statenew process status

Previous state is updated, status queue is flushed and InformServer() is called

Definition at line 227 of file QProcessStatus.cc.

References ProcessStatus_t::AsString(), fPreviousState, fState, fStatusQueue, and InformServer().

Referenced by main().

◆ SetTrgCtrlEnabled()

void QProcessStatus::SetTrgCtrlEnabled ( bool  enabled)
inline

enable or disable trigger status control

Definition at line 100 of file QProcessStatus.hh.

References fTrgCtrl.

◆ TrgCtrlEnabled()

bool QProcessStatus::TrgCtrlEnabled ( ) const
inline

check wether trigger control signals are enabled

Definition at line 98 of file QProcessStatus.hh.

References fTrgCtrl.

Friends And Related Function Documentation

◆ SigHandler

void SigHandler ( int  )
friend

signal handler function

Parameters
signalIdsignal to be handled

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

Definition at line 287 of file QProcessStatus.cc.

Referenced by Associate().

Member Data Documentation

◆ fError

std::string QProcessStatus::fError
private

error string

Definition at line 135 of file QProcessStatus.hh.

Referenced by GetError(), isError(), and SetError().

◆ fInformEnabled

bool QProcessStatus::fInformEnabled
private

wether to inform server about state changes

Definition at line 129 of file QProcessStatus.hh.

Referenced by EnableInformServer(), and InformServer().

◆ fPreviousState

ProcessStatus_t QProcessStatus::fPreviousState
private

previous process status

Definition at line 125 of file QProcessStatus.hh.

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

◆ fSigMap

std::map<int,ProcessStatus_t> QProcessStatus::fSigMap
private

key: system signal

Definition at line 137 of file QProcessStatus.hh.

Referenced by Associate(), Disable(), HandleSignal(), Ignore(), and QProcessStatus().

◆ fState

ProcessStatus_t QProcessStatus::fState
private

current process status

Definition at line 123 of file QProcessStatus.hh.

Referenced by GetLastStatus(), GetNextState(), GetState(), isExiting(), isIdle(), isPaused(), isReady(), isRunning(), isWaiting(), Notify(), and SetState().

◆ fStatusQueue

std::deque<ProcessStatus_t> QProcessStatus::fStatusQueue
private

contains stauts evolution for current process

Definition at line 133 of file QProcessStatus.hh.

Referenced by AddToQueue(), GetLastStatus(), GetNextState(), HandleSignal(), HasChanged(), Notify(), QProcessStatus(), and SetState().

◆ fTrgCtrl

bool QProcessStatus::fTrgCtrl
private

wether trigger control signals are enabled

Definition at line 127 of file QProcessStatus.hh.

Referenced by SetTrgCtrlEnabled(), and TrgCtrlEnabled().

◆ kMaxQueued

const size_t QProcessStatus::kMaxQueued
private

max number of not-notified process states

Definition at line 131 of file QProcessStatus.hh.

Referenced by AddToQueue().


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