Back to index

lightning-sunbird  0.9+nobinonly
GUSIConfig.h
Go to the documentation of this file.
00001 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
00002 // % Project  :      GUSI                        -      Grand Unified Socket Interface                    
00003 // % File            :      GUSIConfig.nw        -      Configuration settings                       
00004 // % Author   :      Matthias Neeracher                                           
00005 // % Language :      C++                                                        
00006 // %                                                                       
00007 // % $Log: GUSIConfig.h,v $
00008 // % Revision 1.1  2001/03/11 22:33:34  sgehani%netscape.com
00009 // % First Checked In.
00010 // %                                               
00011 // % Revision 1.18  2001/01/22 04:31:11  neeri                             
00012 // % Last minute changes for 2.1.5                                         
00013 // %                                                                       
00014 // % Revision 1.17  2001/01/17 08:40:17  neeri                             
00015 // % Prevent inlining of overridable functions                             
00016 // %                                                                       
00017 // % Revision 1.16  2000/05/23 06:54:39  neeri                             
00018 // % Improve formatting, update to latest universal headers                
00019 // %                                                                       
00020 // % Revision 1.15  2000/03/15 07:10:29  neeri                             
00021 // % Fix suffix searching code                                             
00022 // %                                                                       
00023 // % Revision 1.14  2000/03/06 06:24:34  neeri                             
00024 // % Fix plausibility tests for A5                                         
00025 // %                                                                       
00026 // % Revision 1.13  1999/09/26 03:56:44  neeri                             
00027 // % Sanity check for A5                                                   
00028 // %                                                                       
00029 // % Revision 1.12  1999/08/26 05:44:59  neeri                             
00030 // % Fixes for literate edition of source code                             
00031 // %                                                                       
00032 // % Revision 1.11  1999/06/28 05:57:03  neeri                             
00033 // % Support SIGINT generation                                             
00034 // %                                                                       
00035 // % Revision 1.10  1999/05/29 06:26:41  neeri                             
00036 // % Fixed header guards                                                   
00037 // %                                                                       
00038 // % Revision 1.9  1999/03/29 09:51:28  neeri                              
00039 // % New configuration system with support for hardcoded configurations.   
00040 // %                                                                       
00041 // % Revision 1.8  1999/03/17 09:05:05  neeri                              
00042 // % Added GUSITimer, expanded docs                                        
00043 // %                                                                       
00044 // % Revision 1.7  1998/10/11 16:45:10  neeri                              
00045 // % Ready to release 2.0a2                                                
00046 // %                                                                       
00047 // % Revision 1.6  1998/08/01 21:32:01  neeri                              
00048 // % About ready for 2.0a1                                                 
00049 // %                                                                       
00050 // % Revision 1.5  1998/01/25 20:53:52  neeri                              
00051 // % Engine implemented, except for signals & scheduling                   
00052 // %                                                                       
00053 // % Revision 1.4  1997/11/13 21:12:10  neeri                              
00054 // % Fall 1997                                                             
00055 // %                                                                       
00056 // % Revision 1.3  1996/11/24  13:00:27  neeri                             
00057 // % Fix comment leaders                                                   
00058 // %                                                                       
00059 // % Revision 1.2  1996/11/24  12:52:06  neeri                             
00060 // % Added GUSIPipeSockets                                                 
00061 // %                                                                       
00062 // % Revision 1.1.1.1  1996/11/03  02:43:32  neeri                         
00063 // % Imported into CVS                                                     
00064 // %                                                                       
00065 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  
00066 //                                                                         
00067 // \chapter{GUSI Configuration settings}                                   
00068 //                                                                         
00069 // GUSI stores its global configuration settings in the [[GUSIConfiguration]] 
00070 // singleton class. To create the instance, GUSI calls the [[GUSISetupConfig]]
00071 // hook.                                                                   
00072 //                                                                         
00073 // <GUSIConfig.h>=                                                         
00074 #ifndef _GUSIConfig_
00075 #define _GUSIConfig_
00076 
00077 #ifdef GUSI_SOURCE
00078 
00079 #include "GUSIFileSpec.h"
00080 
00081 #include <ConditionalMacros.h>
00082 
00083 #if PRAGMA_STRUCT_ALIGN
00084 #pragma options align=native
00085 #endif
00086 
00087 // \section{Definition of configuration settings}                          
00088 //                                                                         
00089 // The GUSIConfiguration has a single instance with read only access, accessible
00090 // with the static [[Instance]] member function.                           
00091 //                                                                         
00092 // <Definition of class [[GUSIConfiguration]]>=                            
00093 class GUSIConfiguration {
00094 public:
00095        enum { kNoResource = -1, kDefaultResourceID = 10240 };
00096        
00097        static GUSIConfiguration *  Instance();
00098        static GUSIConfiguration *  CreateInstance(short resourceID = kDefaultResourceID);
00099        
00100        // To determine the file type and creator of a newly created file, we first try 
00101  // to match one of the [[FileSuffix]] suffices.                            
00102  //                                                                         
00103  // <Type and creator rules for newly created files>=                       
00104  struct FileSuffix {
00105        char   suffix[4];
00106        OSType suffType;
00107        OSType suffCreator;
00108  };
00109  short               fNumSuffices;
00110  FileSuffix * fSuffices;
00111 
00112  void ConfigureSuffices(short numSuffices, FileSuffix * suffices);
00113  // If none of the suffices matches, we apply the default type and creator. These
00114  // rules are applied with [[SetDefaultFType]].                             
00115  //                                                                         
00116  // <Type and creator rules for newly created files>=                       
00117  OSType              fDefaultType;
00118  OSType              fDefaultCreator;
00119 
00120  void ConfigureDefaultTypeCreator(OSType defaultType, OSType defaultCreator);
00121  void SetDefaultFType(const GUSIFileSpec & name) const;
00122        // To simplify Macintosh friendly ports of simple, I/O bound programs it is 
00123  // possible to specify automatic yielding on read() and write() calls.     
00124  // [[AutoSpin]] will spin a cursor and/or yield the CPU if desired.        
00125  //                                                                         
00126  // <Automatic cursor spin>=                                                
00127  bool fAutoSpin;
00128 
00129  void ConfigureAutoSpin(bool autoSpin);
00130  void AutoSpin() const;
00131        // GUSI applications can crash hard if QuickDraw is not initialized. Therefore, we
00132  // offer to initialize it automatically with the [[fAutoInitGraf]] feature.
00133  //                                                                         
00134  // <Automatic initialization of QuickDraw>=                                
00135  bool fAutoInitGraf;
00136 
00137  void ConfigureAutoInitGraf(bool autoInitGraf);
00138  void AutoInitGraf();
00139        // Due to the organization of a UNIX filesystem, it is fairly easy to find 
00140  // out how many subdirectories a given directory has, since the [[nlink]] field of 
00141  // its inode will automatically contain the number of subdirectories[[+2]]. Therefore,
00142  // some UNIX derived code depends on this behaviour. When [[fAccurateStat]] is set, 
00143  // GUSI emulates this behaviour, but be warned that this makes [[stat]] on 
00144  // directories a much more expensive operation. If [[fAccurateStat]] is not set,
00145  // stat() gives the total number of entries in the directory[[+2]] as a conservative 
00146  // estimate.                                                               
00147  //                                                                         
00148  // <Various flags>=                                                        
00149  bool fAccurateStat;
00150 
00151  void ConfigureAccurateStat(bool accurateState);
00152  // The [[fSigPipe]] feature causes a signal [[SIGPIPE]] to be raised if an attempt
00153  // is made to write to a broken pipe.                                      
00154  //                                                                         
00155  // <Various flags>=                                                        
00156  bool         fSigPipe;
00157 
00158  void ConfigureSigPipe(bool sigPipe);
00159  void BrokenPipe();
00160  // The [[fSigInt]] feature causes a signal [[SIGINT]] to be raised if the user presses
00161  // command-period.                                                         
00162  //                                                                         
00163  // <Various flags>=                                                        
00164  bool         fSigInt;
00165 
00166  void ConfigureSigInt(bool sigInt);
00167  void CheckInterrupt();
00168  // If [[fSharedOpen]] is set, open() opens files with shared read/write permission.
00169  //                                                                         
00170  // <Various flags>=                                                        
00171  bool         fSharedOpen;
00172 
00173  void ConfigureSharedOpen(bool sharedOpen);
00174  // If [[fHandleAppleEvents]] is set, GUSI automatically handles AppleEvents in its 
00175  // event handling routine.                                                 
00176  //                                                                         
00177  // <Various flags>=                                                        
00178  bool         fHandleAppleEvents;
00179 
00180  void ConfigureHandleAppleEvents(bool handleAppleEvents);
00181 protected:
00182        GUSIConfiguration(short resourceID = kDefaultResourceID);
00183 private:
00184        // \section{Implementation of configuration settings}                      
00185  //                                                                         
00186  // The sole instance of [[GUSIConfiguration]] is created on demand.        
00187  //                                                                         
00188  // <Privatissima of [[GUSIConfiguration]]>=                                
00189  static GUSIConfiguration * sInstance;
00190  // [[ConfigureSuffices]] sets up the suffix table.                         
00191  //                                                                         
00192  // <Privatissima of [[GUSIConfiguration]]>=                                
00193  bool fWeOwnSuffices;
00194  // [[AutoSpin]] tests the flag inline, but performs the actual spinning out of
00195  // line.                                                                   
00196  //                                                                         
00197  // <Privatissima of [[GUSIConfiguration]]>=                                
00198  void DoAutoSpin() const;
00199  // [[AutoInitGraf]] works rather similarly to [[AutoSpin]].                
00200  //                                                                         
00201  // <Privatissima of [[GUSIConfiguration]]>=                                
00202  void DoAutoInitGraf();
00203  // [[CheckInterrupt]] raises a [[SIGINT]] signal if desired.               
00204  //                                                                         
00205  // <Privatissima of [[GUSIConfiguration]]>=                                
00206  bool CmdPeriod(const EventRecord * event);
00207 };
00208 
00209 #if PRAGMA_STRUCT_ALIGN
00210 #pragma options align=reset
00211 #endif
00212 
00213 // To create the sole instance of [[GUSIConfiguration]], we call [[GUSISetupConfig]]
00214 // which has to call [[GUSIConfiguration::CreateInstance]].                
00215 //                                                                         
00216 // <Definition of [[GUSISetupConfig]] hook>=                               
00217 #ifdef __MRC__
00218 #pragma noinline_func GUSISetupConfig
00219 #endif
00220 
00221 extern "C" void GUSISetupConfig();
00222 // <Inline member functions for class [[GUSIConfiguration]]>=              
00223 inline GUSIConfiguration * GUSIConfiguration::Instance()
00224 {
00225        if (!sInstance)
00226               GUSISetupConfig();
00227        if (!sInstance)
00228               sInstance = new GUSIConfiguration();
00229        
00230        return sInstance;
00231 }
00232 
00233 inline GUSIConfiguration * GUSIConfiguration::CreateInstance(short resourceID)
00234 {
00235        if (!sInstance)
00236               sInstance = new GUSIConfiguration(resourceID);
00237        
00238        return sInstance;
00239 }
00240 // <Inline member functions for class [[GUSIConfiguration]]>=              
00241 inline void GUSIConfiguration::ConfigureDefaultTypeCreator(OSType defaultType, OSType defaultCreator)
00242 {
00243        fDefaultType  = defaultType;
00244        fDefaultCreator      = defaultCreator;
00245 }
00246 // <Inline member functions for class [[GUSIConfiguration]]>=              
00247 inline void GUSIConfiguration::ConfigureAutoSpin(bool autoSpin)
00248 {
00249        fAutoSpin = autoSpin;
00250 }
00251 // <Inline member functions for class [[GUSIConfiguration]]>=              
00252 inline void GUSIConfiguration::AutoSpin() const
00253 {
00254        if (fAutoSpin)
00255               DoAutoSpin();
00256 }
00257 // <Inline member functions for class [[GUSIConfiguration]]>=              
00258 inline void GUSIConfiguration::ConfigureAutoInitGraf(bool autoInitGraf)
00259 {
00260        fAutoInitGraf        = autoInitGraf;
00261 }
00262 // <Inline member functions for class [[GUSIConfiguration]]>=              
00263 inline void GUSIConfiguration::AutoInitGraf()
00264 {
00265        if (fAutoInitGraf)
00266               DoAutoInitGraf();
00267 }
00268 // <Inline member functions for class [[GUSIConfiguration]]>=              
00269 inline void GUSIConfiguration::ConfigureSigPipe(bool sigPipe)
00270 {
00271        fSigPipe      = sigPipe;
00272 }
00273 // <Inline member functions for class [[GUSIConfiguration]]>=              
00274 inline void GUSIConfiguration::ConfigureSigInt(bool sigInt)
00275 {
00276        fSigInt       = sigInt;
00277 }
00278 // <Inline member functions for class [[GUSIConfiguration]]>=              
00279 inline void GUSIConfiguration::ConfigureAccurateStat(bool accurateStat)
00280 {
00281        fAccurateStat        = accurateStat;
00282 }
00283 inline void GUSIConfiguration::ConfigureSharedOpen(bool sharedOpen)
00284 {
00285        fSharedOpen   = sharedOpen;
00286 }
00287 #endif /* GUSI_SOURCE */
00288 
00289 #endif /* _GUSIConfig_ */