12#include <boost/enable_shared_from_this.hpp>
13#include <boost/noncopyable.hpp>
14#include <boost/shared_ptr.hpp>
15#include <boost/asio/deadline_timer.hpp>
24namespace ph = std::placeholders;
37 public boost::enable_shared_from_this<IntervalTimerImpl>,
38 public boost::noncopyable {
60 void callback(
const boost::system::error_code& error);
64 lock_guard<mutex> lk (mutex_);
67 cbfunc_ = std::function<void()>();
86 std::atomic<long> interval_;
92 boost::asio::deadline_timer timer_;
104 static const long INVALIDATED_INTERVAL = -1;
108 interval_(0), io_service_(io_service), timer_(io_service_->getInternalIOService()),
113 interval_ = INVALIDATED_INTERVAL;
130 lock_guard<mutex> lk(mutex_);
132 interval_ = interval;
142IntervalTimerImpl::update() {
145 timer_.expires_from_now(boost::posix_time::millisec(
long(interval_)));
151 }
catch (
const boost::system::system_error& e) {
153 }
catch (
const boost::bad_weak_ptr&) {
160 if (interval_ == INVALIDATED_INTERVAL) {
163 if (interval_ == 0 || ec) {
167 lock_guard<mutex> lk(mutex_);
191 return (impl_->setup(cbfunc, interval, mode));
201 return (impl_->getInterval());
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
A generic exception that is thrown if a parameter given to a method or function is considered invalid...
A generic exception that is thrown when an unexpected error condition occurs.
This class holds a call back function of asynchronous operations.
long getInterval() const
Get the timer interval.
~IntervalTimerImpl()
Destructor.
void callback(const boost::system::error_code &error)
Callback function which calls the registerd callback.
void cancel()
Cancel timer.
void setup(const IntervalTimer::Callback &cbfunc, const long interval, const IntervalTimer::Mode &interval_mode=IntervalTimer::REPEATING)
Setup function to register callback and start timer.
IntervalTimerImpl(const IOServicePtr &io_service)
Constructor.
The IntervalTimer class is a wrapper for the ASIO boost::asio::deadline_timer class.
~IntervalTimer()
The destructor.
long getInterval() const
Return the timer interval.
void cancel()
Cancel the timer.
std::function< void()> Callback
void setup(const Callback &cbfunc, const long interval, const Mode &mode=REPEATING)
Register timer callback function and interval.
Mode
Defines possible timer modes used to setup a timer.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
boost::shared_ptr< IOService > IOServicePtr
Defines a smart pointer to an IOService instance.
Defines the logger used by the top-level component of kea-lfc.