1 #ifndef MSP_TIME_TIMER_H_
2 #define MSP_TIME_TIMER_H_
5 #include <sigc++/sigc++.h>
6 #include <msp/core/mutex.h>
7 #include <msp/core/semaphore.h>
15 A class for executing functions in a deferred or periodical fashion. The add a
16 timer, use one of the add functions and connect a functor to the timeout signal
19 This class is thread-safe, to allow running timers in a separate thread.
27 sigc::signal<bool> signal_timeout;
34 Slot(const TimeDelta &);
35 Slot(const TimeStamp &);
36 const TimeStamp &get_timeout() const { return timeout; }
46 bool operator<(const SlotProxy &) const;
49 std::vector<SlotProxy> slots;
56 /** Adds a timer that will be executed periodically as long as the timeout
57 signal hander returns true. */
58 Slot &add(const TimeDelta &);
60 /** Adds a timer that will be executed once at a specific time. The return
61 value of the timeout signal handler is ignored. */
62 Slot &add(const TimeStamp &);
64 /** Cancels a previously added timer. */
67 /** Checks all timers, executing any that have timed out. If block is true,
68 waits until one times out.
70 Note: If there are no active timers when a blocking tick is executed, it
71 won't return until a timer is added from another thread. */
72 void tick(bool block = true);
74 TimeStamp get_next_timeout() const;