PEP 55 Update license on source files to current license text and date
[tpot/pegasus/.git] / src / Pegasus / Common / Signal.h
1 //%2003////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 // 
15 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Markus Mueller (markus_mueller@de.ibm.com)
27 //
28 // Modified By: Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
29 //            : Yi Zhou, Hewlett-Packard Company (yi_zhou@hp.com)
30 //
31 //%/////////////////////////////////////////////////////////////////////////////
32
33 #ifndef Pegasus_Signal_h
34 #define Pegasus_Signal_h
35
36 #include <Pegasus/Common/Linkage.h>
37 #include <Pegasus/Common/IPC.h>
38
39 // // Ensure Unix 98
40 // #ifdef PEGASUS_PLATFORM_LINUX_IX86_GNU
41 //    #ifndef _GNU_SOURCE
42 //       #define _GNU_SOURCE
43 //    #endif
44 // #else
45 //    #ifdef _XOPEN_SOURCE
46 //       #undef _XOPEN_SOURCE
47 //    #endif
48 //    #define _XOPEN_SOURCE 600
49 // #endif
50
51 #ifdef PEGASUS_HAS_SIGNALS
52
53 # include <signal.h>
54 typedef siginfo_t PEGASUS_SIGINFO_T;
55 # define PEGASUS_SIGHUP   SIGHUP
56 # define PEGASUS_SIGABRT  SIGABRT
57 # define PEGASUS_SIGPIPE  SIGPIPE
58 # define PEGASUS_SIGTERM  SIGTERM
59 # define PEGASUS_SIGUSR1  SIGUSR1
60
61 #else // PEGASUS_HAS_SIGNALS
62
63 typedef void PEGASUS_SIGINFO_T;
64 # define PEGASUS_SIGHUP   1
65 # define PEGASUS_SIGABRT  11
66 # define PEGASUS_SIGPIPE  13
67 # define PEGASUS_SIGTERM  15
68 # define PEGASUS_SIGUSR1  16
69
70 #endif // PEGASUS_HAS_SIGNALS
71
72
73 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
74 extern "C" {
75 #endif
76
77 typedef void (* signal_handler)(int, PEGASUS_SIGINFO_T *, void *);
78
79 #if defined(PEGASUS_PLATFORM_ZOS_ZSERIES_IBM)
80 }
81 #endif
82
83 // Sample signal handler for SIGABRT that stops the failing thread normally
84 void sig_act(int s_n, PEGASUS_SIGINFO_T * s_info, void * sig);
85
86 PEGASUS_NAMESPACE_BEGIN
87
88 class PEGASUS_COMMON_LINKAGE SignalHandler
89 {
90    public:
91       SignalHandler();
92
93       ~SignalHandler(); // deactivate all registered handlers
94
95       // these functions should throw exceptions
96
97       void registerHandler(Uint32 signum, signal_handler _sighandler);
98
99       void activate(Uint32 signum);
100
101       //void activateAll();
102
103       void deactivate(Uint32 signum);
104
105       void deactivateAll();
106
107       static void ignore(Uint32 signum);
108
109    private:
110
111 #ifdef PEGASUS_HAS_SIGNALS
112       typedef struct {
113           int active;
114           signal_handler sh;
115           struct sigaction oldsa;
116       } register_handler;
117
118       register_handler reg_handler[32];
119       Mutex reg_mutex;
120
121       void deactivate_i(Uint32 signum);
122 #endif
123
124 };
125
126 PEGASUS_COMMON_LINKAGE SignalHandler * getSigHandle();
127
128 PEGASUS_NAMESPACE_END
129
130 #endif // Pegasus_Signal_h