Signal.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    Signal.h
00006  *
00007  *  $Id: Signal.h 80826 2008-03-04 14:51:23Z wotte $
00008  *
00009  *  @author Douglas C. Schmidt <schmidt@cs.wustl.edu>
00010  */
00011 //=============================================================================
00012 
00013 #ifndef ACE_SIGNAL_H
00014 #define ACE_SIGNAL_H
00015 #include /**/ "ace/pre.h"
00016 
00017 #include "ace/config-lite.h"
00018 
00019 #if defined (ACE_DONT_INCLUDE_ACE_SIGNAL_H)
00020 # error ace/Signal.h was #included instead of signal.h by ace/OS_NS_signal.h:  fix!!!!
00021 #endif /* ACE_DONT_INCLUDE_ACE_SIGNAL_H */
00022 
00023 #include /**/ "ace/ACE_export.h"
00024 
00025 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00026 # pragma once
00027 #endif /* ACE_LACKS_PRAGMA_ONCE */
00028 
00029 #include "ace/OS_NS_signal.h"
00030 
00031 // Type of the extended signal handler.
00032 typedef void (*ACE_Sig_Handler_Ex) (int, siginfo_t *siginfo, ucontext_t *ucontext);
00033 
00034 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00035 
00036 /**
00037  * @class ACE_Sig_Set
00038  *
00039  * @brief Provide a C++ wrapper for the C sigset_t interface.
00040  *
00041  * Handle signals via a more elegant C++ interface (e.g.,
00042  * doesn't require the use of global variables or global
00043  * functions in an application).
00044  */
00045 class ACE_Export ACE_Sig_Set
00046 {
00047 public:
00048   // = Initialization and termination methods.
00049   /// Initialize <sigset_> with @a sigset.  If @a sigset == 0 then fill
00050   /// the set.
00051   ACE_Sig_Set (sigset_t *sigset);
00052 
00053   /// Initialize <sigset_> with @a sigset.  If @a sigset == 0 then fill
00054   /// the set.
00055   ACE_Sig_Set (ACE_Sig_Set *sigset);
00056 
00057   /// If @a fill == 0 then initialize the <sigset_> to be empty, else
00058   /// full.
00059   ACE_Sig_Set (int fill = 0);
00060 
00061   ~ACE_Sig_Set (void);
00062 
00063   /// Create a set that excludes all signals defined by the system.
00064   int empty_set (void);
00065 
00066   /// Create a set that includes all signals defined by the system.
00067   int fill_set (void);
00068 
00069   /// Adds the individual signal specified by @a signo to the set.
00070   int sig_add (int signo);
00071 
00072   /// Deletes the individual signal specified by @a signo from the set.
00073   int sig_del (int signo);
00074 
00075   /// Checks whether the signal specified by @a signo is in the set.
00076   int is_member (int signo) const;
00077 
00078   /// Returns a pointer to the underlying @c sigset_t.
00079   operator sigset_t *();
00080 
00081   /// Returns a copy of the underlying @c sigset_t.
00082   sigset_t sigset (void) const;
00083 
00084   /// Dump the state of an object.
00085   void dump (void) const;
00086 
00087   /// Declare the dynamic allocation hooks.
00088   ACE_ALLOC_HOOK_DECLARE;
00089 
00090 private:
00091   /// Set of signals.
00092   sigset_t sigset_;
00093 };
00094 
00095 /**
00096  * @class ACE_Sig_Action
00097  *
00098  * @brief C++ wrapper facade for the @c sigaction struct.
00099  */
00100 class ACE_Export ACE_Sig_Action
00101 {
00102 public:
00103   // = Initialization methods.
00104   /// Default constructor.  Initializes everything to 0.
00105   ACE_Sig_Action (void);
00106 
00107   /// Assigns the various fields of a @c sigaction struct but doesn't
00108   /// register for signal handling via the @c sigaction function.
00109   ACE_Sig_Action (ACE_SignalHandler handler,
00110                   sigset_t *sigmask = 0,
00111                   int flags = 0);
00112 
00113   /// Assigns the various fields of a @c sigaction struct but doesn't
00114   /// register for signal handling via the @c sigaction function.
00115   ACE_Sig_Action (ACE_SignalHandler handler,
00116                   const ACE_Sig_Set &sigmask,
00117                   int flags = 0);
00118 
00119   /**
00120    * Assigns the various fields of a @c sigaction struct and registers
00121    * the @a handler to process signal @a signum via the @c sigaction
00122    * function.
00123    */
00124   ACE_Sig_Action (ACE_SignalHandler handler,
00125                   int signum,
00126                   sigset_t *sigmask = 0,
00127                   int flags = 0);
00128 
00129   /**
00130    * Assigns the various fields of a @c sigaction struct and registers
00131    * the @a handler to process signal @a signum via the @c sigaction
00132    * function.
00133    */
00134   ACE_Sig_Action (ACE_SignalHandler handler,
00135                   int signum,
00136                   const ACE_Sig_Set &sigmask,
00137                   int flags = 0);
00138 
00139 
00140   // @@ The next two methods have a parameter as "signalss". Please do
00141   // not change the argument name as "signals". This causes the
00142   // following problem as reported by
00143   // <James.Briggs@dsto.defence.gov.au>.
00144 
00145   // In the file Signal.h two of the functions have and argument name
00146   // of signals. signals is a Qt macro (to do with their meta object
00147   // stuff.
00148   // We could as well have it as "signal", but I am nost sure whether
00149   // that would cause a problem with something else - Bala <bala@cs>
00150 
00151   /**
00152    * Assigns the various fields of a @c sigaction struct and registers
00153    * the @a handler to process all @a signalss via the @c sigaction
00154    * function.
00155    */
00156   ACE_Sig_Action (const ACE_Sig_Set &signalss,
00157                   ACE_SignalHandler handler,
00158                   const ACE_Sig_Set &sigmask,
00159                   int flags = 0);
00160 
00161   /**
00162    * Assigns the various fields of a @c sigaction struct and registers
00163    * the @a handler to process all @a signalss via the @c sigaction
00164    * function.
00165    */
00166   ACE_Sig_Action (const ACE_Sig_Set &signalss,
00167                   ACE_SignalHandler handler,
00168                   sigset_t *sigmask = 0,
00169                   int flags = 0);
00170 
00171   /// Copy constructor.
00172   ACE_Sig_Action (const ACE_Sig_Action &s);
00173 
00174   /// Default dtor.
00175   ~ACE_Sig_Action (void);
00176 
00177   // = Signal action management.
00178   /// Register @c this as the current disposition and store old
00179   /// disposition into @a oaction if it is non-NULL.
00180   int register_action (int signum,
00181                        ACE_Sig_Action *oaction = 0);
00182 
00183   /// Assign the value of @a oaction to @c this and make it become the
00184   /// new signal disposition.
00185   int restore_action (int signum,
00186                       ACE_Sig_Action &oaction);
00187 
00188   /// Retrieve the current disposition into @c this.
00189   int retrieve_action (int signum);
00190 
00191   /// Set current signal action.
00192   void set (struct sigaction *);
00193 
00194   /// Get current signal action.
00195   struct sigaction *get (void);
00196   operator struct sigaction *();
00197 
00198   /// Set current signal flags.
00199   void flags (int);
00200 
00201   /// Get current signal flags.
00202   int flags (void);
00203 
00204   /// Set current signal mask.
00205   void mask (sigset_t *);
00206   void mask (ACE_Sig_Set &);
00207 
00208   /// Get current signal mask.
00209   sigset_t *mask (void);
00210 
00211   /// Set current signal handler (pointer to function).
00212   void handler (ACE_SignalHandler);
00213 
00214   /// Get current signal handler (pointer to function).
00215   ACE_SignalHandler handler (void);
00216 
00217   /// Dump the state of an object.
00218   void dump (void) const;
00219 
00220   /// Declare the dynamic allocation hooks.
00221   ACE_ALLOC_HOOK_DECLARE;
00222 
00223 private:
00224   /// Controls signal behavior.
00225   struct sigaction sa_;
00226 };
00227 
00228 /**
00229  * @class ACE_Sig_Guard
00230  *
00231  * @brief Hold signals in MASK for duration of a C++ statement block.
00232  * Note that a "0" for mask causes all signals to be held.
00233  */
00234 class ACE_Export ACE_Sig_Guard
00235 {
00236 public:
00237   // = Initialization and termination methods.
00238   /// This is kind of conditional Guard, needed when guard should be
00239   /// activated only when a spcific condition met. When condition ==
00240   /// true (default), Guard is activated
00241   ACE_Sig_Guard (ACE_Sig_Set *mask = 0, bool condition = true);
00242 
00243   /// Restore blocked signals.
00244   ~ACE_Sig_Guard (void);
00245 
00246   /// Dump the state of an object.
00247   void dump (void) const;
00248 
00249   /// Declare the dynamic allocation hooks.
00250   ACE_ALLOC_HOOK_DECLARE;
00251 
00252 private:
00253   /// Original signal mask.
00254   ACE_Sig_Set omask_;
00255 
00256   /// Guard Condition
00257   bool condition_;
00258 };
00259 
00260 ACE_END_VERSIONED_NAMESPACE_DECL
00261 
00262 #if defined (__ACE_INLINE__)
00263 #include "ace/Signal.inl"
00264 #endif /* __ACE_INLINE__ */
00265 
00266 #include /**/ "ace/post.h"
00267 #endif /* ACE_SIGNAL_HANDLER_H */

Generated on Tue Feb 2 17:18:42 2010 for ACE by  doxygen 1.4.7