From fdca164417a14fafeb28efe122c49cc499be7ebe Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 6 Dec 2018 01:16:42 +0100 Subject: [PATCH] roscpp: copy hasStarted() member function from ros::Timer to ros::WallTimer and ros::SteadyTimer ros::Timer::hasStarted() has been added in ros/ros_comm#1464. The same member function should exist in the other two timer implementations, too, for completeness. --- clients/roscpp/include/ros/steady_timer.h | 3 +++ clients/roscpp/include/ros/wall_timer.h | 2 ++ clients/roscpp/src/libros/wall_timer.cpp | 16 +++++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/clients/roscpp/include/ros/steady_timer.h b/clients/roscpp/include/ros/steady_timer.h index c16f282895..866eae110a 100644 --- a/clients/roscpp/include/ros/steady_timer.h +++ b/clients/roscpp/include/ros/steady_timer.h @@ -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; } @@ -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); diff --git a/clients/roscpp/include/ros/wall_timer.h b/clients/roscpp/include/ros/wall_timer.h index 6664abd72f..c25c829787 100644 --- a/clients/roscpp/include/ros/wall_timer.h +++ b/clients/roscpp/include/ros/wall_timer.h @@ -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; } @@ -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); diff --git a/clients/roscpp/src/libros/wall_timer.cpp b/clients/roscpp/src/libros/wall_timer.cpp index 6ed8493272..da0c0a5cca 100644 --- a/clients/roscpp/src/libros/wall_timer.cpp +++ b/clients/roscpp/src/libros/wall_timer.cpp @@ -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_) @@ -51,6 +61,7 @@ void WallTimer::Impl::start() { tracked_object = tracked_object_.lock(); } + timer_handle_ = TimerManager::global().add(period_, callback_, callback_queue_, tracked_object, oneshot_); started_ = true; } @@ -66,11 +77,6 @@ void WallTimer::Impl::stop() } } -bool WallTimer::Impl::isValid() -{ - return !period_.isZero(); -} - bool WallTimer::Impl::hasPending() { if (!isValid() || timer_handle_ == -1)