1 #include <msp/time/utils.h>
3 #include "eventdispatcher.h"
4 #include "eventobject.h"
12 void EventDispatcher::add(EventObject &obj)
14 Slot slot(*this, obj);
15 auto i = objects.find(slot);
18 i = objects.insert(slot).first;
22 poller.set_object(obj, obj.get_events());
26 void EventDispatcher::remove(EventObject &obj)
28 auto i = objects.find(Slot(*this, obj));
33 poller.set_object(obj, P_NONE);
37 void EventDispatcher::tick()
46 void EventDispatcher::tick(const Time::TimeDelta &dt)
55 void EventDispatcher::tick(const Time::Timer &timer)
57 const Time::TimeStamp &timeout = timer.get_next_timeout();
59 tick(timeout-Time::now());
64 void EventDispatcher::dispatch()
66 for(const Poller::PolledObject &po: poller.get_result())
67 if(objects.count(Slot(*this, *po.object)))
68 po.object->event(po.events);
72 EventDispatcher::Slot::Slot(EventDispatcher &d, EventObject &o):
77 void EventDispatcher::Slot::connect_signals() const
79 obj.signal_events_changed.connect(sigc::mem_fun(this, &Slot::events_changed));
80 obj.signal_deleted.connect(sigc::mem_fun(this, &Slot::deleted));
83 void EventDispatcher::Slot::events_changed(PollEvent ev) const
85 disp.poller.set_object(obj, ev);
88 void EventDispatcher::Slot::deleted() const