Main Page · Modules · All Classes · Class Hierarchy
MCTimer.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
24 #include <stdint.h>
25 
26 #ifdef __AIBO_BUILD__
27 #include <MCOOP.h>
28 #endif
29 
36 
37 namespace MC
38 {
45 typedef enum
46 {
51 } TimerType;
52 
54 }
55 
59 class MCTimer
60 {
61 public:
71  MCTimer(MC::TimerType timer_type = MC::SingleShot, int duration = -1);
72  virtual ~MCTimer();
73 
83  static void SetCustomHandler(MASystemTimeHandler& handler);
84 
94  static int64_t GetElapsedSystemTime(bool relative_time = true);
95 
101  static void ResetElapsedSystemTime();
102 
108  static void HibernateSystemTime();
109 
115  static void ResumeSystemTime();
116 
124  void SetDuration(int duration);
125 
133  int GetDuration() const;
134 
142  int GetStartTime() const;
143 
151  bool IsStarted() const;
152 
163  void Start(int time_shift = 0);
164 
172  void StartFromTime(int start_time);
173 
179  void Stop();
180 
188  int GetElapsedTime();
189 
198  int64_t GetElapsedTimeInUSecs();
199 
213  bool Timeout();
214 
215 protected:
223  void Reset();
224 
225 protected:
229  int64_t Duration;
231  int64_t LastShot;
233  int Shots;
235  int64_t StartTime;
236 };
237 
238 
244 {
245 public:
246  // Class destructor
247  virtual ~MASystemTimeHandler() { };
248 
258  virtual int64_t GetSystemTime() = 0;
259 };
260 
int Shots
Shot number.
Definition: MCTimer.hpp:233
int64_t LastShot
The last shot in microseconds.
Definition: MCTimer.hpp:231
MC::TimerType TimerType
The type of the timer.
Definition: MCTimer.hpp:227
System timer handler.
Definition: MCTimer.hpp:243
int64_t Duration
Duration.
Definition: MCTimer.hpp:229
TimerType
Definition: MCTimer.hpp:45
int64_t StartTime
Start time.
Definition: MCTimer.hpp:235
Simple timer class with microsecond precision.
Definition: MCTimer.hpp:59