libdap
Updated for version 3.20.10
libdap4 is an implementation of OPeNDAP's DAP protocol.
SignalHandler.h
1
2
// -*- mode: c++; c-basic-offset:4 -*-
3
4
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
5
// Access Protocol.
6
7
// Copyright (c) 2002,2003 OPeNDAP, Inc.
8
// Author: James Gallagher <jgallagher@opendap.org>
9
//
10
// This library is free software; you can redistribute it and/or
11
// modify it under the terms of the GNU Lesser General Public
12
// License as published by the Free Software Foundation; either
13
// version 2.1 of the License, or (at your option) any later version.
14
//
15
// This library is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
// Lesser General Public License for more details.
19
//
20
// You should have received a copy of the GNU Lesser General Public
21
// License along with this library; if not, write to the Free Software
22
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
//
24
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
25
26
#ifndef signal_handler_h
27
#define signal_handler_h
28
29
#include <signal.h>
30
31
#include "EventHandler.h"
32
#include "InternalErr.h"
33
34
namespace
libdap
35
{
36
37
typedef
void
Sigfunc(
int
);
// Plauger, 1992
38
66
class
SignalHandler
67
{
68
private
:
69
// Ensure we're a Singleton.
70
SignalHandler
() {}
71
SignalHandler
(
const
SignalHandler
&) {}
72
73
// Singleton pointer.
74
static
SignalHandler
*d_instance;
75
76
// Table of pointers to instances of EventHandlers. Since EventHandler is
77
// abstract, the pointers will actually reference instances that are
78
// children of EventHandler. NSIG is defined in signal.h but this may be
79
// a portability issue.
80
static
EventHandler
*d_signal_handlers[NSIG];
81
82
// This array holds the old signal handlers. Once the handler in
83
// d_signal_handler[signum] is run, look here to see what the original
84
// action was. This is important since libdap++ is often embedded in code
85
// that already has a non-default signal handler for things like SIGINT.
86
static
Sigfunc *d_old_handlers[NSIG];
87
88
// Entry point adapter installed into sigaction(). This must be a static
89
// method (or a regular C-function) to conform to sigaction's interface.
90
// this is the part of SignalHandler that uses the Adapter pattern.
91
static
void
dispatcher(
int
signum);
92
93
// Delete the global instance. Call this with atexit().
94
static
void
delete_instance();
95
96
// Call this using pthread_once() to ensure there's only one instance
97
// when running in a MT world.
98
static
void
initialize_instance();
99
100
friend
class
SignalHandlerTest;
101
friend
class
HTTPCacheTest;
102
103
public
:
104
static
SignalHandler
*
instance
();
105
107
virtual
~SignalHandler
() =
default
;
108
109
EventHandler
*
register_handler
(
int
signum,
EventHandler
*eh,
110
bool
ignore_by_default =
false
);
111
112
EventHandler
*
remove_handler
(
int
signum);
113
};
114
115
}
// namespace libdap
116
117
#endif
// signal_handler_h
libdap::EventHandler
Definition
EventHandler.h:43
libdap::SignalHandler
Definition
SignalHandler.h:67
libdap::SignalHandler::register_handler
EventHandler * register_handler(int signum, EventHandler *eh, bool ignore_by_default=false)
Definition
SignalHandler.cc:151
libdap::SignalHandler::instance
static SignalHandler * instance()
Definition
SignalHandler.cc:131
libdap::SignalHandler::remove_handler
EventHandler * remove_handler(int signum)
Definition
SignalHandler.cc:220
libdap
top level DAP object to house generic methods
Definition
AlarmHandler.h:36
SignalHandler.h
Generated by
1.10.0