]> git.tdb.fi Git - libs/core.git/blob - source/eventdispatcher.h
9bea6d2140943f014857a7bd1ee5d629add232e7
[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 "poll.h"
12
13 namespace Msp {
14 namespace IO {
15
16 /**
17 Put your I/O objects inside one of these to get signaled when something happens
18 on some of them.
19 */
20 class EventDispatcher
21 {
22 public:
23         EventDispatcher();
24         void add(Base &);
25         void remove(Base &);
26
27         /**
28         Checks for and dispatches events.  If block is true, will block until events
29         are available.
30         */
31         void tick(bool =true);
32 private:
33         struct Slot
34         {
35                 Base *obj;
36                 sigc::connection evch_conn;
37                 sigc::connection del_conn;
38
39                 Slot(Base *o): obj(o) { }
40         };
41         typedef std::map<Base *, Slot> SlotMap;
42
43         Poller poller;
44         SlotMap objects;
45
46         void object_events_changed(PollEvent, Base *);
47         void object_deleted(Base *);
48 };
49
50 } // namespace IO
51 } // namespace Msp
52
53 #endif