From 5c2e3052815e76e7565038f771cdb235e0516816 Mon Sep 17 00:00:00 2001 From: Andrew Stitcher Date: Mon, 11 Aug 2008 16:00:43 +0000 Subject: Decouple the DispatchHandle from its clients by using a DispatchHandleRef class which can be deleted at any time, but will only cause the DispatchHandle to be deleted later when it's definitely no longer in use. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@684787 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/sys/Dispatcher.h | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'cpp/src') diff --git a/cpp/src/qpid/sys/Dispatcher.h b/cpp/src/qpid/sys/Dispatcher.h index 77a205cc8b..68661e81aa 100644 --- a/cpp/src/qpid/sys/Dispatcher.h +++ b/cpp/src/qpid/sys/Dispatcher.h @@ -36,9 +36,9 @@ namespace qpid { namespace sys { -class Dispatcher; +class DispatchHandleRef; class DispatchHandle : public PollerHandle { - friend class Dispatcher; + friend class DispatchHandleRef; public: typedef boost::function1 Callback; @@ -81,6 +81,28 @@ private: void processEvent(Poller::EventType dir); }; +class DispatchHandleRef { + DispatchHandle* ref; + +public: + typedef boost::function1 Callback; + DispatchHandleRef(const IOHandle& h, Callback rCb, Callback wCb, Callback dCb) : + ref(new DispatchHandle(h, rCb, wCb, dCb)) + {} + + ~DispatchHandleRef() { ref->doDelete(); } + + void startWatch(Poller::shared_ptr poller) { ref->startWatch(poller); } + void rewatch() { ref->rewatch(); } + void rewatchRead() { ref->rewatchRead(); } + void rewatchWrite() { ref->rewatchWrite(); } + void unwatch() { ref->unwatch(); } + void unwatchRead() { ref->unwatchRead(); } + void unwatchWrite() { ref->unwatchWrite(); } + void stopWatch() { ref->stopWatch(); } +}; + + class Dispatcher : public Runnable { const Poller::shared_ptr poller; -- cgit v1.2.1