aboutsummaryrefslogtreecommitdiff
path: root/src/Timer.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/Timer.hh')
-rw-r--r--src/Timer.hh112
1 files changed, 65 insertions, 47 deletions
diff --git a/src/Timer.hh b/src/Timer.hh
index 0cc6bbe..2c7f2c8 100644
--- a/src/Timer.hh
+++ b/src/Timer.hh
@@ -1,3 +1,6 @@
1// Timer.hh for fluxbox
2// Copyright (c) 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
3//
1// Timer.hh for Blackbox - An X11 Window Manager 4// Timer.hh for Blackbox - An X11 Window Manager
2// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net) 5// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
3// 6//
@@ -13,75 +16,90 @@
13// 16//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
21 24
22#ifndef _TIMER_HH_ 25#ifndef TIMER_HH
23#define _TIMER_HH_ 26#define TIMER_HH
24 27
25#ifdef HAVE_CONFIG_H 28#ifdef HAVE_CONFIG_H
26#include "../config.h" 29#include "../config.h"
27#endif //HAVE_CONFIG_H 30#endif //HAVE_CONFIG_H
28 31
29#ifdef TIME_WITH_SYS_TIME 32#ifdef TIME_WITH_SYS_TIME
30# include <sys/time.h> 33#include <sys/time.h>
31# include <time.h> 34#include <time.h>
32#else // !TIME_WITH_SYS_TIME 35#else //!TIME_WITH_SYS_TIME
33# ifdef HAVE_SYS_TIME_H 36#ifdef HAVE_SYS_TIME_H
34#include <sys/time.h> 37#include <sys/time.h>
35# else // !HAVE_SYS_TIME_H 38#else // !HAVE_SYS_TIME_H
36# include <time.h> 39#include <time.h>
37# endif // HAVE_SYS_TIME_H 40#endif // HAVE_SYS_TIME_H
38#endif // TIME_WITH_SYS_TIME 41#endif // TIME_WITH_SYS_TIME
39 42
40// forward declaration 43#include <list>
41class BTimer;
42class TimeoutHandler;
43
44#include "BaseDisplay.hh"
45
46 44
45/**
46 Inherit this to have a timed object, that calls
47 timeout function when the time is out
48*/
47class TimeoutHandler { 49class TimeoutHandler {
48public: 50public:
49 virtual void timeout(void) = 0; 51 /// called when the time is out
52 virtual void timeout() = 0;
50}; 53};
51 54
52 55/**
56 Handles TimeoutHandles
57*/
53class BTimer { 58class BTimer {
54 friend class BaseDisplay;
55private:
56 BaseDisplay *display;
57 TimeoutHandler *handler;
58 int timing, once;
59
60 timeval _start, _timeout;
61
62
63protected:
64 void fireTimeout(void);
65
66
67public: 59public:
68 BTimer(BaseDisplay *, TimeoutHandler *); 60 explicit BTimer(TimeoutHandler *handler);
69 virtual ~BTimer(void); 61 virtual ~BTimer();
62
63 inline int isTiming() const { return m_timing; }
64 inline int doOnce() const { return m_once; }
65
66 inline const timeval &getTimeout() const { return m_timeout; }
67 inline const timeval &getStartTime() const { return m_start; }
68
69 inline void fireOnce(bool once) { m_once = once; }
70 /// set timeout
71 void setTimeout(long val);
72 /// set timeout
73 void setTimeout(timeval val);
74 /// start timing
75 void start();
76 /// stop timing
77 void stop();
78 /// update all timers
79 static void updateTimers(int file_descriptor);
70 80
71 inline const int &isTiming(void) const { return timing; } 81protected:
72 inline const int &doOnce(void) const { return once; } 82 /// force a timeout
73 83 void fireTimeout();
74 inline const timeval &getTimeout(void) const { return _timeout; }
75 inline const timeval &getStartTime(void) const { return _start; }
76 84
77 inline void fireOnce(int o) { once = o; } 85private:
86 /// add a timer to the static list
87 static void addTimer(BTimer *timer);
88 /// remove a timer from the static list
89 static void removeTimer(BTimer *timer);
90
91 typedef std::list<BTimer *> TimerList;
92 static TimerList m_timerlist; ///< list of all timers
93
94 TimeoutHandler *m_handler; ///< handler
95
96 bool m_timing; ///< clock running?
97 bool m_once; ///< do timeout only once?
98
99 timeval m_start; ///< start time
100 timeval m_timeout; ///< time length
78 101
79 void setTimeout(long);
80 void setTimeout(timeval);
81 void start(void);
82 void stop(void);
83}; 102};
84 103
85 104#endif // TIMER_HH
86#endif // _TIMER_HH_
87 105