Gaudi Framework, version v23r10

Home   Generated: Mon Sep 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Gaudi::Utils::StopSignalHandler Class Reference

Service that stop the processing if a signal is received. More...

Inheritance diagram for Gaudi::Utils::StopSignalHandler:
Inheritance graph
[legend]
Collaboration diagram for Gaudi::Utils::StopSignalHandler:
Collaboration graph
[legend]

Public Member Functions

 StopSignalHandler (const std::string &name, ISvcLocator *svcLoc)
 
StatusCode initialize ()
 
StatusCode finalize ()
 
virtual void handle (const Incident &)
 Inform that a new incident has occurred.
 
- Public Member Functions inherited from extends1< Service, IIncidentListener >
 extends1 (A1 a1, A2 a2, A3 a3)
 Templated constructor with 3 arguments.
 
 extends1 (A1 a1, A2 a2)
 Templated constructor with 2 arguments.
 
 extends1 (A1 a1)
 Templated constructor with 1 argument.
 
 extends1 ()
 Default constructor.
 
virtual void * i_cast (const InterfaceID &tid) const
 Implementation of IInterface::i_cast.
 
virtual StatusCode queryInterface (const InterfaceID &ti, void **pp)
 Implementation of IInterface::queryInterface.
 
virtual std::vector< std::stringgetInterfaceNames () const
 Implementation of IInterface::getInterfaceNames.
 
virtual ~extends1 ()
 Virtual destructor.
 
- Public Member Functions inherited from Service
virtual unsigned long release ()
 Release Interface instance.
 
virtual const std::stringname () const
 Retrieve name of the service.
 
virtual StatusCode configure ()
 
virtual StatusCode start ()
 
virtual StatusCode stop ()
 
virtual StatusCode terminate ()
 
virtual Gaudi::StateMachine::State FSMState () const
 
virtual Gaudi::StateMachine::State targetFSMState () const
 
virtual StatusCode reinitialize ()
 
virtual StatusCode restart ()
 
virtual StatusCode sysInitialize ()
 Initialize Service.
 
virtual StatusCode sysStart ()
 Initialize Service.
 
virtual StatusCode sysStop ()
 Initialize Service.
 
virtual StatusCode sysFinalize ()
 Finalize Service.
 
virtual StatusCode sysReinitialize ()
 Re-initialize the Service.
 
virtual StatusCode sysRestart ()
 Re-initialize the Service.
 
virtual StatusCode setProperty (const Property &p)
 
virtual StatusCode setProperty (const std::string &s)
 
virtual StatusCode setProperty (const std::string &n, const std::string &v)
 
virtual StatusCode getProperty (Property *p) const
 
virtual const PropertygetProperty (const std::string &name) const
 
virtual StatusCode getProperty (const std::string &n, std::string &v) const
 
virtual const std::vector
< Property * > & 
getProperties () const
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 
 Service (const std::string &name, ISvcLocator *svcloc)
 Standard Constructor.
 
SmartIF< ISvcLocator > & serviceLocator () const
 Retrieve pointer to service locator.
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job.
 
template<class T >
StatusCode service (const std::string &name, const T *&psvc, bool createIf=true) const
 Access a service by name, creating it if it doesn't already exist.
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist.
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property.
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties.
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
 
- Public Member Functions inherited from CommonMessaging< implements3< IService, IProperty, IStateful > >
 CommonMessaging (const A1 &a1, const A2 &a2, const A3 &a3)
 Templated constructor with 3 arguments.
 
 CommonMessaging (const A1 &a1, const A2 &a2)
 Templated constructor with 2 arguments.
 
 CommonMessaging (const A1 &a1)
 Templated constructor with 1 argument.
 
 CommonMessaging ()
 Default constructor.
 
virtual ~CommonMessaging ()
 Virtual destructor.
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream.
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS)
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL)
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR)
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING)
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO)
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG)
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO)
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream
 
- Public Member Functions inherited from extend_interfaces1< IIncidentListener >
virtual ~extend_interfaces1 ()
 Virtual destructor.
 
- Public Member Functions inherited from IIncidentListener
 DeclareInterfaceID (IIncidentListener, 2, 0)
 InterfaceID.
 
- Public Member Functions inherited from IInterface
virtual unsigned long addRef ()=0
 Increment the reference count of Interface instance.
 
virtual unsigned long release ()=0
 Release Interface instance.
 
virtual unsigned long refCount () const =0
 Current reference count.
 
virtual ~IInterface ()
 Virtual destructor.
 

Private Member Functions

std::pair< int, bool > i_decodeSignal (const std::string &sig)
 Function to translate the signal name to the signal number.
 

Private Attributes

std::vector< std::stringm_usedSignals
 List of signal names or numbers (encoded as strings) to use to schedule a stop.
 
std::map< int, bool > m_signals
 Map of monitored signal numbers to the flag telling if they have to be propagated or not.
 
bool m_stopRequested
 Flag to remember if the stop has been requested because of a signal.
 
SmartIF< Gaudi::ISignalMonitorm_signalMonitor
 Pointer to the signal monitor service.
 
SmartIF< IIncidentSvcm_incidentSvc
 Pointer to the incident service.
 
SmartIF< IPropertym_appProperty
 Pointer to the interface to set the return code of the application.
 

Additional Inherited Members

- Public Types inherited from extends1< Service, IIncidentListener >
typedef extends1 base_class
 Typedef to this class.
 
typedef extend_interfaces1
< IIncidentListener
extend_interfaces_base
 Typedef to the base of this class.
 
typedef
extend_interfaces_base::ext_iids 
interfaces
 MPL set of all the implemented interfaces.
 
- Static Public Member Functions inherited from IInterface
static const InterfaceIDinterfaceID ()
 Return an instance of InterfaceID identifying the interface.
 
- Protected Member Functions inherited from Service
virtual ~Service ()
 Standard Destructor.
 
int outputLevel () const
 get the Service's output level
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel
 Service output level.
 
Gaudi::StateMachine::State m_state
 Service state.
 
Gaudi::StateMachine::State m_targetState
 Service state.
 

Detailed Description

Service that stop the processing if a signal is received.

The signals to be intercepted have to be declared in the property Signals as a list of strings (signal names or numbers). If '+' is appended to the signal name, then the signal is propagated to the signal handlers already registered when this service is initialized.

Definition at line 345 of file SignalMonitorSvc.cpp.

Constructor & Destructor Documentation

Gaudi::Utils::StopSignalHandler::StopSignalHandler ( const std::string name,
ISvcLocator svcLoc 
)
inline

Definition at line 347 of file SignalMonitorSvc.cpp.

: base_class(name, svcLoc) {
m_stopRequested = false;
declareProperty("Signals", m_usedSignals,
"List of signal names or numbers to use to schedule a stop. "
"If the signal is followed by a '+' the signal is propagated the previously "
"registered handler (if any).");
}

Member Function Documentation

StatusCode Gaudi::Utils::StopSignalHandler::finalize ( )
inlinevirtual

Reimplemented from Service.

Definition at line 405 of file SignalMonitorSvc.cpp.

{
m_incidentSvc->removeListener(this, IncidentType::BeginEvent);
// disable the monitoring of the signals
s != m_signals.end(); ++s) {
// tell the signal monitor that we are interested in these signals
m_signalMonitor->ignoreSignal(s->first);
}
}
virtual void Gaudi::Utils::StopSignalHandler::handle ( const Incident )
inlinevirtual

Inform that a new incident has occurred.

Implements IIncidentListener.

Definition at line 418 of file SignalMonitorSvc.cpp.

{
if (!m_stopRequested) {
const SigMap& sigmap(SigMap::instance());
s != m_signals.end(); ++s) {
if (m_signalMonitor->gotSignal(s->first)) {
warning() << "Received signal '" << sigmap.name(s->first)
<< "' (" << s->first;
const std::string &desc = sigmap.desc(s->first);
if ( ! desc.empty() ) {
warning() << ", " << desc;
}
warning() << ")" << endmsg;
// Report the termination by signal at the end of the application
if (Gaudi::setAppReturnCode(m_appProperty, SignalOffset + s->first).isFailure()) {
error() << "Could not set return code of the application ("
<< SignalOffset + s->first << ")"
<< endmsg;
}
}
}
if (m_stopRequested) {
if (ep) {
warning() << "Scheduling a stop" << endmsg;
ep->stopRun().ignore();
}
else {
warning() << "Cannot stop the processing because the IEventProcessor interface cannot be retrieved." << endmsg;
}
}
}
}
std::pair<int, bool> Gaudi::Utils::StopSignalHandler::i_decodeSignal ( const std::string sig)
inlineprivate

Function to translate the signal name to the signal number.

Definition at line 467 of file SignalMonitorSvc.cpp.

{
debug() << "Decoding signal declaration '" << sig << "'" << endmsg;
if ( sig.empty() || sig == "+" ) {
debug() << "Empty signal, ignored" << endmsg;
return std::make_pair<int, bool>(-1, false); // silently ignore empty strings
}
const SigMap& sigmap(SigMap::instance());
std::string signal = sig;
bool propagate = false;
// Check if the signal must be propagated
if (signal[signal.size() - 1] == '+') {
debug() << "Must be propagated to previously registered signal handlers" << endmsg;
propagate = true;
signal.erase(signal.size() - 1, 1); // remove the '+' at the end of the string
}
int signum = -1;
// check if the signal is a number
if (std::isdigit(signal[0])){
std::istringstream ss(signal);
ss >> signum;
} else {
// try to find the signal name in the list of known signals
signum = sigmap.signum(signal);
}
if (signum < 0) {
warning() << "Cannot understand signal identifier '" << sig << "', ignored" << endmsg;
} else {
verbose() << "Matched signal '" << sigmap.name(signum)
<< "' (" << signum;
const std::string &desc = sigmap.desc(signum);
if ( ! desc.empty() ) {
verbose() << ", " << desc;
}
verbose() << ")" << endmsg;
}
return std::make_pair(signum, propagate);
}
StatusCode Gaudi::Utils::StopSignalHandler::initialize ( )
inlinevirtual

Reimplemented from Service.

Definition at line 357 of file SignalMonitorSvc.cpp.

{
if (sc.isFailure()) {
return sc;
}
std::string serviceName("Gaudi::Utils::SignalMonitorSvc");
m_signalMonitor = serviceLocator()->service(serviceName);
if ( ! m_signalMonitor ) {
error() << "Cannot retrieve " << serviceName << endmsg;
}
serviceName = "IncidentSvc";
m_incidentSvc = serviceLocator()->service(serviceName);
if ( ! m_incidentSvc ) {
error() << "Cannot retrieve " << serviceName << endmsg;
}
// Get the IMainAppStatus interface of the ApplicationMgr
if ( ! m_appProperty ) {
warning() << "Cannot retrieve IProperty interface of ApplicationMgr, "
"the return code will not be changed" << endmsg;
}
// Decode the signal names
signame != m_usedSignals.end(); ++signame) {
sigid = i_decodeSignal(*signame);
if (sigid.first >= 0) {
m_signals[sigid.first] = sigid.second;
}
}
debug() << "Stopping on the signals:" << endmsg;
const SigMap& sigmap(SigMap::instance());
s != m_signals.end(); ++s) {
debug() << "\t" << sigmap.name(s->first) << ": "
<< sigmap.desc(s->first) << " (" << s->first << ")";
if (s->second) debug() << " propagated";
debug() << endmsg;
// tell the signal monitor that we are interested in these signals
m_signalMonitor->monitorSignal(s->first, s->second);
}
m_stopRequested = false;
debug() << "Register to the IncidentSvc" << endmsg;
}

Member Data Documentation

SmartIF<IProperty> Gaudi::Utils::StopSignalHandler::m_appProperty
private

Pointer to the interface to set the return code of the application.

Definition at line 465 of file SignalMonitorSvc.cpp.

SmartIF<IIncidentSvc> Gaudi::Utils::StopSignalHandler::m_incidentSvc
private

Pointer to the incident service.

Definition at line 463 of file SignalMonitorSvc.cpp.

SmartIF<Gaudi::ISignalMonitor> Gaudi::Utils::StopSignalHandler::m_signalMonitor
private

Pointer to the signal monitor service.

Definition at line 461 of file SignalMonitorSvc.cpp.

std::map<int, bool> Gaudi::Utils::StopSignalHandler::m_signals
private

Map of monitored signal numbers to the flag telling if they have to be propagated or not.

Definition at line 457 of file SignalMonitorSvc.cpp.

bool Gaudi::Utils::StopSignalHandler::m_stopRequested
private

Flag to remember if the stop has been requested because of a signal.

Definition at line 459 of file SignalMonitorSvc.cpp.

std::vector<std::string> Gaudi::Utils::StopSignalHandler::m_usedSignals
private

List of signal names or numbers (encoded as strings) to use to schedule a stop.

Definition at line 455 of file SignalMonitorSvc.cpp.


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

Generated at Mon Sep 30 2013 14:52:07 for Gaudi Framework, version v23r10 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004