Back to index

lightning-sunbird  0.9+nobinonly
GUSISignal.h
Go to the documentation of this file.
00001 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
00002 // % Project  :      GUSI                        -      Grand Unified Socket Interface                    
00003 // % File            :      GUSISignal.nw        -      Signal engine                                
00004 // % Author   :      Matthias Neeracher                                           
00005 // % Language :      C++                                                        
00006 // %                                                                       
00007 // % $Log: GUSISignal.h,v $
00008 // % Revision 1.1  2001/03/11 22:38:04  sgehani%netscape.com
00009 // % First Checked In.
00010 // %                                               
00011 // % Revision 1.7  2000/10/16 04:08:51  neeri                              
00012 // % Add binary compatibility for CW SIGINT                                
00013 // %                                                                       
00014 // % Revision 1.6  2000/05/23 07:18:03  neeri                              
00015 // % Improve formatting                                                    
00016 // %                                                                       
00017 // % Revision 1.5  2000/03/15 07:22:07  neeri                              
00018 // % Enforce alignment choices                                             
00019 // %                                                                       
00020 // % Revision 1.4  1999/12/13 03:07:25  neeri                              
00021 // % Releasing 2.0.2                                                       
00022 // %                                                                       
00023 // % Revision 1.3  1999/11/15 07:20:18  neeri                              
00024 // % Safe context setup                                                    
00025 // %                                                                       
00026 // % Revision 1.2  1999/08/26 05:45:09  neeri                              
00027 // % Fixes for literate edition of source code                             
00028 // %                                                                       
00029 // % Revision 1.1  1999/06/30 07:42:07  neeri                              
00030 // % Getting ready to release 2.0b3                                        
00031 // %                                                                       
00032 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
00033 //                                                                         
00034 // \chapter{Signal support}                                                
00035 //                                                                         
00036 // We support signals in the half assed way characteristic for GUSI's approach to 
00037 // asynchronous issues: Delivery is very much synchronous, basically within [[Yield]]
00038 // calls. Signal handling behavior is encapsulated in the classes [[GUSISigContext]] and
00039 // [[GUSISigProcess]] whose instances are manufactured by a [[GUSISigFactory]].
00040 //                                                                         
00041 // <GUSISignal.h>=                                                         
00042 #ifndef _GUSISIGNAL_
00043 #define _GUSISIGNAL_
00044 
00045 #include <signal.h>
00046 
00047 #ifdef GUSI_SOURCE
00048 
00049 #include <ConditionalMacros.h>
00050 
00051 #if PRAGMA_STRUCT_ALIGN
00052 #pragma options align=native
00053 #endif
00054 
00055 // \section{Definition of the signal handling engine}                      
00056 //                                                                         
00057 // A [[GUSISigProcess]] contains the per-process signal state. [[GetAction]] and [[SetAction]] manipulate the
00058 // action associated with a signal, [[Pending]] returns the set of pending signals, [[Post]] marks a signal 
00059 // as pending (but possibly blocked), and [[Raise]] executes a signal (which we have determined is not 
00060 // blocked).                                                               
00061 //                                                                         
00062 // <Definition of class [[GUSISigProcess]]>=                               
00063 class GUSISigContext;
00064 
00065 class GUSISigProcess {
00066 public:
00067        virtual struct sigaction &  GetAction(int sig);
00068        virtual int                               SetAction(int sig, const struct sigaction & act);
00069        virtual sigset_t                   Pending() const;
00070        virtual void                       ClearPending(sigset_t clear);
00071        virtual void                       Post(int sig);
00072        virtual bool                       Raise(int sig, GUSISigContext * context);
00073        
00074        virtual ~GUSISigProcess();
00075 protected:
00076        // [[GUSISigProcess]] stores the signal handlers and the set of signals pending against the process.
00077  //                                                                         
00078  // <Privatissima of [[GUSISigProcess]]>=                                   
00079  sigset_t                   fPending;
00080  struct sigaction    fAction[NSIG-1];
00081  // Some actions can't be caught and/or ignored. [[CantCatch]] and [[CantIgnore]] report those.
00082  //                                                                         
00083  // <Privatissima of [[GUSISigProcess]]>=                                   
00084  virtual bool CantCatch(int sig);
00085  virtual bool CantIgnore(int sig);
00086  // The default behavior for many signals is to abort the process.          
00087  //                                                                         
00088  // <Privatissima of [[GUSISigProcess]]>=                                   
00089  virtual bool DefaultAction(int sig, const struct sigaction & act);
00090        
00091        friend class GUSISigFactory;
00092        GUSISigProcess();
00093 };
00094 // A [[GUSISigContext]] contains the per-thread signal state, primarily blocking info. To support 
00095 // [[pthread_kill]], we have out own set of pending signals. [[GetBlocked]] and [[SetBlocked]] manipulate
00096 // the set of blocking signals, [[Pending]] returns the set of pending signals, [[Post]] marks a 
00097 // signal as pending (but possibly blocked), and [[Raise]] executes all eligible signals.
00098 //                                                                         
00099 // <Definition of class [[GUSISigContext]]>=                               
00100 class GUSISigContext {
00101 public:
00102        virtual       sigset_t      GetBlocked() const;
00103        virtual void         SetBlocked(sigset_t sigs);
00104        virtual sigset_t     Pending() const;
00105        virtual sigset_t     Pending(GUSISigProcess * proc) const;
00106        virtual void         ClearPending(sigset_t clear);
00107        virtual void         Post(int sig);
00108        virtual       sigset_t      Ready(GUSISigProcess * proc);      
00109        virtual       bool          Raise(GUSISigProcess * proc, bool allSigs = false);     
00110 
00111        virtual ~GUSISigContext();
00112 protected:
00113        // [[GUSISigContext]] mainly deals with a set of blocked signals, which it inherits from its parent.
00114  //                                                                         
00115  // <Privatissima of [[GUSISigContext]]>=                                   
00116  sigset_t     fPending;
00117  sigset_t     fBlocked;
00118  // Many signals cannot be blocked. [[CantBlock]] defines those.            
00119  //                                                                         
00120  // <Privatissima of [[GUSISigContext]]>=                                   
00121  virtual sigset_t    CantBlock();
00122        
00123        friend class GUSISigFactory;
00124        GUSISigContext(const GUSISigContext * parent);
00125 };
00126 // The [[GUSISigFactory]] singleton creates the above two classes, allowing a future extension to
00127 // handle more signals.                                                    
00128 //                                                                         
00129 // <Definition of class [[GUSISigFactory]]>=                               
00130 class GUSISigFactory {
00131 public:
00132        virtual GUSISigProcess *    CreateSigProcess();
00133        virtual GUSISigContext *    CreateSigContext(const GUSISigContext * parent);
00134 
00135        virtual ~GUSISigFactory();
00136        
00137        static GUSISigFactory *            Instance();
00138        static void                               SetInstance(GUSISigFactory * instance);
00139 protected:
00140        GUSISigFactory()                   {}
00141 };
00142 
00143 #if PRAGMA_STRUCT_ALIGN
00144 #pragma options align=reset
00145 #endif
00146 
00147 #endif
00148 
00149 #endif /* _GUSISIGNAL_ */