diff options
author | Caolán McNamara <caolanm@redhat.com> | 2011-01-21 14:13:20 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2011-01-21 14:21:36 +0000 |
commit | 4d28e6a519e625c41cd820233ff1a0a5e7078e46 (patch) | |
tree | 66ba9b7832093b4f6f33893b34b5651e46bebb84 | |
parent | e7dd167309d82105d320af8aea7263229cf65fb1 (diff) |
resolve more ownership cycles
-rw-r--r-- | framework/inc/helper/mischelper.hxx | 66 | ||||
-rw-r--r-- | framework/inc/jobs/jobexecutor.hxx | 3 | ||||
-rw-r--r-- | framework/inc/services/autorecovery.hxx | 12 | ||||
-rw-r--r-- | framework/source/jobs/jobexecutor.cxx | 9 | ||||
-rw-r--r-- | framework/source/services/autorecovery.cxx | 12 |
5 files changed, 96 insertions, 6 deletions
diff --git a/framework/inc/helper/mischelper.hxx b/framework/inc/helper/mischelper.hxx index dfcb295599..ca99891dd0 100644 --- a/framework/inc/helper/mischelper.hxx +++ b/framework/inc/helper/mischelper.hxx @@ -31,6 +31,8 @@ #include <com/sun/star/linguistic2/XLanguageGuessing.hpp> #include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/document/XEventListener.hpp> +#include <com/sun/star/lang/XEventListener.hpp> #include <com/sun/star/util/XChangesListener.hpp> #include <com/sun/star/container/XContainerListener.hpp> #include <com/sun/star/frame/XFrame.hpp> @@ -228,6 +230,70 @@ class WeakChangesListener : public ::cppu::WeakImplHelper1<com::sun::star::util: } }; +class WeakEventListener : public ::cppu::WeakImplHelper1<com::sun::star::lang::XEventListener> +{ + private: + com::sun::star::uno::WeakReference<com::sun::star::lang::XEventListener> mxOwner; + + public: + WeakEventListener(com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xOwner) + : mxOwner(xOwner) + { + } + + virtual ~WeakEventListener() + { + } + + // lang.XEventListener + virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent) + throw(com::sun::star::uno::RuntimeException) + { + com::sun::star::uno::Reference<com::sun::star::lang::XEventListener> xOwner(mxOwner.get(), + com::sun::star::uno::UNO_QUERY); + if (xOwner.is()) + xOwner->disposing(rEvent); + + } +}; + +class WeakDocumentEventListener : public ::cppu::WeakImplHelper1<com::sun::star::document::XEventListener> +{ + private: + com::sun::star::uno::WeakReference<com::sun::star::document::XEventListener> mxOwner; + + public: + WeakDocumentEventListener(com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner) + : mxOwner(xOwner) + { + } + + virtual ~WeakDocumentEventListener() + { + } + + virtual void SAL_CALL notifyEvent(const com::sun::star::document::EventObject& rEvent) + throw(com::sun::star::uno::RuntimeException) + { + com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner(mxOwner.get(), + com::sun::star::uno::UNO_QUERY); + if (xOwner.is()) + xOwner->notifyEvent(rEvent); + + } + + // lang.XEventListener + virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent) + throw(com::sun::star::uno::RuntimeException) + { + com::sun::star::uno::Reference<com::sun::star::document::XEventListener> xOwner(mxOwner.get(), + com::sun::star::uno::UNO_QUERY); + if (xOwner.is()) + xOwner->disposing(rEvent); + + } +}; + } // namespace framework diff --git a/framework/inc/jobs/jobexecutor.hxx b/framework/inc/jobs/jobexecutor.hxx index 7967fd0dab..febb75c678 100644 --- a/framework/inc/jobs/jobexecutor.hxx +++ b/framework/inc/jobs/jobexecutor.hxx @@ -92,6 +92,9 @@ class JobExecutor : public css::lang::XTypeProvider /** we listen at the configuration for changes at the event list. */ ConfigAccess m_aConfig; + /** helper to allow us listen to the configuration without a cyclic dependency */ + com::sun::star::uno::Reference<com::sun::star::container::XContainerListener> m_xConfigListener; + //___________________________________ // native interface methods diff --git a/framework/inc/services/autorecovery.hxx b/framework/inc/services/autorecovery.hxx index 61e39ea3dc..56f0c90180 100644 --- a/framework/inc/services/autorecovery.hxx +++ b/framework/inc/services/autorecovery.hxx @@ -335,6 +335,12 @@ class AutoRecovery : public css::lang::XTypeProvider css::uno::Reference< css::container::XNameAccess > m_xRecoveryCFG; //--------------------------------------- + /** @short proxy weak binding to forward Events to ourself without + an ownership cycle + */ + css::uno::Reference< css::util::XChangesListener > m_xRecoveryCFGListener; + + //--------------------------------------- /** @short points to the used configuration package or.openoffice.Setup @descr This instance does not cache - it calls directly the configuration API! @@ -348,6 +354,12 @@ class AutoRecovery : public css::lang::XTypeProvider css::uno::Reference< css::document::XEventBroadcaster > m_xNewDocBroadcaster; //--------------------------------------- + /** @short proxy weak binding to forward Events to ourself without + an ownership cycle + */ + css::uno::Reference< css::document::XEventListener > m_xNewDocBroadcasterListener; + + //--------------------------------------- /** @short because we stop/restart listening sometimes, it's a good idea to know if we already registered as listener .-) */ diff --git a/framework/source/jobs/jobexecutor.cxx b/framework/source/jobs/jobexecutor.cxx index 6e87f563a1..cc681a1848 100644 --- a/framework/source/jobs/jobexecutor.cxx +++ b/framework/source/jobs/jobexecutor.cxx @@ -42,6 +42,8 @@ #include <general.h> #include <services.h> +#include "helper/mischelper.hxx" + //________________________________ // interface includes #include <com/sun/star/beans/XPropertySet.hpp> @@ -118,8 +120,8 @@ DEFINE_INIT_SERVICE( JobExecutor, css::uno::Reference< css::container::XContainer > xNotifier(m_aConfig.cfg(), css::uno::UNO_QUERY); if (xNotifier.is()) { - css::uno::Reference< css::container::XContainerListener > xThis(static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY); - xNotifier->addContainerListener(xThis); + m_xConfigListener = new WeakContainerListener(this); + xNotifier->addContainerListener(m_xConfigListener); } // don't close cfg here! @@ -149,6 +151,9 @@ JobExecutor::JobExecutor( /*IN*/ const css::uno::Reference< css::lang::XMultiSer JobExecutor::~JobExecutor() { + css::uno::Reference< css::container::XContainer > xNotifier(m_aConfig.cfg(), css::uno::UNO_QUERY); + if (xNotifier.is()) + xNotifier->removeContainerListener(m_xConfigListener); LOG_ASSERT(m_aConfig.getMode() == ConfigAccess::E_CLOSED, "JobExecutor::~JobExecutor()\nConfiguration don't send dispoing() message!\n") } diff --git a/framework/source/services/autorecovery.cxx b/framework/source/services/autorecovery.cxx index efba6458bc..142b2d4d43 100644 --- a/framework/source/services/autorecovery.cxx +++ b/framework/source/services/autorecovery.cxx @@ -44,6 +44,8 @@ #include <properties.h> #include <services.h> +#include "helper/mischelper.hxx" + //_______________________________________________ // interface includes #include <com/sun/star/ucb/NameClash.hpp> @@ -1362,7 +1364,8 @@ void AutoRecovery::implts_startListening() (! m_bListenForConfigChanges) ) { - xCFG->addChangesListener(static_cast< css::util::XChangesListener* >(this)); + m_xRecoveryCFGListener = new WeakChangesListener(this); + xCFG->addChangesListener(m_xRecoveryCFGListener); m_bListenForConfigChanges = sal_True; } @@ -1381,7 +1384,8 @@ void AutoRecovery::implts_startListening() (! bListenForDocEvents) ) { - xBroadcaster->addEventListener(static_cast< css::document::XEventListener* >(this)); + m_xNewDocBroadcasterListener = new WeakDocumentEventListener(this); + xBroadcaster->addEventListener(m_xNewDocBroadcasterListener); // SAFE -> WriteGuard aWriteLock(m_aLock); m_bListenForDocEvents = sal_True; @@ -1408,7 +1412,7 @@ void AutoRecovery::implts_stopListening() (m_bListenForDocEvents ) ) { - xGlobalEventBroadcaster->removeEventListener(static_cast< css::document::XEventListener* >(this)); + xGlobalEventBroadcaster->removeEventListener(m_xNewDocBroadcasterListener); m_bListenForDocEvents = sal_False; } @@ -1417,7 +1421,7 @@ void AutoRecovery::implts_stopListening() (m_bListenForConfigChanges) ) { - xCFG->removeChangesListener(static_cast< css::util::XChangesListener* >(this)); + xCFG->removeChangesListener(m_xRecoveryCFGListener); m_bListenForConfigChanges = sal_False; } } |