timer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009, Willow Garage, Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice,
7  * this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the names of Willow Garage, Inc. nor the names of its
12  * contributors may be used to endorse or promote products derived from
13  * this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef ROSCPP_TIMER_H
29 #define ROSCPP_TIMER_H
30 
31 #include "common.h"
32 #include "forwards.h"
33 #include "timer_options.h"
34 
35 namespace ros
36 {
37 
46 class ROSCPP_DECL Timer
47 {
48 public:
49  Timer() {}
50  Timer(const Timer& rhs);
51  ~Timer();
52  Timer& operator=(const Timer& other) = default;
53 
57  void start();
62  void stop();
63 
67  bool hasPending();
68 
73  void setPeriod(const Duration& period, bool reset=true);
74 
75  bool hasStarted() const { return impl_ && impl_->hasStarted(); }
76  bool isValid() { return impl_ && impl_->isValid(); }
77  bool isValid() const { return impl_ && impl_->isValid(); }
78  operator void*() { return isValid() ? (void*)1 : (void*)0; }
79 
80  bool operator<(const Timer& rhs)
81  {
82  return impl_ < rhs.impl_;
83  }
84 
85  bool operator==(const Timer& rhs)
86  {
87  return impl_ == rhs.impl_;
88  }
89 
90  bool operator!=(const Timer& rhs)
91  {
92  return impl_ != rhs.impl_;
93  }
94 
95 private:
96  Timer(const TimerOptions& ops);
97 
98  class Impl
99  {
100  public:
101  Impl();
102  ~Impl();
103 
104  bool hasStarted() const;
105  bool isValid();
106  bool isValid() const;
107  bool hasPending();
108  void setPeriod(const Duration& period, bool reset=true);
109 
110  void start();
111  void stop();
112 
113  bool started_;
114  int32_t timer_handle_;
115 
121  bool oneshot_;
122  };
124  typedef boost::weak_ptr<Impl> ImplWPtr;
125 
126  ImplPtr impl_;
127 
128  friend class NodeHandle;
129 };
130 
131 }
132 
133 #endif
bool operator<(const Timer &rhs)
Definition: timer.h:80
ROSCPP_DECL void start()
Actually starts the internals of the node (spins up threads, starts the network polling and xmlrpc lo...
Definition: init.cpp:293
int32_t timer_handle_
Definition: timer.h:114
boost::function< void(const TimerEvent &)> TimerCallback
Definition: forwards.h:146
VoidConstWPtr tracked_object_
Definition: timer.h:119
Abstract interface for a queue used to handle all callbacks within roscpp.
TimerCallback callback_
Definition: timer.h:117
boost::shared_ptr< Impl > ImplPtr
Definition: timer.h:123
bool hasStarted() const
Definition: timer.h:75
bool operator!=(const Timer &rhs)
Definition: timer.h:90
Duration period_
Definition: timer.h:116
bool operator==(const Timer &rhs)
Definition: timer.h:85
Timer()
Definition: timer.h:49
boost::weak_ptr< void const > VoidConstWPtr
Definition: forwards.h:53
roscpp&#39;s interface for creating subscribers, publishers, etc.
Definition: node_handle.h:87
Encapsulates all options available for starting a timer.
Definition: timer_options.h:40
bool isValid()
Definition: timer.h:76
Manages a timer callback.
Definition: timer.h:46
CallbackQueueInterface * callback_queue_
Definition: timer.h:118
bool oneshot_
Definition: timer.h:121
bool started_
Definition: timer.h:113
boost::weak_ptr< Impl > ImplWPtr
Definition: timer.h:124
bool has_tracked_object_
Definition: timer.h:120
ImplPtr impl_
Definition: timer.h:126
bool isValid() const
Definition: timer.h:77


roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Feb 28 2022 23:33:27