Kea 1.5.0
signal_set.h
Go to the documentation of this file.
1// Copyright (C) 2014-2015 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef SIGNAL_SET_H
8#define SIGNAL_SET_H
9
11#include <boost/function.hpp>
12#include <boost/noncopyable.hpp>
13#include <boost/shared_ptr.hpp>
14#include <set>
15#include <list>
16#include <pthread.h>
17#include <signal.h>
18
19namespace isc {
20namespace util {
21
24class SignalSetError : public Exception {
25public:
26 SignalSetError(const char* file, size_t line, const char* what) :
27 isc::Exception(file, line, what) { };
28};
29
30
32typedef std::set<int> SigIntSet;
34typedef boost::shared_ptr<SigIntSet> SigIntSetPtr;
35
37typedef std::list<int> SigIntList;
39typedef boost::shared_ptr<SigIntList> SigIntListPtr;
40
41
43class SignalSet;
45typedef boost::shared_ptr<SignalSet> SignalSetPtr;
47typedef boost::function<void(int signum)> SignalHandler;
48
54typedef boost::function<bool(int signum)> BoolSignalHandler;
55
87class SignalSet : public boost::noncopyable {
88public:
94 SignalSet(const int sig0);
95
102 SignalSet(const int sig0, const int sig1);
103
111 SignalSet(const int sig0, const int sig1, const int sig2);
112
116 ~SignalSet();
117
127 void add(const int sig);
128
133 void clear();
134
139 int getNext() const;
140
149 void handleNext(SignalHandler signal_handler);
150
154 void remove(const int sig);
155
166 static void setOnReceiptHandler(BoolSignalHandler handler);
167
169 static void clearOnReceiptHandler();
170
186 static bool invokeOnReceiptHandler(int sig);
187
188private:
189
194 void block() const;
195
203 void erase(const int sig);
204
210 void insert(const int sig);
211
218 void maskSignals(const int mask) const;
219
225 void popNext();
226
230 void unblock() const;
231
233 std::set<int> local_signals_;
234
238 SigIntSetPtr registered_signals_;
239
243 SigIntListPtr signal_states_;
244};
245
246}
247}
248
249#endif // SIGNAL_SET_H
250
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Exception thrown when the isc::util::SignalSet class experiences an error.
Definition: signal_set.h:24
SignalSetError(const char *file, size_t line, const char *what)
Definition: signal_set.h:26
Represents a collection of signals handled in a customized way.
Definition: signal_set.h:87
~SignalSet()
Destructor.
Definition: signal_set.cc:156
static void setOnReceiptHandler(BoolSignalHandler handler)
Registers a handler as the onreceipt signal handler.
Definition: signal_set.cc:307
void handleNext(SignalHandler signal_handler)
Calls a handler for the next received signal.
Definition: signal_set.cc:233
static bool invokeOnReceiptHandler(int sig)
Invokes the onreceipt handler if it exists.
Definition: signal_set.cc:88
int getNext() const
Returns a code of the next received signal.
Definition: signal_set.cc:201
void add(const int sig)
Installs the handler for the specified signal.
Definition: signal_set.cc:168
void remove(const int sig)
Uninstalls signal handler for a specified signal.
Definition: signal_set.cc:282
static void clearOnReceiptHandler()
Unregisters the onreceipt signal handler.
Definition: signal_set.cc:312
void clear()
Uninstalls all signals.
Definition: signal_set.cc:188
std::list< int > SigIntList
Defines a list of integer signal identifiers: SIGHUP, SIGTERM...
Definition: signal_set.h:37
boost::shared_ptr< SigIntList > SigIntListPtr
Pointer to a list of signal identifiers.
Definition: signal_set.h:39
boost::shared_ptr< SignalSet > SignalSetPtr
Pointer to the isc::util::SignalSet.
Definition: signal_set.h:45
boost::shared_ptr< SigIntSet > SigIntSetPtr
Pointer to a set of signal identifiers.
Definition: signal_set.h:34
std::set< int > SigIntSet
Defines a set of integer signal identifiers: SIGHUP, SIGTERM...
Definition: signal_set.h:32
boost::function< bool(int signum)> BoolSignalHandler
Pointer to a signal handling function which returns bool result.
Definition: signal_set.h:54
boost::function< void(int signum)> SignalHandler
Pointer to the signal handling function.
Definition: signal_set.h:47
Defines the logger used by the top-level component of kea-dhcp-ddns.