00001
00009 #ifndef ATOMS_IO_POLLER_HH
00010 #define ATOMS_IO_POLLER_HH
00011
00012 #include <atoms/gen.hh>
00013 #include <map>
00014 #include <boost/utility.hpp>
00015 #include <boost/function.hpp>
00016 #include <atoms/mutex.hh>
00017 #include <atoms/time.hh>
00018
00019 namespace atoms {
00020
00044 class IOPoller : public IOHandle {
00045 public:
00046 enum Event {
00047 eNone = 0,
00048
00049 eInput = 1,
00050 eOutput = 2,
00051 ePriorityInput = 4,
00052
00053 eAddable = eInput|eOutput|ePriorityInput,
00056 eError = 8,
00057 eHangup = 16,
00058 eEdgeTriggered = 32
00059
00060 };
00061
00071 static boost::shared_ptr<IOPoller> create();
00072
00073 virtual bool supportsEdgeTriggering() const = 0;
00074
00078 typedef boost::function<void (Event)> EventHandler;
00079
00088 virtual void add(int fd, Event eventMask, const EventHandler &onEvent) = 0;
00089
00096 virtual void remove(int fd, Event eventMask) = 0;
00097
00105 virtual void remove(int fd, bool isClosing = false) = 0;
00106
00118 virtual void poll(const Timespan &interval = Timespan::tINFINITY) = 0;
00119
00120 protected:
00121 struct DescriptorInfo {
00123 bool stale;
00124 bool edgeTriggered;
00125 std::map<Event, EventHandler> eventHandlerMap;
00126 };
00127
00128 std::map<int, boost::shared_ptr<DescriptorInfo> > descriptorMap;
00129 };
00130
00131 }
00132 #endif // !ATOMS_IO_POLLER_HH