diff options
author | fluxgen <fluxgen> | 2003-08-11 15:58:34 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2003-08-11 15:58:34 (GMT) |
commit | af9349661477a4bf15c48df94f498f3955cc7c09 (patch) | |
tree | 6c8cde9c981b0238ea91492cb320fad040f6fb31 /src/FbTk/Timer.hh | |
parent | 586f78c56e9c4fd8b13788695bf7030f16d410a9 (diff) | |
download | fluxbox_pavel-af9349661477a4bf15c48df94f498f3955cc7c09.zip fluxbox_pavel-af9349661477a4bf15c48df94f498f3955cc7c09.tar.bz2 |
executing a command on timeout instead of calling a TimeoutHandler
Diffstat (limited to 'src/FbTk/Timer.hh')
-rw-r--r-- | src/FbTk/Timer.hh | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/FbTk/Timer.hh b/src/FbTk/Timer.hh index 6c40155..961d4d7 100644 --- a/src/FbTk/Timer.hh +++ b/src/FbTk/Timer.hh | |||
@@ -25,6 +25,8 @@ | |||
25 | #ifndef FBTK_TIMER_HH | 25 | #ifndef FBTK_TIMER_HH |
26 | #define FBTK_TIMER_HH | 26 | #define FBTK_TIMER_HH |
27 | 27 | ||
28 | #include "RefCount.hh" | ||
29 | |||
28 | #include <ctime> | 30 | #include <ctime> |
29 | #include <list> | 31 | #include <list> |
30 | 32 | ||
@@ -44,36 +46,23 @@ | |||
44 | 46 | ||
45 | namespace FbTk { | 47 | namespace FbTk { |
46 | 48 | ||
47 | /// Handles timeouts | 49 | class Command; |
48 | /** | ||
49 | Inherit this to have a timed object, that calls | ||
50 | timeout function when the time is out | ||
51 | */ | ||
52 | class TimeoutHandler { | ||
53 | public: | ||
54 | /// called when the time is out | ||
55 | virtual void timeout() = 0; | ||
56 | }; | ||
57 | 50 | ||
58 | /** | 51 | /** |
59 | Handles TimeoutHandles | 52 | Handles Timeout |
60 | */ | 53 | */ |
61 | class Timer { | 54 | class Timer { |
62 | public: | 55 | public: |
63 | explicit Timer(TimeoutHandler *handler); | 56 | Timer(); |
57 | explicit Timer(RefCount<Command> &handler); | ||
64 | virtual ~Timer(); | 58 | virtual ~Timer(); |
65 | 59 | ||
66 | inline int isTiming() const { return m_timing; } | ||
67 | inline int doOnce() const { return m_once; } | ||
68 | |||
69 | inline const timeval &getTimeout() const { return m_timeout; } | ||
70 | inline const timeval &getStartTime() const { return m_start; } | ||
71 | |||
72 | inline void fireOnce(bool once) { m_once = once; } | 60 | inline void fireOnce(bool once) { m_once = once; } |
73 | /// set timeout | 61 | /// set timeout |
74 | void setTimeout(long val); | 62 | void setTimeout(long val); |
75 | /// set timeout | 63 | /// set timeout |
76 | void setTimeout(timeval val); | 64 | void setTimeout(timeval val); |
65 | void setCommand(RefCount<Command> &cmd); | ||
77 | /// start timing | 66 | /// start timing |
78 | void start(); | 67 | void start(); |
79 | /// stop timing | 68 | /// stop timing |
@@ -81,6 +70,12 @@ public: | |||
81 | /// update all timers | 70 | /// update all timers |
82 | static void updateTimers(int file_descriptor); | 71 | static void updateTimers(int file_descriptor); |
83 | 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 | |||
84 | protected: | 79 | protected: |
85 | /// force a timeout | 80 | /// force a timeout |
86 | void fireTimeout(); | 81 | void fireTimeout(); |
@@ -94,7 +89,7 @@ private: | |||
94 | typedef std::list<Timer *> TimerList; | 89 | typedef std::list<Timer *> TimerList; |
95 | static TimerList m_timerlist; ///< list of all timers | 90 | static TimerList m_timerlist; ///< list of all timers |
96 | 91 | ||
97 | TimeoutHandler *m_handler; ///< handler | 92 | RefCount<Command> m_handler; ///< what to do on a timeout |
98 | 93 | ||
99 | bool m_timing; ///< clock running? | 94 | bool m_timing; ///< clock running? |
100 | bool m_once; ///< do timeout only once? | 95 | bool m_once; ///< do timeout only once? |