Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNSignals.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 #ifndef MN_OSS_SIGNALS_H 00025 #define MN_OSS_SIGNALS_H 00026 00027 #if 0 00028 00029 #include "MNList.h" 00030 #include "MNThread.h" 00031 #include "MNMsg.h" 00032 00033 /* 00034 * REQUIRES: 00035 * gcc to define _THREAD_SAFE when compiling multi-threading 00036 * configure to define HAVE_STRERROR_R is strerror_r exists 00037 * configure for signal.h 00038 * configure for string.h 00039 */ 00040 00041 #include <signal.h> /* for the signals */ 00042 00043 /*********************************************************************** 00044 * Type: Class 00045 * Name: MNSigHandler 00046 * Short: handle Unix signals that were caught by MNSigMgr 00047 */ 00048 00049 class MNSigHandler 00050 { 00051 public: 00052 /******************************************************************* 00053 * Name: MNSigHandler 00054 * Short: constructor 00055 */ 00056 00057 MNSigHandler() { } 00058 00059 /******************************************************************* 00060 * Name: bool raise() 00061 * Short: pure virtual function implemented for this signal 00062 */ 00063 00064 virtual bool raise() = 0; 00065 }; 00066 00067 00068 /*********************************************************************** 00069 * Type: Class 00070 * Name: MNSigMgr 00071 * Short: handle various Unix signals and direct to MNSigHandlers 00072 */ 00073 00074 class MNSigMgr 00075 : public MNThread 00076 { 00077 sigset_t _oldset; 00078 00079 public: 00080 /*********************************************************************** 00081 * Type: Enum 00082 * Name: MNSignal 00083 * Short: enum of existing signals, assigned to system's signal id 00084 */ 00085 00086 enum MNSignal 00087 { 00088 MNSigNONE = 0, /* not a signal */ 00089 00090 /* 00091 * POSIX signals - supported by medianode 00092 */ 00093 MNSigHUP = SIGHUP, /* hangup, generated when terminal disconnects */ 00094 MNSigINT = SIGINT, /* interrupt, generated from terminal special char */ 00095 MNSigQUIT = SIGQUIT, /* (*) quit, generated from terminal special char */ 00096 MNSigILL = SIGILL, /* (*) illegal instruction (not reset when caught)*/ 00097 MNSigTRAP = SIGTRAP, /* (*) trace trap (not reset when caught) */ 00098 MNSigABRt = SIGABRT, /* (*) abort process */ 00099 MNSigFPE = SIGFPE, /* (*) floating point exception */ 00100 MNSigKILL = SIGKILL, /* kill (cannot be caught or ignored) */ 00101 MNSigBUS = SIGBUS, /* (*) bus error (specification exception) */ 00102 MNSigSEGV = SIGSEGV, /* (*) segmentation violation */ 00103 MNSigPIPE = SIGPIPE, /* write on a pipe with no one to read it */ 00104 MNSigALRM = SIGALRM, /* alarm clock timeout */ 00105 MNSigTERM = SIGTERM, /* software termination signal */ 00106 MNSigCHLD = SIGCHLD, /* (+) sent to parent on child stop or exit */ 00107 MNSigUSR1 = SIGUSR1, /* user defined signal 1 */ 00108 MNSigUSR2 = SIGUSR2, /* user defined signal 2 */ 00109 00110 /* 00111 * POSIX signals - supported by medianode 00112 */ 00113 MNSigURG = SIGURG, /* (+) urgent contition on I/O channel */ 00114 MNSigSTOP = SIGSTOP, /* (@) stop (cannot be caught or ignored) */ 00115 MNSigTSTP = SIGTSTP, /* (@) interactive stop */ 00116 MNSigCONT = SIGCONT, /* (!) continue (cannot be caught or ignored) */ 00117 MNSigTTIN = SIGTTIN, /* (@) background read attempted from control terminal*/ 00118 MNSigTTOU = SIGTTOU, /* (@) background write attempted to control terminal */ 00119 MNSigIO = SIGIO, /* (+) I/O possible, or completed */ 00120 MNSigXCPU = SIGXCPU, /* cpu time limit exceeded (see setrlimit()) */ 00121 MNSigXFSZ = SIGXFSZ, /* file size limit exceeded (see setrlimit()) */ 00122 MNSigWINCH = SIGWINCH, /* (+) window size changed */ 00123 MNSigPROF = SIGPROF, /* profiling time alarm (see setitimer) */ 00124 MNSigVTALRM = SIGVTALRM, /* virtual time alarm (see setitimer) */ 00125 #if defined(_AIX) || defined(linux) 00126 MNSigPWR = SIGPWR, /* (+) power-fail restart */ 00127 #endif 00128 #ifdef _AIX 00129 MNSigEMT = SIGEMT, /* EMT intruction */ 00130 MNSigSYS = SIGSYS, /* (*) bad argument to system call */ 00131 MNSigMSG = SIGMSG, /* input data is in the ring buffer */ 00132 MNSigDANGER = SIGDANGER, /* system crash imminent; free up some page space */ 00133 MNSigMIGRATE = SIGMIGRATE, /* migrate process */ 00134 MNSigPRE = SIGPRE, /* programming exception */ 00135 MNSigVIRT = SIGVIRT, /* AIX virtual time alarm */ 00136 MNSigALRM1 = SIGALRM1, /* m:n condition variables */ 00137 MNSigWAITING = SIGWAITING, /* m:n scheduling */ 00138 MNSigKAP = SIGKAP, /* keep alive poll from native keyboard */ 00139 MNSigRETRACT = SIGRETRACT, /* monitor mode should be relinguished */ 00140 MNSigSOUND = SIGSOUND, /* sound control has completed */ 00141 MNSigSAK = SIGSAK /* secure attention key */ 00142 #endif 00143 }; 00144 00145 private: 00146 /******************************************************************* 00147 * Name: bool _activeHandler[] 00148 * Short: indicates whether a thread has registered a private handler 00149 */ 00150 00151 bool _activeHandler[17]; 00152 00153 /******************************************************************* 00154 * Name: MNList<MNSigHandler*> _handlerList[] 00155 * Short: lists of active handlers, indexed by signal index 00156 */ 00157 00158 MNList<MNSigHandler*> _handlerList[17]; 00159 00160 /******************************************************************* 00161 * Name: const char* mapSigToName( MNSignal ) 00162 * Short: returns a name for a signal id 00163 */ 00164 00165 const char* mapSigToName( MNSignal s ) const; 00166 00167 /******************************************************************* 00168 * Name: int mapSigToIndex( MNSignal ) 00169 * Short: returns an integer for a signal id 00170 */ 00171 00172 inline int mapSigToIndex( MNSignal s ) const 00173 { 00174 switch ( s ) 00175 { 00176 case MNSigHUP : return 1; break; 00177 case MNSigINT : return 2; break; 00178 case MNSigQUIT : return 3; break; 00179 case MNSigILL : return 4; break; 00180 case MNSigTRAP : return 5; break; 00181 case MNSigABRt : return 6; break; 00182 case MNSigFPE : return 7; break; 00183 case MNSigKILL : return 8; break; 00184 case MNSigBUS : return 9; break; 00185 case MNSigSEGV : return 10; break; 00186 case MNSigPIPE : return 11; break; 00187 case MNSigALRM : return 12; break; 00188 case MNSigTERM : return 13; break; 00189 case MNSigCHLD : return 14; break; 00190 case MNSigUSR1 : return 15; break; 00191 case MNSigUSR2 : return 16; break; 00192 default: 00193 // I moved the return to end of file because xlC got 00194 // confused here, below as well. 00195 // cg 24nov1999 00196 break; 00197 } 00198 MN_FATAL("uncaught signal map-to-index"); 00199 return -1; 00200 } 00201 00202 /******************************************************************* 00203 * Name: MNSignal mapIndexToSig( int ) 00204 * Short: returns a signal id for an integer 00205 */ 00206 00207 inline MNSignal mapIndexToSig( int i ) const 00208 { 00209 switch ( i ) 00210 { 00211 case 1: return MNSigHUP; break; 00212 case 2: return MNSigINT; break; 00213 case 3: return MNSigQUIT; break; 00214 case 4: return MNSigILL; break; 00215 case 5: return MNSigTRAP; break; 00216 case 6: return MNSigABRt; break; 00217 case 7: return MNSigFPE; break; 00218 case 8: return MNSigKILL; break; 00219 case 9: return MNSigBUS; break; 00220 case 10: return MNSigSEGV; break; 00221 case 11: return MNSigPIPE; break; 00222 case 12: return MNSigALRM; break; 00223 case 13: return MNSigTERM; break; 00224 case 14: return MNSigCHLD; break; 00225 case 15: return MNSigUSR1; break; 00226 case 16: return MNSigUSR2; break; 00227 default: 00228 break; 00229 } 00230 MN_FATAL("uncaught signal map-to-signal"); 00231 return MNSigNONE; 00232 } 00233 00234 public: 00235 /******************************************************************* 00236 * Name: MNSigMgr 00237 * Short: constructor 00238 */ 00239 MNSigMgr(); 00240 00241 /******************************************************************* 00242 * Name: bool init_before_thread_start() 00243 * Short: we can not really block signals on Solaris 00244 */ 00245 bool init_before_thread_start(); 00246 00247 /******************************************************************* 00248 * Name: void reg( MNSignal, MNSigHandler* ) 00249 * Short: registers a Handler for a signal 00250 */ 00251 00252 void reg( MNSignal s, MNSigHandler* handler ); 00253 00254 /******************************************************************* 00255 * Name: void dereg( MNSignal, MNSigHandler* ) 00256 * Short: removes a handler for a signal 00257 */ 00258 00259 void dereg( MNSignal s, MNSigHandler* handler ); 00260 00261 /******************************************************************* 00262 * Name: virtual void run (); 00263 * Short: body of the thread that waits for signals 00264 */ 00265 00266 virtual void run (); 00267 }; 00268 00269 #endif /* 0 */ 00270 00271 #endif /* MN_OSS_SIGNALS_H */ 00272

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8