3 //=============================================================================
7 * @author Douglas C. Schmidt <d.schmidt@vanderbilt.edu>
9 //=============================================================================
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)
25 #endif /* ACE_LACKS_PRAGMA_ONCE */
27 #include "ace/OS_NS_signal.h"
29 /// Type of the extended signal handler.
30 using ACE_Sig_Handler_Ex
= void (*) (int, siginfo_t
*siginfo
, ucontext_t
*ucontext
);
32 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
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
46 /// Initialize sigset_ with @a sigset. If @a sigset == 0 then fill
48 ACE_Sig_Set (sigset_t
*sigset
);
50 /// Initialize sigset_ with @a sigset. If @a sigset == 0 then fill
52 ACE_Sig_Set (ACE_Sig_Set
*sigset
);
54 /// If @a fill == false then initialize the sigset_ to be empty, else
56 ACE_Sig_Set (bool fill
= false);
60 /// Create a set that excludes all signals defined by the system.
63 /// Create a set that includes all signals defined by the system.
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 () const;
81 /// Dump the state of an object.
84 /// Declare the dynamic allocation hooks.
85 ACE_ALLOC_HOOK_DECLARE
;
93 * @class ACE_Sig_Action
95 * @brief C++ wrapper facade for the @c sigaction struct.
97 class ACE_Export ACE_Sig_Action
100 /// Default constructor. Initializes everything to 0.
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
= nullptr,
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
,
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
120 ACE_Sig_Action (ACE_SignalHandler handler
,
122 sigset_t
*sigmask
= nullptr,
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
130 ACE_Sig_Action (ACE_SignalHandler handler
,
132 const ACE_Sig_Set
&sigmask
,
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
140 ACE_Sig_Action (const ACE_Sig_Set
&signalss
,
141 ACE_SignalHandler handler
,
142 const ACE_Sig_Set
&sigmask
,
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
150 ACE_Sig_Action (const ACE_Sig_Set
&signalss
,
151 ACE_SignalHandler handler
,
152 sigset_t
*sigmask
= nullptr,
155 ACE_Sig_Action (const ACE_Sig_Action
&) = default;
156 ACE_Sig_Action (ACE_Sig_Action
&&) = default;
157 ACE_Sig_Action
& operator = (ACE_Sig_Action
const &) = default;
158 ACE_Sig_Action
&operator = (ACE_Sig_Action
&&) = default;
163 // = Signal action management.
164 /// Register @c this as the current disposition and store old
165 /// disposition into @a oaction if it is non-NULL.
166 int register_action (int signum
,
167 ACE_Sig_Action
*oaction
= nullptr);
169 /// Assign the value of @a oaction to @c this and make it become the
170 /// new signal disposition.
171 int restore_action (int signum
,
172 ACE_Sig_Action
&oaction
);
174 /// Retrieve the current disposition into @c this.
175 int retrieve_action (int signum
);
177 /// Set current signal action.
178 void set (struct sigaction
*);
180 /// Get current signal action.
181 struct sigaction
*get ();
182 operator struct sigaction
*();
184 /// Set current signal flags.
187 /// Get current signal flags.
190 /// Set current signal mask.
191 void mask (sigset_t
*);
192 void mask (ACE_Sig_Set
&);
194 /// Get current signal mask.
197 /// Set current signal handler (pointer to function).
198 void handler (ACE_SignalHandler
);
200 /// Get current signal handler (pointer to function).
201 ACE_SignalHandler
handler ();
203 /// Dump the state of an object.
206 /// Declare the dynamic allocation hooks.
207 ACE_ALLOC_HOOK_DECLARE
;
210 /// Controls signal behavior.
211 struct sigaction sa_
;
215 * @class ACE_Sig_Guard
217 * @brief Hold signals in MASK for duration of a C++ statement block.
218 * Note that a "0" for mask causes all signals to be held.
220 class ACE_Export ACE_Sig_Guard
223 /// This is kind of conditional Guard, needed when guard should be
224 /// activated only when a specific condition met. When condition ==
225 /// true (default), Guard is activated
226 ACE_Sig_Guard (ACE_Sig_Set
*mask
= nullptr, bool condition
= true);
228 /// Restore blocked signals.
231 /// Dump the state of an object.
234 /// Declare the dynamic allocation hooks.
235 ACE_ALLOC_HOOK_DECLARE
;
238 /// Original signal mask.
242 bool const condition_
;
245 ACE_END_VERSIONED_NAMESPACE_DECL
247 #if defined (__ACE_INLINE__)
248 #include "ace/Signal.inl"
249 #endif /* __ACE_INLINE__ */
251 #include /**/ "ace/post.h"
252 #endif /* ACE_SIGNAL_HANDLER_H */