From af9349661477a4bf15c48df94f498f3955cc7c09 Mon Sep 17 00:00:00 2001
From: fluxgen <fluxgen>
Date: Mon, 11 Aug 2003 15:58:34 +0000
Subject: executing a command on timeout instead of calling a TimeoutHandler

---
 src/FbTk/Timer.cc | 16 +++++++++++++---
 src/FbTk/Timer.hh | 33 ++++++++++++++-------------------
 2 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc
index 4305658..1597fa3 100644
--- a/src/FbTk/Timer.cc
+++ b/src/FbTk/Timer.cc
@@ -24,6 +24,8 @@
 
 #include "Timer.hh"
 
+#include "Command.hh"
+
 //use GNU extensions
 #ifndef	_GNU_SOURCE
 #define _GNU_SOURCE
@@ -42,8 +44,12 @@ namespace FbTk {
 
 Timer::TimerList Timer::m_timerlist;
 
-Timer::Timer(TimeoutHandler *h):
-    m_handler(h),
+Timer::Timer():m_timing(false), m_once(false) {
+
+}
+
+Timer::Timer(RefCount<Command> &handler):
+    m_handler(handler),
     m_timing(false),
     m_once(false) {
 }
@@ -67,6 +73,9 @@ void Timer::setTimeout(timeval t) {
     m_timeout.tv_usec = t.tv_usec;
 }
 
+void Timer::setCommand(RefCount<Command> &cmd) {
+    m_handler = cmd;
+}
 
 void Timer::start() {
     gettimeofday(&m_start, 0);
@@ -85,7 +94,8 @@ void Timer::stop() {
 
 
 void Timer::fireTimeout() {
-    if (m_handler) m_handler->timeout();
+    if (*m_handler)
+        m_handler->execute();
 }
 
 void Timer::updateTimers(int fd) {
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 @@
 #ifndef	 FBTK_TIMER_HH
 #define	 FBTK_TIMER_HH
 
+#include "RefCount.hh"
+
 #include <ctime> 
 #include <list>
 
@@ -44,36 +46,23 @@
 
 namespace FbTk {
 
-/// Handles timeouts
-/**
-	Inherit this to have a timed object, that calls
-	timeout function when the time is out
-*/
-class TimeoutHandler {
-public:
-    /// called when the time is out
-    virtual void timeout() = 0;
-};
+class Command;
 
 /**
-	Handles TimeoutHandles
+	Handles Timeout
 */
 class Timer {
 public:
-    explicit Timer(TimeoutHandler *handler);
+    Timer();
+    explicit Timer(RefCount<Command> &handler);
     virtual ~Timer();
 
-    inline int isTiming() const { return m_timing; } 
-    inline int doOnce() const { return m_once; }
-
-    inline const timeval &getTimeout() const { return m_timeout; }
-    inline const timeval &getStartTime() const { return m_start; }
-
     inline void fireOnce(bool once) { m_once = once; }
     /// set timeout
     void setTimeout(long val);
     /// set timeout 
     void setTimeout(timeval val);
+    void setCommand(RefCount<Command> &cmd);
     /// start timing
     void start();
     /// stop timing
@@ -81,6 +70,12 @@ public:
     /// update all timers
     static void updateTimers(int file_descriptor);
 
+    inline int isTiming() const { return m_timing; } 
+    inline int doOnce() const { return m_once; }
+    
+    inline const timeval &getTimeout() const { return m_timeout; }
+    inline const timeval &getStartTime() const { return m_start; }
+
 protected:
     /// force a timeout
     void fireTimeout();
@@ -94,7 +89,7 @@ private:
     typedef std::list<Timer *> TimerList;
     static TimerList m_timerlist; ///< list of all timers
 	
-    TimeoutHandler *m_handler; ///< handler
+    RefCount<Command> m_handler; ///< what to do on a timeout
 	
     bool m_timing; ///< clock running?
     bool m_once;  ///< do timeout only once?
-- 
cgit v0.11.2