aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Timer.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/Timer.hh')
-rw-r--r--src/FbTk/Timer.hh105
1 files changed, 105 insertions, 0 deletions
diff --git a/src/FbTk/Timer.hh b/src/FbTk/Timer.hh
new file mode 100644
index 0000000..5949b73
--- /dev/null
+++ b/src/FbTk/Timer.hh
@@ -0,0 +1,105 @@
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 "RefCount.hh"
29
30#include <ctime>
31#include <list>
32
33#ifdef HAVE_CONFIG_H
34#include "config.h"
35#endif //HAVE_CONFIG_H
36
37#ifdef HAVE_INTTYPES_H
38#include <inttypes.h>
39#include <sys/types.h>
40#endif // HAVE_INTTYPES_H
41
42#include <sys/select.h>
43#include <sys/time.h>
44#include <sys/types.h>
45#include <unistd.h>
46
47namespace FbTk {
48
49class Command;
50
51/**
52 Handles Timeout
53*/
54class Timer {
55public:
56 Timer();
57 explicit Timer(RefCount<Command> &handler);
58 virtual ~Timer();
59
60 inline void fireOnce(bool once) { m_once = once; }
61 /// set timeout
62 void setTimeout(time_t val);
63 /// set timeout
64 void setTimeout(timeval val);
65 void setCommand(RefCount<Command> &cmd);
66 /// start timing
67 void start();
68 /// stop timing
69 void stop();
70 /// update all timers
71 static void updateTimers(int file_descriptor);
72
73 inline int isTiming() const { return m_timing; }
74 inline int doOnce() const { return m_once; }
75
76 inline const timeval &getTimeout() const { return m_timeout; }
77 inline const timeval &getStartTime() const { return m_start; }
78
79protected:
80 /// force a timeout
81 void fireTimeout();
82
83private:
84 /// add a timer to the static list
85 static void addTimer(Timer *timer);
86 /// remove a timer from the static list
87 static void removeTimer(Timer *timer);
88
89 typedef std::list<Timer *> TimerList;
90 static TimerList m_timerlist; ///< list of all timers
91
92 RefCount<Command> m_handler; ///< what to do on a timeout
93
94 bool m_timing; ///< clock running?
95 bool m_once; ///< do timeout only once?
96
97 timeval m_start; ///< start time
98 timeval m_timeout; ///< time length
99
100};
101
102}; // end namespace FbTk
103
104#endif // FBTK_TIMER_HH
105