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
SigHandlersList.h
Go to the documentation of this file.
1
// -*- c++ -*-
2
//---------------------------------------------------------------------------
3
// SigHandlersList.h
4
//------------------------------------------------------------------------------
5
// Copyright (c) 1997 by Vladislav Grinchenko
6
//
7
// Permission to use, copy, modify, and distribute this software
8
// and its documentation for any purpose and without fee is hereby
9
// granted, provided that the above copyright notice appear in all
10
// copies. The author makes no representations about the suitability
11
// of this software for any purpose. It is provided "as is" without
12
// express or implied warranty.
13
//---------------------------------------------------------------------------
14
15
#ifndef _SigHandlersList_h
16
#define _SigHandlersList_h
17
18
#include <signal.h>
19
#include <errno.h>
20
#include <sys/time.h>
21
#include <sys/types.h>
22
23
#include "
assa/SigHandler.h
"
24
25
#include <set>
26
using
std::set;
27
28
namespace
ASSA {
29
30
#if !defined(WIN32)
31
44
class
CFUNC_Handler
:
public
EventHandler
45
{
46
public
:
47
CFUNC_Handler
(
C_SIG_HANDLER
csigh_);
48
49
int
handle_signal
(
int
signum_);
50
C_SIG_HANDLER
handler
() {
return
m_c_sig_hand
; }
51
52
private
:
53
C_SIG_HANDLER
m_c_sig_hand
;
54
};
55
65
class
SigHandlersList
66
{
67
public
:
68
typedef
EventHandler
*
key_type
;
69
typedef
EventHandler
*
data_type
;
70
71
struct
CompSHL
{
72
bool
operator ()
(
const
key_type
c1_,
const
key_type
c2_)
const
73
{
74
// This wouldn't fly on 64-bit machines, 'cause ptr size there is 8 bytes long
75
// return int(c1_) < int(c2_);
76
//
77
return
(c1_ < c2_);
78
}
79
};
80
81
typedef
set< key_type, CompSHL >
set_t
;
82
typedef
set< key_type, CompSHL >::iterator
iterator
;
83
87
static
SigHandlersList
*
instance
(
int
signum_);
88
90
~SigHandlersList
();
91
93
bool
empty
()
const
;
94
96
size_t
size
()
const
;
97
101
bool
insert
(
data_type
data_);
102
105
void
erase
(
const
key_type
key_);
106
110
void
erase
(
iterator
it_);
111
114
void
erase
();
115
118
iterator
begin
();
119
122
iterator
end
();
123
127
iterator
find
(
const
key_type
key_);
128
134
CFUNC_Handler
*
cfunc_handler
(
CFUNC_Handler
* cfp_);
135
139
CFUNC_Handler
*
cfunc_handler
()
const
;
140
144
void
seen_cfunc_handler
(
bool
ft_);
145
149
bool
seen_cfunc_handler
()
const
;
150
151
protected
:
152
SigHandlersList
();
// Singleton
153
SigHandlersList
(
const
SigHandlersList
& map_);
// prohibit copying
154
SigHandlersList
&
operator=
(
const
SigHandlersList
& map_);
155
156
public
:
159
static
SigHandlersList
*
m_instance
[NSIG];
160
161
private
:
163
set_t
*
m_set
;
164
169
int
m_seen_cfh
;
170
173
CFUNC_Handler
*
m_cfhp
;
174
};
175
176
//-------------------------------------------------------------------------
177
//----------------------- SigHandlersList Inlines -------------------------
178
//-------------------------------------------------------------------------
179
180
inline
181
SigHandlersList::
182
SigHandlersList
()
183
: m_seen_cfh (false), m_cfhp (NULL)
184
{
185
trace_with_mask
(
"SigHandlersList::SigHandlersList"
,
SIGHAND
);
186
187
m_set
=
new
set_t
;
188
}
189
190
inline
191
SigHandlersList::
192
~SigHandlersList
()
193
{
194
trace_with_mask
(
"SigHandlersList::~SigHandlersList"
,
SIGHAND
);
195
196
erase
();
197
delete
m_set
;
198
m_set
= NULL;
199
}
200
201
inline
SigHandlersList
*
202
SigHandlersList::
203
instance
(
int
signum_)
204
{
205
trace_with_mask
(
"SigHandlersList::instance"
,
SIGHAND
);
206
207
DL
((
APP
,
"m_instance[%d] = 0x%x\n"
, signum_,
208
SigHandlersList::m_instance
[signum_]));
209
210
if
(
SigHandlersList::m_instance
[signum_] == 0) {
211
DL
((
APP
,
"new SigHandlersList allocated\n"
));
212
SigHandlersList::m_instance
[signum_] =
new
SigHandlersList
();
213
}
214
return
SigHandlersList::m_instance
[signum_];
215
}
216
217
inline
bool
218
SigHandlersList::
219
empty
()
const
220
{
221
trace_with_mask
(
"SigHandlersList::empty"
,
SIGHAND
);
222
223
// true if map is empty, false otherwise
224
225
return
m_set
->empty ();
226
}
227
228
inline
size_t
229
SigHandlersList::
230
size
()
const
231
{
232
trace_with_mask
(
"SigHandlersList::size"
,
SIGHAND
);
233
234
// return number of elements in the map
235
236
return
m_set
->size ();
237
}
238
239
inline
bool
240
SigHandlersList::
241
insert
(
data_type
eh_)
242
{
243
trace_with_mask
(
"SigHandlersList::insert"
,
SIGHAND
);
244
245
/*---
246
Insert 'eh_' into the set. set::insert() returns a 'pair' object.
247
248
If the set doesn't contain an element that matches 'eh_', insert a
249
copy of 'eh_' and returns a 'pair' whose first element is an
250
iterator positioned at the new element and second element is
251
'true'.
252
253
If the set already contains an element that matches 'eh_', returns
254
a pair whose first element is an iterator positioned at the
255
existing element and second element is false!
256
---*/
257
258
set_t::const_iterator it =
m_set
->find (eh_);
259
260
/*--- Not in the set ---*/
261
if
(it ==
m_set
->end ()) {
262
return
(
m_set
->insert (eh_)).second;
263
}
264
/*--- Already in the set ---*/
265
return
true
;
266
}
267
268
inline
void
269
SigHandlersList::
270
erase
(
const
key_type
key_)
271
{
272
// return number of erased elements
273
trace_with_mask
(
"SigHandlersList::erase(key_)"
,
SIGHAND
);
274
275
m_set
->erase (key_);
276
}
277
278
inline
void
279
SigHandlersList::
280
erase
()
281
{
282
// empty the map
283
trace_with_mask
(
"SigHandlersList::erase(void)"
,
SIGHAND
);
284
285
m_set
->erase (
m_set
->begin(),
m_set
->end());
286
}
287
288
inline
void
289
SigHandlersList::
290
erase
(
iterator
it_)
291
{
292
// erase element pointed by iterator
293
trace_with_mask
(
"SigHandlersList::erase(it_)"
,
SIGHAND
);
294
295
m_set
->erase(it_);
296
}
297
298
inline
SigHandlersList::iterator
299
SigHandlersList::
300
begin
()
301
{
302
trace_with_mask
(
"SigHandlersList::begin()"
,
SIGHAND
);
303
304
return
m_set
->begin ();
305
}
306
307
inline
SigHandlersList::iterator
308
SigHandlersList::
309
end
()
310
{
311
trace_with_mask
(
"SigHandlersList::end"
,
SIGHAND
);
312
313
return
m_set
->end ();
314
}
315
316
inline
SigHandlersList::iterator
317
SigHandlersList::
318
find
(
const
key_type
key_)
319
{
320
trace_with_mask
(
"SigHandlersList::find"
,
SIGHAND
);
321
322
return
m_set
->find (key_);
323
}
324
325
326
inline
CFUNC_Handler
*
327
SigHandlersList::
328
cfunc_handler
(
CFUNC_Handler
* cfhp_)
329
{
330
trace_with_mask
(
"SigHandlersList::cfunc_handler"
,
SIGHAND
);
331
332
CFUNC_Handler
* old_cfhp =
m_cfhp
;
333
m_cfhp
= cfhp_;
334
m_seen_cfh
= cfhp_ == NULL ?
false
:
true
;
335
return
old_cfhp;
336
}
337
338
inline
CFUNC_Handler
*
339
SigHandlersList::
340
cfunc_handler
()
const
341
{
342
trace_with_mask
(
"SigHandlersList::cfunc_handler"
,
SIGHAND
);
343
344
return
m_cfhp
;
345
}
346
347
inline
void
348
SigHandlersList::
349
seen_cfunc_handler
(
bool
ft_)
350
{
351
trace_with_mask
(
"SigHandlersList::seen_cfunc_handler"
,
SIGHAND
);
352
353
m_seen_cfh
= ft_;
354
}
355
356
inline
bool
357
SigHandlersList::
358
seen_cfunc_handler
()
const
359
{
360
trace_with_mask
(
"SigHandlersList::seen_cfunc_handler"
,
SIGHAND
);
361
362
return
m_seen_cfh
;
363
}
364
365
//-------------------------------------------------------------------------
366
//------------------------ CFUNC_Handler Inlines --------------------------
367
//-------------------------------------------------------------------------
368
369
inline
370
CFUNC_Handler::
371
CFUNC_Handler
(
C_SIG_HANDLER
csigh_)
372
: m_c_sig_hand (csigh_)
373
{
374
trace_with_mask
(
"CFUNC_Handler::CFUNC_Handler"
,
SIGHAND
);
375
}
376
377
inline
int
378
CFUNC_Handler::
379
handle_signal
(
int
signum_)
380
{
381
trace_with_mask
(
"CFUNC_Handler::handle_signal"
,
SIGHAND
);
382
383
if
(
m_c_sig_hand
) {
384
(*m_c_sig_hand)(signum_);
385
}
386
return
1;
387
}
388
389
#endif // !defined(WIN32)
390
391
}
// end namespace ASSA
392
393
#endif
/* _SigHandlersList_h */
394
Generated on Fri Apr 11 2014 13:12:32 for libassa by
1.8.1.2