Timer.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: FMTC Tue Mar 11 21:49:25 CET 2008 Timer.hpp
3 
4  Timer.hpp - description
5  -------------------
6  begin : Tue March 11 2008
7  copyright : (C) 2008 FMTC
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_RTT_TIMER_HPP
40 #define ORO_RTT_TIMER_HPP
41 
42 #include "Time.hpp"
43 #include "TimeService.hpp"
44 #include "Mutex.hpp"
45 #include "Semaphore.hpp"
46 #include "Condition.hpp"
47 #include "ThreadInterface.hpp"
48 #include "../base/RunnableInterface.hpp"
49 #include <string>
50 #include <vector>
51 #include <utility>
52 
53 namespace RTT
54 { namespace os {
55 
68  class RTT_API Timer
70  {
71  public:
75  typedef int TimerId;
76  protected:
79  mutable Mutex mmutex;
81 
82  struct TimerInfo
83  {
84  TimerInfo() : expires(0), period(0) {}
85  TimerInfo(const TimerInfo& other) { *this = other; }
86  TimerInfo& operator=(const TimerInfo& other) { this->expires = other.expires; this->period = other.period; return *this; }
87  Time expires; // was .first
88  Time period; // was .second
90  };
91 
97  typedef std::vector<TimerInfo> TimerIds;
98  TimerIds mtimers;
99  bool mdo_quit;
100 
101  bool initialize();
102  void finalize();
103  void step();
104 
105  // The main 'event' loop.
106  void loop();
107 
108  bool breakLoop();
109 
110  public:
124  Timer(TimerId max_timers, int scheduler = -1, int priority = 0, const std::string& name = std::string("Timer"));
125 
126  ~Timer();
127 
133  virtual void timeout(TimerId timer_id);
134 
139  void setMaxTimers(TimerId max);
140 
149  bool startTimer(TimerId timer_id, Seconds period);
150 
158  bool arm(TimerId timer_id, Seconds wait_time);
159 
165  TimeService::Seconds timeRemaining(TimerId timer_id) const;
166 
171  bool isArmed(TimerId timer_id) const;
172 
177  bool killTimer(TimerId timer_id);
178 
184  bool waitFor(RTT::os::Timer::TimerId id);
185 
194  bool waitForUntil(RTT::os::Timer::TimerId id, nsecs abs_time);
195 
196  };
197 }}
198 
199 #endif
Condition mcond
Definition: Timer.hpp:78
TimerInfo(const TimerInfo &other)
Definition: Timer.hpp:85
double Seconds
Definition: os/Time.hpp:53
std::vector< TimerInfo > TimerIds
Definition: Timer.hpp:97
TimerInfo & operator=(const TimerInfo &other)
Definition: Timer.hpp:86
base::ActivityInterface * mThread
Definition: Timer.hpp:77
A class for running a certain piece of code in a thread.
An object oriented wrapper around a condition variable.
Definition: Condition.hpp:60
TimeService::nsecs Time
Definition: Timer.hpp:80
Interface to start/stop and query a Activity.
TimerIds mtimers
Definition: Timer.hpp:98
Mutex mmutex
Definition: Timer.hpp:79
An object oriented wrapper around a non recursive mutex.
Definition: Mutex.hpp:92
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:53
long long nsecs
Definition: os/Time.hpp:69
bool mdo_quit
Definition: Timer.hpp:99


rtt
Author(s): RTT Developers
autogenerated on Fri Oct 25 2019 03:59:44