BLSignal Class Reference

#include <BLSignal.hh>

List of all members.


Detailed Description

class BLSignal implements a signal handler to permit G4beamline to exit cleanly when a UNIX signal is received.

Note that a second received signal causes an immediate call to g4bl_exit() from the signal handler.

If BLAlarm is also used, BLSignal::init() must be called first.

Note that BLManager checks received() in UserSteppingAction(), and issues a fatal exception when any signal is received..

Static Public Member Functions

static void init ()
 init() will setup the signal handler
static bool received ()
 received() returns true if a signal has been received.
static void setSignalReceived (bool v)
 setSignalReceived() will set the signalReceived flag.

Static Private Member Functions

static void sighandler (int sig)
 sighandler() handles the alarm signal

Static Private Attributes

static bool signalReceived = false


Member Function Documentation

void BLSignal::init (  )  [static]

init() will setup the signal handler

References sighandler(), and signalReceived.

Referenced by BLManager::BLManager().

00044 {
00045 #ifdef WIN32
00046         static int sigs[] = {SIGINT, SIGILL, SIGABRT,
00047                 SIGSEGV, SIGTERM, SIGFPE};
00048 #else
00049         static int sigs[] = {SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGABRT,
00050                 SIGKILL, SIGBUS, SIGSEGV, SIGSYS, SIGPIPE, SIGTERM, SIGXCPU,
00051                 SIGUSR1, SIGUSR2};
00052 #endif
00053 
00054         signalReceived = false;
00055 
00056         for(unsigned i=0; i<sizeof(sigs)/sizeof(sigs[0]); ++i)
00057                 signal(sigs[i],sighandler); 
00058 
00059 #ifdef WIN32
00060         SetConsoleCtrlHandler( (PHANDLER_ROUTINE) CtrlHandler, TRUE );
00061 #endif
00062 }

static bool BLSignal::received (  )  [inline, static]

received() returns true if a signal has been received.

References signalReceived.

Referenced by BLManager::UserSteppingAction().

00039 { return signalReceived; };

static void BLSignal::setSignalReceived ( bool  v  )  [inline, static]

setSignalReceived() will set the signalReceived flag.

References signalReceived.

Referenced by BLCommand::getNextCommand().

00042 { signalReceived = v; }

void BLSignal::sighandler ( int  sig  )  [static, private]

sighandler() handles the alarm signal

References g4bl_exit(), and signalReceived.

Referenced by init().

00065 {
00066         static int prev=0;
00067 
00068         signal(sig,sighandler);
00069 
00070         if(signalReceived) {
00071                 static bool moreThanTwo=false;
00072                 if(moreThanTwo) 
00073                         _exit(99);
00074                 moreThanTwo = true;
00075                 fflush(stdout);
00076                 fprintf(stderr, "\n"
00077                     "***************************************************\n"
00078                     "***  Multiple signals received (%d,%d), exiting  ***\n"
00079                     "***************************************************\n",
00080                     prev,sig);
00081                 g4bl_exit(99);
00082         }
00083 
00084         prev = sig;
00085         signalReceived = true;
00086 }


Member Data Documentation

bool BLSignal::signalReceived = false [static, private]


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