]> git.tdb.fi Git - libs/core.git/blob - source/io/poll.h
Use #ifdef _WIN32 rather than WIN32
[libs/core.git] / source / io / poll.h
1 #ifndef MSP_IO_POLL_H_
2 #define MSP_IO_POLL_H_
3
4 #include <list>
5 #include <map>
6 #include <vector>
7 #include <msp/time/timedelta.h>
8
9 namespace Msp {
10 namespace IO {
11
12 class EventObject;
13
14 enum PollEvent
15 {
16         P_NONE = 0,
17         P_INPUT = 1,
18         P_PRIO = 2,
19         P_OUTPUT = 4,
20         P_ERROR = 8,
21         P_HANGUP = 16
22 };
23
24 inline PollEvent operator|(PollEvent e, PollEvent f)
25 { return PollEvent(static_cast<int>(e)|static_cast<int>(f)); }
26
27 inline PollEvent operator&(PollEvent e, PollEvent f)
28 { return PollEvent(static_cast<int>(e)&static_cast<int>(f)); }
29
30 inline PollEvent operator~(PollEvent e)
31 { return PollEvent(~static_cast<int>(e)); }
32
33
34 class Poller
35 {
36 public:
37         struct Slot
38         {
39                 EventObject *object;
40                 PollEvent events;
41
42                 Slot(EventObject *o, PollEvent e): object(o), events(e) { }
43         };
44
45         typedef std::list<Slot> SlotList;
46 private:
47         typedef std::map<EventObject *, PollEvent> EventMap;
48
49         struct Private;
50
51         EventMap objects;
52         Private *priv;
53         bool objs_changed;
54         SlotList poll_result;
55
56 public:
57         Poller();
58         ~Poller();
59
60         void set_object(EventObject &, PollEvent);
61         int poll();
62         int poll(const Time::TimeDelta &);
63 private:
64         void rebuild_array();
65         int do_poll(int);
66         void platform_poll(int);
67 public:
68         const SlotList &get_result() const { return poll_result; }
69 };
70
71 PollEvent poll(EventObject &, PollEvent);
72 PollEvent poll(EventObject &, PollEvent, const Time::TimeDelta &);
73
74 } // namespace IO
75 } // namespace Msp
76
77 #endif