]> git.tdb.fi Git - libs/core.git/blob - source/core/event.h
Add a missing mutex unlock into Semaphore::wait
[libs/core.git] / source / core / event.h
1 /*
2 This file is part of libmspframework
3 Copyright © 2006 Mikko Rasa, Mikkosoft Productions
4 Distributed under the LGPL
5 */
6 #ifndef MSP_FRAMEWORK_EVENT_H_
7 #define MSP_FRAMEWORK_EVENT_H_
8
9 #include <sigc++/sigc++.h>
10 #include "pollable.h"
11
12 namespace Msp {
13
14 class Application;
15
16 /**
17 Events can be used in multi-threaded applictions to trigger actions in the main
18 thread.
19 */
20 class EventManager
21 {
22 public:
23         class Event
24         {
25         public:
26                 sigc::signal<void> signal_triggered;
27
28                 Event(EventManager &m, unsigned i): mgr(m), id(i) { }
29                 unsigned get_id() const { return id; }
30                 void trigger();
31         private:
32                 EventManager &mgr;
33                 unsigned id;
34         };
35
36         EventManager(Application &);
37         Event &create_event();
38 private:
39         class Pipe: public Pollable
40         {
41         public:
42                 Pipe();
43                 int write(char *, unsigned);
44                 int read(char *, unsigned);
45         private:
46                 int fd[2];
47         
48                 int get_fd() { return fd[0]; }
49         };
50
51         Application &app;
52         Pipe        pipe;
53         unsigned    next_id;
54         std::list<Event> events;
55
56         void data_available(short);
57 };
58
59 } // namespace Msp
60
61 #endif