COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
coSignal.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef _CO_SIGNAL_H_
9 #define _CO_SIGNAL_H_
10 
11 #ifdef _WIN32
12 #define USE_BSD_SIGNALS
13 #endif
14 
15 /**************************************************************************\
16  ** **
17  ** **
18  ** Description: Signal manager class for the COVISE **
19  ** software environment **
20  ** **
21  ** **
22  ** **
23  ** **
24  ** **
25  ** **
26  ** (C) 1995 **
27  ** Computer Center University of Stuttgart **
28  ** Allmandring 30 **
29  ** 70550 Stuttgart **
30  ** **
31  ** Author: A. Werner **
32  ** **
33  ** Date: 25.11.99 V2.0 **
34  ** Last: **
35 \*************************************************************************/
36 
37 #include <stdio.h>
38 #include "coTypes.h"
39 
40 /*
41 #ifdef __sgi
42 
43 // extern "C" void (*signal(int,void (*)(int)))(int);
44 
45 // #define SIG_IGN (void (*)())0 // ignore
46 #define SIGHUP 1 // hangup
47 #define SIGINT 2 // interrupt (rubout)
48 #define SIGQUIT 3 // quit (ASCII FS)
49 #define SIGILL 4 // illegal instruction (not reset when caught)
50 #define SIGTRAP 5 // trace trap (not reset when caught)
51 #define SIGIOT 6 // IOT instruction
52 #define SIGABRT 6 // used by abort, replace SIGIOT in the future
53 #define SIGEMT 7 // EMT instruction
54 #define SIGFPE 8 // floating point exception
55 #define SIGKILL 9 // kill (cannot be caught or ignored)
56 #define SIGBUS 10 // bus error
57 #define SIGSEGV 11 // segmentation violation
58 #define SIGSYS 12 // bad argument to system call
59 #define SIGPIPE 13 // write on a pipe with no one to read it
60 #define SIGALRM 14 // alarm clock
61 #define SIGTERM 15 // software termination signal from kill
62 #define SIGUSR1 16 // user defined signal 1
63 #define SIGUSR2 17 // user defined signal 2
64 //#define SIGCLD 18 // death of a child
65 #define SIGCHLD 18 // 4.3BSD's/POSIX name
66 #define SIGPWR 19 // power-fail restart
67 #define SIGWINCH 20 // window size changes
68 #define SIGURG 21 // urgent condition on IO channel
69 #define SIGPOLL 22 // pollable event occurred
70 #define SIGIO 22 // input/output possible signal
71 #define SIGSTOP 23 // sendable stop signal not from tty
72 #define SIGTSTP 24 // stop signal from tty
73 #define SIGCONT 25 // continue a stopped process
74 #define SIGTTIN 26 // to readers pgrp upon background tty read
75 #define SIGTTOU 27 // like TTIN for output if (tp->t_local&LTOSTOP)
76 #define SIGVTALRM 28 // virtual time alarm
77 #define SIGPROF 29 // profiling alarm
78 #define SIGXCPU 30 // Cpu time limit exceeded
79 #define SIGXFSZ 31 // Filesize limit exceeded
80 #define SIG32 32 // Reserved for kernel usage
81 #define SIGRTMIN 49 // Posix 1003.1b signals
82 #define SIGRTMAX 64 // Posix 1003.1b signals
83 
84 #endif
85 */
86 
87 #if (defined(__sgi) && !defined(_BOOL)) || defined(__sun)
88 
89 typedef int bool;
90 static const int false = 0;
91 static const int true = !false;
92 #endif
93 
94 #include <signal.h>
95 
96 namespace covise
97 {
98 
103 {
104 public:
105  virtual void sigHandler(int sigNo)
106  {
107  (void)sigNo;
108  }
109 
110  virtual const char *sigHandlerName()
111  {
112  return "No name specified";
113  }
114 
116  {
117  }
118 };
119 
124 {
125 
126 public:
128  enum
129  {
130  SIG_NAME_LENGTH = 15
131  };
132 
134  static const char *sigName[NSIG];
135 
136 protected:
138  coSignal();
139 
141  ~coSignal(void);
142 
143 private:
144  // the static and only existing signal handler class : init once
146 
147  // this static function calls the handler class functions
148  static void doHandle(int sig);
149 
150  // a system-independent 'signal' function
151  void my_signal(int sigNo, void (*func)(int));
152 
153  struct handlerRec
154  {
156  struct handlerRec *next;
157  };
158  static handlerRec *s_handler[NSIG];
159 
160 #ifdef USE_BSD_SIGNALS
161  // 'blocking' under BSD : =1 blocked =0 unblocked =-1 pending
162  static int s_blockMask[NSIG];
163 #else
164  // this is what the system blocked before we came in...
165  static sigset_t s_sysMask;
166 #endif
167 
168  // whether we call the system's handler afterwards
169  static bool s_callSys[NSIG];
170 
171 public:
174  {
175  if (!s_instance)
176  s_instance = new coSignal;
177  return s_instance;
178  }
179 
181  static void kill()
182  {
183  delete s_instance;
184  s_instance = NULL;
185  }
186 
188  {
190  KEEP_DFL
191  };
192 
197  static void addSignal(int signo, coSignalHandler &myHandler,
198  enum ReplaceOption sysOpt = REPLACE_DFL,
199  bool atEnd = true);
200 
202  static void removeSignal(int signo, coSignalHandler &myHandler);
203 
205  static void blockSignal(int signo);
206 
208  static void unblockSignal(int signo);
209 
211  static void blockAllSignals();
212 
214  static void unblockAllSignals();
215 
216  //is a signal pending
217  static bool isPending(int signo);
218 
219  static void printBlocks();
220 };
221 }
222 #endif
static void kill()
stop all user-defined signal handling, kill internal states
Definition: coSignal.h:181
void(*)(int) my_signal(int signo, void(*func)(int))
Definition: covise_signal.cpp:157
virtual ~coSignalHandler()
Definition: coSignal.h:115
ReplaceOption
Definition: coSignal.h:187
#define NULL
Definition: covise_list.h:22
virtual void sigHandler(int sigNo)
Definition: coSignal.h:105
static sigset_t s_sysMask
Definition: coSignal.h:165
GLenum func
Definition: khronos-glext.h:6719
virtual const char * sigHandlerName()
Definition: coSignal.h:110
static coSignal * s_instance
Singleton with late construction: construct with first getHandler() call.
Definition: coSignal.h:145
struct handlerRec * next
Definition: coSignal.h:156
Definition: coSignal.h:153
typedef void(APIENTRY *GLDEBUGPROCARB)(GLenum source
Definition: coSignal.h:102
Definition: coSignal.h:189
static coSignal * getHandler()
get a signal handler: if none exists, create it
Definition: coSignal.h:173
Definition: coSignal.h:123
#define UTILEXPORT
Definition: coExport.h:182
coSignalHandler * handler
Definition: coSignal.h:155