12#include <boost/enable_shared_from_this.hpp>
13#include <boost/noncopyable.hpp>
14#include <boost/shared_ptr.hpp>
23namespace ph = std::placeholders;
36 public boost::enable_shared_from_this<IntervalTimerImpl>,
37 public boost::noncopyable {
64 lock_guard<mutex> lk (mutex_);
67 cbfunc_ = std::function<void()>();
86 std::atomic<long> interval_;
89 boost::asio::deadline_timer timer_;
101 static const long INVALIDATED_INTERVAL = -1;
105 interval_(0), timer_(io_service.get_io_service()),
110 interval_ = INVALIDATED_INTERVAL;
127 lock_guard<mutex> lk(mutex_);
129 interval_ = interval;
139IntervalTimerImpl::update() {
142 timer_.expires_from_now(boost::posix_time::millisec(
long(interval_)));
148 }
catch (
const boost::system::system_error& e) {
150 }
catch (
const boost::bad_weak_ptr&) {
157 if (interval_ == INVALIDATED_INTERVAL) {
160 if (interval_ == 0 || ec) {
164 lock_guard<mutex> lk(mutex_);
188 return (impl_->setup(cbfunc, interval, mode));
198 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.
The IOService class is a wrapper for the ASIO io_service class.
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.
IntervalTimerImpl(IOService &io_service)
Constructor.
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.
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.
A wrapper interface for the ASIO library.
Defines the logger used by the top-level component of kea-lfc.