]> git.tdb.fi Git - libs/core.git/blobdiff - source/io/poll.h
Make sure all classes have sensible copy semantics
[libs/core.git] / source / io / poll.h
index 6367d8f2b301544f26953220284868d7658b22fb..b65166d24bffb7cf8d7aea7e30f09f525c7b84d2 100644 (file)
@@ -1,19 +1,16 @@
 #ifndef MSP_IO_POLL_H_
 #define MSP_IO_POLL_H_
 
-#ifndef WIN32
-#include <poll.h>
-#endif
 #include <list>
 #include <map>
 #include <vector>
+#include <msp/core/noncopyable.h>
 #include <msp/time/timedelta.h>
-#include "types.h"
 
 namespace Msp {
 namespace IO {
 
-class Base;
+class EventObject;
 
 enum PollEvent
 {
@@ -21,7 +18,8 @@ enum PollEvent
        P_INPUT = 1,
        P_PRIO = 2,
        P_OUTPUT = 4,
-       P_ERROR = 8
+       P_ERROR = 8,
+       P_HANGUP = 16
 };
 
 inline PollEvent operator|(PollEvent e, PollEvent f)
@@ -34,47 +32,45 @@ inline PollEvent operator~(PollEvent e)
 { return PollEvent(~static_cast<int>(e)); }
 
 
-class Poller
+class Poller: private NonCopyable
 {
 public:
        struct Slot
        {
-               Base *object;
+               EventObject *object;
                PollEvent events;
 
-               Slot(Base *o, PollEvent e): object(o), events(e) { }
+               Slot(EventObject *o, PollEvent e): object(o), events(e) { }
        };
 
-       typedef std::list<Slot> SlotSeq;
+       typedef std::list<Slot> SlotList;
 private:
-       typedef std::map<Base *, Slot> SlotMap;
+       typedef std::map<EventObject *, PollEvent> EventMap;
 
-#ifdef WIN32
-       struct pollfd
-       {
-               Handle fd;
-       };
-#endif
+       struct Private;
 
-       SlotMap objects;
-       std::vector<pollfd> pfd;
-       bool pfd_dirty;
-       SlotSeq poll_result;
-
-       void rebuild_pfd();
-       int do_poll(int);
+       EventMap objects;
+       Private *priv;
+       bool objs_changed;
+       SlotList poll_result;
 
 public:
        Poller();
+       ~Poller();
 
-       void set_object(Base &, PollEvent);
+       void set_object(EventObject &, PollEvent);
        int poll();
        int poll(const Time::TimeDelta &);
-       const SlotSeq &get_result() const { return poll_result; }
+private:
+       void rebuild_array();
+       int do_poll(int);
+       void platform_poll(int);
+public:
+       const SlotList &get_result() const { return poll_result; }
 };
 
-PollEvent poll(Base &, PollEvent);
-PollEvent poll(Base &, PollEvent, const Time::TimeDelta &);
+PollEvent poll(EventObject &, PollEvent);
+PollEvent poll(EventObject &, PollEvent, const Time::TimeDelta &);
 
 } // namespace IO
 } // namespace Msp