| # Gaudi Framework, version v23r1 |

Home |  | Generated: Wed Feb 29 2012

Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes

# Gaudi::Utils::SignalMonitorSvc Class Reference

Implementation of Gaudi::ISignalMonitor. More...

Inheritance diagram for Gaudi::Utils::SignalMonitorSvc:
[legend]
Collaboration diagram for Gaudi::Utils::SignalMonitorSvc:
[legend]

List of all members.

## Public Types
typedef struct sigaction | handler_t
## Public Member Functions
void | monitorSignal (int signum, bool propagate)
| Declare a signal to be monitored.
void | ignoreSignal (int signum)
| Remove the specific signal handler for the requested signal, restoring the previous signal handler.
bool | gotSignal (int signum) const
| Check if the given signal has been received.
void | setSignal (int signum)
| Set the flag for the given signal, as if the signal was received.
void | clearSignal (int signum)
| 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.
virtual | ~SignalMonitorSvc ()
| Stop monitoring signals and clear the instance pointer.
## 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 = 0
| Pointer to the current instance.

## 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 26 of file SignalMonitorSvc.cpp.

## Member Typedef Documentation

typedef struct sigaction Gaudi::Utils::SignalMonitorSvc::handler_t

Definition at line 31 of file SignalMonitorSvc.cpp.

## Member Enumeration Documentation

enum Gaudi::Utils::SignalMonitorSvc::MonitoringMode`[private]`

Possible monitoring modes.

Enumerator:

  ignored |
  trap |
  propagate |

Definition at line 112 of file SignalMonitorSvc.cpp.

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

## Constructor & Destructor Documentation

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 85 of file SignalMonitorSvc.cpp.

                                                                      : base_class(name, svcLoc) {
    #ifdef _WIN32
            m_defaultAction = SIG_DFL;
    #else
            m_defaultAction.sa_handler = SIG_DFL;
            sigemptyset(&m_defaultAction.sa_mask);
            m_defaultAction.sa_flags = 0;
    #endif
            for(int i = 0; i < NSIG; ++i){
              m_caught[i] = 0;
              m_monitored[i] = ignored;
              m_oldActions[i] = m_defaultAction;
            }

            setInstance(this);
          }

virtual Gaudi::Utils::SignalMonitorSvc::~SignalMonitorSvc | ( | ) | `[inline, virtual]`

Stop monitoring signals and clear the instance pointer.

Definition at line 103 of file SignalMonitorSvc.cpp.

                                      {
            for (int i = 0; i < NSIG; ++i) {
              ignoreSignal(i);
            }
            setInstance(0);
          }

## Member Function Documentation

void Gaudi::Utils::SignalMonitorSvc::clearSignal | ( | int | signum ) | `[inline, virtual]`

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

Implements Gaudi::ISignalMonitor.

Definition at line 80 of file SignalMonitorSvc.cpp.

                                       {
            m_caught[signum] = 0;
          }

void Gaudi::Utils::SignalMonitorSvc::dispatcher | ( | int | signum ) | `[static, private]`

Signal handler function.

Definition at line 161 of file SignalMonitorSvc.cpp.

                                                   {
          if (instance()) instance()->i_handle(signum);
        }

bool Gaudi::Utils::SignalMonitorSvc::gotSignal | ( | int | signum ) | const`[inline, virtual]`

Check if the given signal has been received.

Implements Gaudi::ISignalMonitor.

Definition at line 70 of file SignalMonitorSvc.cpp.

                                           {
            return m_caught[signum] != 0;
          }

void Gaudi::Utils::SignalMonitorSvc::i_handle | ( | int | signum ) | `[inline, private]`

Definition at line 126 of file SignalMonitorSvc.cpp.

                                    {
            m_caught[signum] = 1;
            if ( m_monitored[signum] == propagate &&
    #ifdef _WIN32
                m_oldActions[signum] != SIG_DFL
    #else
                m_oldActions[signum].sa_handler != SIG_DFL
    #endif
            ) {
    #ifdef _WIN32
              m_oldActions[signum](signum);
    #else
              m_oldActions[signum].sa_handler(signum);
    #endif
            }
          }

void Gaudi::Utils::SignalMonitorSvc::ignoreSignal | ( | int | signum ) | `[inline, virtual]`

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

Implements Gaudi::ISignalMonitor.

Definition at line 57 of file SignalMonitorSvc.cpp.

                                        {
            if (m_monitored[signum]) {
    #ifdef _WIN32
              (void) signal(signum, m_oldActions[signum]);
    #else
              sigaction(signum, &m_oldActions[signum], 0);
    #endif
              m_oldActions[signum] = m_defaultAction;
              m_monitored[signum] = ignored;
            }
          }

static SignalMonitorSvc* Gaudi::Utils::SignalMonitorSvc::instance | ( | ) | `[inline, static, private]`

Method to get the singleton instance.

Bypass the serviceLocator for efficiency.

Definition at line 152 of file SignalMonitorSvc.cpp.

                                                     {
            return s_instance;
          }

void Gaudi::Utils::SignalMonitorSvc::monitorSignal | ( | int | signum,
|  | bool | propagate
| ) |  | `[inline, virtual]`

Declare a signal to be monitored.

It installs a signal handler for the requested signal.

Implements Gaudi::ISignalMonitor.

Definition at line 36 of file SignalMonitorSvc.cpp.

                                                         {
            if (!m_monitored[signum]) {
              handler_t sa;
              handler_t oldact;
    #ifdef _WIN32
              sa = SignalMonitorSvc::dispatcher;
              oldact = signal(signum, sa);
    #else
              sa.sa_handler = SignalMonitorSvc::dispatcher;
              sigemptyset(&sa.sa_mask);
              sa.sa_flags = 0;
              sigaction(signum, &sa, &oldact);
    #endif
              m_oldActions[signum] = oldact;
              m_monitored[signum] = (propagate) ? SignalMonitorSvc::propagate
                                                : SignalMonitorSvc::trap;
            }
          }

static void Gaudi::Utils::SignalMonitorSvc::setInstance | ( | SignalMonitorSvc * | i ) | `[inline, static, private]`

Definition at line 146 of file SignalMonitorSvc.cpp.

                                                              {
            s_instance = i;
          }

void Gaudi::Utils::SignalMonitorSvc::setSignal | ( | int | signum ) | `[inline, virtual]`

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

Implements Gaudi::ISignalMonitor.

Definition at line 75 of file SignalMonitorSvc.cpp.

                                     {
            m_caught[signum] = 1;
          }

## Member Data Documentation

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

Array of flags for received signals.

Definition at line 120 of file SignalMonitorSvc.cpp.

handler_t Gaudi::Utils::SignalMonitorSvc::m_defaultAction`[private]`

Helper variable for default signal action.

Definition at line 122 of file SignalMonitorSvc.cpp.

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

Array of flags to keep track of monitored signals.

Definition at line 118 of file SignalMonitorSvc.cpp.

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

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

Definition at line 124 of file SignalMonitorSvc.cpp.

Gaudi::Utils::SignalMonitorSvc * Gaudi::Utils::SignalMonitorSvc::s_instance = 0`[static, private]`

Pointer to the current instance.

Definition at line 144 of file SignalMonitorSvc.cpp.

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v23r1/GaudiUtils/src/component/SignalMonitorSvc.cpp

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines