Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 #include "ros/timer.h"
00029 #include "ros/timer_manager.h"
00030 
00031 namespace ros
00032 {
00033 
00034 Timer::Impl::Impl()
00035   : started_(false)
00036   , timer_handle_(-1)
00037 { }
00038 
00039 Timer::Impl::~Impl()
00040 {
00041   ROS_DEBUG("Timer deregistering callbacks.");
00042   stop();
00043 }
00044 
00045 bool Timer::Impl::isValid()
00046 {
00047   return !period_.isZero();
00048 }
00049 
00050 void Timer::Impl::start()
00051 {
00052   if (!started_)
00053   {
00054     VoidConstPtr tracked_object;
00055     if (has_tracked_object_)
00056     {
00057       tracked_object = tracked_object_.lock();
00058     }
00059 
00060     timer_handle_ = TimerManager<Time, Duration, TimerEvent>::global().add(period_, callback_, callback_queue_, tracked_object, oneshot_);
00061     started_ = true;
00062   }
00063 }
00064 
00065 void Timer::Impl::stop()
00066 {
00067   if (started_)
00068   {
00069     started_ = false;
00070     TimerManager<Time, Duration, TimerEvent>::global().remove(timer_handle_);
00071     timer_handle_ = -1;
00072   }
00073 }
00074 
00075 bool Timer::Impl::hasPending()
00076 {
00077   if (!isValid() || timer_handle_ == -1)
00078   {
00079     return false;
00080   }
00081 
00082   return TimerManager<Time, Duration, TimerEvent>::global().hasPending(timer_handle_);
00083 }
00084 
00085 void Timer::Impl::setPeriod(const Duration& period, bool reset)
00086 {
00087   period_ = period;
00088   TimerManager<Time, Duration, TimerEvent>::global().setPeriod(timer_handle_, period, reset);
00089 }
00090 
00091 Timer::Timer(const TimerOptions& ops)
00092 : impl_(new Impl)
00093 {
00094   impl_->period_ = ops.period;
00095   impl_->callback_ = ops.callback;
00096   impl_->callback_queue_ = ops.callback_queue;
00097   impl_->tracked_object_ = ops.tracked_object;
00098   impl_->has_tracked_object_ = (ops.tracked_object != NULL);
00099   impl_->oneshot_ = ops.oneshot;
00100 }
00101 
00102 Timer::Timer(const Timer& rhs)
00103 {
00104   impl_ = rhs.impl_;
00105 }
00106 
00107 Timer::~Timer()
00108 {
00109 }
00110 
00111 void Timer::start()
00112 {
00113   if (impl_)
00114   {
00115     impl_->start();
00116   }
00117 }
00118 
00119 void Timer::stop()
00120 {
00121   if (impl_)
00122   {
00123     impl_->stop();
00124   }
00125 }
00126 
00127 bool Timer::hasPending()
00128 {
00129   if (impl_)
00130   {
00131     return impl_->hasPending();
00132   }
00133 
00134   return false;
00135 }
00136 
00137 void Timer::setPeriod(const Duration& period, bool reset)
00138 {
00139   if (impl_)
00140   {
00141     impl_->setPeriod(period, reset);
00142   }
00143 }
00144 
00145 }
 
roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Thu Jun 6 2019 21:10:05