SignalHandler.h
// -*- mode: c++; c-basic-offset:4 -*-
// This file is part of libdap, A C++ implementation of the OPeNDAP Data
// Access Protocol.
// Copyright (c) 2002,2003 OPeNDAP, Inc.
// Author: James Gallagher <jgallagher@opendap.org>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
#ifndef signal_handler_h
#define signal_handler_h
#include <csignal>
#include <vector>
#include "EventHandler.h"
#include "InternalErr.h"
namespace libdap {
typedef void Sigfunc(int); // Plauger, 1992
class SignalHandler {
private:
// Table of pointers to instances of EventHandlers. Since EventHandler is
// abstract, the pointers will actually reference instances that are
// children of EventHandler. NSIG is defined in signal.h but this may be
// a portability issue. This has to be static because it is used by a
// static method.
static std::vector<EventHandler *> d_signal_handlers;
// This array holds the old signal handlers. Once the handler in
// d_signal_handler[signum] is run, look here to see what the original
// action was. This is important since libdap++ is often embedded in code
// that already has a non-default signal handler for things like SIGINT.
static std::vector<Sigfunc *> d_old_handlers;
// Entry point adapter installed into sigaction(). This must be a static
// method (or a regular C-function) to conform to sigaction's interface.
// this is the part of SignalHandler that uses the Adapter pattern.
static void dispatcher(int signum);
friend class SignalHandlerTest;
friend class HTTPCacheTest;
public:
SignalHandler() = default;
SignalHandler(const SignalHandler &) = delete;
SignalHandler &operator=(const SignalHandler &) = delete;
SignalHandler(SignalHandler &&) = delete;
SignalHandler &operator=(SignalHandler &&) = delete;
static SignalHandler *instance();
virtual ~SignalHandler() = default;
static EventHandler *register_handler(int signum, EventHandler *eh, bool ignore_by_default = false);
static EventHandler *remove_handler(int signum);
};
} // namespace libdap
#endif // signal_handler_h
libdap::EventHandler
Definition EventHandler.h:41
libdap::SignalHandler::register_handler
static EventHandler * register_handler(int signum, EventHandler *eh, bool ignore_by_default=false)
Definition SignalHandler.cc:86
libdap::SignalHandler::instance
static SignalHandler * instance()
Definition SignalHandler.cc:69
libdap::SignalHandler::remove_handler
static EventHandler * remove_handler(int signum)
Definition SignalHandler.cc:154
libdap
top level DAP object to house generic methods
Definition AlarmHandler.h:35