Kea 2.7.6
|
The IntervalTimer
class is a wrapper for the ASIO boost::asio::deadline_timer
class.
More...
#include <interval_timer.h>
Public Types | |
The type of timer callback function | |
enum | Mode { REPEATING , ONE_SHOT } |
Defines possible timer modes used to setup a timer. More... | |
typedef std::function< void()> | Callback |
Constructors and Destructor | |
Note: The copy constructor and the assignment operator are intentionally defined as private, making this class non-copyable. | |
IntervalTimer (const IOServicePtr &io_service) | |
The constructor with IOService . | |
~IntervalTimer () | |
The destructor. | |
void | setup (const Callback &cbfunc, const long interval, const Mode &mode=REPEATING) |
Register timer callback function and interval. | |
void | cancel () |
Cancel the timer. | |
long | getInterval () const |
Return the timer interval. | |
The IntervalTimer
class is a wrapper for the ASIO boost::asio::deadline_timer
class.
This class is implemented to use boost::asio::deadline_timer
as interval timer.
setup()
sets a timer to expire on (now + interval), a call back function, and an interval mode.
IntervalTimerImpl::callback()
is called by the timer when it expires.
The function calls the call back function set by setup()
and if the the interval mode indicates a repeating interval, will reschedule the timer to expire in (now + interval) milliseconds.
The type of call back function is void(void)
.
The call back function will not be called if the instance of this class is destroyed before the timer is expired.
Sample code:
Definition at line 52 of file interval_timer.h.
std::function<void()> isc::asiolink::IntervalTimer::Callback |
Definition at line 55 of file interval_timer.h.
Defines possible timer modes used to setup a timer.
Enumerator | |
---|---|
REPEATING | |
ONE_SHOT |
Definition at line 60 of file interval_timer.h.
isc::asiolink::IntervalTimer::IntervalTimer | ( | const IOServicePtr & | io_service | ) |
The constructor with IOService
.
This constructor may throw a standard exception if memory allocation fails inside the method. This constructor may also throw boost::system::system_error
.
io_service | A smart pointer to an instance of IOService |
Definition at line 178 of file interval_timer.cc.
isc::asiolink::IntervalTimer::~IntervalTimer | ( | ) |
The destructor.
This destructor never throws an exception.
On the destruction of this class the timer will be canceled inside boost::asio::deadline_timer
.
Definition at line 182 of file interval_timer.cc.
References cancel().
void isc::asiolink::IntervalTimer::cancel | ( | ) |
Cancel the timer.
If the timer has been set up, this method cancels any asynchronous events waiting on the timer and stops the timer itself. If the timer has already been canceled, this method effectively does nothing.
This method never throws an exception.
Definition at line 194 of file interval_timer.cc.
Referenced by ~IntervalTimer(), isc::http::HttpConnection::close(), isc::tcp::TcpConnection::close(), isc::tcp::TcpConnection::postData(), isc::http::HttpConnection::shutdown(), isc::tcp::TcpConnection::shutdown(), and isc::http::HttpConnection::socketReadCallback().
long isc::asiolink::IntervalTimer::getInterval | ( | ) | const |
Return the timer interval.
This method returns the timer interval in milliseconds if it's running; if the timer has been canceled it returns 0.
This method never throws an exception.
Definition at line 199 of file interval_timer.cc.
void isc::asiolink::IntervalTimer::setup | ( | const Callback & | cbfunc, |
const long | interval, | ||
const Mode & | mode = REPEATING ) |
Register timer callback function and interval.
This function sets callback function and interval in milliseconds. Timer will actually start after calling IOService::run()
.
cbfunc | A reference to a function void(void) to call back when the timer is expired (should not be an empty functor) |
interval | Interval in milliseconds (greater than 0) |
mode | Determines if the timer will automatically reschedule after each expiration (the default) or behave as a one-shot which will run for a single interval and not reschedule. |
Note: IntervalTimer will not pass boost::system::error_code
to call back function. In case the timer is canceled, the function will not be called.
isc::InvalidParameter | cbfunc is empty |
isc::BadValue | interval is less than or equal to 0 |
isc::Unexpected | internal runtime error |
Definition at line 188 of file interval_timer.cc.
Referenced by isc::config::ClientConnectionImpl::scheduleTimer(), isc::http::HttpConnection::setupIdleTimer(), isc::tcp::TcpConnection::setupIdleTimer(), and isc::http::HttpConnection::setupRequestTimer().