]> git.tdb.fi Git - libs/core.git/blob - source/eventdispatcher.h
6f6fe6f72a9455320e8954655eda10f2a01d1dcd
[libs/core.git] / source / eventdispatcher.h
1 /* $Id$
2
3 This file is part of libmspio
4 Copyright © 2007 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7 #ifndef EVENTDISPATCHER_H_
8 #define EVENTDISPATCHER_H_
9
10 #include <sigc++/connection.h>
11 #include <sigc++/trackable.h>
12 #include "poll.h"
13
14 namespace Msp {
15 namespace IO {
16
17 /**
18 Put your I/O objects inside one of these to get signaled when something happens
19 on some of them.
20 */
21 class EventDispatcher: public sigc::trackable
22 {
23 public:
24         EventDispatcher();
25         void add(Base &);
26         void remove(Base &);
27
28         /**
29         Checks for and dispatches events.  If block is true, will block until events
30         are available.
31         */
32         void tick(bool =true);
33 private:
34         struct Slot
35         {
36                 Base *obj;
37                 sigc::connection evch_conn;
38                 sigc::connection del_conn;
39
40                 Slot(Base *o): obj(o) { }
41         };
42         typedef std::map<Base *, Slot> SlotMap;
43
44         Poller poller;
45         SlotMap objects;
46
47         void object_events_changed(PollEvent, Base *);
48         void object_deleted(Base *);
49 };
50
51 } // namespace IO
52 } // namespace Msp
53
54 #endif