Kea 1.5.0
io_service_signal.h
Go to the documentation of this file.
1// Copyright (C) 2014-2017 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 IO_SERVICE_SIGNAL_H
8#define IO_SERVICE_SIGNAL_H
9
10#include <asiolink/io_service.h>
13
14#include <map>
15#include <stdint.h>
16
17namespace isc {
18namespace process {
19
22public:
23 IOSignalError(const char* file, size_t line, const char* what) :
24 isc::Exception(file, line, what) { };
25};
26
28typedef uint64_t IOSignalId;
29
33typedef boost::function<void(IOSignalId sequence_id)> IOSignalHandler;
34
93class IOSignal {
94public:
103 IOSignal(asiolink::IOService& io_service, int signum,
104 IOSignalHandler handler);
105
107 ~IOSignal();
108
118 static IOSignalId next_id_ = 0;
119 return (++next_id_);
120 }
121
126 return (sequence_id_);
127 }
128
132 int getSignum() const {
133 return (signum_);
134 }
135
142 class TimerCallback : public std::unary_function<void, void> {
143 public:
150 TimerCallback(IOSignalId sequence_id, IOSignalHandler handler);
151
156 void operator()();
157
158 private:
160 IOSignalId sequence_id_;
161
163 IOSignalHandler handler_;
164 };
165
166private:
168 IOSignalId sequence_id_;
169
171 int signum_;
172
175};
176
178typedef boost::shared_ptr<IOSignal> IOSignalPtr;
179
181typedef std::map<IOSignalId, IOSignalPtr> IOSignalMap;
182
195public:
201
204
220 IOSignalId pushSignal(int signum, IOSignalHandler handler);
221
235 IOSignalPtr popSignal(IOSignalId sequence_id);
236
242 void clear();
243
244private:
246 asiolink::IOServicePtr io_service_;
247
249 IOSignalMap signals_;
250};
251
253typedef boost::shared_ptr<IOSignalQueue> IOSignalQueuePtr;
254
255
256}; // end of isc::process namespace
257}; // end of isc namespace
258
259#endif // IO_SERVICE_SIGNAL_H
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 if IOSignal encounters an error.
IOSignalError(const char *file, size_t line, const char *what)
Creates and manages IOSignals.
void clear()
Erases the contents of the queue.
IOSignalPtr popSignal(IOSignalId sequence_id)
Removes an IOSignal from the map and returns it.
IOSignalId pushSignal(int signum, IOSignalHandler handler)
Creates an IOSignal.
Defines the callback used by IOSignal's internal timer.
void operator()()
() Operator which serves as the timer's callback
Implements an asynchronous "signal" for IOService driven processing.
IOSignalId getSequenceId() const
Gets the IOSignal's sequence_id.
static IOSignalId nextSequenceId()
Static method for generating IOSignal sequence_ids.
int getSignum() const
Gets the OS signal value this IOSignal represents.
boost::shared_ptr< IOSignalQueue > IOSignalQueuePtr
Defines a pointer to an IOSignalQueue.
uint64_t IOSignalId
Defines a unique identifier type for IOSignal.
boost::function< void(IOSignalId sequence_id)> IOSignalHandler
Defines a handler function for an IOSignal.
boost::shared_ptr< IOSignal > IOSignalPtr
Defines a pointer to an IOSignal.
std::map< IOSignalId, IOSignalPtr > IOSignalMap
Defines a map of IOSignalPtr keyed by id.
Defines the logger used by the top-level component of kea-dhcp-ddns.