The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
Gaudi::Utils::SignalMonitorSvc Class Reference

Implementation of Gaudi::ISignalMonitor. More...

Inheritance diagram for Gaudi::Utils::SignalMonitorSvc:
Collaboration diagram for Gaudi::Utils::SignalMonitorSvc:

Public Types

typedef struct sigaction handler_t
Public Types inherited from extends< Service, Gaudi::ISignalMonitor >
using base_class
 Typedef to this class.
using extend_interfaces_base
 Typedef to the base of this class.
Public Types inherited from Service
using Factory = Gaudi::PluginService::Factory<IService*( const std::string&, ISvcLocator* )>
Public Types inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
using PropertyHolderImpl
 Typedef used to refer to this class from derived classes, as in.
Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class
Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids
 take union of the ext_iids of all Interfaces...

Public Member Functions

void monitorSignal (int signum, bool propagate) override
 Declare a signal to be monitored.
void ignoreSignal (int signum) override
 Remove the specific signal handler for the requested signal, restoring the previous signal handler.
bool gotSignal (int signum) const override
 Check if the given signal has been received.
void setSignal (int signum) override
 Set the flag for the given signal, as if the signal was received.
void clearSignal (int signum) override
 Clear the flag for the given signal, so that a new occurrence can be identified.
 SignalMonitorSvc (const std::string &name, ISvcLocator *svcLoc)
 Initialize internal variables of the service and set the instance pointer.
 ~SignalMonitorSvc () override
 Stop monitoring signals and clear the instance pointer.
Public Member Functions inherited from extends< Service, Gaudi::ISignalMonitor >
void const * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast.
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface.
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames.
Public Member Functions inherited from Service
const std::string & name () const override
 Retrieve name of the service.
StatusCode configure () override
StatusCode initialize () override
StatusCode start () override
StatusCode stop () override
StatusCode finalize () override
StatusCode terminate () override
Gaudi::StateMachine::State FSMState () const override
Gaudi::StateMachine::State targetFSMState () const override
StatusCode reinitialize () override
StatusCode restart () override
StatusCode sysInitialize () override
 Initialize Service.
StatusCode sysStart () override
 Initialize Service.
StatusCode sysStop () override
 Initialize Service.
StatusCode sysFinalize () override
 Finalize Service.
StatusCode sysReinitialize () override
 Re-initialize the Service.
StatusCode sysRestart () override
 Re-initialize the Service.
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor.
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator.
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
template<class T>
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, ToolHandle< T > &hndl, const std::string &doc="none")
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, bool createIf=true)
template<class T>
StatusCode declareTool (ToolHandle< T > &handle, const std::string &toolTypeAndName, bool createIf=true)
 Declare used tool.
template<class T>
Gaudi::Details::PropertyBase * declareProperty (const std::string &name, ToolHandleArray< T > &hndlArr, const std::string &doc="none")
template<class T>
void addToolsArray (ToolHandleArray< T > &hndlArr)
const std::vector< IAlgTool * > & tools () const
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked.
Public Member Functions inherited from PropertyHolder< CommonMessaging< implements< IService, IProperty, IStateful > > >
StatusCode setProperty (const Gaudi::Details::PropertyBase &p)
 Set the property from a property.
StatusCode setProperty (const std::string &name, const char *v)
 Special case for string literals.
StatusCode setProperty (const std::string &name, const std::string &v)
 Special case for std::string.
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value
 PropertyHolder ()=default
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Details::PropertyBase &prop)
 Declare a property.
Gaudi::Details::PropertyBase * declareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="")
 Declare a remote property.
StatusCode setPropertyRepr (const std::string &n, const std::string &r) override
 set the property from name and value string representation
StatusCode getProperty (Gaudi::Details::PropertyBase *p) const override
 get the property
const std::vector< Gaudi::Details::PropertyBase * > & getProperties () const override
 get all properties
bool hasProperty (std::string_view name) const override
 Return true if we have a property with the given name.
Gaudi::Details::PropertyBase * property (std::string_view name) const
 \fixme property and bindPropertiesTo should be protected
void bindPropertiesTo (Gaudi::Interfaces::IOptionsSvc &optsSvc)
PropertyHolder & operator= (const PropertyHolder &)=delete
Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor.
const SmartIF< IMessageSvc > & msgSvc () const
 The standard message service.
MsgStream & msgStream () const
 Return an uninitialized MsgStream.
MsgStream & msgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts.
MsgStream & always () const
 shortcut for the method msgStream(MSG::ALWAYS)
MsgStream & fatal () const
 shortcut for the method msgStream(MSG::FATAL)
MsgStream & err () const
 shortcut for the method msgStream(MSG::ERROR)
MsgStream & error () const
 shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning () const
 shortcut for the method msgStream(MSG::WARNING)
MsgStream & info () const
 shortcut for the method msgStream(MSG::INFO)
MsgStream & debug () const
 shortcut for the method msgStream(MSG::DEBUG)
MsgStream & verbose () const
 shortcut for the method msgStream(MSG::VERBOSE)
MsgStream & msg () const
 shortcut for the method msgStream(MSG::INFO)
MSG::Level msgLevel () const
 get the cached level (originally extracted from the embedded MsgStream)
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream

Private Types

enum  MonitoringMode { ignored , trap , propagate }
 Possible monitoring modes. More...

Private Member Functions

void i_handle (int signum)

Static Private Member Functions

static void setInstance (SignalMonitorSvc *i)
static SignalMonitorSvc * instance ()
 Method to get the singleton instance.
static void dispatcher (int signum)
 Signal handler function.

Private Attributes

MonitoringMode m_monitored [NSIG]
 Array of flags to keep track of monitored signals.
sig_atomic_t m_caught [NSIG]
 Array of flags for received signals.
handler_t m_defaultAction
 Helper variable for default signal action.
handler_t m_oldActions [NSIG]
 List of replaced signal actions (for the recovery when disable the monitoring).

Static Private Attributes

static SignalMonitorSvc * s_instance = nullptr
 Pointer to the current instance.

Additional Inherited Members

Protected Member Functions inherited from Service
std::vector< IAlgTool * > & tools ()
 ~Service () override
int outputLevel () const
 get the Service's output level
Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
MSG::Level setUpMessaging () const override final
 Set up local caches.
MSG::Level resetMessaging ()
 Reinitialize internal states.
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream.
Protected Attributes inherited from Service
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state.
Gaudi::Property< int > m_outputLevel { this, "OutputLevel", MSG::NIL, "output level" }
 flag indicating whether ToolHandle tools have been added to m_tools
Gaudi::Property< bool > m_auditorInitialize { this, "AuditInitialize", false, "trigger auditor on initialize()" }
Gaudi::Property< bool > m_auditorStart { this, "AuditStart", false, "trigger auditor on start()" }
Gaudi::Property< bool > m_auditorStop { this, "AuditStop", false, "trigger auditor on stop()" }
Gaudi::Property< bool > m_auditorFinalize { this, "AuditFinalize", false, "trigger auditor on finalize()" }
Gaudi::Property< bool > m_auditorReinitialize { this, "AuditReinitialize", false, "trigger auditor on reinitialize()" }
Gaudi::Property< bool > m_auditorRestart { this, "AuditRestart", false, "trigger auditor on restart()" }
Gaudi::Property< bool > m_autoRetrieveTools
Gaudi::Property< bool > m_checkToolDeps
SmartIF< IAuditorSvc > m_pAuditorSvc
 Auditor Service.

Detailed Description

Implementation of Gaudi::ISignalMonitor.

If instantiated, intercepts the system signals and keep track of the recorded ones.

The signal to be monitored have to be declared via the method monitorSignal(). It can be interrogated to check if a signal has been received.

Definition at line 36 of file SignalMonitorSvc.cpp.

Member Typedef Documentation

◆ handler_t

Definition at line 38 of file SignalMonitorSvc.cpp.

Member Enumeration Documentation

◆ MonitoringMode

Possible monitoring modes.

Enumerator
ignored 
trap 
propagate 

Definition at line 96 of file SignalMonitorSvc.cpp.

96 {
97 ignored, //< the signal is not monitored
98 trap, //< the signal is monitored and not propagated to previously registered handlers
99 propagate //< the signal is monitored and propagated to previously registered handlers
100 };

Constructor & Destructor Documentation

◆ SignalMonitorSvc()

Gaudi::Utils::SignalMonitorSvc::SignalMonitorSvc ( const std::string & name,
ISvcLocator * svcLoc )
inline

Initialize internal variables of the service and set the instance pointer.

Definition at line 75 of file SignalMonitorSvc.cpp.

75 : base_class( name, svcLoc ) {
76 m_defaultAction.sa_handler = SIG_DFL;
77 sigemptyset( &m_defaultAction.sa_mask );
78 m_defaultAction.sa_flags = 0;
79 for ( int i = 0; i < NSIG; ++i ) {
80 m_caught[i] = 0;
83 }
84
85 setInstance( this );
86 }
handler_t m_defaultAction
Helper variable for default signal action.
sig_atomic_t m_caught[NSIG]
Array of flags for received signals.
static void setInstance(SignalMonitorSvc *i)
MonitoringMode m_monitored[NSIG]
Array of flags to keep track of monitored signals.
handler_t m_oldActions[NSIG]
List of replaced signal actions (for the recovery when disable the monitoring).
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333

◆ ~SignalMonitorSvc()

Gaudi::Utils::SignalMonitorSvc::~SignalMonitorSvc ( )
inlineoverride

Stop monitoring signals and clear the instance pointer.

Definition at line 89 of file SignalMonitorSvc.cpp.

89 {
90 for ( int i = 0; i < NSIG; ++i ) ignoreSignal( i );
91 setInstance( nullptr );
92 }
void ignoreSignal(int signum) override
Remove the specific signal handler for the requested signal, restoring the previous signal handler.

Member Function Documentation

◆ clearSignal()

void Gaudi::Utils::SignalMonitorSvc::clearSignal ( int signum)
inlineoverride

Clear the flag for the given signal, so that a new occurrence can be identified.

Definition at line 72 of file SignalMonitorSvc.cpp.

72{ m_caught[signum] = 0; }

◆ dispatcher()

void Gaudi::Utils::SignalMonitorSvc::dispatcher ( int signum)
staticprivate

Signal handler function.

Definition at line 131 of file SignalMonitorSvc.cpp.

131 {
132 if ( instance() ) instance()->i_handle( signum );
133 }
static SignalMonitorSvc * instance()
Method to get the singleton instance.

◆ gotSignal()

bool Gaudi::Utils::SignalMonitorSvc::gotSignal ( int signum) const
inlineoverride

Check if the given signal has been received.

Definition at line 66 of file SignalMonitorSvc.cpp.

66{ return m_caught[signum] != 0; }

◆ i_handle()

void Gaudi::Utils::SignalMonitorSvc::i_handle ( int signum)
inlineprivate

Definition at line 110 of file SignalMonitorSvc.cpp.

110 {
111 m_caught[signum] = 1;
112 if ( m_monitored[signum] == propagate && m_oldActions[signum].sa_handler != SIG_DFL ) {
113 m_oldActions[signum].sa_handler( signum );
114 }
115 }

◆ ignoreSignal()

void Gaudi::Utils::SignalMonitorSvc::ignoreSignal ( int signum)
inlineoverride

Remove the specific signal handler for the requested signal, restoring the previous signal handler.

Definition at line 57 of file SignalMonitorSvc.cpp.

57 {
58 if ( m_monitored[signum] ) {
59 sigaction( signum, &m_oldActions[signum], nullptr );
61 m_monitored[signum] = ignored;
62 }
63 }

◆ instance()

SignalMonitorSvc * Gaudi::Utils::SignalMonitorSvc::instance ( )
inlinestaticprivate

Method to get the singleton instance.

Bypass the serviceLocator for efficiency.

Definition at line 124 of file SignalMonitorSvc.cpp.

124{ return s_instance; }
static SignalMonitorSvc * s_instance
Pointer to the current instance.

◆ monitorSignal()

void Gaudi::Utils::SignalMonitorSvc::monitorSignal ( int signum,
bool propagate )
inlineoverride

Declare a signal to be monitored.

It installs a signal handler for the requested signal.

Definition at line 42 of file SignalMonitorSvc.cpp.

42 {
43 if ( !m_monitored[signum] ) {
44 handler_t sa;
45 handler_t oldact;
46 sa.sa_handler = SignalMonitorSvc::dispatcher;
47 sigemptyset( &sa.sa_mask );
48 sa.sa_flags = 0;
49 sigaction( signum, &sa, &oldact );
50 m_oldActions[signum] = oldact;
52 }
53 }
SignalMonitorSvc(const std::string &name, ISvcLocator *svcLoc)
Initialize internal variables of the service and set the instance pointer.
static void dispatcher(int signum)
Signal handler function.

◆ setInstance()

void Gaudi::Utils::SignalMonitorSvc::setInstance ( SignalMonitorSvc * i)
inlinestaticprivate

Definition at line 120 of file SignalMonitorSvc.cpp.

120{ s_instance = i; }

◆ setSignal()

void Gaudi::Utils::SignalMonitorSvc::setSignal ( int signum)
inlineoverride

Set the flag for the given signal, as if the signal was received.

Definition at line 69 of file SignalMonitorSvc.cpp.

69{ m_caught[signum] = 1; }

Member Data Documentation

◆ m_caught

sig_atomic_t Gaudi::Utils::SignalMonitorSvc::m_caught[NSIG]
private

Array of flags for received signals.

Definition at line 104 of file SignalMonitorSvc.cpp.

◆ m_defaultAction

handler_t Gaudi::Utils::SignalMonitorSvc::m_defaultAction
private

Helper variable for default signal action.

Definition at line 106 of file SignalMonitorSvc.cpp.

◆ m_monitored

MonitoringMode Gaudi::Utils::SignalMonitorSvc::m_monitored[NSIG]
private

Array of flags to keep track of monitored signals.

Definition at line 102 of file SignalMonitorSvc.cpp.

◆ m_oldActions

handler_t Gaudi::Utils::SignalMonitorSvc::m_oldActions[NSIG]
private

List of replaced signal actions (for the recovery when disable the monitoring).

Definition at line 108 of file SignalMonitorSvc.cpp.

◆ s_instance

Gaudi::Utils::SignalMonitorSvc * Gaudi::Utils::SignalMonitorSvc::s_instance = nullptr
staticprivate

Pointer to the current instance.

Definition at line 118 of file SignalMonitorSvc.cpp.


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