2 #include <msp/core/algorithm.h>
3 #include "eventobject.h"
5 #include "poll_platform.h"
21 void Poller::set_object(EventObject &obj, PollEvent ev)
23 // Verify that the object has an event handle
25 obj.get_event_handle();
27 auto i = find_member(objects, &obj, &PolledObject::object);
38 events_changed = true;
46 if(objects.size()>=MAXIMUM_WAIT_OBJECTS)
47 throw logic_error("Maximum number of wait objects reached");
50 objects.push_back(PolledObject(&obj, ev));
54 unsigned Poller::poll()
59 unsigned Poller::poll(const Time::TimeDelta &timeout)
61 if(timeout<Time::zero)
62 throw invalid_argument("Poller::poll");
64 return do_poll(static_cast<int>(timeout/Time::msec));
67 unsigned Poller::do_poll(int timeout)
69 if(objs_changed || events_changed)
72 events_changed = false;
78 platform_poll(timeout);
80 return poll_result.size();
84 PollEvent platform_poll(EventObject &, PollEvent, int);
86 PollEvent poll(EventObject &obj, PollEvent pe)
88 return platform_poll(obj, pe, -1);
91 PollEvent poll(EventObject &obj, PollEvent pe, const Time::TimeDelta &timeout)
93 if(timeout<Time::zero)
94 throw invalid_argument("poll");
96 return platform_poll(obj, pe, static_cast<int>(timeout/Time::msec));