[Libreoffice-commits] core.git: 4 commits - basctl/source bin/benchmark-document-loading bin/convwatch.py cppuhelper/source cui/source dbaccess/qa dbaccess/source desktop/source extensions/source filter/source framework/inc framework/source offapi/com offapi/UnoApi_offapi.mk sfx2/Library_sfx.mk sfx2/source sfx2/util sw/qa ucb/source
Stephan Bergmann
sbergman at redhat.com
Thu Jan 16 09:40:35 PST 2014
basctl/source/basicide/doceventnotifier.cxx | 6
basctl/source/inc/doceventnotifier.hxx | 2
bin/benchmark-document-loading | 3
bin/convwatch.py | 4
cppuhelper/source/servicemanager.cxx | 456 ++++++++-----
cppuhelper/source/servicemanager.hxx | 31
cui/source/customize/eventdlg.cxx | 4
dbaccess/qa/complex/dbaccess/Beamer.java | 6
dbaccess/qa/complex/dbaccess/DatabaseDocument.java | 9
dbaccess/source/core/dataaccess/ModelImpl.cxx | 4
desktop/source/app/app.cxx | 4
extensions/source/update/ui/updatecheckui.cxx | 21
filter/source/config/cache/lateinitlistener.cxx | 4
filter/source/xsltdialog/xmlfiltertestdialog.cxx | 4
framework/inc/services/autorecovery.hxx | 2
framework/source/services/autorecovery.cxx | 6
offapi/UnoApi_offapi.mk | 1
offapi/com/sun/star/frame/GlobalEventBroadcaster.idl | 9
offapi/com/sun/star/frame/XGlobalEventBroadcaster.idl | 2
offapi/com/sun/star/frame/theGlobalEventBroadcaster.idl | 46 +
sfx2/Library_sfx.mk | 1
sfx2/source/appl/appinit.cxx | 4
sfx2/source/appl/appuno.cxx | 45 -
sfx2/source/config/evntconf.cxx | 4
sfx2/source/doc/objstor.cxx | 4
sfx2/source/inc/eventsupplier.hxx | 137 ----
sfx2/source/notify/eventsupplier.cxx | 353 ----------
sfx2/source/notify/globalevents.cxx | 542 ++++++++++++++++
sfx2/util/sfx.component | 4
sw/qa/complex/writer/LoadSaveTest.java | 10
sw/qa/extras/uiwriter/uiwriter.cxx | 1
ucb/source/ucp/tdoc/tdoc_docmgr.cxx | 4
32 files changed, 969 insertions(+), 764 deletions(-)
New commits:
commit 7b3e7c46d7245aba87a3f4742b2c7911095a3bc0
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Jan 16 18:32:28 2014 +0100
Assert SwReaderWriter::GetReader returning non-null
...happened to fail for me once, for unclear reasons.
Change-Id: Idf88ff4952924a814e465b039fbae384691ba7a6
diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index a40f4c0..080b879 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -163,6 +163,7 @@ void SwUiWriterTest::testImportRTF()
SvMemoryStream aStream(const_cast<sal_Char*>(aData.getStr()), aData.getLength(), STREAM_READ);
SwReader aReader(aStream, OUString(), OUString(), *pWrtShell->GetCrsr());
Reader* pRTFReader = SwReaderWriter::GetReader(READER_WRITER_RTF);
+ CPPUNIT_ASSERT(pRTFReader != 0);
CPPUNIT_ASSERT_EQUAL(sal_uLong(0), aReader.Read(*pRTFReader));
sal_uLong nIndex = pWrtShell->GetCrsr()->GetNode()->GetIndex();
commit 3557c07899e363a9b7e1cceca632ad9112d039a2
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Jan 16 09:25:21 2014 +0100
Revert "Revert "sfx: Use constructor feature for SfxGlobalEvents_Impl.""
This reverts commit ef37781683e28d1837cfce86de990e59d2c10c5f, now that
constructor function support for singleton implementations is in place and the
proper singleton theGlobalEventBroadcaster has been introduced (and drops
sfx_component_getFactory completely, which had become unused except for
SfxGlobalEvents_Impl in the meantime).
Change-Id: I2d587989dd0a1fbea6fe75f7dc2af954ac81c4ed
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index bdd6812..f4eafa2 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -236,6 +236,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
sfx2/source/menu/thessubmenu \
sfx2/source/menu/virtmenu \
sfx2/source/notify/eventsupplier \
+ sfx2/source/notify/globalevents \
sfx2/source/notify/hintpost \
sfx2/source/sidebar/Sidebar \
sfx2/source/sidebar/SidebarChildWindow \
diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx
index 778ec14..a642ce5 100644
--- a/sfx2/source/appl/appuno.cxx
+++ b/sfx2/source/appl/appuno.cxx
@@ -21,7 +21,6 @@
#pragma warning( disable : 4290 )
#endif
-#include "eventsupplier.hxx"
#include "fltoptint.hxx"
#include "objshimp.hxx"
#include <sfx2/app.hxx>
@@ -1693,50 +1692,6 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b
rArgs = aSequ;
}
-// -----------------------------------------------------------------------
-
-extern "C" {
-
-SFX2_DLLPUBLIC void* SAL_CALL sfx_component_getFactory(
- const sal_Char* pImplementationName ,
- void* pServiceManager ,
- void* )
-{
- // Set default return value for this operation - if it failed.
- void* pReturn = NULL ;
-
- if (
- ( pImplementationName != NULL ) &&
- ( pServiceManager != NULL )
- )
- {
- // Define variables which are used in following macros.
- uno::Reference<uno::XInterface> xFactory;
- uno::Reference<lang::XMultiServiceFactory> xServiceManager( reinterpret_cast<lang::XMultiServiceFactory*>( pServiceManager ) ) ;
-
- //=============================================================================
- // Add new macro line to handle new service.
- // !!! ATTENTION !!!
- // Write no ";" at end of line and dont forget "else" ! (see macro)
- //=============================================================================
- IF_NAME_CREATECOMPONENTFACTORY( SfxGlobalEvents_Impl )
-
- // Factory is valid - service was found.
-
- // Factory is valid - service was found.
- if ( xFactory.is() )
- {
- xFactory->acquire();
- pReturn = xFactory.get();
- }
- }
- // Return with result of this operation.
- return pReturn ;
-}
-} // extern "C"
-
-//=========================================================================
-
void SAL_CALL FilterOptionsContinuation::setFilterOptions(
const uno::Sequence<beans::PropertyValue>& rProps )
throw (uno::RuntimeException)
diff --git a/sfx2/source/inc/eventsupplier.hxx b/sfx2/source/inc/eventsupplier.hxx
index 2465ca8..d8d2a8d 100644
--- a/sfx2/source/inc/eventsupplier.hxx
+++ b/sfx2/source/inc/eventsupplier.hxx
@@ -20,9 +20,9 @@
#ifndef INCLUDED_SFX2_SOURCE_INC_EVENTSUPPLIER_HXX
#define INCLUDED_SFX2_SOURCE_INC_EVENTSUPPLIER_HXX
-#include <com/sun/star/lang/XTypeProvider.hpp>
+#include <sal/types.h>
+
#include <com/sun/star/container/XNameReplace.hpp>
-#include <com/sun/star/container/XSet.hpp>
#include <com/sun/star/document/XEventListener.hpp>
#include <com/sun/star/document/XEventBroadcaster.hpp>
#include <com/sun/star/document/XDocumentEventListener.hpp>
@@ -32,11 +32,7 @@
#include <com/sun/star/task/XJobExecutor.hpp>
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Type.hxx>
-#include <sal/types.h>
-#include <osl/mutex.hxx>
-#include <cppuhelper/implbase1.hxx>
#include <cppuhelper/implbase2.hxx>
-#include <cppuhelper/implbase3.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <comphelper/sequenceasvector.hxx>
#include <sfx2/sfxuno.hxx>
@@ -98,134 +94,7 @@ public:
const ::comphelper::NamedValueCollection& i_eventDescriptor,
::comphelper::NamedValueCollection& o_normalizedDescriptor,
SfxObjectShell* i_document );
-};
-
-//=============================================================================
-struct ModelCollectionMutexBase
-{
- public:
- ::osl::Mutex m_aLock;
-};
-
-//=============================================================================
-typedef ::std::vector< css::uno::Reference< css::frame::XModel > > TModelList;
-
-//=============================================================================
-class ModelCollectionEnumeration : public ModelCollectionMutexBase
- , public ::cppu::WeakImplHelper1< css::container::XEnumeration >
-{
-
- //-------------------------------------------------------------------------
- // member
- //-------------------------------------------------------------------------
- private:
- TModelList m_lModels;
- TModelList::iterator m_pEnumerationIt;
-
- //-------------------------------------------------------------------------
- // native interface
- //-------------------------------------------------------------------------
- public:
- ModelCollectionEnumeration();
- virtual ~ModelCollectionEnumeration();
- void setModelList(const TModelList& rList);
-
- //-------------------------------------------------------------------------
- // uno interface
- //-------------------------------------------------------------------------
- public:
-
- // css.container.XEnumeration
- virtual sal_Bool SAL_CALL hasMoreElements()
- throw(css::uno::RuntimeException);
-
- virtual css::uno::Any SAL_CALL nextElement()
- throw(css::container::NoSuchElementException,
- css::lang::WrappedTargetException ,
- css::uno::RuntimeException );
-};
-
-//=============================================================================
-//TODO: remove support of obsolete document::XEventBroadcaster/Listener
-class SfxGlobalEvents_Impl : public ModelCollectionMutexBase
- , public ::cppu::WeakImplHelper3< css::lang::XServiceInfo
- , css::frame::XGlobalEventBroadcaster
- , css::document::XEventListener
- >
-{
- css::uno::Reference< css::container::XNameReplace > m_xEvents;
- css::uno::Reference< css::document::XEventListener > m_xJobExecutorListener;
- ::cppu::OInterfaceContainerHelper m_aLegacyListeners;
- ::cppu::OInterfaceContainerHelper m_aDocumentListeners;
- TModelList m_lModels;
- GlobalEventConfig* pImp;
-
-public:
- SfxGlobalEvents_Impl(const css::uno::Reference < css::uno::XComponentContext >& rxContext);
- virtual ~SfxGlobalEvents_Impl();
-
- SFX_DECL_XSERVICEINFO
-
- // css.document.XEventBroadcaster
- virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents()
- throw(css::uno::RuntimeException);
-
- virtual void SAL_CALL addEventListener(const css::uno::Reference< css::document::XEventListener >& xListener)
- throw(css::uno::RuntimeException);
-
- virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::document::XEventListener >& xListener)
- throw(css::uno::RuntimeException);
-
- // css.document.XDocumentEventBroadcaster
- virtual void SAL_CALL addDocumentEventListener( const css::uno::Reference< css::document::XDocumentEventListener >& _Listener ) throw (css::uno::RuntimeException);
- virtual void SAL_CALL removeDocumentEventListener( const css::uno::Reference< css::document::XDocumentEventListener >& _Listener ) throw (css::uno::RuntimeException);
- virtual void SAL_CALL notifyDocumentEvent( const OUString& _EventName, const css::uno::Reference< css::frame::XController2 >& _ViewController, const css::uno::Any& _Supplement ) throw (css::lang::IllegalArgumentException, css::lang::NoSupportException, css::uno::RuntimeException);
-
- // css.document.XEventListener
- virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent)
- throw(css::uno::RuntimeException);
-
- // css.document.XDocumentEventListener
- virtual void SAL_CALL documentEventOccured( const css::document::DocumentEvent& Event ) throw (css::uno::RuntimeException);
-
- // css.container.XSet
- virtual sal_Bool SAL_CALL has(const css::uno::Any& aElement)
- throw(css::uno::RuntimeException);
-
- virtual void SAL_CALL insert(const css::uno::Any& aElement)
- throw(css::lang::IllegalArgumentException ,
- css::container::ElementExistException,
- css::uno::RuntimeException );
-
- virtual void SAL_CALL remove(const css::uno::Any& aElement)
- throw(css::lang::IllegalArgumentException ,
- css::container::NoSuchElementException,
- css::uno::RuntimeException );
-
- // css.container.XEnumerationAccess
- virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration()
- throw(css::uno::RuntimeException);
-
- // css.container.XElementAccess
- virtual css::uno::Type SAL_CALL getElementType()
- throw(css::uno::RuntimeException);
-
- virtual sal_Bool SAL_CALL hasElements()
- throw(css::uno::RuntimeException);
-
- // css.lang.XEventListener
- virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
- throw(css::uno::RuntimeException);
-
-private:
-
- // threadsafe
- void implts_notifyJobExecution(const css::document::EventObject& aEvent);
- void implts_checkAndExecuteEventBindings(const css::document::DocumentEvent& aEvent);
- void implts_notifyListener(const css::document::DocumentEvent& aEvent);
-
- // not threadsafe
- TModelList::iterator impl_searchDoc(const css::uno::Reference< css::frame::XModel >& xModel);
+ static void Execute( css::uno::Any& aEventData, const css::document::DocumentEvent& aTrigger, SfxObjectShell* pDoc );
};
#endif
diff --git a/sfx2/source/notify/eventsupplier.cxx b/sfx2/source/notify/eventsupplier.cxx
index 418f35d..067ae21 100644
--- a/sfx2/source/notify/eventsupplier.cxx
+++ b/sfx2/source/notify/eventsupplier.cxx
@@ -179,7 +179,7 @@ sal_Bool SAL_CALL SfxEvents_Impl::hasElements() throw ( uno::RuntimeException )
return sal_False;
}
-static void Execute( uno::Any& aEventData, const document::DocumentEvent& aTrigger, SfxObjectShell* pDoc )
+void SfxEvents_Impl::Execute( uno::Any& aEventData, const document::DocumentEvent& aTrigger, SfxObjectShell* pDoc )
{
uno::Sequence < beans::PropertyValue > aProperties;
if ( aEventData >>= aProperties )
@@ -488,355 +488,4 @@ void SfxEvents_Impl::NormalizeMacro( const ::comphelper::NamedValueCollection& i
}
}
-ModelCollectionEnumeration::ModelCollectionEnumeration()
- : ModelCollectionMutexBase( )
- , m_pEnumerationIt (m_lModels.begin())
-{
-}
-
-ModelCollectionEnumeration::~ModelCollectionEnumeration()
-{
-}
-
-void ModelCollectionEnumeration::setModelList(const TModelList& rList)
-{
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- m_lModels = rList;
- m_pEnumerationIt = m_lModels.begin();
- aLock.clear();
- // <- SAFE
-}
-
-sal_Bool SAL_CALL ModelCollectionEnumeration::hasMoreElements()
- throw(uno::RuntimeException)
-{
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- return (m_pEnumerationIt != m_lModels.end());
- // <- SAFE
-}
-
-uno::Any SAL_CALL ModelCollectionEnumeration::nextElement()
- throw(container::NoSuchElementException,
- lang::WrappedTargetException ,
- uno::RuntimeException )
-{
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- if (m_pEnumerationIt == m_lModels.end())
- throw container::NoSuchElementException(
- OUString("End of model enumeration reached."),
- static_cast< container::XEnumeration* >(this));
- uno::Reference< frame::XModel > xModel(*m_pEnumerationIt, uno::UNO_QUERY);
- ++m_pEnumerationIt;
- aLock.clear();
- // <- SAFE
-
- return uno::makeAny(xModel);
-}
-
-SFX_IMPL_XSERVICEINFO_CTX( SfxGlobalEvents_Impl, "com.sun.star.frame.GlobalEventBroadcaster", "com.sun.star.comp.sfx2.GlobalEventBroadcaster" )
-SFX_IMPL_ONEINSTANCEFACTORY( SfxGlobalEvents_Impl );
-
-//-----------------------------------------------------------------------------
-SfxGlobalEvents_Impl::SfxGlobalEvents_Impl( const uno::Reference < uno::XComponentContext >& rxContext)
- : ModelCollectionMutexBase( )
- , m_xJobExecutorListener( task::JobExecutor::create( rxContext ), uno::UNO_QUERY_THROW )
- , m_aLegacyListeners (m_aLock)
- , m_aDocumentListeners (m_aLock)
- , pImp (0 )
-{
- m_refCount++;
- SFX_APP();
- pImp = new GlobalEventConfig();
- m_xEvents = pImp;
- m_refCount--;
-}
-
-//-----------------------------------------------------------------------------
-SfxGlobalEvents_Impl::~SfxGlobalEvents_Impl()
-{
-}
-
-//-----------------------------------------------------------------------------
-uno::Reference< container::XNameReplace > SAL_CALL SfxGlobalEvents_Impl::getEvents()
- throw(uno::RuntimeException)
-{
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- return m_xEvents;
- // <- SAFE
-}
-
-//-----------------------------------------------------------------------------
-void SAL_CALL SfxGlobalEvents_Impl::addEventListener(const uno::Reference< document::XEventListener >& xListener)
- throw(uno::RuntimeException)
-{
- // container is threadsafe
- m_aLegacyListeners.addInterface(xListener);
-}
-
-//-----------------------------------------------------------------------------
-void SAL_CALL SfxGlobalEvents_Impl::removeEventListener(const uno::Reference< document::XEventListener >& xListener)
- throw(uno::RuntimeException)
-{
- // container is threadsafe
- m_aLegacyListeners.removeInterface(xListener);
-}
-
-//-----------------------------------------------------------------------------
-void SAL_CALL SfxGlobalEvents_Impl::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& _Listener )
- throw(uno::RuntimeException)
-{
- m_aDocumentListeners.addInterface( _Listener );
-}
-
-//-----------------------------------------------------------------------------
-void SAL_CALL SfxGlobalEvents_Impl::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& _Listener )
- throw(uno::RuntimeException)
-{
- m_aDocumentListeners.removeInterface( _Listener );
-}
-
-//-----------------------------------------------------------------------------
-void SAL_CALL SfxGlobalEvents_Impl::notifyDocumentEvent( const OUString& /*_EventName*/,
- const uno::Reference< frame::XController2 >& /*_ViewController*/, const uno::Any& /*_Supplement*/ )
- throw (lang::IllegalArgumentException, lang::NoSupportException, uno::RuntimeException)
-{
- // we're a multiplexer only, no chance to generate artifical events here
- throw lang::NoSupportException(OUString(), *this);
-}
-
-//-----------------------------------------------------------------------------
-void SAL_CALL SfxGlobalEvents_Impl::notifyEvent(const document::EventObject& aEvent)
- throw(uno::RuntimeException)
-{
- document::DocumentEvent aDocEvent(aEvent.Source, aEvent.EventName, NULL, uno::Any());
- implts_notifyJobExecution(aEvent);
- implts_checkAndExecuteEventBindings(aDocEvent);
- implts_notifyListener(aDocEvent);
-}
-
-//-----------------------------------------------------------------------------
-void SAL_CALL SfxGlobalEvents_Impl::documentEventOccured( const document::DocumentEvent& _Event )
- throw (uno::RuntimeException)
-{
- implts_notifyJobExecution(document::EventObject(_Event.Source, _Event.EventName));
- implts_checkAndExecuteEventBindings(_Event);
- implts_notifyListener(_Event);
-}
-
-//-----------------------------------------------------------------------------
-void SAL_CALL SfxGlobalEvents_Impl::disposing(const lang::EventObject& aEvent)
- throw(uno::RuntimeException)
-{
- uno::Reference< frame::XModel > xDoc(aEvent.Source, uno::UNO_QUERY);
-
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- TModelList::iterator pIt = impl_searchDoc(xDoc);
- if (pIt != m_lModels.end())
- m_lModels.erase(pIt);
- aLock.clear();
- // <- SAFE
-}
-
-//-----------------------------------------------------------------------------
-sal_Bool SAL_CALL SfxGlobalEvents_Impl::has(const uno::Any& aElement)
- throw (uno::RuntimeException)
-{
- uno::Reference< frame::XModel > xDoc;
- aElement >>= xDoc;
-
- sal_Bool bHas = sal_False;
-
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- TModelList::iterator pIt = impl_searchDoc(xDoc);
- if (pIt != m_lModels.end())
- bHas = sal_True;
- aLock.clear();
- // <- SAFE
-
- return bHas;
-}
-
-//-----------------------------------------------------------------------------
-void SAL_CALL SfxGlobalEvents_Impl::insert( const uno::Any& aElement )
- throw (lang::IllegalArgumentException ,
- container::ElementExistException,
- uno::RuntimeException )
-{
- uno::Reference< frame::XModel > xDoc;
- aElement >>= xDoc;
- if (!xDoc.is())
- throw lang::IllegalArgumentException(
- OUString("Cant locate at least the model parameter."),
- static_cast< container::XSet* >(this),
- 0);
-
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- TModelList::iterator pIt = impl_searchDoc(xDoc);
- if (pIt != m_lModels.end())
- throw container::ElementExistException(
- OUString(),
- static_cast< container::XSet* >(this));
- m_lModels.push_back(xDoc);
- aLock.clear();
- // <- SAFE
-
- uno::Reference< document::XDocumentEventBroadcaster > xDocBroadcaster(xDoc, uno::UNO_QUERY );
- if (xDocBroadcaster.is())
- xDocBroadcaster->addDocumentEventListener(this);
- else
- {
- // try the "legacy version" of XDocumentEventBroadcaster, which is XEventBroadcaster
- uno::Reference< document::XEventBroadcaster > xBroadcaster(xDoc, uno::UNO_QUERY);
- if (xBroadcaster.is())
- xBroadcaster->addEventListener(static_cast< document::XEventListener* >(this));
- }
-}
-
-//-----------------------------------------------------------------------------
-void SAL_CALL SfxGlobalEvents_Impl::remove( const uno::Any& aElement )
- throw (lang::IllegalArgumentException ,
- container::NoSuchElementException,
- uno::RuntimeException )
-{
- uno::Reference< frame::XModel > xDoc;
- aElement >>= xDoc;
- if (!xDoc.is())
- throw lang::IllegalArgumentException(
- OUString("Cant locate at least the model parameter."),
- static_cast< container::XSet* >(this),
- 0);
-
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- TModelList::iterator pIt = impl_searchDoc(xDoc);
- if (pIt == m_lModels.end())
- throw container::NoSuchElementException(
- OUString(),
- static_cast< container::XSet* >(this));
- m_lModels.erase(pIt);
- aLock.clear();
- // <- SAFE
-
- uno::Reference< document::XDocumentEventBroadcaster > xDocBroadcaster(xDoc, uno::UNO_QUERY );
- if (xDocBroadcaster.is())
- xDocBroadcaster->removeDocumentEventListener(this);
- else
- {
- // try the "legacy version" of XDocumentEventBroadcaster, which is XEventBroadcaster
- uno::Reference< document::XEventBroadcaster > xBroadcaster(xDoc, uno::UNO_QUERY);
- if (xBroadcaster.is())
- xBroadcaster->removeEventListener(static_cast< document::XEventListener* >(this));
- }
-}
-
-//-----------------------------------------------------------------------------
-uno::Reference< container::XEnumeration > SAL_CALL SfxGlobalEvents_Impl::createEnumeration()
- throw (uno::RuntimeException)
-{
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- ModelCollectionEnumeration* pEnum = new ModelCollectionEnumeration();
- pEnum->setModelList(m_lModels);
- uno::Reference< container::XEnumeration > xEnum(
- static_cast< container::XEnumeration* >(pEnum),
- uno::UNO_QUERY);
- aLock.clear();
- // <- SAFE
-
- return xEnum;
-}
-
-//-----------------------------------------------------------------------------
-uno::Type SAL_CALL SfxGlobalEvents_Impl::getElementType()
- throw (uno::RuntimeException)
-{
- return ::getCppuType(static_cast< uno::Reference< frame::XModel >* >(NULL));
-}
-
-//-----------------------------------------------------------------------------
-sal_Bool SAL_CALL SfxGlobalEvents_Impl::hasElements()
- throw (uno::RuntimeException)
-{
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- return (m_lModels.size()>0);
- // <- SAFE
-}
-
-//-----------------------------------------------------------------------------
-void SfxGlobalEvents_Impl::implts_notifyJobExecution(const document::EventObject& aEvent)
-{
- try
- {
- m_xJobExecutorListener->notifyEvent(aEvent);
- }
- catch(const uno::RuntimeException&)
- { throw; }
- catch(const uno::Exception&)
- {}
-}
-
-//-----------------------------------------------------------------------------
-void SfxGlobalEvents_Impl::implts_checkAndExecuteEventBindings(const document::DocumentEvent& aEvent)
-{
- try
- {
- // SAFE ->
- ::osl::ResettableMutexGuard aLock(m_aLock);
- uno::Reference< container::XNameReplace > xEvents = m_xEvents;
- aLock.clear();
- // <- SAFE
-
- uno::Any aAny;
- if ( xEvents.is() && xEvents->hasByName( aEvent.EventName ) )
- aAny = xEvents->getByName(aEvent.EventName);
- Execute(aAny, aEvent, 0);
- }
- catch ( uno::RuntimeException const & )
- {
- throw;
- }
- catch ( uno::Exception const & )
- {
- DBG_UNHANDLED_EXCEPTION();
- }
-}
-
-//-----------------------------------------------------------------------------
-void SfxGlobalEvents_Impl::implts_notifyListener(const document::DocumentEvent& aEvent)
-{
- // containers are threadsafe
- document::EventObject aLegacyEvent(aEvent.Source, aEvent.EventName);
- m_aLegacyListeners.notifyEach( &document::XEventListener::notifyEvent, aLegacyEvent );
-
- m_aDocumentListeners.notifyEach( &document::XDocumentEventListener::documentEventOccured, aEvent );
-}
-
-//-----------------------------------------------------------------------------
-// not threadsafe ... must be locked from outside!
-TModelList::iterator SfxGlobalEvents_Impl::impl_searchDoc(const uno::Reference< frame::XModel >& xModel)
-{
- if (!xModel.is())
- return m_lModels.end();
-
- TModelList::iterator pIt;
- for ( pIt = m_lModels.begin();
- pIt != m_lModels.end() ;
- ++pIt )
- {
- uno::Reference< frame::XModel > xContainerDoc(*pIt, uno::UNO_QUERY);
- if (xContainerDoc == xModel)
- break;
- }
-
- return pIt;
-}
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/notify/globalevents.cxx b/sfx2/source/notify/globalevents.cxx
new file mode 100644
index 0000000..b8f5c42
--- /dev/null
+++ b/sfx2/source/notify/globalevents.cxx
@@ -0,0 +1,542 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/types.h>
+
+#include <com/sun/star/task/JobExecutor.hpp>
+#include <com/sun/star/container/XNameReplace.hpp>
+#include <com/sun/star/container/XSet.hpp>
+#include <com/sun/star/document/XEventListener.hpp>
+#include <com/sun/star/document/XEventBroadcaster.hpp>
+#include <com/sun/star/document/XDocumentEventListener.hpp>
+#include <com/sun/star/frame/XGlobalEventBroadcaster.hpp>
+#include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/uno/Type.hxx>
+
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/implbase3.hxx>
+#include <cppuhelper/interfacecontainer.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <rtl/ref.hxx>
+#include <sfx2/app.hxx>
+#include <sfx2/objsh.hxx>
+#include <sfx2/sfxbasemodel.hxx>
+#include <sfx2/evntconf.hxx>
+#include <tools/diagnose_ex.h>
+#include <unotools/eventcfg.hxx>
+#include <eventsupplier.hxx>
+
+#include <vector>
+
+using namespace css;
+
+namespace {
+
+struct ModelCollectionMutexBase
+{
+public:
+ osl::Mutex m_aLock;
+};
+
+typedef ::std::vector< css::uno::Reference< css::frame::XModel > > TModelList;
+
+class ModelCollectionEnumeration : public ModelCollectionMutexBase
+ , public ::cppu::WeakImplHelper1< css::container::XEnumeration >
+{
+private:
+ TModelList m_lModels;
+ TModelList::iterator m_pEnumerationIt;
+
+public:
+ ModelCollectionEnumeration();
+ virtual ~ModelCollectionEnumeration();
+ void setModelList(const TModelList& rList);
+
+ // css.container.XEnumeration
+ virtual sal_Bool SAL_CALL hasMoreElements()
+ throw(css::uno::RuntimeException);
+
+ virtual css::uno::Any SAL_CALL nextElement()
+ throw(css::container::NoSuchElementException,
+ css::lang::WrappedTargetException ,
+ css::uno::RuntimeException );
+};
+
+//=============================================================================
+//TODO: remove support of obsolete document::XEventBroadcaster/Listener
+class SfxGlobalEvents_Impl : public ModelCollectionMutexBase
+ , public ::cppu::WeakImplHelper3< css::lang::XServiceInfo
+ , css::frame::XGlobalEventBroadcaster
+ , css::document::XEventListener
+ >
+{
+ css::uno::Reference< css::container::XNameReplace > m_xEvents;
+ css::uno::Reference< css::document::XEventListener > m_xJobExecutorListener;
+ ::cppu::OInterfaceContainerHelper m_aLegacyListeners;
+ ::cppu::OInterfaceContainerHelper m_aDocumentListeners;
+ TModelList m_lModels;
+ GlobalEventConfig* pImp;
+
+public:
+ SfxGlobalEvents_Impl(const css::uno::Reference < css::uno::XComponentContext >& rxContext);
+ virtual ~SfxGlobalEvents_Impl();
+
+ virtual OUString SAL_CALL getImplementationName()
+ throw (css::uno::RuntimeException)
+ {
+ return OUString("com.sun.star.comp.sfx2.GlobalEventBroadcaster");
+ }
+
+ virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
+ throw (css::uno::RuntimeException)
+ {
+ return cppu::supportsService(this, ServiceName);
+ }
+
+ virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
+ throw (css::uno::RuntimeException)
+ {
+ css::uno::Sequence< OUString > aSeq(1);
+ aSeq[0] = OUString("com.sun.star.frame.GlobalEventBroadcaster");
+ return aSeq;
+ }
+
+ // css.document.XEventBroadcaster
+ virtual css::uno::Reference< css::container::XNameReplace > SAL_CALL getEvents()
+ throw(css::uno::RuntimeException);
+
+ virtual void SAL_CALL addEventListener(const css::uno::Reference< css::document::XEventListener >& xListener)
+ throw(css::uno::RuntimeException);
+
+ virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::document::XEventListener >& xListener)
+ throw(css::uno::RuntimeException);
+
+ // css.document.XDocumentEventBroadcaster
+ virtual void SAL_CALL addDocumentEventListener( const css::uno::Reference< css::document::XDocumentEventListener >& _Listener ) throw (css::uno::RuntimeException);
+ virtual void SAL_CALL removeDocumentEventListener( const css::uno::Reference< css::document::XDocumentEventListener >& _Listener ) throw (css::uno::RuntimeException);
+ virtual void SAL_CALL notifyDocumentEvent( const OUString& _EventName, const css::uno::Reference< css::frame::XController2 >& _ViewController, const css::uno::Any& _Supplement ) throw (css::lang::IllegalArgumentException, css::lang::NoSupportException, css::uno::RuntimeException);
+
+ // css.document.XEventListener
+ virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent)
+ throw(css::uno::RuntimeException);
+
+ // css.document.XDocumentEventListener
+ virtual void SAL_CALL documentEventOccured( const css::document::DocumentEvent& Event ) throw (css::uno::RuntimeException);
+
+ // css.container.XSet
+ virtual sal_Bool SAL_CALL has(const css::uno::Any& aElement)
+ throw(css::uno::RuntimeException);
+
+ virtual void SAL_CALL insert(const css::uno::Any& aElement)
+ throw(css::lang::IllegalArgumentException ,
+ css::container::ElementExistException,
+ css::uno::RuntimeException );
+
+ virtual void SAL_CALL remove(const css::uno::Any& aElement)
+ throw(css::lang::IllegalArgumentException ,
+ css::container::NoSuchElementException,
+ css::uno::RuntimeException );
+
+ // css.container.XEnumerationAccess
+ virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration()
+ throw(css::uno::RuntimeException);
+
+ // css.container.XElementAccess
+ virtual css::uno::Type SAL_CALL getElementType()
+ throw(css::uno::RuntimeException);
+
+ virtual sal_Bool SAL_CALL hasElements()
+ throw(css::uno::RuntimeException);
+
+ // css.lang.XEventListener
+ virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
+ throw(css::uno::RuntimeException);
+
+private:
+
+ // threadsafe
+ void implts_notifyJobExecution(const css::document::EventObject& aEvent);
+ void implts_checkAndExecuteEventBindings(const css::document::DocumentEvent& aEvent);
+ void implts_notifyListener(const css::document::DocumentEvent& aEvent);
+
+ // not threadsafe
+ TModelList::iterator impl_searchDoc(const css::uno::Reference< css::frame::XModel >& xModel);
+};
+
+ModelCollectionEnumeration::ModelCollectionEnumeration()
+ : ModelCollectionMutexBase( )
+ , m_pEnumerationIt (m_lModels.begin())
+{
+}
+
+ModelCollectionEnumeration::~ModelCollectionEnumeration()
+{
+}
+
+void ModelCollectionEnumeration::setModelList(const TModelList& rList)
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ m_lModels = rList;
+ m_pEnumerationIt = m_lModels.begin();
+ aLock.clear();
+ // <- SAFE
+}
+
+sal_Bool SAL_CALL ModelCollectionEnumeration::hasMoreElements()
+ throw(uno::RuntimeException)
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ return (m_pEnumerationIt != m_lModels.end());
+ // <- SAFE
+}
+
+uno::Any SAL_CALL ModelCollectionEnumeration::nextElement()
+ throw(container::NoSuchElementException,
+ lang::WrappedTargetException ,
+ uno::RuntimeException )
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ if (m_pEnumerationIt == m_lModels.end())
+ throw container::NoSuchElementException(
+ OUString("End of model enumeration reached."),
+ static_cast< container::XEnumeration* >(this));
+ uno::Reference< frame::XModel > xModel(*m_pEnumerationIt, uno::UNO_QUERY);
+ ++m_pEnumerationIt;
+ aLock.clear();
+ // <- SAFE
+
+ return uno::makeAny(xModel);
+}
+
+//-----------------------------------------------------------------------------
+SfxGlobalEvents_Impl::SfxGlobalEvents_Impl( const uno::Reference < uno::XComponentContext >& rxContext)
+ : ModelCollectionMutexBase( )
+ , m_xJobExecutorListener( task::JobExecutor::create( rxContext ), uno::UNO_QUERY_THROW )
+ , m_aLegacyListeners (m_aLock)
+ , m_aDocumentListeners (m_aLock)
+ , pImp (0 )
+{
+ m_refCount++;
+ SFX_APP();
+ pImp = new GlobalEventConfig();
+ m_xEvents = pImp;
+ m_refCount--;
+}
+
+//-----------------------------------------------------------------------------
+SfxGlobalEvents_Impl::~SfxGlobalEvents_Impl()
+{
+}
+
+//-----------------------------------------------------------------------------
+uno::Reference< container::XNameReplace > SAL_CALL SfxGlobalEvents_Impl::getEvents()
+ throw(uno::RuntimeException)
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ return m_xEvents;
+ // <- SAFE
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::addEventListener(const uno::Reference< document::XEventListener >& xListener)
+ throw(uno::RuntimeException)
+{
+ // container is threadsafe
+ m_aLegacyListeners.addInterface(xListener);
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::removeEventListener(const uno::Reference< document::XEventListener >& xListener)
+ throw(uno::RuntimeException)
+{
+ // container is threadsafe
+ m_aLegacyListeners.removeInterface(xListener);
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::addDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& _Listener )
+ throw(uno::RuntimeException)
+{
+ m_aDocumentListeners.addInterface( _Listener );
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::removeDocumentEventListener( const uno::Reference< document::XDocumentEventListener >& _Listener )
+ throw(uno::RuntimeException)
+{
+ m_aDocumentListeners.removeInterface( _Listener );
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::notifyDocumentEvent( const OUString& /*_EventName*/,
+ const uno::Reference< frame::XController2 >& /*_ViewController*/, const uno::Any& /*_Supplement*/ )
+ throw (lang::IllegalArgumentException, lang::NoSupportException, uno::RuntimeException)
+{
+ // we're a multiplexer only, no chance to generate artifical events here
+ throw lang::NoSupportException(OUString(), *this);
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::notifyEvent(const document::EventObject& aEvent)
+ throw(uno::RuntimeException)
+{
+ document::DocumentEvent aDocEvent(aEvent.Source, aEvent.EventName, NULL, uno::Any());
+ implts_notifyJobExecution(aEvent);
+ implts_checkAndExecuteEventBindings(aDocEvent);
+ implts_notifyListener(aDocEvent);
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::documentEventOccured( const document::DocumentEvent& _Event )
+ throw (uno::RuntimeException)
+{
+ implts_notifyJobExecution(document::EventObject(_Event.Source, _Event.EventName));
+ implts_checkAndExecuteEventBindings(_Event);
+ implts_notifyListener(_Event);
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::disposing(const lang::EventObject& aEvent)
+ throw(uno::RuntimeException)
+{
+ uno::Reference< frame::XModel > xDoc(aEvent.Source, uno::UNO_QUERY);
+
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt != m_lModels.end())
+ m_lModels.erase(pIt);
+ aLock.clear();
+ // <- SAFE
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxGlobalEvents_Impl::has(const uno::Any& aElement)
+ throw (uno::RuntimeException)
+{
+ uno::Reference< frame::XModel > xDoc;
+ aElement >>= xDoc;
+
+ sal_Bool bHas = sal_False;
+
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt != m_lModels.end())
+ bHas = sal_True;
+ aLock.clear();
+ // <- SAFE
+
+ return bHas;
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::insert( const uno::Any& aElement )
+ throw (lang::IllegalArgumentException ,
+ container::ElementExistException,
+ uno::RuntimeException )
+{
+ uno::Reference< frame::XModel > xDoc;
+ aElement >>= xDoc;
+ if (!xDoc.is())
+ throw lang::IllegalArgumentException(
+ OUString("Cant locate at least the model parameter."),
+ static_cast< container::XSet* >(this),
+ 0);
+
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt != m_lModels.end())
+ throw container::ElementExistException(
+ OUString(),
+ static_cast< container::XSet* >(this));
+ m_lModels.push_back(xDoc);
+ aLock.clear();
+ // <- SAFE
+
+ uno::Reference< document::XDocumentEventBroadcaster > xDocBroadcaster(xDoc, uno::UNO_QUERY );
+ if (xDocBroadcaster.is())
+ xDocBroadcaster->addDocumentEventListener(this);
+ else
+ {
+ // try the "legacy version" of XDocumentEventBroadcaster, which is XEventBroadcaster
+ uno::Reference< document::XEventBroadcaster > xBroadcaster(xDoc, uno::UNO_QUERY);
+ if (xBroadcaster.is())
+ xBroadcaster->addEventListener(static_cast< document::XEventListener* >(this));
+ }
+}
+
+//-----------------------------------------------------------------------------
+void SAL_CALL SfxGlobalEvents_Impl::remove( const uno::Any& aElement )
+ throw (lang::IllegalArgumentException ,
+ container::NoSuchElementException,
+ uno::RuntimeException )
+{
+ uno::Reference< frame::XModel > xDoc;
+ aElement >>= xDoc;
+ if (!xDoc.is())
+ throw lang::IllegalArgumentException(
+ OUString("Cant locate at least the model parameter."),
+ static_cast< container::XSet* >(this),
+ 0);
+
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ TModelList::iterator pIt = impl_searchDoc(xDoc);
+ if (pIt == m_lModels.end())
+ throw container::NoSuchElementException(
+ OUString(),
+ static_cast< container::XSet* >(this));
+ m_lModels.erase(pIt);
+ aLock.clear();
+ // <- SAFE
+
+ uno::Reference< document::XDocumentEventBroadcaster > xDocBroadcaster(xDoc, uno::UNO_QUERY );
+ if (xDocBroadcaster.is())
+ xDocBroadcaster->removeDocumentEventListener(this);
+ else
+ {
+ // try the "legacy version" of XDocumentEventBroadcaster, which is XEventBroadcaster
+ uno::Reference< document::XEventBroadcaster > xBroadcaster(xDoc, uno::UNO_QUERY);
+ if (xBroadcaster.is())
+ xBroadcaster->removeEventListener(static_cast< document::XEventListener* >(this));
+ }
+}
+
+//-----------------------------------------------------------------------------
+uno::Reference< container::XEnumeration > SAL_CALL SfxGlobalEvents_Impl::createEnumeration()
+ throw (uno::RuntimeException)
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ ModelCollectionEnumeration* pEnum = new ModelCollectionEnumeration();
+ pEnum->setModelList(m_lModels);
+ uno::Reference< container::XEnumeration > xEnum(
+ static_cast< container::XEnumeration* >(pEnum),
+ uno::UNO_QUERY);
+ aLock.clear();
+ // <- SAFE
+
+ return xEnum;
+}
+
+//-----------------------------------------------------------------------------
+uno::Type SAL_CALL SfxGlobalEvents_Impl::getElementType()
+ throw (uno::RuntimeException)
+{
+ return ::getCppuType(static_cast< uno::Reference< frame::XModel >* >(NULL));
+}
+
+//-----------------------------------------------------------------------------
+sal_Bool SAL_CALL SfxGlobalEvents_Impl::hasElements()
+ throw (uno::RuntimeException)
+{
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ return (m_lModels.size()>0);
+ // <- SAFE
+}
+
+//-----------------------------------------------------------------------------
+void SfxGlobalEvents_Impl::implts_notifyJobExecution(const document::EventObject& aEvent)
+{
+ try
+ {
+ m_xJobExecutorListener->notifyEvent(aEvent);
+ }
+ catch(const uno::RuntimeException&)
+ { throw; }
+ catch(const uno::Exception&)
+ {}
+}
+
+//-----------------------------------------------------------------------------
+void SfxGlobalEvents_Impl::implts_checkAndExecuteEventBindings(const document::DocumentEvent& aEvent)
+{
+ try
+ {
+ // SAFE ->
+ ::osl::ResettableMutexGuard aLock(m_aLock);
+ uno::Reference< container::XNameReplace > xEvents = m_xEvents;
+ aLock.clear();
+ // <- SAFE
+
+ uno::Any aAny;
+ if ( xEvents.is() && xEvents->hasByName( aEvent.EventName ) )
+ aAny = xEvents->getByName(aEvent.EventName);
+ SfxEvents_Impl::Execute(aAny, aEvent, 0);
+ }
+ catch ( uno::RuntimeException const & )
+ {
+ throw;
+ }
+ catch ( uno::Exception const & )
+ {
+ DBG_UNHANDLED_EXCEPTION();
+ }
+}
+
+//-----------------------------------------------------------------------------
+void SfxGlobalEvents_Impl::implts_notifyListener(const document::DocumentEvent& aEvent)
+{
+ // containers are threadsafe
+ document::EventObject aLegacyEvent(aEvent.Source, aEvent.EventName);
+ m_aLegacyListeners.notifyEach( &document::XEventListener::notifyEvent, aLegacyEvent );
+
+ m_aDocumentListeners.notifyEach( &document::XDocumentEventListener::documentEventOccured, aEvent );
+}
+
+//-----------------------------------------------------------------------------
+// not threadsafe ... must be locked from outside!
+TModelList::iterator SfxGlobalEvents_Impl::impl_searchDoc(const uno::Reference< frame::XModel >& xModel)
+{
+ if (!xModel.is())
+ return m_lModels.end();
+
+ TModelList::iterator pIt;
+ for ( pIt = m_lModels.begin();
+ pIt != m_lModels.end() ;
+ ++pIt )
+ {
+ uno::Reference< frame::XModel > xContainerDoc(*pIt, uno::UNO_QUERY);
+ if (xContainerDoc == xModel)
+ break;
+ }
+
+ return pIt;
+}
+
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
+com_sun_star_comp_sfx2_GlobalEventBroadcaster_get_implementation(
+ css::uno::XComponentContext *context,
+ css::uno::Sequence<css::uno::Any> const &)
+{
+ rtl::Reference<SfxGlobalEvents_Impl> x(new SfxGlobalEvents_Impl(context));
+ x->acquire();
+ return static_cast<cppu::OWeakObject *>(x.get());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/util/sfx.component b/sfx2/util/sfx.component
index 30cd3fc..e0fb72b 100644
--- a/sfx2/util/sfx.component
+++ b/sfx2/util/sfx.component
@@ -68,7 +68,8 @@
constructor="com_sun_star_comp_sfx2_DocumentTemplates_get_implementation">
<service name="com.sun.star.frame.DocumentTemplates"/>
</implementation>
- <implementation name="com.sun.star.comp.sfx2.GlobalEventBroadcaster">
+ <implementation name="com.sun.star.comp.sfx2.GlobalEventBroadcaster"
+ constructor="com_sun_star_comp_sfx2_GlobalEventBroadcaster_get_implementation">
<service name="com.sun.star.frame.GlobalEventBroadcaster"/>
<singleton name="com.sun.star.frame.theGlobalEventBroadcaster"/>
</implementation>
commit 62951cdd17530f6218232f3d482bfd4ddd8a95ec
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Jan 16 16:06:33 2014 +0100
Introduce com.sun.star.frame.theGlobalEventBroadcaster singleton
...to supersede com.sun.star.frame.GlobalEventBroadcaster single-instance
service.
Change-Id: I74ecaadadb4c600d39979aa7c13b6389bed38fd7
diff --git a/basctl/source/basicide/doceventnotifier.cxx b/basctl/source/basicide/doceventnotifier.cxx
index 957ae1b..9aa94f0 100644
--- a/basctl/source/basicide/doceventnotifier.cxx
+++ b/basctl/source/basicide/doceventnotifier.cxx
@@ -21,7 +21,7 @@
#include "doceventnotifier.hxx"
#include "scriptdocument.hxx"
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/document/XEventBroadcaster.hpp>
#include <vcl/svapp.hxx>
@@ -50,7 +50,7 @@ namespace basctl
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::frame::XModel;
- using ::com::sun::star::frame::GlobalEventBroadcaster;
+ using ::com::sun::star::frame::theGlobalEventBroadcaster;
using ::com::sun::star::uno::UNO_QUERY;
namespace csslang = ::com::sun::star::lang;
@@ -212,7 +212,7 @@ namespace basctl
{
Reference< com::sun::star::uno::XComponentContext > aContext(
comphelper::getProcessComponentContext() );
- xBroadcaster.set( GlobalEventBroadcaster::create(aContext), UNO_QUERY_THROW );
+ xBroadcaster.set( theGlobalEventBroadcaster::get(aContext), UNO_QUERY_THROW );
}
void ( SAL_CALL XEventBroadcaster::*listenerAction )( const Reference< XEventListener >& ) =
diff --git a/basctl/source/inc/doceventnotifier.hxx b/basctl/source/inc/doceventnotifier.hxx
index 4b950b1..372f5fc 100644
--- a/basctl/source/inc/doceventnotifier.hxx
+++ b/basctl/source/inc/doceventnotifier.hxx
@@ -55,7 +55,7 @@ namespace basctl
//====================================================================
//= DocumentEventNotifier
//====================================================================
- /** allows registering at the GlobalEventBroadcaster for global document events
+ /** allows registering at theGlobalEventBroadcaster for global document events
*/
class DocumentEventNotifier
{
diff --git a/bin/benchmark-document-loading b/bin/benchmark-document-loading
index 98d2855..07dc459 100644
--- a/bin/benchmark-document-loading
+++ b/bin/benchmark-document-loading
@@ -275,7 +275,8 @@ def loadFromURL(xContext, url, t, component):
xListener = None
if component == "writer":
xListener = EventListener()
- xGEB = xContext.ServiceManager.createInstanceWithContext("com.sun.star.frame.GlobalEventBroadcaster", xContext)
+ xGEB = xContext.getValueByName(
+ "/singletons/com.sun.star.frame.theGlobalEventBroadcaster")
xGEB.addDocumentEventListener(xListener)
try:
xDoc = None
diff --git a/bin/convwatch.py b/bin/convwatch.py
index bdb09be..bef3f9e 100644
--- a/bin/convwatch.py
+++ b/bin/convwatch.py
@@ -237,8 +237,8 @@ def loadFromURL(xContext, url):
props = [("Hidden", True), ("ReadOnly", True)] # FilterName?
loadProps = tuple([mkPropertyValue(name, value) for (name, value) in props])
xListener = EventListener()
- xGEB = xContext.ServiceManager.createInstanceWithContext(
- "com.sun.star.frame.GlobalEventBroadcaster", xContext)
+ xGEB = xContext.getValueByName(
+ "/singletons/com.sun.star.frame.theGlobalEventBroadcaster")
xGEB.addDocumentEventListener(xListener)
try:
xDoc = xDesktop.loadComponentFromURL(url, "_blank", 0, loadProps)
diff --git a/cui/source/customize/eventdlg.cxx b/cui/source/customize/eventdlg.cxx
index e3563ee..abe8013 100644
--- a/cui/source/customize/eventdlg.cxx
+++ b/cui/source/customize/eventdlg.cxx
@@ -21,7 +21,7 @@
#include <tools/diagnose_ex.h>
#include <com/sun/star/document/XEventsSupplier.hpp>
#include <com/sun/star/frame/Desktop.hpp>
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/frame/XModuleManager.hpp>
#include <comphelper/processfactory.hxx>
@@ -83,7 +83,7 @@ SvxEventConfigPage::SvxEventConfigPage( Window *pParent, const SfxItemSet& rSet,
uno::Reference< frame::XGlobalEventBroadcaster > xSupplier;
xSupplier =
- frame::GlobalEventBroadcaster::create(::comphelper::getProcessComponentContext());
+ frame::theGlobalEventBroadcaster::get(::comphelper::getProcessComponentContext());
sal_uInt16 nPos(0);
m_xAppEvents = xSupplier->getEvents();
diff --git a/dbaccess/qa/complex/dbaccess/Beamer.java b/dbaccess/qa/complex/dbaccess/Beamer.java
index 6fc022c..97c4c6b 100644
--- a/dbaccess/qa/complex/dbaccess/Beamer.java
+++ b/dbaccess/qa/complex/dbaccess/Beamer.java
@@ -20,14 +20,15 @@ package complex.dbaccess;
import com.sun.star.beans.PropertyState;
import com.sun.star.beans.PropertyValue;
import com.sun.star.container.XEnumeration;
-import com.sun.star.container.XEnumerationAccess;
import com.sun.star.frame.FrameSearchFlag;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XController;
import com.sun.star.frame.XDispatch;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.frame.XFrame;
+import com.sun.star.frame.XGlobalEventBroadcaster;
import com.sun.star.frame.XModel;
+import com.sun.star.frame.theGlobalEventBroadcaster;
import com.sun.star.lang.XComponent;
import com.sun.star.sdb.CommandType;
import com.sun.star.uno.Exception;
@@ -111,7 +112,8 @@ public class Beamer extends TestCase
final XFrame beamer = frame.findFrame("_beamer", 0);
assertNotNull(beamer);
- final XEnumerationAccess evtBc = UnoRuntime.queryInterface(XEnumerationAccess.class, getMSF().createInstance("com.sun.star.frame.GlobalEventBroadcaster"));
+ final XGlobalEventBroadcaster evtBc = theGlobalEventBroadcaster.get(
+ getComponentContext());
XEnumeration enumeration = evtBc.createEnumeration();
int count = -1;
while (enumeration.hasMoreElements())
diff --git a/dbaccess/qa/complex/dbaccess/DatabaseDocument.java b/dbaccess/qa/complex/dbaccess/DatabaseDocument.java
index fc5999d..7f1ab13 100644
--- a/dbaccess/qa/complex/dbaccess/DatabaseDocument.java
+++ b/dbaccess/qa/complex/dbaccess/DatabaseDocument.java
@@ -36,7 +36,6 @@ import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XNameContainer;
import com.sun.star.container.XSet;
-import com.sun.star.document.XDocumentEventBroadcaster;
import com.sun.star.document.XDocumentEventListener;
import com.sun.star.document.XEmbeddedScripts;
import com.sun.star.document.XEventsSupplier;
@@ -45,10 +44,12 @@ import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XDispatch;
import com.sun.star.frame.XDispatchProvider;
import com.sun.star.frame.XFrame;
+import com.sun.star.frame.XGlobalEventBroadcaster;
import com.sun.star.frame.XLoadable;
import com.sun.star.frame.XModel;
import com.sun.star.frame.XModel2;
import com.sun.star.frame.XTitle;
+import com.sun.star.frame.theGlobalEventBroadcaster;
import com.sun.star.lang.EventObject;
import com.sun.star.lang.XServiceInfo;
import com.sun.star.lang.XSingleComponentFactory;
@@ -260,7 +261,8 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document.
globalFactory.insert(m_callbackFactory);
// register ourself as listener at the global event broadcaster
- final XDocumentEventBroadcaster broadcaster = UnoRuntime.queryInterface(XDocumentEventBroadcaster.class, getMSF().createInstance("com.sun.star.frame.GlobalEventBroadcaster"));
+ final XGlobalEventBroadcaster broadcaster
+ = theGlobalEventBroadcaster.get(getComponentContext());
broadcaster.addDocumentEventListener(this);
}
catch (Exception e)
@@ -282,7 +284,8 @@ public class DatabaseDocument extends TestCase implements com.sun.star.document.
m_callbackFactory.dispose();
// revoke ourself as listener at the global event broadcaster
- final XDocumentEventBroadcaster broadcaster = UnoRuntime.queryInterface(XDocumentEventBroadcaster.class, getMSF().createInstance("com.sun.star.frame.GlobalEventBroadcaster"));
+ final XGlobalEventBroadcaster broadcaster
+ = theGlobalEventBroadcaster.get(getComponentContext());
broadcaster.removeDocumentEventListener(this);
}
catch (Exception e)
diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx
index ba4ec618..ae1f9b9 100644
--- a/dbaccess/source/core/dataaccess/ModelImpl.cxx
+++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx
@@ -36,7 +36,7 @@
#include <com/sun/star/embed/XTransactionBroadcaster.hpp>
#include <com/sun/star/embed/StorageFactory.hpp>
#include <com/sun/star/form/XLoadable.hpp>
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/sdb/BooleanComparisonMode.hpp>
#include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
@@ -952,7 +952,7 @@ Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _b
try
{
- Reference< XGlobalEventBroadcaster > xModelCollection = GlobalEventBroadcaster::create( m_aContext );
+ Reference< XGlobalEventBroadcaster > xModelCollection = theGlobalEventBroadcaster::get( m_aContext );
xModelCollection->insert( makeAny( xModel ) );
}
catch( const Exception& )
diff --git a/desktop/source/app/app.cxx b/desktop/source/app/app.cxx
index 79eabdb..691dc6c 100644
--- a/desktop/source/app/app.cxx
+++ b/desktop/source/app/app.cxx
@@ -40,7 +40,7 @@
#include <svtools/javacontext.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/frame/AutoRecovery.hpp>
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/frame/SessionListener.hpp>
#include <com/sun/star/frame/XSessionManagerListener.hpp>
#include <com/sun/star/frame/XSynchronousDispatch.hpp>
@@ -1513,7 +1513,7 @@ int Desktop::Main()
// create service for loadin SFX (still needed in startup)
pExecGlobals->xGlobalBroadcaster = Reference < css::document::XEventListener >
- ( css::frame::GlobalEventBroadcaster::create(xContext), UNO_QUERY_THROW );
+ ( css::frame::theGlobalEventBroadcaster::get(xContext), UNO_QUERY_THROW );
/* ensure existance of a default window that messages can be dispatched to
This is for the benefit of testtool which uses PostUserEvent extensively
diff --git a/extensions/source/update/ui/updatecheckui.cxx b/extensions/source/update/ui/updatecheckui.cxx
index 9d1e535..f52f5c5 100644
--- a/extensions/source/update/ui/updatecheckui.cxx
+++ b/extensions/source/update/ui/updatecheckui.cxx
@@ -28,7 +28,7 @@
#include <com/sun/star/document/XEventListener.hpp>
#include <com/sun/star/document/XEventBroadcaster.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/graphic/GraphicProvider.hpp>
#include <com/sun/star/graphic/XGraphicProvider.hpp>
#include <com/sun/star/task/XJob.hpp>
@@ -155,9 +155,6 @@ private:
void AddMenuBarIcon( SystemWindow* pSysWin, bool bAddEventHdl );
Image GetBubbleImage( OUString &rURL );
- uno::Reference< document::XEventBroadcaster > getGlobalEventBroadcaster() const
- throw (uno::RuntimeException);
-
public:
UpdateCheckUI(const uno::Reference<uno::XComponentContext>&);
virtual ~UpdateCheckUI();
@@ -220,7 +217,7 @@ UpdateCheckUI::UpdateCheckUI(const uno::Reference<uno::XComponentContext>& xCont
maTimeoutTimer.SetTimeout( 10000 );
maTimeoutTimer.SetTimeoutHdl( LINK( this, UpdateCheckUI, TimeOutHdl ) );
- uno::Reference< document::XEventBroadcaster > xBroadcaster( getGlobalEventBroadcaster() );
+ uno::Reference< document::XEventBroadcaster > xBroadcaster( frame::theGlobalEventBroadcaster::get(m_xContext) );
xBroadcaster->addEventListener( this );
maWindowEventHdl = LINK( this, UpdateCheckUI, WindowEventHdl );
@@ -238,20 +235,6 @@ UpdateCheckUI::~UpdateCheckUI()
}
//------------------------------------------------------------------------------
-uno::Reference<document::XEventBroadcaster>
-UpdateCheckUI::getGlobalEventBroadcaster() const throw (uno::RuntimeException)
-{
- if( !m_xContext.is() )
- throw uno::RuntimeException(
- "UpdateCheckUI: empty component context",
- uno::Reference< uno::XInterface >() );
-
- return uno::Reference<document::XEventBroadcaster> (
- frame::GlobalEventBroadcaster::create(m_xContext),
- uno::UNO_QUERY_THROW);
-}
-
-//------------------------------------------------------------------------------
OUString SAL_CALL
UpdateCheckUI::getImplementationName() throw (uno::RuntimeException)
{
diff --git a/filter/source/config/cache/lateinitlistener.cxx b/filter/source/config/cache/lateinitlistener.cxx
index 141cfff..222446d 100644
--- a/filter/source/config/cache/lateinitlistener.cxx
+++ b/filter/source/config/cache/lateinitlistener.cxx
@@ -25,7 +25,7 @@
#include "lateinitlistener.hxx"
#include "lateinitthread.hxx"
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
namespace filter{
@@ -40,7 +40,7 @@ LateInitListener::LateInitListener(const css::uno::Reference< css::uno::XCompone
osl_atomic_increment( &m_refCount );
m_xBroadcaster = css::uno::Reference< css::document::XEventBroadcaster >(
- css::frame::GlobalEventBroadcaster::create(rxContext),
+ css::frame::theGlobalEventBroadcaster::get(rxContext),
css::uno::UNO_QUERY_THROW);
m_xBroadcaster->addEventListener(static_cast< css::document::XEventListener* >(this));
diff --git a/filter/source/xsltdialog/xmlfiltertestdialog.cxx b/filter/source/xsltdialog/xmlfiltertestdialog.cxx
index 359863c..70e2350 100644
--- a/filter/source/xsltdialog/xmlfiltertestdialog.cxx
+++ b/filter/source/xsltdialog/xmlfiltertestdialog.cxx
@@ -24,7 +24,7 @@
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
#include <com/sun/star/document/XGraphicObjectResolver.hpp>
#include <com/sun/star/document/XEmbeddedObjectResolver.hpp>
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/frame/XConfigManager.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/frame/XComponentLoader.hpp>
@@ -166,7 +166,7 @@ XMLFilterTestDialog::XMLFilterTestDialog(Window* pParent,
try
{
- mxGlobalBroadcaster = GlobalEventBroadcaster::create(mxContext);
+ mxGlobalBroadcaster = theGlobalEventBroadcaster::get(mxContext);
mxGlobalEventListener = new GlobalEventListenerImpl( this );
mxGlobalBroadcaster->addEventListener( mxGlobalEventListener );
}
diff --git a/framework/inc/services/autorecovery.hxx b/framework/inc/services/autorecovery.hxx
index 02ae9a8..04f0c8f 100644
--- a/framework/inc/services/autorecovery.hxx
+++ b/framework/inc/services/autorecovery.hxx
@@ -31,8 +31,8 @@
#include <com/sun/star/lang/XTypeProvider.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
#include <com/sun/star/frame/XDispatch.hpp>
+#include <com/sun/star/frame/XGlobalEventBroadcaster.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/document/XEventListener.hpp>
#include <com/sun/star/document/XEventBroadcaster.hpp>
diff --git a/framework/source/services/autorecovery.cxx b/framework/source/services/autorecovery.cxx
index fef85c4..1e12efc 100644
--- a/framework/source/services/autorecovery.cxx
+++ b/framework/source/services/autorecovery.cxx
@@ -38,7 +38,7 @@
#include <com/sun/star/ucb/NameClash.hpp>
#include <com/sun/star/container/XNameAccess.hpp>
#include <com/sun/star/frame/Desktop.hpp>
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/frame/XLoadable.hpp>
#include <com/sun/star/frame/XModel2.hpp>
#include <com/sun/star/frame/ModuleManager.hpp>
@@ -1364,7 +1364,7 @@ void AutoRecovery::implts_startListening()
if (!xBroadcaster.is())
{
- xBroadcaster = css::frame::GlobalEventBroadcaster::create( xContext );
+ xBroadcaster = css::frame::theGlobalEventBroadcaster::get( xContext );
// SAFE -> ----------------------------------
WriteGuard aWriteLock(m_aLock);
m_xNewDocBroadcaster = xBroadcaster;
@@ -2597,7 +2597,7 @@ AutoRecovery::ETimerType AutoRecovery::implts_openDocs(const DispatchParams& aPa
since our last AutoSave. And we deregister us in case we know this state.
But directly after one document as recovered ... we must start listening.
Otherwhise the first "modify" doesn't reach us. Because we ourself called setModified()
- on the document via API. And currently we dont listen for any events (not at the GlobalEventBroadcaster
+ on the document via API. And currently we dont listen for any events (not at theGlobalEventBroadcaster
nor at any document!).
*/
implts_startModifyListeningOnDoc(rInfo);
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index 66d1b6e..bd38826 100755
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -200,6 +200,7 @@ $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/frame,\
StartModule \
TaskCreator \
UICommandDescription \
+ theGlobalEventBroadcaster \
))
$(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/graphic,\
GraphicObject \
diff --git a/offapi/com/sun/star/frame/GlobalEventBroadcaster.idl b/offapi/com/sun/star/frame/GlobalEventBroadcaster.idl
index 6fe6af8..47fbc9e 100644
--- a/offapi/com/sun/star/frame/GlobalEventBroadcaster.idl
+++ b/offapi/com/sun/star/frame/GlobalEventBroadcaster.idl
@@ -25,12 +25,11 @@
module com { module sun { module star { module frame {
/**
- This service offers the document event functionality that can be found at any
- com::sun::star::document::OfficeDocument, but it does it for all existing documents.
- So it is a single place where a listener can be registered for all events in all
- documents.
- */
+ A legacy (single-instance) service-variant of theGlobalEventBroadcaster
+ singleton.
+ @deprecated Use theGlobalEventBroadcaster singleton instead.
+*/
service GlobalEventBroadcaster : XGlobalEventBroadcaster;
diff --git a/offapi/com/sun/star/frame/XGlobalEventBroadcaster.idl b/offapi/com/sun/star/frame/XGlobalEventBroadcaster.idl
index ca5d9fd..e4b6043 100644
--- a/offapi/com/sun/star/frame/XGlobalEventBroadcaster.idl
+++ b/offapi/com/sun/star/frame/XGlobalEventBroadcaster.idl
@@ -28,7 +28,7 @@
module com { module sun { module star { module frame {
/**
- Provides a unified interface for the GlobalEventBroadcaster service to implement.
+ Provides the unified interface of theGlobalEventBroadcaster singleton.
@since LibreOffice 4.0
*/
diff --git a/offapi/com/sun/star/frame/theGlobalEventBroadcaster.idl b/offapi/com/sun/star/frame/theGlobalEventBroadcaster.idl
new file mode 100644
index 0000000..b802a13
--- /dev/null
+++ b/offapi/com/sun/star/frame/theGlobalEventBroadcaster.idl
@@ -0,0 +1,46 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef COM_SUN_STAR_FRAME_GLOBALEVENTBROADCASTER_IDL
+#define COM_SUN_STAR_FRAME_GLOBALEVENTBROADCASTER_IDL
+
+#include <com/sun/star/frame/XGlobalEventBroadcaster.idl>
+
+module com { module sun { module star { module frame {
+
+/**
+ This singleton offers the document event functionality that can be found at
+ any com::sun::star::document::OfficeDocument, but it does it for all
+ existing documents.
+
+ So it is a single place where a listener can be registered for all events in
+ all documents.
+
+ Prior to LibreOffice 4.3, this singleton was only available as a
+ (single-instance) GlobalEventBroadcaster service.
+
+ @since LibreOffice 4.3
+*/
+singleton theGlobalEventBroadcaster: XGlobalEventBroadcaster;
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/appl/appinit.cxx b/sfx2/source/appl/appinit.cxx
index 5256a58..a5f1fde 100644
--- a/sfx2/source/appl/appinit.cxx
+++ b/sfx2/source/appl/appinit.cxx
@@ -21,7 +21,7 @@
#include <sfx2/app.hxx>
#include <com/sun/star/frame/XTerminateListener.hpp>
#include <com/sun/star/uno/Reference.hxx>
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
@@ -112,7 +112,7 @@ void SAL_CALL SfxTerminateListener_Impl::notifyTermination( const EventObject& a
pApp->Get_Impl()->pAppDispatch->release();
css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
- css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(css::frame::GlobalEventBroadcaster::create(xContext), css::uno::UNO_QUERY_THROW);
+ css::uno::Reference< css::document::XEventListener > xGlobalBroadcaster(css::frame::theGlobalEventBroadcaster::get(xContext), css::uno::UNO_QUERY_THROW);
css::document::EventObject aEvent2;
aEvent2.EventName = "OnCloseApp";
diff --git a/sfx2/source/config/evntconf.cxx b/sfx2/source/config/evntconf.cxx
index 6b5c3e7..06f056d 100644
--- a/sfx2/source/config/evntconf.cxx
+++ b/sfx2/source/config/evntconf.cxx
@@ -44,7 +44,7 @@
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/container/XNameReplace.hpp>
#include <com/sun/star/document/XEventsSupplier.hpp>
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/uno/Reference.hxx>
@@ -232,7 +232,7 @@ void PropagateEvent_Impl( SfxObjectShell *pDoc, OUString aEventName, const SvxMa
else
{
xSupplier = uno::Reference < document::XEventsSupplier >
- ( frame::GlobalEventBroadcaster::create(::comphelper::getProcessComponentContext()),
+ ( frame::theGlobalEventBroadcaster::get(::comphelper::getProcessComponentContext()),
uno::UNO_QUERY );
}
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index 2fa26fc..311eedc 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -27,7 +27,7 @@
#include <svl/eitem.hxx>
#include <svl/stritem.hxx>
#include <svl/intitem.hxx>
-#include <com/sun/star/frame/GlobalEventBroadcaster.hpp>
+#include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/frame/XModel.hpp>
#include <com/sun/star/frame/XFrame.hpp>
@@ -150,7 +150,7 @@ void impl_addToModelCollection(const css::uno::Reference< css::frame::XModel >&
css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
css::uno::Reference< css::frame::XGlobalEventBroadcaster > xModelCollection =
- css::frame::GlobalEventBroadcaster::create(xContext);
+ css::frame::theGlobalEventBroadcaster::get(xContext);
try
{
xModelCollection->insert(css::uno::makeAny(xModel));
diff --git a/sfx2/util/sfx.component b/sfx2/util/sfx.component
index a66335e..30cd3fc 100644
--- a/sfx2/util/sfx.component
+++ b/sfx2/util/sfx.component
@@ -70,6 +70,7 @@
</implementation>
<implementation name="com.sun.star.comp.sfx2.GlobalEventBroadcaster">
<service name="com.sun.star.frame.GlobalEventBroadcaster"/>
+ <singleton name="com.sun.star.frame.theGlobalEventBroadcaster"/>
</implementation>
<implementation name="com.sun.star.comp.sfx2.IFrameObject"
constructor="com_sun_star_comp_sfx2_IFrameObject_get_implementation">
diff --git a/sw/qa/complex/writer/LoadSaveTest.java b/sw/qa/complex/writer/LoadSaveTest.java
index 3a16fd8..8fd9fdf 100644
--- a/sw/qa/complex/writer/LoadSaveTest.java
+++ b/sw/qa/complex/writer/LoadSaveTest.java
@@ -27,9 +27,10 @@ import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.lang.XComponent;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.Pair;
+import com.sun.star.frame.XGlobalEventBroadcaster;
import com.sun.star.frame.XStorable;
+import com.sun.star.frame.theGlobalEventBroadcaster;
import com.sun.star.document.DocumentEvent;
-import com.sun.star.document.XDocumentEventBroadcaster;
import com.sun.star.document.XDocumentEventListener;
import org.openoffice.test.OfficeConnection;
@@ -63,7 +64,7 @@ public class LoadSaveTest
private XMultiServiceFactory m_xMSF = null;
private XComponentContext m_xContext = null;
- private XDocumentEventBroadcaster m_xGEB = null;
+ private XGlobalEventBroadcaster m_xGEB = null;
private String m_TmpDir = null;
private String m_fileURL = "file://";
@@ -77,10 +78,7 @@ public class LoadSaveTest
assertNotNull("could not get component context.", m_xContext);
m_xMSF = UnoRuntime.queryInterface(
XMultiServiceFactory.class, m_xContext.getServiceManager());
- Object oGEB = m_xMSF.createInstance(
- "com.sun.star.frame.GlobalEventBroadcaster");
- m_xGEB = UnoRuntime.queryInterface(XDocumentEventBroadcaster.class, oGEB);
- assertNotNull("could not get global event broadcaster.", m_xGEB);
+ m_xGEB = theGlobalEventBroadcaster.get(m_xContext);
m_TmpDir = util.utils.getOfficeTemp/*Dir*/(m_xMSF);
System.out.println("tempdir: " + m_TmpDir);
System.out.println("sourcedir: " + m_SourceDir);
diff --git a/ucb/source/ucp/tdoc/tdoc_docmgr.cxx b/ucb/source/ucp/tdoc/tdoc_docmgr.cxx
index c08f9cf..bda606a 100644
--- a/ucb/source/ucp/tdoc/tdoc_docmgr.cxx
+++ b/ucb/source/ucp/tdoc/tdoc_docmgr.cxx
@@ -35,7 +35,7 @@
#include "com/sun/star/beans/XPropertySet.hpp"
#include "com/sun/star/document/XEventBroadcaster.hpp"
#include "com/sun/star/document/XStorageBasedDocument.hpp"
-#include "com/sun/star/frame/GlobalEventBroadcaster.hpp"
+#include "com/sun/star/frame/theGlobalEventBroadcaster.hpp"
#include "com/sun/star/frame/XStorable.hpp"
#include "com/sun/star/frame/ModuleManager.hpp"
#include "com/sun/star/lang/DisposedException.hpp"
@@ -105,7 +105,7 @@ OfficeDocumentsManager::OfficeDocumentsManager(
const uno::Reference< uno::XComponentContext > & rxContext,
OfficeDocumentsEventListener * pDocEventListener )
: m_xContext( rxContext ),
- m_xDocEvtNotifier( frame::GlobalEventBroadcaster::create( rxContext ) ),
+ m_xDocEvtNotifier( frame::theGlobalEventBroadcaster::get( rxContext ) ),
m_pDocEventListener( pDocEventListener ),
m_xDocCloseListener( new OfficeDocumentsCloseListener( this ) )
{
commit 997d21183322a0a94b96868073808841d2773902
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Thu Jan 16 15:29:41 2014 +0100
Support for singleton constructor functions
The service manager now keeps track of instances of singleton implementations
(i.e., implementations whose XML description lists at least one
<singleton ...>). These instances will be disposed either when the service
manager is disposed, or, for instances that have been instantiated into the
component context's /singleton/* map, when the component context is disposed.
This change allows to use constructor functions for such singleton
implementations, too.
Change-Id: I220c9ddc9824e4d7f7556daefb599e2ec36b0e6c
diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx
index d7ab48a..9bc3113 100644
--- a/cppuhelper/source/servicemanager.cxx
+++ b/cppuhelper/source/servicemanager.cxx
@@ -519,6 +519,58 @@ css::beans::Property getDefaultContextProperty() {
css::beans::PropertyAttribute::READONLY);
}
+class SingletonFactory:
+ public cppu::WeakImplHelper1<css::lang::XSingleComponentFactory>,
+ private boost::noncopyable
+{
+public:
+ SingletonFactory(
+ rtl::Reference< cppuhelper::ServiceManager > const & manager,
+ boost::shared_ptr<
+ cppuhelper::ServiceManager::Data::Implementation > const &
+ implementation):
+ manager_(manager), implementation_(implementation)
+ { assert(manager.is()); assert(implementation.get() != 0); }
+
+private:
+ virtual ~SingletonFactory() {}
+
+ virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
+ createInstanceWithContext(
+ css::uno::Reference< css::uno::XComponentContext > const & Context)
+ throw (css::uno::Exception, css::uno::RuntimeException);
+
+ virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
+ createInstanceWithArgumentsAndContext(
+ css::uno::Sequence< css::uno::Any > const & Arguments,
+ css::uno::Reference< css::uno::XComponentContext > const & Context)
+ throw (css::uno::Exception, css::uno::RuntimeException);
+
+ rtl::Reference< cppuhelper::ServiceManager > manager_;
+ boost::shared_ptr< cppuhelper::ServiceManager::Data::Implementation >
+ implementation_;
+};
+
+css::uno::Reference< css::uno::XInterface >
+SingletonFactory::createInstanceWithContext(
+ css::uno::Reference< css::uno::XComponentContext > const & Context)
+ throw (css::uno::Exception, css::uno::RuntimeException)
+{
+ manager_->loadImplementation(Context, implementation_);
+ return implementation_->createInstance(Context, true);
+}
+
+css::uno::Reference< css::uno::XInterface >
+SingletonFactory::createInstanceWithArgumentsAndContext(
+ css::uno::Sequence< css::uno::Any > const & Arguments,
+ css::uno::Reference< css::uno::XComponentContext > const & Context)
+ throw (css::uno::Exception, css::uno::RuntimeException)
+{
+ manager_->loadImplementation(Context, implementation_);
+ return implementation_->createInstanceWithArguments(
+ Context, true, Arguments);
+}
+
class ImplementationWrapper:
public cppu::WeakImplHelper3<
css::lang::XSingleComponentFactory, css::lang::XSingleServiceFactory,
@@ -529,10 +581,10 @@ public:
ImplementationWrapper(
rtl::Reference< cppuhelper::ServiceManager > const & manager,
boost::shared_ptr<
- cppuhelper::ServiceManager::Data::ImplementationInfo > const &
- info):
- manager_(manager), info_(info), loaded_(false), constructor_(0)
- { assert(manager.is() && info.get() != 0); }
+ cppuhelper::ServiceManager::Data::Implementation > const &
+ implementation):
+ manager_(manager), implementation_(implementation)
+ { assert(manager.is()); assert(implementation.get() != 0); }
private:
virtual ~ImplementationWrapper() {}
@@ -565,18 +617,9 @@ private:
virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException);
- void loadImplementation(
- css::uno::Reference< css::uno::XComponentContext > const & context);
-
rtl::Reference< cppuhelper::ServiceManager > manager_;
- boost::shared_ptr< cppuhelper::ServiceManager::Data::ImplementationInfo >
- info_;
-
- osl::Mutex mutex_;
- bool loaded_;
- cppuhelper::ImplementationConstructorFn * constructor_;
- css::uno::Reference< css::lang::XSingleComponentFactory > factory1_;
- css::uno::Reference< css::lang::XSingleServiceFactory > factory2_;
+ boost::shared_ptr< cppuhelper::ServiceManager::Data::Implementation >
+ implementation_;
};
css::uno::Reference< css::uno::XInterface >
@@ -584,15 +627,8 @@ ImplementationWrapper::createInstanceWithContext(
css::uno::Reference< css::uno::XComponentContext > const & Context)
throw (css::uno::Exception, css::uno::RuntimeException)
{
- loadImplementation(Context);
- return constructor_ != 0
- ? css::uno::Reference<css::uno::XInterface>(
- (*constructor_)(
- Context.get(), css::uno::Sequence<css::uno::Any>()),
- SAL_NO_ACQUIRE)
- : factory1_.is()
- ? factory1_->createInstanceWithContext(Context)
- : factory2_->createInstance();
+ manager_->loadImplementation(Context, implementation_);
+ return implementation_->createInstance(Context, false);
}
css::uno::Reference< css::uno::XInterface >
@@ -601,19 +637,9 @@ ImplementationWrapper::createInstanceWithArgumentsAndContext(
css::uno::Reference< css::uno::XComponentContext > const & Context)
throw (css::uno::Exception, css::uno::RuntimeException)
{
- loadImplementation(Context);
- if (constructor_ != 0) {
- css::uno::Reference<css::uno::XInterface> xRet(
- (*constructor_)(Context.get(), Arguments), SAL_NO_ACQUIRE);
- css::uno::Reference<css::lang::XInitialization> xInit(
- xRet, css::uno::UNO_QUERY);
- if (xInit.is())
- xInit->initialize(Arguments);
- return xRet;
- } else
- return factory1_.is()
- ? factory1_->createInstanceWithArgumentsAndContext(Arguments, Context)
- : factory2_->createInstanceWithArguments(Arguments);
+ manager_->loadImplementation(Context, implementation_);
+ return implementation_->createInstanceWithArguments(
+ Context, false, Arguments);
}
css::uno::Reference< css::uno::XInterface >
@@ -635,7 +661,7 @@ ImplementationWrapper::createInstanceWithArguments(
rtl::OUString ImplementationWrapper::getImplementationName()
throw (css::uno::RuntimeException)
{
- return info_->name;
+ return implementation_->info->name;
}
sal_Bool ImplementationWrapper::supportsService(rtl::OUString const & ServiceName)
@@ -648,58 +674,149 @@ css::uno::Sequence< rtl::OUString >
ImplementationWrapper::getSupportedServiceNames()
throw (css::uno::RuntimeException)
{
- if (info_->services.size() > static_cast< sal_uInt32 >(SAL_MAX_INT32)) {
+ if (implementation_->info->services.size()
+ > static_cast< sal_uInt32 >(SAL_MAX_INT32))
+ {
throw css::uno::RuntimeException(
- "Implementation " + info_->name + " supports too many services",
+ ("Implementation " + implementation_->info->name
+ + " supports too many services"),
static_cast< cppu::OWeakObject * >(this));
}
css::uno::Sequence< rtl::OUString > names(
- static_cast< sal_Int32 >(info_->services.size()));
+ static_cast< sal_Int32 >(implementation_->info->services.size()));
sal_Int32 i = 0;
for (std::vector< rtl::OUString >::const_iterator j(
- info_->services.begin());
- j != info_->services.end(); ++j)
+ implementation_->info->services.begin());
+ j != implementation_->info->services.end(); ++j)
{
names[i++] = *j;
}
return names;
}
-void ImplementationWrapper::loadImplementation(
- css::uno::Reference< css::uno::XComponentContext > const & context)
+}
+
+css::uno::Reference<css::uno::XInterface>
+cppuhelper::ServiceManager::Data::Implementation::createInstance(
+ css::uno::Reference<css::uno::XComponentContext> const & context,
+ bool singletonRequest)
{
- {
- osl::MutexGuard g(mutex_);
- if (loaded_) {
- return;
+ if (info->singletons.empty()) {
+ assert(!singletonRequest);
+ if (constructor != 0) {
+ return css::uno::Reference<css::uno::XInterface>(
+ (*constructor)(
+ context.get(), css::uno::Sequence<css::uno::Any>()),
+ SAL_NO_ACQUIRE);
+ }
+ if (factory1.is()) {
+ return factory1->createInstanceWithContext(context);
+ }
+ if (factory2.is()) {
+ return factory2->createInstance();
}
- }
- cppuhelper::ImplementationConstructorFn * ctor = 0;
- css::uno::Reference< css::lang::XSingleComponentFactory > f1;
- css::uno::Reference< css::lang::XSingleServiceFactory > f2;
- //TODO: There is a race here, as the relevant service factory can already
- // have been removed and loading can thus fail, as the entity from which to
- // load can disappear once the service factory is removed:
- manager_->loadImplementation(context, info_, &ctor, &f1, &f2);
- if (ctor == 0 && !f1.is() && !f2.is()) {
throw css::uno::DeploymentException(
- ("Implementation " + info_->name
+ ("Implementation " + info->name
+ " does not provide a constructor or factory"),
- static_cast< cppu::OWeakObject * >(this));
- }
- osl::MutexGuard g(mutex_);
- if (!loaded_) {
- loaded_ = true;
- constructor_ = ctor;
- factory1_ = f1;
- factory2_ = f2;
+ css::uno::Reference<css::uno::XInterface>());
+ } else {
+ osl::MutexGuard g(mutex); //TODO: must be a non-recursive mutex
+ if (singleton.is()) {
+ if (singletonRequest) {
+ dispose = false;
+ }
+ return singleton;
+ }
+ if (constructor != 0) {
+ singleton.set(
+ (*constructor)(
+ context.get(), css::uno::Sequence<css::uno::Any>()),
+ SAL_NO_ACQUIRE);
+ } else if (factory1.is()) {
+ singleton = factory1->createInstanceWithContext(context);
+ } else if (factory2.is()) {
+ singleton = factory2->createInstance();
+ } else {
+ throw css::uno::DeploymentException(
+ ("Implementation " + info->name
+ + " does not provide a constructor or factory"),
+ css::uno::Reference<css::uno::XInterface>());
+ }
+ dispose = singleton.is() && !singletonRequest;
+ return singleton;
}
}
+css::uno::Reference<css::uno::XInterface>
+cppuhelper::ServiceManager::Data::Implementation::createInstanceWithArguments(
+ css::uno::Reference<css::uno::XComponentContext> const & context,
+ bool singletonRequest, css::uno::Sequence<css::uno::Any> const & arguments)
+{
+ if (info->singletons.empty()) {
+ assert(!singletonRequest);
+ if (constructor != 0) {
+ //HACK: The constructor will either observe arguments and return
+ // inst that does not implement XInitialization (or null), or ignore
+ // arguments and return inst that implements XInitialization; this
+ // should be removed again once XInitialization-based
+ // implementations have become rare:
+ css::uno::Reference<css::uno::XInterface> inst(
+ (*constructor)(context.get(), arguments), SAL_NO_ACQUIRE);
+ css::uno::Reference<css::lang::XInitialization> init(
+ inst, css::uno::UNO_QUERY);
+ if (init.is()) {
+ init->initialize(arguments);
+ }
+ return inst;
+ }
+ if (factory1.is()) {
+ return factory1->createInstanceWithArgumentsAndContext(
+ arguments, context);
+ }
+ if (factory2.is()) {
+ return factory2->createInstanceWithArguments(arguments);
+ }
+ throw css::uno::DeploymentException(
+ "Implementation " + info->name + " does not provide a factory",
+ css::uno::Reference<css::uno::XInterface>());
+ } else {
+ osl::MutexGuard g(mutex); //TODO: must be a non-recursive mutex
+ if (singleton.is()) {
+ SAL_WARN(
+ "cppuhelper",
+ "createInstanceWithArguments request for already instantiated"
+ " singleton implementation " << info->name);
+ if (singletonRequest) {
+ dispose = false;
+ }
+ return singleton;
+ }
+ if (constructor != 0) {
+ //HACK: see above
+ singleton.set(
+ (*constructor)(context.get(), arguments), SAL_NO_ACQUIRE);
+ css::uno::Reference<css::lang::XInitialization> init(
+ singleton, css::uno::UNO_QUERY);
+ if (init.is()) {
+ init->initialize(arguments);
+ }
+ } else if (factory1.is()) {
+ singleton = factory1->createInstanceWithArgumentsAndContext(
+ arguments, context);
+ } else if (factory2.is()) {
+ singleton = factory2->createInstanceWithArguments(arguments);
+ } else {
+ throw css::uno::DeploymentException(
+ "Implementation " + info->name + " does not provide a factory",
+ css::uno::Reference<css::uno::XInterface>());
+ }
+ dispose = singleton.is() && !singletonRequest;
+ return singleton;
+ }
}
void cppuhelper::ServiceManager::addSingletonContextEntries(
- std::vector< cppu::ContextEntry_Init > * entries) const
+ std::vector< cppu::ContextEntry_Init > * entries)
{
assert(entries != 0);
for (Data::ImplementationMap::const_iterator i(data_.singletons.begin());
@@ -714,44 +831,50 @@ void cppuhelper::ServiceManager::addSingletonContextEntries(
entries->push_back(
cppu::ContextEntry_Init(
"/singletons/" + i->first,
- css::uno::makeAny(i->second[0]->info->name), true));
+ css::uno::makeAny<
+ css::uno::Reference<css::lang::XSingleComponentFactory> >(
+ new SingletonFactory(this, i->second[0])),
+ true));
}
}
void cppuhelper::ServiceManager::loadImplementation(
css::uno::Reference< css::uno::XComponentContext > const & context,
- boost::shared_ptr< Data::ImplementationInfo > const & info,
- ImplementationConstructorFn ** constructor,
- css::uno::Reference< css::lang::XSingleComponentFactory > * factory1,
- css::uno::Reference< css::lang::XSingleServiceFactory > * factory2)
+ boost::shared_ptr< Data::Implementation > & implementation)
{
- assert(
- info.get() != 0 && constructor != 0 && *constructor == 0
- && factory1 != 0 && !factory1->is() && factory2 != 0
- && !factory2->is());
+ assert(implementation.get() != 0);
+ {
+ osl::MutexGuard g(rBHelper.rMutex);
+ if (implementation->status == Data::Implementation::STATUS_LOADED) {
+ return;
+ }
+ }
rtl::OUString uri;
try {
- uri = cppu::bootstrap_expandUri(info->uri);
+ uri = cppu::bootstrap_expandUri(implementation->info->uri);
} catch (css::lang::IllegalArgumentException & e) {
throw css::uno::DeploymentException(
- "Cannot expand URI" + info->uri + ": " + e.Message,
+ "Cannot expand URI" + implementation->info->uri + ": " + e.Message,
static_cast< cppu::OWeakObject * >(this));
}
+ cppuhelper::ImplementationConstructorFn * ctor = 0;
css::uno::Reference< css::uno::XInterface > f0;
// Special handling of SharedLibrary loader, with support for environment,
// constructor, and prefix arguments:
- if (!info->alienContext.is()
- && info->loader == "com.sun.star.loader.SharedLibrary")
+ if (!implementation->info->alienContext.is()
+ && implementation->info->loader == "com.sun.star.loader.SharedLibrary")
{
cppuhelper::detail::loadSharedLibComponentFactory(
- uri, info->environment, info->prefix, info->name, info->constructor,
- this, constructor, &f0);
- if (constructor != 0 && *constructor != 0) {
- assert(!info->environment.isEmpty());
+ uri, implementation->info->environment,
+ implementation->info->prefix, implementation->info->name,
+ implementation->info->constructor, this, &ctor, &f0);
+ if (ctor != 0) {
+ assert(!implementation->info->environment.isEmpty());
css::uno::Environment curEnv(css::uno::Environment::getCurrent());
css::uno::Environment env(
cppuhelper::detail::getEnvironment(
- info->environment, info->name));
+ implementation->info->environment,
+ implementation->info->name));
if (!(curEnv.is() && env.is())) {
throw css::uno::DeploymentException(
"cannot get environments",
@@ -763,21 +886,23 @@ void cppuhelper::ServiceManager::loadImplementation(
}
} else {
SAL_WARN_IF(
- !info->environment.isEmpty(), "cppuhelper",
- "Loader " << info->loader << " and non-empty environment "
- << info->environment);
+ !implementation->info->environment.isEmpty(), "cppuhelper",
+ "Loader " << implementation->info->loader
+ << " and non-empty environment "
+ << implementation->info->environment);
SAL_WARN_IF(
- !info->prefix.isEmpty(), "cppuhelper",
- "Loader " << info->loader << " and non-empty constructor "
- << info->constructor);
+ !implementation->info->prefix.isEmpty(), "cppuhelper",
+ "Loader " << implementation->info->loader
+ << " and non-empty constructor "
+ << implementation->info->constructor);
SAL_WARN_IF(
- !info->prefix.isEmpty(), "cppuhelper",
- "Loader " << info->loader << " and non-empty prefix "
- << info->prefix);
+ !implementation->info->prefix.isEmpty(), "cppuhelper",
+ "Loader " << implementation->info->loader
+ << " and non-empty prefix " << implementation->info->prefix);
css::uno::Reference< css::uno::XComponentContext > ctxt;
css::uno::Reference< css::lang::XMultiComponentFactory > smgr;
- if (info->alienContext.is()) {
- ctxt = info->alienContext;
+ if (implementation->info->alienContext.is()) {
+ ctxt = implementation->info->alienContext;
smgr = css::uno::Reference< css::lang::XMultiComponentFactory >(
ctxt->getServiceManager(), css::uno::UNO_SET_THROW);
} else {
@@ -786,28 +911,69 @@ void cppuhelper::ServiceManager::loadImplementation(
smgr = this;
}
css::uno::Reference< css::loader::XImplementationLoader > loader(
- smgr->createInstanceWithContext(info->loader, ctxt),
+ smgr->createInstanceWithContext(implementation->info->loader, ctxt),
css::uno::UNO_QUERY_THROW);
f0 = loader->activate(
- info->name, rtl::OUString(), uri,
+ implementation->info->name, rtl::OUString(), uri,
css::uno::Reference< css::registry::XRegistryKey >());
}
- factory1->set(f0, css::uno::UNO_QUERY);
- if (!factory1->is()) {
- factory2->set(f0, css::uno::UNO_QUERY);
+ css::uno::Reference<css::lang::XSingleComponentFactory> f1;
+ css::uno::Reference<css::lang::XSingleServiceFactory> f2;
+ if (ctor == 0) {
+ f1.set(f0, css::uno::UNO_QUERY);
+ if (!f1.is()) {
+ f2.set(f0, css::uno::UNO_QUERY);
+ if (!f2.is()) {
+ throw css::uno::DeploymentException(
+ ("Implementation " + implementation->info->name
+ + " does not provide a constructor or factory"),
+ static_cast< cppu::OWeakObject * >(this));
+ }
+ }
+ }
+ //TODO: There is a race here, as the relevant service factory can be removed
+ // while the mutex is unlocked and loading can thus fail, as the entity from
+ // which to load can disappear once the service factory is removed.
+ osl::MutexGuard g(rBHelper.rMutex);
+ if (!(isDisposed()
+ || implementation->status == Data::Implementation::STATUS_LOADED))
+ {
+ implementation->status = Data::Implementation::STATUS_LOADED;
+ implementation->constructor = ctor;
+ implementation->factory1 = f1;
+ implementation->factory2 = f2;
}
}
void cppuhelper::ServiceManager::disposing() {
+ std::vector< css::uno::Reference<css::uno::XInterface> > sngls;
std::vector< css::uno::Reference< css::lang::XComponent > > comps;
Data clear;
{
osl::MutexGuard g(rBHelper.rMutex);
+ for (Data::NamedImplementations::const_iterator i(
+ data_.namedImplementations.begin());
+ i != data_.namedImplementations.end(); ++i)
+ {
+ assert(i->second.get() != 0);
+ if (!i->second->info->singletons.empty()) {
+ osl::MutexGuard g2(i->second->mutex);
+ if (i->second->dispose) {
+ sngls.push_back(i->second->singleton);
+ }
+ }
+ }
for (Data::DynamicImplementations::const_iterator i(
data_.dynamicImplementations.begin());
i != data_.dynamicImplementations.end(); ++i)
{
assert(i->second.get() != 0);
+ if (!i->second->info->singletons.empty()) {
+ osl::MutexGuard g2(i->second->mutex);
+ if (i->second->dispose) {
+ sngls.push_back(i->second->singleton);
+ }
+ }
if (i->second->component.is()) {
comps.push_back(i->second->component);
}
@@ -818,6 +984,24 @@ void cppuhelper::ServiceManager::disposing() {
data_.singletons.swap(clear.singletons);
}
for (std::vector<
+ css::uno::Reference<css::uno::XInterface> >::const_iterator i(
+ sngls.begin());
+ i != sngls.end(); ++i)
+ {
+ css::uno::Reference<css::lang::XComponent> comp(
+ *i, css::uno::UNO_QUERY);
+ if (comp.is()) {
+ try {
+ comp->dispose();
+ } catch (css::uno::RuntimeException & e) {
+ SAL_WARN(
+ "cppuhelper",
+ "Ignoring RuntimeException \"" << e.Message
+ << "\" while disposing singleton");
+ }
+ }
+ }
+ for (std::vector<
css::uno::Reference< css::lang::XComponent > >::const_iterator i(
comps.begin());
i != comps.end(); ++i)
@@ -903,23 +1087,9 @@ cppuhelper::ServiceManager::createInstanceWithContext(
{
boost::shared_ptr< Data::Implementation > impl(
findServiceImplementation(Context, aServiceSpecifier));
- if (impl.get() == 0) {
- return css::uno::Reference< css::uno::XInterface >();
- }
- if (impl->constructor != 0) {
- return css::uno::Reference<css::uno::XInterface>(
- (*impl->constructor)(
- Context.get(), css::uno::Sequence<css::uno::Any>()),
- SAL_NO_ACQUIRE);
- } else if (impl->factory1.is()) {
- return impl->factory1->createInstanceWithContext(Context);
- }
- if (impl->factory2.is()) {
- return impl->factory2->createInstance();
- }
- throw css::uno::DeploymentException(
- "Implementation " + impl->info->name + " does not provide a factory",
- static_cast< cppu::OWeakObject * >(this));
+ return impl.get() == 0
+ ? css::uno::Reference< css::uno::XInterface >()
+ : impl->createInstance(Context, false);
}
css::uno::Reference< css::uno::XInterface >
@@ -931,28 +1101,9 @@ cppuhelper::ServiceManager::createInstanceWithArgumentsAndContext(
{
boost::shared_ptr< Data::Implementation > impl(
... etc. - the rest is truncated
More information about the Libreoffice-commits
mailing list