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
34namespace libdap
35{
36
37typedef void Sigfunc(int); // Plauger, 1992
38
67{
68private:
69 // Ensure we're a Singleton.
70 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
103public:
104 static SignalHandler *instance();
105
107 virtual ~SignalHandler() = default;
108
110 bool ignore_by_default = false);
111
112 EventHandler *remove_handler(int signum);
113};
114
115} // namespace libdap
116
117#endif // signal_handler_h
EventHandler * register_handler(int signum, EventHandler *eh, bool ignore_by_default=false)
static SignalHandler * instance()
EventHandler * remove_handler(int signum)
top level DAP object to house generic methods