From dfc598af62ccb812ebd53d5d8532f61b01b18245 Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Thu, 24 Jul 2008 05:31:07 +0000 Subject: Refactored so that Dispatcher is now independent from DispatchHandle git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@679276 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/sys/Dispatcher.cpp | 8 +++---- cpp/src/qpid/sys/Dispatcher.h | 2 +- cpp/src/qpid/sys/Poller.h | 52 ++++++++++++++++++++++++----------------- 3 files changed, 34 insertions(+), 28 deletions(-) (limited to 'cpp/src') diff --git a/cpp/src/qpid/sys/Dispatcher.cpp b/cpp/src/qpid/sys/Dispatcher.cpp index 1df88ce0ae..3f901737fd 100644 --- a/cpp/src/qpid/sys/Dispatcher.cpp +++ b/cpp/src/qpid/sys/Dispatcher.cpp @@ -38,12 +38,10 @@ Dispatcher::~Dispatcher() { void Dispatcher::run() { do { Poller::Event event = poller->wait(); - DispatchHandle* h = - boost::polymorphic_downcast(event.handle); // If can read/write then dispatch appropriate callbacks - if (h) { - h->dispatchCallbacks(event.type); + if (event.handle) { + event.process(); } else { // Handle shutdown switch (event.type) { @@ -344,7 +342,7 @@ void DispatchHandle::doDelete() { deferDelete(); } -void DispatchHandle::dispatchCallbacks(Poller::EventType type) { +void DispatchHandle::processEvent(Poller::EventType type) { // Note that we are now doing the callbacks { ScopedLock lock(stateLock); diff --git a/cpp/src/qpid/sys/Dispatcher.h b/cpp/src/qpid/sys/Dispatcher.h index cd7a0bdb66..77a205cc8b 100644 --- a/cpp/src/qpid/sys/Dispatcher.h +++ b/cpp/src/qpid/sys/Dispatcher.h @@ -78,7 +78,7 @@ protected: void doDelete(); private: - void dispatchCallbacks(Poller::EventType dir); + void processEvent(Poller::EventType dir); }; class Dispatcher : public Runnable { diff --git a/cpp/src/qpid/sys/Poller.h b/cpp/src/qpid/sys/Poller.h index 86e7181df8..bd0fff1d02 100644 --- a/cpp/src/qpid/sys/Poller.h +++ b/cpp/src/qpid/sys/Poller.h @@ -29,32 +29,11 @@ namespace qpid { namespace sys { -/** - * Handle class to use for polling - */ -class IOHandle; -class Poller; -class PollerHandlePrivate; -class PollerHandle { - friend class Poller; - - PollerHandlePrivate* const impl; - -public: - PollerHandle(const IOHandle& h); - - // Usual way to delete (will defer deletion until we - // can't be returned from a Poller::wait any more) - void deferDelete(); - - // Class clients shouldn't ever use this - virtual ~PollerHandle(); -}; - /** * Poller: abstract class to encapsulate a file descriptor poll to be used * by a reactor */ +class PollerHandle; class PollerPrivate; class Poller { PollerPrivate* const impl; @@ -87,6 +66,8 @@ public: handle(handle0), type(type0) { } + + void process(); }; Poller(); @@ -101,5 +82,32 @@ public: Event wait(Duration timeout = TIME_INFINITE); }; +/** + * Handle class to use for polling + */ +class IOHandle; +class PollerHandlePrivate; +class PollerHandle { + friend class Poller; + friend struct Poller::Event; + + PollerHandlePrivate* const impl; + virtual void processEvent(Poller::EventType) {}; + +public: + PollerHandle(const IOHandle& h); + + // Usual way to delete (will defer deletion until we + // can't be returned from a Poller::wait any more) + void deferDelete(); + + // Class clients shouldn't ever use this + virtual ~PollerHandle(); +}; + +inline void Poller::Event::process() { + handle->processEvent(type); +} + }} #endif // _sys_Poller_h -- cgit v1.2.1