]> git.tdb.fi Git - libs/core.git/commitdiff
Add integration between EventDispatcher and Timer
authorMikko Rasa <tdb@tdb.fi>
Sun, 30 Oct 2016 15:15:40 +0000 (17:15 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 30 Oct 2016 15:15:40 +0000 (17:15 +0200)
source/io/eventdispatcher.cpp
source/io/eventdispatcher.h

index 144ad49bcf89a0670ea6f5c9e254120586bd91df..cf37c1e7e1fbd81155608895bd14ebe9bd882e10 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/time/utils.h>
 #include "base.h"
 #include "eventdispatcher.h"
 #include "eventobject.h"
@@ -57,6 +58,15 @@ void EventDispatcher::tick(const Time::TimeDelta &dt)
                dispatch();
 }
 
+void EventDispatcher::tick(const Time::Timer &timer)
+{
+       const Time::TimeStamp &timeout = timer.get_next_timeout();
+       if(timeout)
+               tick(timeout-Time::now());
+       else
+               tick();
+}
+
 void EventDispatcher::object_events_changed(PollEvent ev, EventObject *obj)
 {
        poller.set_object(*obj, ev);
index 25455ab842f510f10e5c18f14e28779de8467b5f..b542d67e74d3fa896811b4a04263e9554e4f8902 100644 (file)
@@ -4,6 +4,7 @@
 #include <sigc++/connection.h>
 #include <sigc++/trackable.h>
 #include <msp/time/timedelta.h>
+#include <msp/time/timer.h>
 #include "poll.h"
 
 namespace Msp {
@@ -45,6 +46,10 @@ public:
        waits at most the specified time before returning. */
        void tick(const Time::TimeDelta &);
 
+       /** Checks for and dispatches events.  If there are no events available,
+       waits until the timer's next timeout before returning. */
+       void tick(const Time::Timer &);
+
 private:
        void object_events_changed(PollEvent, EventObject *);
        void object_deleted(EventObject *);