]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/eventdispatcher.h
Refactor signal connection handling in EventDispatcher
[libs/core.git] / source / io / eventdispatcher.h
index 7e89d4739e845f0e0c180845ffedb43184eefd9f..f95f477daac5199df5995698a217baa64e6e3f99 100644 (file)
@@ -1,8 +1,10 @@
-#ifndef EVENTDISPATCHER_H_
-#define EVENTDISPATCHER_H_
+#ifndef MSP_IO_EVENTDISPATCHER_H_
+#define MSP_IO_EVENTDISPATCHER_H_
 
-#include <sigc++/connection.h>
+#include <set>
 #include <sigc++/trackable.h>
+#include <msp/time/timedelta.h>
+#include <msp/time/timer.h>
 #include "poll.h"
 
 namespace Msp {
@@ -12,28 +14,29 @@ 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
        {
-               Base *obj;
-               sigc::connection evch_conn;
-               sigc::connection del_conn;
+               EventDispatcher &disp;
+               EventObject &obj;
 
-               Slot(Base *o): obj(o) { }
-       };
+               Slot(EventDispatcher &, EventObject &);
+
+               void connect_signals() const;
+               void events_changed(PollEvent) const;
+               void deleted() const;
 
-       typedef std::map<Base *, Slot> SlotMap;
+               bool operator<(const Slot &o) const { return &obj<&o.obj; }
+       };
 
        Poller poller;
-       SlotMap objects;
+       std::set<Slot> objects;
 
 public:
-       EventDispatcher();
-
-       void add(Base &);
-       void remove(Base &);
+       void add(EventObject &);
+       void remove(EventObject &);
 
        /** Checks for and dispatches events.  If there are no events available,
        blocks until there are. */
@@ -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, Base *);
-       void object_deleted(Base *);
        void dispatch();
 };