CARMA C++
Signal.h
Go to the documentation of this file.
1 #ifndef SIGNAL_H
2 #define SIGNAL_H
3 
11 #include <signal.h> // Needed for SIGPIPE, etc.
12 #include <setjmp.h> // Needed for jmp_buf, etc.
13 
14 #define SIG_HANDLER(fn) void (fn)(int sigNo)
15 #define SIG_ACTION(fn) void (fn)(int sigNo, siginfo_t* sigInfo, void* arg)
16 
17 #if !HAVE_RT
18 #define SIGRTMAX 31
19 #endif
20 
21 namespace sza {
22  namespace util {
23 
27  class Signal {
28  public:
29 
33  Signal(int sigNo);
34 
38  Signal(int sigNo, SIG_HANDLER(*handler));
39 
43  Signal(int sigNo, SIG_HANDLER(*handler), sigset_t* sigSet);
44 
48  Signal(int sigNo, SIG_ACTION(*action));
49 
53  Signal(int sigNo, SIG_ACTION(*action), sigset_t* sigSet);
54 
59  void installHandler(SIG_HANDLER(*handler));
60 
66  void installHandler(SIG_ACTION(*action));
67 
71  ~Signal();
72 
73  private:
74 
78  static Signal* signal_;
79 
83  int sigNo_;
84 
88  sigset_t sigSet_;
89 
93  bool sigSetIsEmpty;
94 
99  static SIG_ACTION(action_);
100 
114  SIG_HANDLER(*userhandler_);
115 
116  SIG_ACTION(*useraction_);
117 
138  void privateConstructor(int sigNo, SIG_HANDLER(*handler),
139  SIG_ACTION(*action), sigset_t* sigSet);
144  void setUpSigAction();
145 
146  }; // End class Signal
147 
148  }; // End namespace util
149  }; // End namespace sza
150 
151 #endif // End #ifndef
Signal(int sigNo)
Constructor with no sigset or handler.
Class to encapsulate signal handling.
Definition: Signal.h:27
~Signal()
Destructor.
void installHandler(void(*handler)(int sigNo))
Install a handler, in case we want to declare a global Signal type before the handler is declared...