Back to index

natlog  0.91.0
signal.h
Go to the documentation of this file.
00001 #ifndef INCLUDED_SIGNAL_
00002 #define INCLUDED_SIGNAL_
00003 
00004 #include <vector>
00005 #include <cstddef>
00006 #include <signal.h>
00007 
00008 class SignalHandler
00009 {
00010     friend class Signal;
00011 
00012     public:
00013         virtual ~SignalHandler();
00014     private:
00015         virtual void signaled(size_t signum) = 0;
00016 };
00017 
00018 class Signal
00019 {
00020     typedef std::vector<SignalHandler *> SignalHandlerVector;
00021     std::vector<SignalHandlerVector> d_signals;
00022 
00023     static Signal *s_signal;
00024 
00025     public:
00026         static Signal &instance();
00027         
00028         Signal(Signal const &) = delete;
00029         Signal &operator=(Signal const &) = delete;
00030 
00031         void add(size_t signum, SignalHandler &object);
00032         void ignore(size_t signum);
00033         void reset(size_t signum);
00034 
00035     private:
00036         Signal();
00037 
00038         static void verify(size_t signum, char const *member);
00039         static void handler(int signum);
00040 };
00041         
00042 #endif