Fawkes API  Fawkes Development Version
signal.h
1 
2 /***************************************************************************
3  * signal.h - This header defines a true OOo signal handler
4  * based on
5  * Douglas C. Schmidt
6  * "Applying Design Patterns to Simplify Signal Handling"
7  * http://www.cs.wustl.edu/~schmidt/signal-patterns.html
8  *
9  * Generated: Thu Jan 12 22:44:59 2006 (from FireVision)
10  * Copyright 2005-2006 Tim Niemueller [www.niemueller.de]
11  *
12  ****************************************************************************/
13 
14 /* This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version. A runtime exception applies to
18  * this software (see LICENSE.GPL_WRE file mentioned below for details).
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU Library General Public License for more details.
24  *
25  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
26  */
27 
28 #ifndef _UTILS_SYSTEM_SIGNAL_H_
29 #define _UTILS_SYSTEM_SIGNAL_H_
30 
31 #include <signal.h>
32 
33 namespace fawkes {
34 
36 {
37 public:
38  virtual ~SignalHandler()
39  {
40  }
41  virtual void handle_signal(int signal) = 0;
42 };
43 
45 {
46 public:
47  static SignalManager *instance();
48  static void finalize();
49  static SignalHandler *register_handler(int signum, SignalHandler *handler);
50  static void unregister_handler(int signum);
51  static void unregister_handler(SignalHandler *handler);
52  static void ignore(int signum);
53 
54 private:
55  // Guard constructors, make sure we are a singleton
56  SignalManager();
57  SignalManager(const SignalManager &cc);
58 
59  static SignalManager *instance_;
60 
61  // Entry point adapter installed into <sigaction>
62  // (must be a static method or a stand-alone
63  // extern "C" function).
64  static void dispatcher(int signum);
65 
66  // restores default signal handler, called by unregister_*
67  static void restore_default(int signum);
68 
69  // Table of pointers to concrete <SignalHandler>s
70  // registered by applications. NSIG is the number of
71  // signals defined in <signal.h>.
72  static SignalHandler *signal_handlers_[NSIG];
73 };
74 
75 } // end namespace fawkes
76 
77 #endif
Interface for signal handling.
Definition: signal.h:36
virtual ~SignalHandler()
Virtual destructor.
Definition: signal.h:38
virtual void handle_signal(int signal)=0
Signal hanlding method.
System signal manager.
Definition: signal.h:45
static void finalize()
Finalize (and free) the SignalManager instance, this does NOT implicitly delete the signal handlers,...
Definition: signal.cpp:96
static void ignore(int signum)
Ignore a signal.
Definition: signal.cpp:174
static SignalManager * instance()
Get the SignalManager instance.
Definition: signal.cpp:80
static void unregister_handler(int signum)
Unregister a SignalHandler for a signal.
Definition: signal.cpp:136
static SignalHandler * register_handler(int signum, SignalHandler *handler)
Register a SignalHandler for a signal.
Definition: signal.cpp:113
Fawkes library namespace.