]> git.tdb.fi Git - libs/core.git/commitdiff
Refactor EventDispatcher::tick to allow arbitary timeouts
authorMikko Rasa <tdb@tdb.fi>
Sat, 19 Jul 2008 13:02:13 +0000 (13:02 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 19 Jul 2008 13:02:13 +0000 (13:02 +0000)
source/eventdispatcher.cpp
source/eventdispatcher.h

index 04147e9bee4647e6d452c2d8e35e4f3eac61265c..2150fe23b7055fb0fd1e0d5eb3ae770d60c9b9dc 100644 (file)
@@ -47,23 +47,22 @@ void EventDispatcher::remove(Base &obj)
        }
 }
 
-void EventDispatcher::tick(bool block)
+void EventDispatcher::tick()
 {
        if(objects.empty())
                return;
 
-       int ret;
-       if(block)
-               ret=poller.poll();
-       else
-               ret=poller.poll(Time::zero);
+       if(poller.poll()>0)
+               dispatch();
+}
 
-       if(ret>0)
-       {
-               const Poller::SlotSeq &result=poller.get_result();
-               for(Poller::SlotSeq::const_iterator i=result.begin(); i!=result.end(); ++i)
-                       i->object->event(i->events);
-       }
+void EventDispatcher::tick(const Time::TimeDelta &dt)
+{
+       if(objects.empty())
+               return;
+
+       if(poller.poll(dt)>0)
+               dispatch();
 }
 
 void EventDispatcher::object_events_changed(PollEvent ev, Base *obj)
@@ -76,5 +75,12 @@ void EventDispatcher::object_deleted(Base *obj)
        remove(*obj);
 }
 
+void EventDispatcher::dispatch()
+{
+       const Poller::SlotSeq &result=poller.get_result();
+       for(Poller::SlotSeq::const_iterator i=result.begin(); i!=result.end(); ++i)
+               i->object->event(i->events);
+}
+
 } // namespace IO
 } // namespace Msp
index 6f6fe6f72a9455320e8954655eda10f2a01d1dcd..8142b080e2bec9140ddccc1be51ba5f70222fc7c 100644 (file)
@@ -26,10 +26,16 @@ public:
        void remove(Base &);
 
        /**
-       Checks for and dispatches events.  If block is true, will block until events
-       are available.
+       Checks for and dispatches events.  If there are no events available, blocks
+       until there are.
        */
-       void tick(bool =true);
+       void tick();
+
+       /**
+       Checks for and dispatches events.  If there are no events available, waits
+       at most the specified time before returning.
+       */
+       void tick(const Time::TimeDelta &);
 private:
        struct Slot
        {
@@ -46,6 +52,7 @@ private:
 
        void object_events_changed(PollEvent, Base *);
        void object_deleted(Base *);
+       void dispatch();
 };
 
 } // namespace IO