#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>
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<EventObject *, Slot> SlotMap;
+ bool operator<(const Slot &o) const { return &obj<&o.obj; }
+ };
Poller poller;
- SlotMap objects;
+ std::set<Slot> objects;
public:
- EventDispatcher();
- ~EventDispatcher();
-
void add(EventObject &);
void remove(EventObject &);
void tick(const Time::Timer &);
private:
- void object_events_changed(PollEvent, EventObject *);
- void object_deleted(EventObject *);
void dispatch();
};