Commit ee7acfcc authored by Yoshitaka Aharen's avatar Yoshitaka Aharen
Browse files

Changed the type of interval from 'uint32_t' to 'long' (Comment on Trac ticket #513)

parent 80dd41d2
......@@ -383,20 +383,20 @@ private:
public:
IntervalTimerImpl(IOService& io_service);
~IntervalTimerImpl();
void setup(const IntervalTimer::Callback& cbfunc, const uint32_t interval);
void setup(const IntervalTimer::Callback& cbfunc, const long interval);
void callback(const asio::error_code& error);
void cancel() {
timer_.cancel();
interval_ = 0;
}
uint32_t getInterval() const { return (interval_); }
long getInterval() const { return (interval_); }
private:
// a function to update timer_ when it expires
void update();
// a function to call back when timer_ expires
IntervalTimer::Callback cbfunc_;
// interval in seconds
uint32_t interval_;
long interval_;
// asio timer
asio::deadline_timer timer_;
};
......@@ -410,11 +410,12 @@ IntervalTimerImpl::~IntervalTimerImpl()
void
IntervalTimerImpl::setup(const IntervalTimer::Callback& cbfunc,
const uint32_t interval)
const long interval)
{
// Interval should not be 0.
if (interval == 0) {
isc_throw(isc::BadValue, "Interval should not be 0");
// Interval should not be less than or equal to 0.
if (interval <= 0) {
isc_throw(isc::BadValue, "Interval should not be less than or "
"equal to 0");
}
// Call back function should not be empty.
if (cbfunc.empty()) {
......@@ -465,7 +466,7 @@ IntervalTimer::~IntervalTimer() {
}
void
IntervalTimer::setup(const Callback& cbfunc, const uint32_t interval) {
IntervalTimer::setup(const Callback& cbfunc, const long interval) {
return (impl_->setup(cbfunc, interval));
}
......@@ -474,7 +475,7 @@ IntervalTimer::cancel() {
impl_->cancel();
}
uint32_t
long
IntervalTimer::getInterval() const {
return (impl_->getInterval());
}
......
......@@ -652,10 +652,10 @@ public:
/// will not be called.
///
/// \throw isc::InvalidParameter cbfunc is empty
/// \throw isc::BadValue interval is 0
/// \throw isc::BadValue interval is less than or equal to 0
/// \throw isc::Unexpected ASIO library error
///
void setup(const Callback& cbfunc, const uint32_t interval);
void setup(const Callback& cbfunc, const long interval);
/// Cancel the timer.
///
......@@ -677,7 +677,7 @@ public:
/// Note: We may want to change the granularity of the timer to
/// milliseconds or even finer. If and when this happens the semantics
/// of the return value of this method will be changed accordingly.
uint32_t getInterval() const;
long getInterval() const;
private:
IntervalTimerImpl* impl_;
......
......@@ -862,8 +862,9 @@ TEST_F(IntervalTimerTest, invalidArgumentToIntervalTimer) {
// expect throw if call back function is empty
EXPECT_THROW(itimer.setup(IntervalTimer::Callback(), 1),
isc::InvalidParameter);
// expect throw if interval is 0
// expect throw if interval is not greater than 0
EXPECT_THROW(itimer.setup(TimerCallBack(this), 0), isc::BadValue);
EXPECT_THROW(itimer.setup(TimerCallBack(this), -1), isc::BadValue);
}
TEST_F(IntervalTimerTest, startIntervalTimer) {
......
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