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