aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/TickTracker.hh
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbcompose/TickTracker.hh')
-rw-r--r--util/fbcompose/TickTracker.hh138
1 files changed, 138 insertions, 0 deletions
diff --git a/util/fbcompose/TickTracker.hh b/util/fbcompose/TickTracker.hh
new file mode 100644
index 0000000..bf1e60e
--- /dev/null
+++ b/util/fbcompose/TickTracker.hh
@@ -0,0 +1,138 @@
1/** TickTracker.hh file for the fluxbox compositor. */
2
3// Copyright (c) 2011 Gediminas Liktaras (gliktaras at gmail dot com)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21// THE SOFTWARE.
22
23
24#ifndef FBCOMPOSITOR_TIMER_HH
25#define FBCOMPOSITOR_TIMER_HH
26
27#include "config.h"
28
29#include "Exceptions.hh"
30
31#include <sys/time.h>
32
33
34namespace FbCompositor {
35
36 class TimeException;
37 class TickTracker;
38
39
40 /**
41 * A timer class.
42 *
43 * This class provides a simpler and more flexible interface to deal with
44 * time. It was added, since it is not possible to make continuous time
45 * measurements with FbTk::FbTickTracker.
46 */
47 class TickTracker {
48 public:
49 //--- CONSTRUCTORS AND DESTRUCTORS -------------------------------------
50
51 /** Constructor. */
52 TickTracker();
53
54 /** Copy constructor. */
55 TickTracker(const TickTracker &other);
56
57 /** Assignment operator. */
58 TickTracker &operator=(const TickTracker &other);
59
60 /** Destructor. */
61 ~TickTracker();
62
63
64 //--- TIMER MANIPULATION -----------------------------------------------
65
66 /** Starts the timer. */
67 void start();
68
69 /** Stops the timer. */
70 void stop();
71
72
73 //--- TIMER QUERIES ----------------------------------------------------
74
75 /** \returns whether the timer is running. */
76 bool isRunning() const;
77
78 /** \returns the tick size. */
79 int tickSize() const;
80
81
82 /** \returns the new number of elapsed ticks since last call of this function. */
83 int newElapsedTicks();
84
85 /** \returns the total number of elapsed ticks. */
86 int totalElapsedTicks();
87
88
89 /** Sets the size of a tick. */
90 void setTickSize(int usec);
91
92
93 private:
94 //--- INTERNAL FUNTIONS ------------------------------------------------
95
96 /** \returns the difference in time between two timevals. */
97 timeval timeDifference(timeval t1, timeval t2);
98
99 /** \returns the difference between two timevals in ticks. */
100 int tickDifference(const timeval &t1, const timeval &t2);
101
102
103 //--- PRIVATE VARIABLES ------------------------------------------------
104
105 /** Whether the timer is running or not. */
106 bool m_is_running;
107
108 /** Time the timer was started. */
109 timeval m_startTime;
110
111
112 /** Size of the timer ticks. */
113 int m_tick_size;
114
115 /** The number of ticks per second. */
116 double m_ticks_per_second;
117
118
119 /** The number of observed ticks with newElapsedTicks(). */
120 int m_observed_ticks;
121 };
122
123
124 //--- INLINE FUNCTIONS -----------------------------------------------------
125
126 // Returns whether the timer is running.
127 inline bool TickTracker::isRunning() const {
128 return m_is_running;
129 }
130
131 // Returns the tick size.
132 inline int TickTracker::tickSize() const {
133 return m_tick_size;
134 }
135}
136
137
138#endif // FBCOMPOSITOR_TIMER_HH