libassa
3.5.1
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
assa
Handlers.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//------------------------------------------------------------------------------
3
// Handlers.h
4
//------------------------------------------------------------------------------
5
// Copyright (c) 2000,2005 by Vladislav Grinchenko
6
//
7
// This library is free software; you can redistribute it and/or
8
// modify it under the terms of the GNU Library General Public
9
// License as published by the Free Software Foundation; either
10
// version 2 of the License, or (at your option) any later version.
11
//------------------------------------------------------------------------
12
13
#ifndef _Handlers_h
14
#define _Handlers_h
15
16
#include <sys/types.h>
17
18
#if !defined(WIN32)
19
# include <sys/wait.h>
20
#endif
21
22
#include "
assa/EventHandler.h
"
23
#include "
assa/Assure.h
"
24
25
namespace
ASSA {
26
27
#if !defined(WIN32)
28
35
#if defined (__FreeBSD__) || defined(__FreeBSD_kernel__) || defined (__NetBSD__)
36
# define ASSAIOSIG SIGIO
37
#else
38
# define ASSAIOSIG SIGPOLL
39
#endif
40
45
class
SIGINTHandler
:
public
EventHandler
46
{
47
public
:
49
SIGINTHandler
();
50
54
int
handle_signal
(
int
signum_);
55
60
sig_atomic_t
graceful_quit
();
61
63
void
resetState
();
64
65
private
:
67
sig_atomic_t
m_graceful_quit
;
68
};
69
70
inline
71
SIGINTHandler::
72
SIGINTHandler
()
73
: m_graceful_quit (0)
74
{
75
trace_with_mask
(
"SIGINTHandler::SIGINTHandler"
,
SIGHAND
);
76
}
77
78
inline
int
79
SIGINTHandler::
80
handle_signal
(
int
signum_)
81
{
82
trace_with_mask
(
"SIGINTHandler::handle_signal"
,
SIGHAND
);
83
84
if
(signum_ == SIGINT) {
85
m_graceful_quit
= 1;
86
return
0;
87
}
88
return
-1;
89
}
90
91
inline
sig_atomic_t
92
SIGINTHandler::
93
graceful_quit
()
94
{
95
return
m_graceful_quit
;
96
}
97
98
inline
void
99
SIGINTHandler::
100
resetState
()
101
{
102
trace_with_mask
(
"SIGINTHandler::resetState"
,
SIGHAND
);
103
104
m_graceful_quit
= 0;
105
}
106
112
class
SIGUSR1Handler
:
public
EventHandler
113
{
114
public
:
117
SIGUSR1Handler
() :
m_count
(0) {
118
trace_with_mask
(
"SIGUSR1Handler::SIGUSR1Handler"
,
SIGHAND
);
119
}
120
123
int
handle_signal
(
int
signum_) {
124
trace_with_mask
(
"SIGUSR1Handler::handle_signal()"
,
SIGHAND
);
125
126
if
(signum_ == SIGUSR1) {
127
m_count
++;
128
DL
((
TRACE
,
"signal count = %d\n"
,
m_count
));
129
return
0;
130
}
131
return
-1;
132
}
133
136
sig_atomic_t
received_count
()
const
{
return
m_count
; }
137
140
void
resetState
() {
m_count
= 0; }
141
142
private
:
144
sig_atomic_t
m_count
;
145
};
146
147
150
class
SIGUSR2Handler
:
public
EventHandler
151
{
152
public
:
155
SIGUSR2Handler
() :
m_count
(0) {
156
trace_with_mask
(
"SIGUSR2Handler::SIGUSR2Handler"
,
SIGHAND
);
157
}
158
161
int
handle_signal
(
int
signum_) {
162
trace_with_mask
(
"SIGUSR2Handler::handle_signal()"
,
SIGHAND
);
163
164
if
(signum_ == SIGUSR2) {
165
m_count
++;
166
DL
((
TRACE
,
"signal count = %d\n"
,
m_count
));
167
return
0;
168
}
169
return
-1;
170
}
171
174
sig_atomic_t
received_count
()
const
{
return
m_count
; }
175
178
void
resetState
() {
m_count
= 0; }
179
180
private
:
182
sig_atomic_t
m_count
;
183
};
184
187
class
SIGCHLDHandler
:
public
EventHandler
188
{
189
public
:
191
SIGCHLDHandler
() :
m_child_exit_flag
(0) {
192
trace_with_mask
(
"SIGCHLDHandler::SIGCHLDHandler"
,
SIGHAND
);
193
}
194
197
int
handle_signal
(
int
signum_) {
198
trace_with_mask
(
"SIGCHLDHandler::handle_signal"
,
SIGHAND
);
199
200
if
(signum_ == SIGCHLD && wait(NULL) != -1) {
201
m_child_exit_flag
= 1;
202
return
0;
203
}
204
return
-1;
205
}
208
sig_atomic_t
child_exited
() {
return
m_child_exit_flag
; }
209
212
void
resetState
() {
m_child_exit_flag
= 0; }
213
214
private
:
216
sig_atomic_t
m_child_exit_flag
;
217
};
218
221
class
SIGALRMHandler
:
public
EventHandler
222
{
223
public
:
225
SIGALRMHandler
() :
m_alarm_flag
(0) {
226
trace_with_mask
(
"SIGALRMHandler::SIGALRMHandler"
,
SIGHAND
);
227
}
228
231
int
handle_signal
(
int
signum_) {
232
trace_with_mask
(
"SIGALRMHandler::handle_signal"
,
SIGHAND
);
233
234
if
(signum_ == SIGALRM) {
235
m_alarm_flag
= 1;
// notice that we have seen alarm
236
return
0;
237
}
238
return
-1;
239
}
240
242
sig_atomic_t
alarmed
() {
return
m_alarm_flag
; }
243
245
void
resetState
() {
m_alarm_flag
= 0; }
246
247
private
:
249
sig_atomic_t
m_alarm_flag
;
250
};
251
252
261
class
SIGPOLLHandler
:
public
EventHandler
262
{
263
public
:
266
SIGPOLLHandler
() {
267
trace_with_mask
(
"SIGPOLLHandler"
,
SIGHAND
);
268
}
271
int
handle_signal
(
int
signum_ ) {
272
trace_with_mask
(
"SIGPOLLHandler::handle_signal"
,
SIGHAND
);
273
274
return
(signum_ ==
ASSAIOSIG
) ? 0 : -1;
275
}
276
};
277
278
#endif // !defined(WIN32)
279
280
}
// end namespace ASSA
281
282
#endif
Generated on Tue Jun 19 2012 09:59:44 for libassa by
1.8.1.1