[Libreoffice-commits] core.git: ucb/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Thu Oct 1 07:48:23 UTC 2020


 ucb/source/core/cmdenv.cxx     |   21 ++-------------------
 ucb/source/core/cmdenv.hxx     |    3 ---
 ucb/source/core/provprox.cxx   |   20 +++-----------------
 ucb/source/core/provprox.hxx   |    3 ---
 ucb/source/core/ucb.cxx        |   14 ++------------
 ucb/source/core/ucb1.component |   20 +++++---------------
 ucb/source/core/ucbprops.cxx   |    6 ++----
 ucb/source/core/ucbstore.cxx   |   18 ++----------------
 ucb/source/core/ucbstore.hxx   |    3 ---
 9 files changed, 16 insertions(+), 92 deletions(-)

New commits:
commit 5204be412e0e0fc138b82f886b83d5b8e0e77dd2
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Wed Sep 30 22:21:49 2020 +0200
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Thu Oct 1 09:47:05 2020 +0200

    Use the new single-instance="true" attribute in ucb
    
    It looks like 3d44c6a49b20415616dab7a2de2820da5efab309 "ucb/core: create
    instances with uno constructors" mixed up
    com.sun.star.comp.ucb.UcbPropertiesManager (which had originally been
    implemented with the single-instance cppu::createOneInstanceFactory) and
    com.sun.star.comp.ucb.SimpleFileAccess (which had originally been implemented
    with the multi-instance cppu::createSingleFactory), using a static
    g_Instance in the C++ constructor function of the former but adding a fake
    <singleton> to the *.component <implementation> of the latter.
    
    Change-Id: Ida7cb242a73fbe7689094e239ffe0c0291cf1d3c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103738
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Reviewed-by: Stephan Bergmann <sbergman at redhat.com>

diff --git a/ucb/source/core/cmdenv.cxx b/ucb/source/core/cmdenv.cxx
index 66216895bfe5..a768032f228d 100644
--- a/ucb/source/core/cmdenv.cxx
+++ b/ucb/source/core/cmdenv.cxx
@@ -20,8 +20,8 @@
 
 #include <cppuhelper/factory.hxx>
 #include <cppuhelper/supportsservice.hxx>
+#include <cppuhelper/weak.hxx>
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
-#include <rtl/ref.hxx>
 
 #include "cmdenv.hxx"
 
@@ -33,10 +33,6 @@
 using namespace com::sun::star;
 using namespace ucb_cmdenv;
 
-static osl::Mutex g_InstanceGuard;
-static rtl::Reference<UcbCommandEnvironment> g_Instance;
-
-
 // UcbCommandEnvironment Implementation.
 
 
@@ -50,15 +46,6 @@ UcbCommandEnvironment::~UcbCommandEnvironment()
 {
 }
 
-// XComponent
-void SAL_CALL UcbCommandEnvironment::dispose()
-{
-    UcbCommandEnvironment_Base::dispose();
-    osl::MutexGuard aGuard(g_InstanceGuard);
-    g_Instance.clear();
-}
-
-
 // XInitialization methods.
 
 
@@ -124,11 +111,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
 ucb_UcbCommandEnvironment_get_implementation(
     css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
 {
-    osl::MutexGuard aGuard(g_InstanceGuard);
-    if (!g_Instance)
-        g_Instance.set(new UcbCommandEnvironment());
-    g_Instance->acquire();
-    return static_cast<cppu::OWeakObject*>(g_Instance.get());
+    return cppu::acquire(static_cast<cppu::OWeakObject*>(new UcbCommandEnvironment()));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/core/cmdenv.hxx b/ucb/source/core/cmdenv.hxx
index c11401039f0a..7ed048ff304b 100644
--- a/ucb/source/core/cmdenv.hxx
+++ b/ucb/source/core/cmdenv.hxx
@@ -44,9 +44,6 @@ public:
     explicit UcbCommandEnvironment();
     virtual ~UcbCommandEnvironment() override;
 
-    // XComponent
-    virtual void SAL_CALL dispose() override;
-
     // XInitialization
     virtual void SAL_CALL
     initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
diff --git a/ucb/source/core/provprox.cxx b/ucb/source/core/provprox.cxx
index d0d9cccbe1ef..2352aebf8e9a 100644
--- a/ucb/source/core/provprox.cxx
+++ b/ucb/source/core/provprox.cxx
@@ -25,16 +25,13 @@
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
 #include <cppuhelper/queryinterface.hxx>
+#include <cppuhelper/weak.hxx>
 #include <ucbhelper/macros.hxx>
-#include <rtl/ref.hxx>
 
 using namespace com::sun::star::lang;
 using namespace com::sun::star::ucb;
 using namespace com::sun::star::uno;
 
-static osl::Mutex g_InstanceGuard;
-static rtl::Reference<UcbContentProviderProxyFactory> g_Instance;
-
 // UcbContentProviderProxyFactory Implementation.
 
 
@@ -50,14 +47,6 @@ UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
 {
 }
 
-// XComponent
-void SAL_CALL UcbContentProviderProxyFactory::dispose()
-{
-    UcbContentProviderProxyFactory_Base::dispose();
-    osl::MutexGuard aGuard(g_InstanceGuard);
-    g_Instance.clear();
-}
-
 // XServiceInfo methods.
 
 OUString SAL_CALL UcbContentProviderProxyFactory::getImplementationName()
@@ -80,11 +69,8 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
 ucb_UcbContentProviderProxyFactory_get_implementation(
     css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
 {
-    osl::MutexGuard aGuard(g_InstanceGuard);
-    if (!g_Instance)
-        g_Instance.set(new UcbContentProviderProxyFactory(context));
-    g_Instance->acquire();
-    return static_cast<cppu::OWeakObject*>(g_Instance.get());
+    return cppu::acquire(
+        static_cast<cppu::OWeakObject*>(new UcbContentProviderProxyFactory(context)));
 }
 
 
diff --git a/ucb/source/core/provprox.hxx b/ucb/source/core/provprox.hxx
index 0e607abafe94..ef08fefebac5 100644
--- a/ucb/source/core/provprox.hxx
+++ b/ucb/source/core/provprox.hxx
@@ -48,9 +48,6 @@ public:
             const css::uno::Reference< css::uno::XComponentContext >& rxContext );
     virtual ~UcbContentProviderProxyFactory() override;
 
-    // XComponent
-    virtual void SAL_CALL dispose() override;
-
     // XServiceInfo
     virtual OUString SAL_CALL getImplementationName() override;
     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
diff --git a/ucb/source/core/ucb.cxx b/ucb/source/core/ucb.cxx
index 304e37c37728..64f74ec26d00 100644
--- a/ucb/source/core/ucb.cxx
+++ b/ucb/source/core/ucb.cxx
@@ -39,9 +39,9 @@
 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
 #include <com/sun/star/container/XNameAccess.hpp>
 #include <com/sun/star/uno/Any.hxx>
+#include <cppuhelper/weak.hxx>
 #include <ucbhelper/cancelcommandexecution.hxx>
 #include <ucbhelper/macros.hxx>
-#include <rtl/ref.hxx>
 #include "identify.hxx"
 #include "ucbcmds.hxx"
 
@@ -55,9 +55,6 @@ using namespace ucb_impl;
 using namespace com::sun::star;
 using namespace ucbhelper;
 
-static osl::Mutex g_InstanceGuard;
-static rtl::Reference<UniversalContentBroker> g_Instance;
-
 namespace {
 
 bool fillPlaceholders(OUString const & rInput,
@@ -254,9 +251,6 @@ void SAL_CALL UniversalContentBroker::dispose()
 
     if ( m_xNotifier.is() )
         m_xNotifier->removeChangesListener( this );
-
-    osl::MutexGuard aGuard(g_InstanceGuard);
-    g_Instance.clear();
 }
 
 
@@ -302,11 +296,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
 ucb_UniversalContentBroker_get_implementation(
     css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
 {
-    osl::MutexGuard aGuard(g_InstanceGuard);
-    if (!g_Instance)
-        g_Instance.set(new UniversalContentBroker(context));
-    g_Instance->acquire();
-    return static_cast<cppu::OWeakObject*>(g_Instance.get());
+    return cppu::acquire(static_cast<cppu::OWeakObject*>(new UniversalContentBroker(context)));
 }
 
 
diff --git a/ucb/source/core/ucb1.component b/ucb/source/core/ucb1.component
index 7cfb35264e11..952d37406be7 100644
--- a/ucb/source/core/ucb1.component
+++ b/ucb/source/core/ucb1.component
@@ -20,37 +20,27 @@
 <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
     xmlns="http://openoffice.org/2010/uno-components">
   <implementation name="com.sun.star.comp.ucb.CommandEnvironment"
-    constructor="ucb_UcbCommandEnvironment_get_implementation">
-    <!-- fake singleton so the servicemanager shuts us down and we can clean up our global instance var -->
-    <singleton name="com.sun.star.comp.ucb.theCommandEnvironment"/>
+    constructor="ucb_UcbCommandEnvironment_get_implementation" single-instance="true">
     <service name="com.sun.star.ucb.CommandEnvironment"/>
   </implementation>
   <implementation name="com.sun.star.comp.ucb.UcbContentProviderProxyFactory"
-    constructor="ucb_UcbContentProviderProxyFactory_get_implementation">
-    <!-- fake singleton so the servicemanager shuts us down and we can clean up our global instance var -->
-    <singleton name="com.sun.star.comp.ucb.theUcbContentProviderProxyFactory"/>
+    constructor="ucb_UcbContentProviderProxyFactory_get_implementation" single-instance="true">
     <service name="com.sun.star.ucb.ContentProviderProxyFactory"/>
   </implementation>
   <implementation name="com.sun.star.comp.ucb.UcbPropertiesManager"
-    constructor="ucb_UcbPropertiesManager_get_implementation">
+    constructor="ucb_UcbPropertiesManager_get_implementation" single-instance="true">
     <service name="com.sun.star.ucb.PropertiesManager"/>
   </implementation>
   <implementation name="com.sun.star.comp.ucb.UcbStore"
-    constructor="ucb_UcbStore_get_implementation">
-    <!-- fake singleton so the servicemanager shuts us down and we can clean up our global instance var -->
-    <singleton name="com.sun.star.comp.ucb.theUcbStore"/>
+    constructor="ucb_UcbStore_get_implementation" single-instance="true">
     <service name="com.sun.star.ucb.Store"/>
   </implementation>
   <implementation name="com.sun.star.comp.ucb.UniversalContentBroker"
-    constructor="ucb_UniversalContentBroker_get_implementation">
-    <!-- fake singleton so the servicemanager shuts us down and we can clean up our global instance var -->
-    <singleton name="com.sun.star.comp.ucb.theUniversalContentBroker"/>
+    constructor="ucb_UniversalContentBroker_get_implementation" single-instance="true">
     <service name="com.sun.star.ucb.UniversalContentBroker"/>
   </implementation>
   <implementation name="com.sun.star.comp.ucb.SimpleFileAccess"
     constructor="ucb_OFileAccess_get_implementation">
-    <!-- fake singleton so the servicemanager shuts us down and we can clean up our global instance var -->
-    <singleton name="com.sun.star.comp.ucb.theSimpleFileAccess"/>
     <service name="com.sun.star.ucb.SimpleFileAccess"/>
   </implementation>
 </component>
diff --git a/ucb/source/core/ucbprops.cxx b/ucb/source/core/ucbprops.cxx
index fe64bfad6cfe..95d9d90e6c36 100644
--- a/ucb/source/core/ucbprops.cxx
+++ b/ucb/source/core/ucbprops.cxx
@@ -34,8 +34,8 @@
 #include <com/sun/star/ucb/SynchronizePolicy.hpp>
 #include <com/sun/star/ucb/VerificationMode.hpp>
 #include <com/sun/star/ucb/XDataContainer.hpp>
+#include <cppuhelper/weak.hxx>
 #include <ucbhelper/macros.hxx>
-#include <rtl/ref.hxx>
 
 #include "ucbprops.hxx"
 
@@ -216,9 +216,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
 ucb_UcbPropertiesManager_get_implementation(
     css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
 {
-    static rtl::Reference<UcbPropertiesManager> g_Instance(new UcbPropertiesManager());
-    g_Instance->acquire();
-    return static_cast<cppu::OWeakObject*>(g_Instance.get());
+    return cppu::acquire(static_cast<cppu::OWeakObject*>(new UcbPropertiesManager()));
 }
 
 // XPropertySetInfo methods.
diff --git a/ucb/source/core/ucbstore.cxx b/ucb/source/core/ucbstore.cxx
index 617207efd31b..3274c777fdc5 100644
--- a/ucb/source/core/ucbstore.cxx
+++ b/ucb/source/core/ucbstore.cxx
@@ -45,6 +45,7 @@
 #include <com/sun/star/util/XChangesBatch.hpp>
 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
 #include <cppuhelper/implbase.hxx>
+#include <cppuhelper/weak.hxx>
 #include <ucbhelper/macros.hxx>
 #include <tools/diagnose_ex.h>
 #include "ucbstore.hxx"
@@ -59,9 +60,6 @@ using namespace com::sun::star::util;
 using namespace comphelper;
 using namespace cppu;
 
-static osl::Mutex g_InstanceGuard;
-static rtl::Reference<UcbStore> g_Instance;
-
 static OUString makeHierarchalNameSegment( const OUString & rIn  )
 {
     OUStringBuffer aBuffer;
@@ -160,14 +158,6 @@ UcbStore::~UcbStore()
 {
 }
 
-// XComponent
-void SAL_CALL UcbStore::dispose()
-{
-    UcbStore_Base::dispose();
-    osl::MutexGuard aGuard(g_InstanceGuard);
-    g_Instance.clear();
-}
-
 OUString SAL_CALL UcbStore::getImplementationName()
 {
     return "com.sun.star.comp.ucb.UcbStore";
@@ -187,11 +177,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
 ucb_UcbStore_get_implementation(
     css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
 {
-    osl::MutexGuard aGuard(g_InstanceGuard);
-    if (!g_Instance)
-        g_Instance.set(new UcbStore(context));
-    g_Instance->acquire();
-    return static_cast<cppu::OWeakObject*>(g_Instance.get());
+    return cppu::acquire(static_cast<cppu::OWeakObject*>(new UcbStore(context)));
 }
 
 
diff --git a/ucb/source/core/ucbstore.hxx b/ucb/source/core/ucbstore.hxx
index 3c0cdef87649..310f8bc97337 100644
--- a/ucb/source/core/ucbstore.hxx
+++ b/ucb/source/core/ucbstore.hxx
@@ -55,9 +55,6 @@ public:
     explicit UcbStore( const css::uno::Reference< css::uno::XComponentContext >& xContext );
     virtual ~UcbStore() override;
 
-    // XComponent
-    virtual void SAL_CALL dispose() override;
-
     // XServiceInfo
     virtual OUString SAL_CALL getImplementationName() override;
     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;


More information about the Libreoffice-commits mailing list