Commit 80dd41d2 authored by Yoshitaka Aharen's avatar Yoshitaka Aharen
Browse files

Renamed member functions of asiolink::IntervalTimer (Trac ticket #515)

Renamed IntervalTimer::setupTimer() -> IntervalTimer::setup()
Renamed IntervalTimerImpl::updateTimer() -> IntervalTimerImpl::update()
parent 7c89825c
......@@ -363,8 +363,9 @@ AuthSrv::setStatisticsTimerInterval(uint32_t interval) {
if (interval == 0) {
impl_->statistics_timer_.cancel();
} else {
impl_->statistics_timer_.setupTimer(
boost::bind(&AuthSrv::submitStatistics, this), interval);
impl_->statistics_timer_.setup(boost::bind(&AuthSrv::submitStatistics,
this),
interval);
}
if (impl_->verbose_mode_) {
if (interval == 0) {
......
......@@ -98,7 +98,7 @@ AuthConmmandTest::stopServer() {
TEST_F(AuthConmmandTest, shutdown) {
asiolink::IntervalTimer itimer(server.getIOService());
itimer.setupTimer(boost::bind(&AuthConmmandTest::stopServer, this), 1);
itimer.setup(boost::bind(&AuthConmmandTest::stopServer, this), 1);
server.getIOService().run();
EXPECT_EQ(0, rcode);
}
......
......@@ -383,8 +383,7 @@ private:
public:
IntervalTimerImpl(IOService& io_service);
~IntervalTimerImpl();
void setupTimer(const IntervalTimer::Callback& cbfunc,
const uint32_t interval);
void setup(const IntervalTimer::Callback& cbfunc, const uint32_t interval);
void callback(const asio::error_code& error);
void cancel() {
timer_.cancel();
......@@ -393,7 +392,7 @@ public:
uint32_t getInterval() const { return (interval_); }
private:
// a function to update timer_ when it expires
void updateTimer();
void update();
// a function to call back when timer_ expires
IntervalTimer::Callback cbfunc_;
// interval in seconds
......@@ -410,8 +409,8 @@ IntervalTimerImpl::~IntervalTimerImpl()
{}
void
IntervalTimerImpl::setupTimer(const IntervalTimer::Callback& cbfunc,
const uint32_t interval)
IntervalTimerImpl::setup(const IntervalTimer::Callback& cbfunc,
const uint32_t interval)
{
// Interval should not be 0.
if (interval == 0) {
......@@ -426,12 +425,12 @@ IntervalTimerImpl::setupTimer(const IntervalTimer::Callback& cbfunc,
// Set initial expire time.
// At this point the timer is not running yet and will not expire.
// After calling IOService::run(), the timer will expire.
updateTimer();
update();
return;
}
void
IntervalTimerImpl::updateTimer() {
IntervalTimerImpl::update() {
if (interval_ == 0) {
// timer has been canceled. Do nothing.
return;
......@@ -453,7 +452,7 @@ IntervalTimerImpl::callback(const asio::error_code& cancelled) {
if (!cancelled) {
cbfunc_();
// Set next expire time.
updateTimer();
update();
}
}
......@@ -466,8 +465,8 @@ IntervalTimer::~IntervalTimer() {
}
void
IntervalTimer::setupTimer(const Callback& cbfunc, const uint32_t interval) {
return (impl_->setupTimer(cbfunc, interval));
IntervalTimer::setup(const Callback& cbfunc, const uint32_t interval) {
return (impl_->setup(cbfunc, interval));
}
void
......
......@@ -572,24 +572,23 @@ private:
/// \brief The \c IntervalTimer class is a wrapper for the ASIO
/// \c asio::deadline_timer class.
///
/// This class is implemented to use \c asio::deadline_timer as
/// interval timer.
/// This class is implemented to use \c asio::deadline_timer as interval
/// timer.
///
/// \c setupTimer() sets a timer to expire on (now + interval) and
/// a call back function.
/// \c setup() sets a timer to expire on (now + interval) and a call back
/// function.
///
/// \c IntervalTimerImpl::callback() is called by the timer when
/// it expires.
/// \c IntervalTimerImpl::callback() is called by the timer when it expires.
///
/// The function calls the call back function set by \c setupTimer()
/// and updates the timer to expire in (now + interval) seconds.
/// The function calls the call back function set by \c setup() and updates
/// the timer to expire in (now + interval) seconds.
/// The type of call back function is \c void(void).
///
/// The call back function will not be called if the instance of this
/// class is destructed before the timer is expired.
/// The call back function will not be called if the instance of this class is
/// destructed before the timer is expired.
///
/// Note: Destruction of an instance of this class while call back
/// is pending causes throwing an exception from \c IOService.
/// Note: Destruction of an instance of this class while call back is pending
/// causes throwing an exception from \c IOService.
///
/// Sample code:
/// \code
......@@ -600,7 +599,7 @@ private:
/// IOService io_service;
///
/// IntervalTimer intervalTimer(io_service);
/// intervalTimer.setupTimer(function_to_call_back, interval_in_seconds);
/// intervalTimer.setup(function_to_call_back, interval_in_seconds);
/// io_service.run();
/// \endcode
///
......@@ -656,7 +655,7 @@ public:
/// \throw isc::BadValue interval is 0
/// \throw isc::Unexpected ASIO library error
///
void setupTimer(const Callback& cbfunc, const uint32_t interval);
void setup(const Callback& cbfunc, const uint32_t interval);
/// Cancel the timer.
///
......
......@@ -834,13 +834,12 @@ protected:
++count_;
if (count_ == 1) {
// First time of call back.
// Call setupTimer() to update callback function
// to TimerCallBack.
// Call setup() to update callback function to TimerCallBack.
test_obj_->timer_called_ = false;
timer_.setupTimer(TimerCallBack(test_obj_), 1);
timer_.setup(TimerCallBack(test_obj_), 1);
} else if (count_ == 2) {
// Second time of call back.
// If it reaches here, re-setupTimer() is failed (unexpected).
// If it reaches here, re-setup() is failed (unexpected).
// We should stop here.
test_obj_->io_service_.stop();
}
......@@ -861,10 +860,10 @@ TEST_F(IntervalTimerTest, invalidArgumentToIntervalTimer) {
// Create asio_link::IntervalTimer and setup.
IntervalTimer itimer(io_service_);
// expect throw if call back function is empty
EXPECT_THROW(itimer.setupTimer(IntervalTimer::Callback(), 1),
isc::InvalidParameter);
EXPECT_THROW(itimer.setup(IntervalTimer::Callback(), 1),
isc::InvalidParameter);
// expect throw if interval is 0
EXPECT_THROW(itimer.setupTimer(TimerCallBack(this), 0), isc::BadValue);
EXPECT_THROW(itimer.setup(TimerCallBack(this), 0), isc::BadValue);
}
TEST_F(IntervalTimerTest, startIntervalTimer) {
......@@ -876,7 +875,7 @@ TEST_F(IntervalTimerTest, startIntervalTimer) {
boost::posix_time::ptime start;
start = boost::posix_time::microsec_clock::universal_time();
// setup timer
itimer.setupTimer(TimerCallBack(this), 1);
itimer.setup(TimerCallBack(this), 1);
EXPECT_EQ(1, itimer.getInterval());
io_service_.run();
// reaches here after timer expired
......@@ -931,10 +930,9 @@ TEST_F(IntervalTimerTest, destructIntervalTimer) {
IntervalTimer itimer_canceller(io_service_);
timer_cancel_success_ = false;
TimerCallBackCounter callback_canceller(this);
itimer_counter->setupTimer(callback_canceller, 2);
itimer_canceller.setupTimer(
TimerCallBackCancelDeleter(this, itimer_counter,
callback_canceller),
itimer_counter->setup(callback_canceller, 2);
itimer_canceller.setup(
TimerCallBackCancelDeleter(this, itimer_counter, callback_canceller),
3);
io_service_.run();
EXPECT_TRUE(timer_cancel_success_);
......@@ -946,9 +944,8 @@ TEST_F(IntervalTimerTest, cancel) {
IntervalTimer itimer_counter(io_service_);
IntervalTimer itimer_watcher(io_service_);
unsigned int counter = 0;
itimer_counter.setupTimer(TimerCallBackCanceller(counter, itimer_counter),
1);
itimer_watcher.setupTimer(TimerCallBack(this), 3);
itimer_counter.setup(TimerCallBackCanceller(counter, itimer_counter), 1);
itimer_watcher.setup(TimerCallBack(this), 3);
io_service_.run();
EXPECT_EQ(1, counter);
EXPECT_EQ(0, itimer_counter.getInterval());
......@@ -962,8 +959,7 @@ TEST_F(IntervalTimerTest, overwriteIntervalTimer) {
// finer granularity and timer periods in this test should be shorter
// in the future.
// Calling setupTimer() multiple times updates call back function
// and interval.
// Calling setup() multiple times updates call back function and interval.
//
// There are two timers:
// itimer (A)
......@@ -975,9 +971,8 @@ TEST_F(IntervalTimerTest, overwriteIntervalTimer) {
// interval: 1 second
// itimer_overwriter (B)
// (Calls TimerCallBackOverwriter)
// - first time of callback, it calls setupTimer() to change
// call back function and interval of itimer to
// TimerCallBack / 1 second
// - first time of callback, it calls setup() to change call back
// function and interval of itimer to TimerCallBack / 1 second
// after 3 + 1 seconds from the beginning of this test,
// TimerCallBack() will be called and io_service_ stops.
// - second time of callback, it means the test fails.
......@@ -995,8 +990,8 @@ TEST_F(IntervalTimerTest, overwriteIntervalTimer) {
// store start time
boost::posix_time::ptime start;
start = boost::posix_time::microsec_clock::universal_time();
itimer.setupTimer(TimerCallBackCounter(this), 2);
itimer_overwriter.setupTimer(TimerCallBackOverwriter(this, itimer), 3);
itimer.setup(TimerCallBackCounter(this), 2);
itimer_overwriter.setup(TimerCallBackOverwriter(this, itimer), 3);
io_service_.run();
// reaches here after timer expired
// if interval is updated, it takes
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment