X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fio%2Feventdispatcher.h;fp=source%2Fio%2Feventdispatcher.h;h=7e89d4739e845f0e0c180845ffedb43184eefd9f;hp=0000000000000000000000000000000000000000;hb=6e0fd758970bcb5bad5e3f2454b694cc4d7b4b66;hpb=b97d4e9f86e90254ab9edef7ee62a910f6333c78 diff --git a/source/io/eventdispatcher.h b/source/io/eventdispatcher.h new file mode 100644 index 0000000..7e89d47 --- /dev/null +++ b/source/io/eventdispatcher.h @@ -0,0 +1,55 @@ +#ifndef EVENTDISPATCHER_H_ +#define EVENTDISPATCHER_H_ + +#include +#include +#include "poll.h" + +namespace Msp { +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 +{ +private: + struct Slot + { + Base *obj; + sigc::connection evch_conn; + sigc::connection del_conn; + + Slot(Base *o): obj(o) { } + }; + + typedef std::map SlotMap; + + Poller poller; + SlotMap objects; + +public: + EventDispatcher(); + + void add(Base &); + void remove(Base &); + + /** Checks for and dispatches events. If there are no events available, + blocks until there are. */ + 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: + void object_events_changed(PollEvent, Base *); + void object_deleted(Base *); + void dispatch(); +}; + +} // namespace IO +} // namespace Msp + +#endif