BLSignal.hh

Go to the documentation of this file.
00001 //      BLSignal.cc
00002 /*
00003 This source file is part of G4beamline, http://g4beamline.muonsinc.com
00004 Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved.
00005 
00006 This program is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU General Public License
00008 as published by the Free Software Foundation; either version 2
00009 of the License, or (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 http://www.gnu.org/copyleft/gpl.html
00017 */
00018 
00019 #ifndef BLSIGNAL_HH
00020 #define BLSIGNAL_HH
00021 
00022 /**     class BLSignal implements a signal handler to permit G4beamline
00023  *      to exit cleanly when a UNIX signal is received.
00024  *
00025  *      Note that a second received signal causes an immediate call to
00026  *      g4bl_exit() from the signal handler.
00027  *
00028  *      If BLAlarm is also used, BLSignal::init() must be called first.
00029  *
00030  *      Note that BLManager checks received() in UserSteppingAction(), and
00031  *      issues a fatal exception when any signal is received..
00032  **/
00033 class BLSignal {
00034 public:
00035         /// init() will setup the signal handler
00036         static void init();
00037 
00038         /// received() returns true if a signal has been received.
00039         static bool received() { return signalReceived; };
00040 
00041         /// setSignalReceived() will set the signalReceived flag.
00042         static void setSignalReceived(bool v) { signalReceived = v; }
00043 
00044 private:
00045         static bool signalReceived;
00046 
00047         /// sighandler() handles the alarm signal
00048         static void sighandler(int sig);
00049 };
00050 
00051 #endif // BLSIGNAL_HH
g4beamline