Skip to content

Commit

Permalink
Add hasStarted() const to WallTimer and SteadyTimer API (ros#1565)
Browse files Browse the repository at this point in the history
* roscpp: copy hasStarted() member function from ros::Timer to ros::WallTimer and ros::SteadyTimer

ros::Timer::hasStarted() has been added in ros#1464. The same member function should exist in the other
two timer implementations, too, for completeness.

* Check for nullptr in WallTimer::hasStarted() and SteadyTimer::hasStarted()

Analogous to fe9479c (ros#1541).
  • Loading branch information
meyerj authored and tahsinkose committed Apr 15, 2019
1 parent 0a911ca commit 9c47287
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 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_ && 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_ && 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
5 changes: 5 additions & 0 deletions clients/roscpp/src/libros/steady_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ SteadyTimer::Impl::~Impl()
stop();
}

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

void SteadyTimer::Impl::start()
{
if (!started_)
Expand Down
5 changes: 5 additions & 0 deletions clients/roscpp/src/libros/wall_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ WallTimer::Impl::~Impl()
stop();
}

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

void WallTimer::Impl::start()
{
if (!started_)
Expand Down

0 comments on commit 9c47287

Please sign in to comment.