X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Feventdispatcher.h;h=f95f477daac5199df5995698a217baa64e6e3f99;hp=fec8ded63049ba28911b2e92ef6257accec162e0;hb=df6fc46950e15bb30a92368f34dc2005393b0e5b;hpb=c21ab7e49852585df01b4cc19599e25a918b581b diff --git a/source/io/eventdispatcher.h b/source/io/eventdispatcher.h index fec8ded..f95f477 100644 --- a/source/io/eventdispatcher.h +++ b/source/io/eventdispatcher.h @@ -1,8 +1,10 @@ -#ifndef EVENTDISPATCHER_H_ -#define EVENTDISPATCHER_H_ +#ifndef MSP_IO_EVENTDISPATCHER_H_ +#define MSP_IO_EVENTDISPATCHER_H_ -#include +#include #include +#include +#include #include "poll.h" namespace Msp { @@ -12,26 +14,27 @@ namespace IO { Put your I/O objects inside one of these to get signaled when something happens on some of them. */ -class EventDispatcher: public sigc::trackable +class EventDispatcher { private: - struct Slot + struct Slot: public sigc::trackable { - EventObject *obj; - sigc::connection evch_conn; - sigc::connection del_conn; + EventDispatcher &disp; + EventObject &obj; - Slot(EventObject *o): obj(o) { } - }; + Slot(EventDispatcher &, EventObject &); + + void connect_signals() const; + void events_changed(PollEvent) const; + void deleted() const; - typedef std::map SlotMap; + bool operator<(const Slot &o) const { return &obj<&o.obj; } + }; Poller poller; - SlotMap objects; + std::set objects; public: - EventDispatcher(); - void add(EventObject &); void remove(EventObject &); @@ -43,9 +46,11 @@ 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 *); void dispatch(); };