Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / ace / Signal.h
blob7683e9c789d631cbd2fbdb8e1d8f65bfb1030d8a
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 using ACE_Sig_Handler_Ex = void (*) (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 == false then initialize the sigset_ to be empty, else
55 /// full.
56 ACE_Sig_Set (bool fill = false);
58 ~ACE_Sig_Set ();
60 /// Create a set that excludes all signals defined by the system.
61 int empty_set ();
63 /// Create a set that includes all signals defined by the system.
64 int fill_set ();
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.
82 void dump () 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 ();
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,
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 = nullptr,
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 = nullptr,
153 int flags = 0);
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;
160 /// Default dtor.
161 ~ACE_Sig_Action ();
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.
185 void flags (int);
187 /// Get current signal flags.
188 int flags ();
190 /// Set current signal mask.
191 void mask (sigset_t *);
192 void mask (ACE_Sig_Set &);
194 /// Get current signal mask.
195 sigset_t *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.
204 void dump () const;
206 /// Declare the dynamic allocation hooks.
207 ACE_ALLOC_HOOK_DECLARE;
209 private:
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
222 public:
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.
229 ~ACE_Sig_Guard ();
231 /// Dump the state of an object.
232 void dump () const;
234 /// Declare the dynamic allocation hooks.
235 ACE_ALLOC_HOOK_DECLARE;
237 private:
238 /// Original signal mask.
239 ACE_Sig_Set omask_;
241 /// Guard Condition
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 */