12 #include <boost/enable_shared_from_this.hpp>
13 #include <boost/noncopyable.hpp>
14 #include <boost/shared_ptr.hpp>
23 namespace ph = std::placeholders;
36 public boost::enable_shared_from_this<IntervalTimerImpl>,
37 public boost::noncopyable {
55 = IntervalTimer::REPEATING);
60 void callback(
const boost::system::error_code&
error);
64 lock_guard<mutex> lk (mutex_);
85 std::atomic<long> interval_;
88 boost::asio::deadline_timer timer_;
100 static const long INVALIDATED_INTERVAL = -1;
103 IntervalTimerImpl::IntervalTimerImpl(
IOService& io_service) :
104 interval_(0), timer_(io_service.get_io_service()),
109 interval_ = INVALIDATED_INTERVAL;
126 lock_guard<mutex> lk(mutex_);
128 interval_ = interval;
138 IntervalTimerImpl::update() {
141 timer_.expires_from_now(boost::posix_time::millisec(
long(interval_)));
147 }
catch (
const boost::system::system_error& e) {
149 }
catch (
const boost::bad_weak_ptr&) {
156 if (interval_ == INVALIDATED_INTERVAL) {
159 if (interval_ == 0 || ec) {
163 lock_guard<mutex> lk(mutex_);
187 return (impl_->setup(cbfunc, interval, mode));
197 return (impl_->getInterval());
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
This class holds a call back function of asynchronous operations.
void cancel()
Cancel the timer.
long getInterval() const
Return the timer interval.
std::function< void()> Callback
The IOService class is a wrapper for the ASIO io_service class.
long getInterval() const
Get the timer interval.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
The IntervalTimer class is a wrapper for the ASIO boost::asio::deadline_timer class.
void cancel()
Cancel timer.
A generic exception that is thrown when an unexpected error condition occurs.
Mode
Defines possible timer modes used to setup a timer.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
~IntervalTimer()
The destructor.
void setup(const IntervalTimer::Callback &cbfunc, const long interval, const IntervalTimer::Mode &interval_mode=IntervalTimer::REPEATING)
Setup function to register callback and start timer.
Defines the logger used by the top-level component of kea-dhcp-ddns.
A wrapper interface for the ASIO library.
~IntervalTimerImpl()
Destructor.
void callback(const boost::system::error_code &error)
Callback function which calls the registerd callback.
void setup(const Callback &cbfunc, const long interval, const Mode &mode=REPEATING)
Register timer callback function and interval.