2 This file is part of libmspframework
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
6 #ifndef MSP_TIME_TIMER_H_
7 #define MSP_TIME_TIMER_H_
10 #include <sigc++/sigc++.h>
11 #include "../core/mutex.h"
12 #include "../core/semaphore.h"
13 #include "../core/thread.h"
14 #include "timedelta.h"
15 #include "timestamp.h"
21 A class for executing functions periodically. Every time the timeout is
22 reached, signal_timeout will be emitted. If the functor connected to this
23 signal returns true, the timer is rescheduled by incrementing the timeout
24 by the interval. Otherwise the timer is canceled.
26 A separate thread is used for running the timers. All signal emissions will
27 happen in this thread - be careful with your variables.
32 sigc::signal<bool> signal_timeout;
34 Timer(const Time::TimeDelta &);
35 const Time::TimeStamp &get_timeout() const { return timeout; }
39 A thread to run the timers independently of the rest of the program.
41 class Thread: public Msp::Thread
55 Proxy class to handle automatic starting and termination of the thread.
60 ThreadProxy(): thread(0) { }
67 Time::TimeDelta interval;
68 Time::TimeStamp timeout;
70 static ThreadProxy thread;
71 static Mutex set_mutex;
72 static std::set<Timer *> timers;