]> git.tdb.fi Git - libs/core.git/blob - source/io/poll.h
Add move semantics to Variant
[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/mspcore_api.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 MSPCORE_API Poller: private NonCopyable
36 {
37 public:
38         struct PolledObject
39         {
40                 EventObject *object;
41                 PollEvent events;
42         };
43
44 private:
45         struct Private;
46
47         std::vector<PolledObject> objects;
48         Private *priv = nullptr;
49         bool events_changed = false;
50         bool objs_changed = false;
51         std::vector<PolledObject> poll_result;
52
53 public:
54         Poller();
55         ~Poller();
56
57         void set_object(EventObject &, PollEvent);
58         unsigned poll();
59         unsigned poll(const Time::TimeDelta &);
60 private:
61         void rebuild_array();
62         unsigned do_poll(int);
63         void platform_poll(int);
64 public:
65         const std::vector<PolledObject> &get_result() const { return poll_result; }
66 };
67
68 MSPCORE_API PollEvent poll(EventObject &, PollEvent);
69 MSPCORE_API PollEvent poll(EventObject &, PollEvent, const Time::TimeDelta &);
70
71 } // namespace IO
72 } // namespace Msp
73
74 #endif