void EventDispatcher::dispatch()
{
- const vector<Poller::Slot> &result = poller.get_result();
- for(vector<Poller::Slot>::const_iterator i=result.begin(); i!=result.end(); ++i)
+ const vector<Poller::PolledObject> &result = poller.get_result();
+ for(vector<Poller::PolledObject>::const_iterator i=result.begin(); i!=result.end(); ++i)
i->object->event(i->events);
}
if(ev)
obj.get_event_handle();
- for(vector<Slot>::iterator i=objects.begin(); i!=objects.end(); ++i)
+ for(vector<PolledObject>::iterator i=objects.begin(); i!=objects.end(); ++i)
if(i->object==&obj)
{
if(ev)
throw logic_error("Maximum number of wait objects reached");
#endif
- objects.push_back(Slot(&obj, ev));
+ objects.push_back(PolledObject(&obj, ev));
objs_changed = true;
}
-int Poller::poll()
+unsigned Poller::poll()
{
return do_poll(-1);
}
-int Poller::poll(const Time::TimeDelta &timeout)
+unsigned Poller::poll(const Time::TimeDelta &timeout)
{
if(timeout<Time::zero)
throw invalid_argument("Poller::poll");
return do_poll(static_cast<int>(timeout/Time::msec));
}
-int Poller::do_poll(int timeout)
+unsigned Poller::do_poll(int timeout)
{
if(objs_changed || events_changed)
{
}
-
PollEvent platform_poll(EventObject &, PollEvent, int);
PollEvent poll(EventObject &obj, PollEvent pe)
class Poller: private NonCopyable
{
public:
- struct Slot
+ struct PolledObject
{
EventObject *object;
PollEvent events;
- Slot(EventObject *o, PollEvent e): object(o), events(e) { }
+ PolledObject(EventObject *o, PollEvent e): object(o), events(e) { }
};
- typedef std::vector<Slot> SlotList DEPRECATED;
+ typedef PolledObject Slot DEPRECATED;
+
+ typedef std::vector<PolledObject> SlotList DEPRECATED;
private:
struct Private;
- std::vector<Slot> objects;
+ std::vector<PolledObject> objects;
Private *priv;
bool events_changed;
bool objs_changed;
- std::vector<Slot> poll_result;
+ std::vector<PolledObject> poll_result;
public:
Poller();
~Poller();
void set_object(EventObject &, PollEvent);
- int poll();
- int poll(const Time::TimeDelta &);
+ unsigned poll();
+ unsigned poll(const Time::TimeDelta &);
private:
void rebuild_array();
- int do_poll(int);
+ unsigned do_poll(int);
void platform_poll(int);
public:
- const std::vector<Slot> &get_result() const { return poll_result; }
+ const std::vector<PolledObject> &get_result() const { return poll_result; }
};
PollEvent poll(EventObject &, PollEvent);
priv->pfd.clear();
priv->pfd.reserve(objects.size());
- for(vector<Slot>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+ for(vector<PolledObject>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
{
pollfd p;
p.fd = *i->object->get_event_handle();
for(unsigned i=0; (i<objects.size() && ret>0); ++i)
if(priv->pfd[i].revents)
{
- poll_result.push_back(Slot(objects[i].object, poll_event_from_sys(priv->pfd[i].revents)));
+ poll_result.push_back(PolledObject(objects[i].object, poll_event_from_sys(priv->pfd[i].revents)));
--ret;
}
}
priv->handles.clear();
priv->handles.reserve(objects.size());
- for(vector<Slot>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
+ for(vector<PolledObject>::const_iterator i=objects.begin(); i!=objects.end(); ++i)
priv->handles.push_back(*i->object->get_event_handle());
}
DWORD ret = WaitForMultipleObjects(priv->handles.size(), &priv->handles.front(), false, timeout);
if(/*ret>=WAIT_OBJECT_0 &&*/ ret<WAIT_OBJECT_0+priv->handles.size())
{
- const Slot &slot = objects[ret-WAIT_OBJECT_0];
- poll_result.push_back(slot);
+ const PolledObject &obj = objects[ret-WAIT_OBJECT_0];
+ poll_result.push_back(obj);
}
else if(ret==WAIT_FAILED)
throw system_error("WaitForMultipleObjects");