[Libreoffice-commits] .: 2 commits - framework/inc framework/source
Caolán McNamara
caolan at kemper.freedesktop.org
Fri Jan 21 07:01:30 PST 2011
framework/inc/helper/mischelper.hxx | 105 +++++++++++++++++++++++++++++
framework/inc/jobs/jobexecutor.hxx | 3
framework/inc/services/autorecovery.hxx | 12 +++
framework/inc/services/pathsettings.hxx | 11 ---
framework/source/jobs/jobexecutor.cxx | 9 +-
framework/source/services/autorecovery.cxx | 12 ++-
framework/source/services/pathsettings.cxx | 41 ++---------
7 files changed, 146 insertions(+), 47 deletions(-)
New commits:
commit 4d28e6a519e625c41cd820233ff1a0a5e7078e46
Author: Caolán McNamara <caolanm at redhat.com>
Date: Fri Jan 21 14:13:20 2011 +0000
resolve more ownership cycles
diff --git a/framework/inc/helper/mischelper.hxx b/framework/inc/helper/mischelper.hxx
index dfcb295..ca99891 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 7967fd0..febb75c 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 61e39ea..56f0c90 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 6e87f56..cc681a1 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 efba645..142b2d4 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;
}
}
commit e7dd167309d82105d320af8aea7263229cf65fb1
Author: Caolán McNamara <caolanm at redhat.com>
Date: Fri Jan 21 12:50:42 2011 +0000
use a weakchangeslistener instead
diff --git a/framework/inc/helper/mischelper.hxx b/framework/inc/helper/mischelper.hxx
index e142893..dfcb295 100644
--- a/framework/inc/helper/mischelper.hxx
+++ b/framework/inc/helper/mischelper.hxx
@@ -31,6 +31,7 @@
#include <com/sun/star/linguistic2/XLanguageGuessing.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/util/XChangesListener.hpp>
#include <com/sun/star/container/XContainerListener.hpp>
#include <com/sun/star/frame/XFrame.hpp>
@@ -190,6 +191,44 @@ class WeakContainerListener : public ::cppu::WeakImplHelper1<com::sun::star::con
}
};
+class WeakChangesListener : public ::cppu::WeakImplHelper1<com::sun::star::util::XChangesListener>
+{
+ private:
+ com::sun::star::uno::WeakReference<com::sun::star::util::XChangesListener> mxOwner;
+
+ public:
+ WeakChangesListener(com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner)
+ : mxOwner(xOwner)
+ {
+ }
+
+ virtual ~WeakChangesListener()
+ {
+ }
+
+ // util.XChangesListener
+ virtual void SAL_CALL changesOccurred(const com::sun::star::util::ChangesEvent& rEvent)
+ throw(com::sun::star::uno::RuntimeException)
+ {
+ com::sun::star::uno::Reference<com::sun::star::util::XChangesListener> xOwner(mxOwner.get(),
+ com::sun::star::uno::UNO_QUERY);
+ if (xOwner.is())
+ xOwner->changesOccurred(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::util::XChangesListener> xOwner(mxOwner.get(),
+ com::sun::star::uno::UNO_QUERY);
+ if (xOwner.is())
+ xOwner->disposing(rEvent);
+
+ }
+};
+
+
} // namespace framework
#endif // __MISC_HELPER_HXX_
diff --git a/framework/inc/services/pathsettings.hxx b/framework/inc/services/pathsettings.hxx
index b8c3454..41585af 100644
--- a/framework/inc/services/pathsettings.hxx
+++ b/framework/inc/services/pathsettings.hxx
@@ -47,7 +47,6 @@
//_________________________________________________________________________________________________________________
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XTypeProvider.hpp>
-#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/util/XStringSubstitution.hpp>
#include <com/sun/star/util/XChangesListener.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
@@ -71,7 +70,6 @@ namespace framework
class PathSettings : public css::lang::XTypeProvider ,
public css::lang::XServiceInfo ,
- public css::lang::XComponent ,
public css::util::XChangesListener , // => XEventListener
// base classes
// Order is neccessary for right initialization!
@@ -161,8 +159,8 @@ class PathSettings : public css::lang::XTypeProvider ,
/** provides access to the new configuration schema. */
css::uno::Reference< css::container::XNameAccess > m_xCfgNew;
- /** container for ALL Listeners. */
- ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer;
+ /** helper to listen for configuration changes without ownership cycle problems */
+ css::uno::Reference< css::util::XChangesListener > m_xCfgNewListener;
::cppu::OPropertyArrayHelper* m_pPropHelp;
@@ -187,11 +185,6 @@ class PathSettings : public css::lang::XTypeProvider ,
FWK_DECLARE_XTYPEPROVIDER
DECLARE_XSERVICEINFO
- // css:lang::XComponent
- void SAL_CALL dispose() throw ( ::com::sun::star::uno::RuntimeException );
- void SAL_CALL addEventListener( const com::sun::star::uno::Reference< XEventListener >& xListener ) throw( com::sun::star::uno::RuntimeException );
- void SAL_CALL removeEventListener( const com::sun::star::uno::Reference< XEventListener >& xListener ) throw( com::sun::star::uno::RuntimeException );
-
// css::util::XChangesListener
virtual void SAL_CALL changesOccurred(const css::util::ChangesEvent& aEvent) throw (css::uno::RuntimeException);
diff --git a/framework/source/services/pathsettings.cxx b/framework/source/services/pathsettings.cxx
index 1eee95e..3fc6a08 100644
--- a/framework/source/services/pathsettings.cxx
+++ b/framework/source/services/pathsettings.cxx
@@ -40,6 +40,8 @@
#include <threadhelp/writeguard.hxx>
#include <services.h>
+#include "helper/mischelper.hxx"
+
// ______________________________________________
// interface includes
#include <com/sun/star/beans/Property.hpp>
@@ -48,7 +50,6 @@
#include <com/sun/star/container/XContainer.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/util/XChangesNotifier.hpp>
-#include <com/sun/star/lang/XComponent.hpp>
// ______________________________________________
// includes of other projects
@@ -99,11 +100,10 @@ namespace framework
//-----------------------------------------------------------------------------
// XInterface, XTypeProvider, XServiceInfo
-DEFINE_XINTERFACE_8 ( PathSettings ,
+DEFINE_XINTERFACE_7 ( PathSettings ,
OWeakObject ,
DIRECT_INTERFACE ( css::lang::XTypeProvider ),
DIRECT_INTERFACE ( css::lang::XServiceInfo ),
- DIRECT_INTERFACE ( css::lang::XComponent ),
DERIVED_INTERFACE( css::lang::XEventListener, css::util::XChangesListener),
DIRECT_INTERFACE ( css::util::XChangesListener ),
DIRECT_INTERFACE ( css::beans::XPropertySet ),
@@ -111,11 +111,10 @@ DEFINE_XINTERFACE_8 ( PathSettings
DIRECT_INTERFACE ( css::beans::XMultiPropertySet )
)
-DEFINE_XTYPEPROVIDER_8 ( PathSettings ,
+DEFINE_XTYPEPROVIDER_7 ( PathSettings ,
css::lang::XTypeProvider ,
css::lang::XServiceInfo ,
css::lang::XEventListener ,
- css::lang::XComponent ,
css::util::XChangesListener ,
css::beans::XPropertySet ,
css::beans::XFastPropertySet ,
@@ -153,7 +152,6 @@ PathSettings::PathSettings( const css::uno::Reference< css::lang::XMultiServiceF
, ::cppu::OWeakObject()
// Init member
, m_xSMGR (xSMGR)
- , m_aListenerContainer(m_aLock.getShareableOslMutex())
, m_pPropHelp(0 )
, m_bIgnoreEvents(sal_False)
{
@@ -163,6 +161,9 @@ PathSettings::PathSettings( const css::uno::Reference< css::lang::XMultiServiceF
//-----------------------------------------------------------------------------
PathSettings::~PathSettings()
{
+ css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfgNew, css::uno::UNO_QUERY);
+ if (xBroadcaster.is())
+ xBroadcaster->removeChangesListener(m_xCfgNewListener);
if (m_pPropHelp)
delete m_pPropHelp;
}
@@ -209,37 +210,12 @@ void SAL_CALL PathSettings::disposing(const css::lang::EventObject& aSource)
throw(css::uno::RuntimeException)
{
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "framework", "Ocke.Janssen at sun.com", "PathSettings::disposing" );
- // SAFE ->
WriteGuard aWriteLock(m_aLock);
if (aSource.Source == m_xCfgNew)
m_xCfgNew.clear();
aWriteLock.unlock();
- // <- SAFE
-}
-
-void SAL_CALL PathSettings::dispose() throw (css::uno::RuntimeException)
-{
- css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(m_xCfgNew, css::uno::UNO_QUERY_THROW);
- if (xBroadcaster.is())
- xBroadcaster->removeChangesListener(static_cast< css::util::XChangesListener* >(this));
-
- css::uno::Reference< css::uno::XInterface > xThis ( static_cast< ::cppu::OWeakObject* >(this), css::uno::UNO_QUERY );
- css::lang::EventObject aEvent( xThis );
- m_aListenerContainer.disposeAndClear( aEvent );
-}
-
-void SAL_CALL PathSettings::addEventListener(const css::uno::Reference< css::lang::XEventListener >& xListener)
- throw (css::uno::RuntimeException)
-{
- m_aListenerContainer.addInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >*) NULL ), xListener );
-}
-
-void SAL_CALL PathSettings::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener)
- throw (css::uno::RuntimeException)
-{
- m_aListenerContainer.addInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >*) NULL ), xListener );
}
//-----------------------------------------------------------------------------
@@ -1196,10 +1172,11 @@ css::uno::Reference< css::container::XNameAccess > PathSettings::fa_getCfgNew()
// SAFE ->
WriteGuard aWriteLock(m_aLock);
m_xCfgNew = xCfg;
+ m_xCfgNewListener = new WeakChangesListener(this);
aWriteLock.unlock();
css::uno::Reference< css::util::XChangesNotifier > xBroadcaster(xCfg, css::uno::UNO_QUERY_THROW);
- xBroadcaster->addChangesListener(static_cast< css::util::XChangesListener* >(this));
+ xBroadcaster->addChangesListener(m_xCfgNewListener);
}
return xCfg;
More information about the Libreoffice-commits
mailing list