]> git.tdb.fi Git - libs/core.git/blob - source/poller.h
Win32 tweaks
[libs/core.git] / source / poller.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_POLLER_H_
7 #define MSP_FRAMEWORK_POLLER_H_
8
9 #ifdef WIN32
10 #include "win32poll.h"
11 #else
12 #include <sys/poll.h>
13 #endif
14 #include <vector>
15 #include <sigc++/sigc++.h>
16 #include "mutex.h"
17
18 namespace Msp {
19
20 class Pollable;
21
22 class Poller
23 {
24 public:
25         class Slot
26         {
27         public:
28                 sigc::signal<void, short> signal_event;
29
30                 Slot(Pollable *, short);
31                 Pollable *get_object() const { return obj; }
32                 short    get_events() const  { return events; }
33         private:
34                 Pollable *obj;
35                 short    events;
36                 
37                 void obj_deleted() { obj=0; }
38         };
39
40         Slot &add_pollable(Pollable *, short);
41         int  poll(int =0);
42 private:
43         std::list<Slot *>   slots;
44         std::vector<pollfd> pfd;
45         Mutex               slots_mutex;
46         Mutex               pfd_mutex;
47         bool                dirty;
48
49         void remove_stale_slots();
50         void rebuild_pfd();
51         void pollable_deleted(Pollable *);
52 };
53
54 };
55
56 #endif