Skip to content

Commit

Permalink
roscpp: copy hasStarted() member function from ros::Timer to ros::Wal…
Browse files Browse the repository at this point in the history
…lTimer and ros::SteadyTimer

ros::Timer::hasStarted() has been added in #1464. The same member function should exist in the other
two timer implementations, too, for completeness.
  • Loading branch information
meyerj committed Dec 6, 2018
1 parent 56ecdfa commit fdca164
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions clients/roscpp/include/ros/steady_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ class ROSCPP_DECL SteadyTimer

/**
* \brief Set the period of this timer
* \param reset Whether to reset the timer. If true, timer ignores elapsed time and next cb occurs at now()+period
*/
void setPeriod(const WallDuration& period, bool reset=true);

bool hasStarted() const { return impl_->hasStarted(); }
bool isValid() { return impl_ && impl_->isValid(); }
operator void*() { return isValid() ? (void *) 1 : (void *) 0; }

Expand Down Expand Up @@ -97,6 +99,7 @@ class ROSCPP_DECL SteadyTimer
Impl();
~Impl();

bool hasStarted() const;
bool isValid();
bool hasPending();
void setPeriod(const WallDuration &period, bool reset=true);
Expand Down
2 changes: 2 additions & 0 deletions clients/roscpp/include/ros/wall_timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class ROSCPP_DECL WallTimer
*/
void setPeriod(const WallDuration& period, bool reset=true);

bool hasStarted() const { return impl_->hasStarted(); }
bool isValid() { return impl_ && impl_->isValid(); }
operator void*() { return isValid() ? (void*)1 : (void*)0; }

Expand Down Expand Up @@ -98,6 +99,7 @@ class ROSCPP_DECL WallTimer
Impl();
~Impl();

bool hasStarted() const;
bool isValid();
bool hasPending();
void setPeriod(const WallDuration& period, bool reset=true);
Expand Down
16 changes: 11 additions & 5 deletions clients/roscpp/src/libros/wall_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ WallTimer::Impl::~Impl()
stop();
}

bool WallTimer::Impl::hasStarted() const
{
return started_;
}

bool WallTimer::Impl::isValid()
{
return !period_.isZero();
}

void WallTimer::Impl::start()
{
if (!started_)
Expand All @@ -51,6 +61,7 @@ void WallTimer::Impl::start()
{
tracked_object = tracked_object_.lock();
}

timer_handle_ = TimerManager<WallTime, WallDuration, WallTimerEvent>::global().add(period_, callback_, callback_queue_, tracked_object, oneshot_);
started_ = true;
}
Expand All @@ -66,11 +77,6 @@ void WallTimer::Impl::stop()
}
}

bool WallTimer::Impl::isValid()
{
return !period_.isZero();
}

bool WallTimer::Impl::hasPending()
{
if (!isValid() || timer_handle_ == -1)
Expand Down

0 comments on commit fdca164

Please sign in to comment.