00001 #ifndef _sys_Poller_h
00002 #define _sys_Poller_h
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Time.h"
00026
00027 #include <boost/shared_ptr.hpp>
00028
00029 namespace qpid {
00030 namespace sys {
00031
00038 class PollerHandle;
00039 class PollerPrivate;
00040 class Poller {
00041 PollerPrivate* const impl;
00042
00043 public:
00044 typedef boost::shared_ptr<Poller> shared_ptr;
00045
00046 enum Direction {
00047 NONE = 0,
00048 IN,
00049 OUT,
00050 INOUT
00051 };
00052
00053 enum EventType {
00054 INVALID = 0,
00055 READABLE,
00056 WRITABLE,
00057 READ_WRITABLE,
00058 DISCONNECTED,
00059 SHUTDOWN,
00060 TIMEOUT
00061 };
00062
00063 struct Event {
00064 PollerHandle* handle;
00065 EventType type;
00066
00067 Event(PollerHandle* handle0, EventType type0) :
00068 handle(handle0),
00069 type(type0) {
00070 }
00071
00072 void process();
00073 };
00074
00075 Poller();
00076 ~Poller();
00078 void shutdown();
00079
00080 void addFd(PollerHandle& handle, Direction dir);
00081 void delFd(PollerHandle& handle);
00082 void modFd(PollerHandle& handle, Direction dir);
00083 void rearmFd(PollerHandle& handle);
00084 Event wait(Duration timeout = TIME_INFINITE);
00085 };
00086
00090 class IOHandle;
00091 class PollerHandlePrivate;
00092 class PollerHandle {
00093 friend class Poller;
00094 friend struct Poller::Event;
00095
00096 PollerHandlePrivate* const impl;
00097 virtual void processEvent(Poller::EventType) {};
00098
00099 public:
00100 PollerHandle(const IOHandle& h);
00101 virtual ~PollerHandle();
00102 };
00103
00104 inline void Poller::Event::process() {
00105 handle->processEvent(type);
00106 }
00107
00108 }}
00109 #endif // _sys_Poller_h