Correct feature names
[ACE_TAO.git] / ACE / ace / Signal.h
blob416722eb8114018c493d3aa79c84dde768c999e9
1 // -*- C++ -*-
3 //=============================================================================
4 /**
5 * @file Signal.h
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
8 */
9 //=============================================================================
11 #ifndef ACE_SIGNAL_H
12 #define ACE_SIGNAL_H
13 #include /**/ "ace/pre.h"
15 #include /**/ "ace/config-lite.h"
17 #if defined (ACE_DONT_INCLUDE_ACE_SIGNAL_H)
18 # error ace/Signal.h was #included instead of signal.h by ace/OS_NS_signal.h: fix!!!!
19 #endif /* ACE_DONT_INCLUDE_ACE_SIGNAL_H */
21 #include /**/ "ace/ACE_export.h"
23 #if !defined (ACE_LACKS_PRAGMA_ONCE)
24 # pragma once
25 #endif /* ACE_LACKS_PRAGMA_ONCE */
27 #include "ace/OS_NS_signal.h"
29 /// Type of the extended signal handler.
30 typedef void (*ACE_Sig_Handler_Ex) (int, siginfo_t *siginfo, ucontext_t *ucontext);
32 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
34 /**
35 * @class ACE_Sig_Set
37 * @brief Provide a C++ wrapper for the C sigset_t interface.
39 * Handle signals via a more elegant C++ interface (e.g.,
40 * doesn't require the use of global variables or global
41 * functions in an application).
43 class ACE_Export ACE_Sig_Set
45 public:
46 /// Initialize <sigset_> with @a sigset. If @a sigset == 0 then fill
47 /// the set.
48 ACE_Sig_Set (sigset_t *sigset);
50 /// Initialize <sigset_> with @a sigset. If @a sigset == 0 then fill
51 /// the set.
52 ACE_Sig_Set (ACE_Sig_Set *sigset);
54 /// If @a fill == 0 then initialize the <sigset_> to be empty, else
55 /// full.
56 ACE_Sig_Set (int fill = 0);
58 ~ACE_Sig_Set (void);
60 /// Create a set that excludes all signals defined by the system.
61 int empty_set (void);
63 /// Create a set that includes all signals defined by the system.
64 int fill_set (void);
66 /// Adds the individual signal specified by @a signo to the set.
67 int sig_add (int signo);
69 /// Deletes the individual signal specified by @a signo from the set.
70 int sig_del (int signo);
72 /// Checks whether the signal specified by @a signo is in the set.
73 int is_member (int signo) const;
75 /// Returns a pointer to the underlying @c sigset_t.
76 operator sigset_t *();
78 /// Returns a copy of the underlying @c sigset_t.
79 sigset_t sigset (void) const;
81 /// Dump the state of an object.
82 void dump (void) const;
84 /// Declare the dynamic allocation hooks.
85 ACE_ALLOC_HOOK_DECLARE;
87 private:
88 /// Set of signals.
89 sigset_t sigset_;
92 /**
93 * @class ACE_Sig_Action
95 * @brief C++ wrapper facade for the @c sigaction struct.
97 class ACE_Export ACE_Sig_Action
99 public:
100 /// Default constructor. Initializes everything to 0.
101 ACE_Sig_Action (void);
103 /// Assigns the various fields of a @c sigaction struct but doesn't
104 /// register for signal handling via the @c sigaction function.
105 ACE_Sig_Action (ACE_SignalHandler handler,
106 sigset_t *sigmask = 0,
107 int flags = 0);
109 /// Assigns the various fields of a @c sigaction struct but doesn't
110 /// register for signal handling via the @c sigaction function.
111 ACE_Sig_Action (ACE_SignalHandler handler,
112 const ACE_Sig_Set &sigmask,
113 int flags = 0);
116 * Assigns the various fields of a @c sigaction struct and registers
117 * the @a handler to process signal @a signum via the @c sigaction
118 * function.
120 ACE_Sig_Action (ACE_SignalHandler handler,
121 int signum,
122 sigset_t *sigmask = 0,
123 int flags = 0);
126 * Assigns the various fields of a @c sigaction struct and registers
127 * the @a handler to process signal @a signum via the @c sigaction
128 * function.
130 ACE_Sig_Action (ACE_SignalHandler handler,
131 int signum,
132 const ACE_Sig_Set &sigmask,
133 int flags = 0);
136 * Assigns the various fields of a @c sigaction struct and registers
137 * the @a handler to process all @a signalss via the @c sigaction
138 * function.
140 ACE_Sig_Action (const ACE_Sig_Set &signalss,
141 ACE_SignalHandler handler,
142 const ACE_Sig_Set &sigmask,
143 int flags = 0);
146 * Assigns the various fields of a @c sigaction struct and registers
147 * the @a handler to process all @a signalss via the @c sigaction
148 * function.
150 ACE_Sig_Action (const ACE_Sig_Set &signalss,
151 ACE_SignalHandler handler,
152 sigset_t *sigmask = 0,
153 int flags = 0);
155 #if defined (ACE_HAS_CPP11)
156 ACE_Sig_Action (const ACE_Sig_Action&) = default;
157 ACE_Sig_Action (ACE_Sig_Action&&) = default;
158 ACE_Sig_Action& operator = (ACE_Sig_Action const &) = default;
159 ACE_Sig_Action &operator = (ACE_Sig_Action&&) = default;
160 #endif /* ACE_HAS_CPP11 */
162 /// Default dtor.
163 ~ACE_Sig_Action (void);
165 // = Signal action management.
166 /// Register @c this as the current disposition and store old
167 /// disposition into @a oaction if it is non-NULL.
168 int register_action (int signum,
169 ACE_Sig_Action *oaction = 0);
171 /// Assign the value of @a oaction to @c this and make it become the
172 /// new signal disposition.
173 int restore_action (int signum,
174 ACE_Sig_Action &oaction);
176 /// Retrieve the current disposition into @c this.
177 int retrieve_action (int signum);
179 /// Set current signal action.
180 void set (struct sigaction *);
182 /// Get current signal action.
183 struct sigaction *get (void);
184 operator struct sigaction *();
186 /// Set current signal flags.
187 void flags (int);
189 /// Get current signal flags.
190 int flags (void);
192 /// Set current signal mask.
193 void mask (sigset_t *);
194 void mask (ACE_Sig_Set &);
196 /// Get current signal mask.
197 sigset_t *mask (void);
199 /// Set current signal handler (pointer to function).
200 void handler (ACE_SignalHandler);
202 /// Get current signal handler (pointer to function).
203 ACE_SignalHandler handler (void);
205 /// Dump the state of an object.
206 void dump (void) const;
208 /// Declare the dynamic allocation hooks.
209 ACE_ALLOC_HOOK_DECLARE;
211 private:
212 /// Controls signal behavior.
213 struct sigaction sa_;
217 * @class ACE_Sig_Guard
219 * @brief Hold signals in MASK for duration of a C++ statement block.
220 * Note that a "0" for mask causes all signals to be held.
222 class ACE_Export ACE_Sig_Guard
224 public:
225 /// This is kind of conditional Guard, needed when guard should be
226 /// activated only when a specific condition met. When condition ==
227 /// true (default), Guard is activated
228 ACE_Sig_Guard (ACE_Sig_Set *mask = 0, bool condition = true);
230 /// Restore blocked signals.
231 ~ACE_Sig_Guard (void);
233 /// Dump the state of an object.
234 void dump (void) const;
236 /// Declare the dynamic allocation hooks.
237 ACE_ALLOC_HOOK_DECLARE;
239 private:
240 /// Original signal mask.
241 ACE_Sig_Set omask_;
243 /// Guard Condition
244 bool condition_;
247 ACE_END_VERSIONED_NAMESPACE_DECL
249 #if defined (__ACE_INLINE__)
250 #include "ace/Signal.inl"
251 #endif /* __ACE_INLINE__ */
253 #include /**/ "ace/post.h"
254 #endif /* ACE_SIGNAL_HANDLER_H */