signal.h

00001 
00002 /***************************************************************************
00003  *  signal.h - This header defines a true OOo signal handler
00004  *  based on
00005  *  Douglas C. Schmidt
00006  *  "Applying Design Patterns to Simplify Signal Handling"
00007  *  http://www.cs.wustl.edu/~schmidt/signal-patterns.html
00008  *
00009  *  Generated: Thu Jan 12 22:44:59 2006 (from FireVision)
00010  *  Copyright  2005-2006  Tim Niemueller [www.niemueller.de]
00011  *
00012  ****************************************************************************/
00013 
00014 /*  This program is free software; you can redistribute it and/or modify
00015  *  it under the terms of the GNU General Public License as published by
00016  *  the Free Software Foundation; either version 2 of the License, or
00017  *  (at your option) any later version. A runtime exception applies to
00018  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00019  *
00020  *  This program is distributed in the hope that it will be useful,
00021  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023  *  GNU Library General Public License for more details.
00024  *
00025  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00026  */
00027 
00028 #ifndef __UTILS_SYSTEM_SIGNAL_H_
00029 #define __UTILS_SYSTEM_SIGNAL_H_
00030 
00031 #include <signal.h>
00032 
00033 namespace fawkes {
00034 
00035 class SignalHandler {
00036  public:
00037   virtual ~SignalHandler() {}
00038   virtual void handle_signal(int signal)   = 0;
00039 };
00040 
00041 
00042 class SignalManager {
00043 
00044  public:
00045   static SignalManager *  instance();
00046   static void             finalize();
00047   static SignalHandler *  register_handler(int signum, SignalHandler *handler);
00048   static void             unregister_handler(int signum);
00049   static void             unregister_handler(SignalHandler *handler);
00050   static void             ignore(int signum);
00051 
00052  private:
00053   // Guard constructors, make sure we are a singleton
00054   SignalManager();
00055   SignalManager(const SignalManager& cc);
00056 
00057   static SignalManager *__instance;
00058 
00059   // Entry point adapter installed into <sigaction> 
00060   // (must be a static method or a stand-alone 
00061   // extern "C" function).
00062   static void dispatcher (int signum);
00063 
00064   // restores default signal handler, called by unregister_*
00065   static void restore_default(int signum);
00066 
00067   // Table of pointers to concrete <SignalHandler>s
00068   // registered by applications.  NSIG is the number of 
00069   // signals defined in <signal.h>.
00070   static SignalHandler *  __signal_handlers[NSIG];
00071 
00072 };
00073 
00074 } // end namespace fawkes
00075 
00076 #endif

Generated on 1 Mar 2011 for Fawkes API by  doxygen 1.6.1