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>
12 #include <exceptions/exceptions.h>
13 
14 #include <map>
15 #include <stdint.h>
16 
17 namespace isc {
18 namespace process {
19 
21 class IOSignalError : public isc::Exception {
22 public:
23  IOSignalError(const char* file, size_t line, const char* what) :
24  isc::Exception(file, line, what) { };
25 };
26 
28 typedef uint64_t IOSignalId;
29 
33 typedef boost::function<void(IOSignalId sequence_id)> IOSignalHandler;
34 
93 class IOSignal {
94 public:
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 
166 private:
168  IOSignalId sequence_id_;
169 
171  int signum_;
172 
175 };
176 
178 typedef boost::shared_ptr<IOSignal> IOSignalPtr;
179 
181 typedef std::map<IOSignalId, IOSignalPtr> IOSignalMap;
182 
195 public:
201 
203  ~IOSignalQueue();
204 
220  IOSignalId pushSignal(int signum, IOSignalHandler handler);
221 
235  IOSignalPtr popSignal(IOSignalId sequence_id);
236 
242  void clear();
243 
244 private:
246  asiolink::IOServicePtr io_service_;
247 
249  IOSignalMap signals_;
250 };
251 
253 typedef 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
int getSignum() const
Gets the OS signal value this IOSignal represents.
Creates and manages IOSignals.
Exception thrown if IOSignal encounters an error.
IOSignal(asiolink::IOService &io_service, int signum, IOSignalHandler handler)
Constructor.
IOSignalPtr popSignal(IOSignalId sequence_id)
Removes an IOSignal from the map and returns it.
boost::function< void(IOSignalId sequence_id)> IOSignalHandler
Defines a handler function for an IOSignal.
Defines the callback used by IOSignal's internal timer.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::map< IOSignalId, IOSignalPtr > IOSignalMap
Defines a map of IOSignalPtr keyed by id.
static IOSignalId nextSequenceId()
Static method for generating IOSignal sequence_ids.
Implements an asynchronous "signal" for IOService driven processing.
TimerCallback(IOSignalId sequence_id, IOSignalHandler handler)
Constructor.
IOSignalId getSequenceId() const
Gets the IOSignal's sequence_id.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
void operator()()
() Operator which serves as the timer's callback
boost::shared_ptr< IOSignal > IOSignalPtr
Defines a pointer to an IOSignal.
IOSignalError(const char *file, size_t line, const char *what)
boost::shared_ptr< IOSignalQueue > IOSignalQueuePtr
Defines a pointer to an IOSignalQueue.
void clear()
Erases the contents of the queue.
uint64_t IOSignalId
Defines a unique identifier type for IOSignal.
IOSignalId pushSignal(int signum, IOSignalHandler handler)
Creates an IOSignal.
IOSignalQueue(asiolink::IOServicePtr &io_service)
Constructor.