aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Timer.hh
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2003-01-09 21:09:49 (GMT)
committerfluxgen <fluxgen>2003-01-09 21:09:49 (GMT)
commit7dd4823340ae5f710a08ff3a8fbe4276defc6b85 (patch)
treef4b6623ecf435a643fcf247d3075aaf79d6e82f3 /src/FbTk/Timer.hh
parent7a74a56fe48b319fecf56cede8e16f9c03dfaa96 (diff)
downloadfluxbox_pavel-7dd4823340ae5f710a08ff3a8fbe4276defc6b85.zip
fluxbox_pavel-7dd4823340ae5f710a08ff3a8fbe4276defc6b85.tar.bz2
moved from fluxbox to fbtk
Diffstat (limited to 'src/FbTk/Timer.hh')
-rw-r--r--src/FbTk/Timer.hh96
1 files changed, 96 insertions, 0 deletions
diff --git a/src/FbTk/Timer.hh b/src/FbTk/Timer.hh
new file mode 100644
index 0000000..df86d60
--- /dev/null
+++ b/src/FbTk/Timer.hh
@@ -0,0 +1,96 @@
1// Timer.hh for FbTk - Fluxbox Toolkit
2// Copyright (c) 2002-2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3//
4// Timer.hh for Blackbox - An X11 Window Manager
5// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net)
6//
7// Permission is hereby granted, free of charge, to any person obtaining a
8// copy of this software and associated documentation files (the "Software"),
9// to deal in the Software without restriction, including without limitation
10// the rights to use, copy, modify, merge, publish, distribute, sublicense,
11// and/or sell copies of the Software, and to permit persons to whom the
12// Software is furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in
15// all copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE.
24
25#ifndef FBTK_TIMER_HH
26#define FBTK_TIMER_HH
27
28#include <ctime>
29#include <list>
30
31namespace FbTk {
32
33/// Handles timeouts
34/**
35 Inherit this to have a timed object, that calls
36 timeout function when the time is out
37*/
38class TimeoutHandler {
39public:
40 /// called when the time is out
41 virtual void timeout() = 0;
42};
43
44/**
45 Handles TimeoutHandles
46*/
47class Timer {
48public:
49 explicit Timer(TimeoutHandler *handler);
50 virtual ~Timer();
51
52 inline int isTiming() const { return m_timing; }
53 inline int doOnce() const { return m_once; }
54
55 inline const timeval &getTimeout() const { return m_timeout; }
56 inline const timeval &getStartTime() const { return m_start; }
57
58 inline void fireOnce(bool once) { m_once = once; }
59 /// set timeout
60 void setTimeout(long val);
61 /// set timeout
62 void setTimeout(timeval val);
63 /// start timing
64 void start();
65 /// stop timing
66 void stop();
67 /// update all timers
68 static void updateTimers(int file_descriptor);
69
70protected:
71 /// force a timeout
72 void fireTimeout();
73
74private:
75 /// add a timer to the static list
76 static void addTimer(Timer *timer);
77 /// remove a timer from the static list
78 static void removeTimer(Timer *timer);
79
80 typedef std::list<Timer *> TimerList;
81 static TimerList m_timerlist; ///< list of all timers
82
83 TimeoutHandler *m_handler; ///< handler
84
85 bool m_timing; ///< clock running?
86 bool m_once; ///< do timeout only once?
87
88 timeval m_start; ///< start time
89 timeval m_timeout; ///< time length
90
91};
92
93}; // end namespace FbTk
94
95#endif // FBTK_TIMER_HH
96