[Libreoffice-commits] core.git: solenv/bin ucb/Library_ucb1.mk ucb/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sun Aug 9 10:04:26 UTC 2020


 solenv/bin/native-code.py      |    8 ++
 ucb/Library_ucb1.mk            |    1 
 ucb/source/core/FileAccess.cxx |   20 ++-----
 ucb/source/core/FileAccess.hxx |   43 ---------------
 ucb/source/core/cmdenv.cxx     |   61 ++++++++--------------
 ucb/source/core/cmdenv.hxx     |   20 +++----
 ucb/source/core/provprox.cxx   |   53 +++++++++++--------
 ucb/source/core/provprox.hxx   |   33 +++++-------
 ucb/source/core/ucb.cxx        |   44 ++++++++--------
 ucb/source/core/ucb.hxx        |   10 ---
 ucb/source/core/ucb1.component |   30 ++++++++---
 ucb/source/core/ucbprops.cxx   |   51 +++++++++++-------
 ucb/source/core/ucbprops.hxx   |   24 +++-----
 ucb/source/core/ucbserv.cxx    |  111 -----------------------------------------
 ucb/source/core/ucbstore.cxx   |   55 +++++++++++---------
 ucb/source/core/ucbstore.hxx   |   28 ++++------
 16 files changed, 220 insertions(+), 372 deletions(-)

New commits:
commit 3d44c6a49b20415616dab7a2de2820da5efab309
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Wed Jul 15 09:28:31 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sun Aug 9 12:03:30 2020 +0200

    ucb/core: create instances with uno constructors
    
    See tdf#74608 for motivation.
    
    Change-Id: Ieabf6d417a482ea7cc17e78a78954687e8894cb1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98801
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/solenv/bin/native-code.py b/solenv/bin/native-code.py
index 198768b9c28a..28066c1f42d3 100755
--- a/solenv/bin/native-code.py
+++ b/solenv/bin/native-code.py
@@ -21,7 +21,6 @@ import xml.etree.ElementTree as ET
 
 core_factory_list = [
     ("libi18npoollo.a", "i18npool_component_getFactory"),
-    ("libucb1.a", "ucb_component_getFactory"),
     ("libvcllo.a", "vcl_component_getFactory"),
     ("libsvtlo.a", "svt_component_getFactory"),
     ]
@@ -345,6 +344,13 @@ core_constructor_list = [
     "stardiv_Toolkit_VCLXPointer_get_implementation",
     "stardiv_Toolkit_VCLXPopupMenu_get_implementation",
     "stardiv_Toolkit_VCLXToolkit_get_implementation",
+# ucb/source/core/ucb1.component
+    "ucb_UcbCommandEnvironment_get_implementation",
+    "ucb_UcbContentProviderProxyFactory_get_implementation",
+    "ucb_UcbPropertiesManager_get_implementation",
+    "ucb_UcbStore_get_implementation",
+    "ucb_UniversalContentBroker_get_implementation",
+    "ucb_OFileAccess_get_implementation",
 # ucb/source/ucp/file/ucpfile1.component
     "ucb_file_FileProvider_get_implementation",
 # ucb/source/ucp/expand/ucpexpand1.component
diff --git a/ucb/Library_ucb1.mk b/ucb/Library_ucb1.mk
index ce7144f8fe13..6dbb347c1043 100644
--- a/ucb/Library_ucb1.mk
+++ b/ucb/Library_ucb1.mk
@@ -38,7 +38,6 @@ $(eval $(call gb_Library_add_exception_objects,ucb1,\
 	ucb/source/core/ucb \
 	ucb/source/core/ucbcmds \
 	ucb/source/core/ucbprops \
-	ucb/source/core/ucbserv \
 	ucb/source/core/ucbstore \
 	ucb/source/core/FileAccess \
 	ucb/source/regexp/regexp \
diff --git a/ucb/source/core/FileAccess.cxx b/ucb/source/core/FileAccess.cxx
index 218bcad33a81..4a816618471e 100644
--- a/ucb/source/core/FileAccess.cxx
+++ b/ucb/source/core/FileAccess.cxx
@@ -53,8 +53,6 @@
 
 #include <vector>
 
-#include "FileAccess.hxx"
-
 #define SERVICE_NAME "com.sun.star.ucb.SimpleFileAccess"
 
 using namespace ::com::sun::star::uno;
@@ -117,13 +115,13 @@ public:
     virtual void SAL_CALL setHidden( const OUString& FileURL, sal_Bool bHidden ) override;
 
     OUString SAL_CALL getImplementationName() override
-    { return IMPLEMENTATION_NAME; }
+    { return "com.sun.star.comp.ucb.SimpleFileAccess"; }
 
     sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
     { return cppu::supportsService(this, ServiceName); }
 
     css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
-    { return FileAccess_getSupportedServiceNames(); }
+    { return { SERVICE_NAME }; }
 };
 
 // Implementation XActiveDataSink
@@ -694,17 +692,15 @@ void OFileAccess::setHidden( const OUString& FileURL, sal_Bool bHidden )
     aCnt.setPropertyValue("IsHidden", Any(bHidden) );
 }
 
-}; // namespace end
 
-Reference< XInterface > FileAccess_CreateInstance( const Reference< XMultiServiceFactory > & xSMgr )
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+ucb_OFileAccess_get_implementation(
+    css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
 {
-    return Reference < XInterface >( static_cast<cppu::OWeakObject *>(new OFileAccess( comphelper::getComponentContext(xSMgr) )) );
+    return cppu::acquire(new OFileAccess(context));
 }
 
-Sequence< OUString > FileAccess_getSupportedServiceNames()
-{
-    Sequence< OUString > seqNames { SERVICE_NAME };
-    return seqNames;
-}
+}; // namespace end
+
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/core/FileAccess.hxx b/ucb/source/core/FileAccess.hxx
deleted file mode 100644
index 7b7b8a037103..000000000000
--- a/ucb/source/core/FileAccess.hxx
+++ /dev/null
@@ -1,43 +0,0 @@
-/* -*- 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 INCLUDED_UCB_SOURCE_CORE_FILEACCESS_HXX
-#define INCLUDED_UCB_SOURCE_CORE_FILEACCESS_HXX
-
-#include <sal/config.h>
-
-#include <com/sun/star/uno/Reference.hxx>
-#include <com/sun/star/uno/Sequence.hxx>
-#include <rtl/ustring.hxx>
-
-namespace com::sun::star {
-    namespace lang { class XMultiServiceFactory; }
-    namespace uno { class XInterface; }
-}
-
-#define IMPLEMENTATION_NAME "com.sun.star.comp.ucb.SimpleFileAccess"
-
-css::uno::Reference<css::uno::XInterface> FileAccess_CreateInstance(
-css::uno::Reference<css::lang::XMultiServiceFactory> const & xSMgr);
-
-css::uno::Sequence<OUString> FileAccess_getSupportedServiceNames();
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/core/cmdenv.cxx b/ucb/source/core/cmdenv.cxx
index 638db5cc6044..66216895bfe5 100644
--- a/ucb/source/core/cmdenv.cxx
+++ b/ucb/source/core/cmdenv.cxx
@@ -21,6 +21,7 @@
 #include <cppuhelper/factory.hxx>
 #include <cppuhelper/supportsservice.hxx>
 #include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <rtl/ref.hxx>
 
 #include "cmdenv.hxx"
 
@@ -32,11 +33,14 @@
 using namespace com::sun::star;
 using namespace ucb_cmdenv;
 
+static osl::Mutex g_InstanceGuard;
+static rtl::Reference<UcbCommandEnvironment> g_Instance;
+
 
 // UcbCommandEnvironment Implementation.
 
 
-UcbCommandEnvironment::UcbCommandEnvironment()
+UcbCommandEnvironment::UcbCommandEnvironment() : UcbCommandEnvironment_Base(m_aMutex)
 {
 }
 
@@ -46,6 +50,14 @@ UcbCommandEnvironment::~UcbCommandEnvironment()
 {
 }
 
+// XComponent
+void SAL_CALL UcbCommandEnvironment::dispose()
+{
+    UcbCommandEnvironment_Base::dispose();
+    osl::MutexGuard aGuard(g_InstanceGuard);
+    g_Instance.clear();
+}
+
 
 // XInitialization methods.
 
@@ -67,7 +79,7 @@ void SAL_CALL UcbCommandEnvironment::initialize(
 // virtual
 OUString SAL_CALL UcbCommandEnvironment::getImplementationName()
 {
-    return getImplementationName_Static();
+    return "com.sun.star.comp.ucb.CommandEnvironment";
 }
 
 
@@ -83,23 +95,7 @@ UcbCommandEnvironment::supportsService( const OUString& ServiceName )
 uno::Sequence< OUString > SAL_CALL
 UcbCommandEnvironment::getSupportedServiceNames()
 {
-    return getSupportedServiceNames_Static();
-}
-
-
-// static
-OUString UcbCommandEnvironment::getImplementationName_Static()
-{
-    return "com.sun.star.comp.ucb.CommandEnvironment";
-}
-
-
-// static
-uno::Sequence< OUString >
-UcbCommandEnvironment::getSupportedServiceNames_Static()
-{
-    uno::Sequence<OUString> aSNS { "com.sun.star.ucb.CommandEnvironment" };
-    return aSNS;
+    return { "com.sun.star.ucb.CommandEnvironment" };
 }
 
 
@@ -124,26 +120,15 @@ UcbCommandEnvironment::getProgressHandler()
 
 // Service factory implementation.
 
-/// @throws uno::Exception
-static uno::Reference< uno::XInterface >
-UcbCommandEnvironment_CreateInstance(
-    const uno::Reference< lang::XMultiServiceFactory> & /*rSMgr*/ )
-{
-    lang::XServiceInfo* pX = new UcbCommandEnvironment;
-    return uno::Reference< uno::XInterface >::query( pX );
-}
-
-
-// static
-uno::Reference< lang::XSingleServiceFactory >
-UcbCommandEnvironment::createServiceFactory(
-    const uno::Reference< lang::XMultiServiceFactory >& rxServiceMgr )
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+ucb_UcbCommandEnvironment_get_implementation(
+    css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
 {
-    return cppu::createSingleFactory(
-                rxServiceMgr,
-                UcbCommandEnvironment::getImplementationName_Static(),
-                UcbCommandEnvironment_CreateInstance,
-                UcbCommandEnvironment::getSupportedServiceNames_Static() );
+    osl::MutexGuard aGuard(g_InstanceGuard);
+    if (!g_Instance)
+        g_Instance.set(new UcbCommandEnvironment());
+    g_Instance->acquire();
+    return static_cast<cppu::OWeakObject*>(g_Instance.get());
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/core/cmdenv.hxx b/ucb/source/core/cmdenv.hxx
index 546df31418c6..c11401039f0a 100644
--- a/ucb/source/core/cmdenv.hxx
+++ b/ucb/source/core/cmdenv.hxx
@@ -20,7 +20,8 @@
 #ifndef INCLUDED_UCB_SOURCE_CORE_CMDENV_HXX
 #define INCLUDED_UCB_SOURCE_CORE_CMDENV_HXX
 
-#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/compbase.hxx>
+#include <cppuhelper/basemutex.hxx>
 
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
@@ -30,10 +31,11 @@
 
 namespace ucb_cmdenv {
 
-class UcbCommandEnvironment :
-        public cppu::WeakImplHelper< css::lang::XInitialization,
+using UcbCommandEnvironment_Base = cppu::WeakComponentImplHelper< css::lang::XInitialization,
                                       css::lang::XServiceInfo,
-                                      css::ucb::XCommandEnvironment >
+                                      css::ucb::XCommandEnvironment >;
+
+class UcbCommandEnvironment : public cppu::BaseMutex, public UcbCommandEnvironment_Base
 {
     css::uno::Reference< css::task::XInteractionHandler > m_xIH;
     css::uno::Reference< css::ucb::XProgressHandler >     m_xPH;
@@ -42,6 +44,9 @@ 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;
@@ -60,13 +65,6 @@ public:
     getInteractionHandler() override;
     virtual css::uno::Reference< css::ucb::XProgressHandler > SAL_CALL
     getProgressHandler() override;
-
-    // Non-UNO interfaces
-    static OUString  getImplementationName_Static();
-    static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
-
-    static css::uno::Reference< css::lang::XSingleServiceFactory >
-    createServiceFactory( const css::uno::Reference< css::lang::XMultiServiceFactory > & rxServiceMgr );
 };
 
 } // namespace ucb_cmdenv
diff --git a/ucb/source/core/provprox.cxx b/ucb/source/core/provprox.cxx
index 71c337fe1238..d0d9cccbe1ef 100644
--- a/ucb/source/core/provprox.cxx
+++ b/ucb/source/core/provprox.cxx
@@ -26,18 +26,21 @@
 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
 #include <cppuhelper/queryinterface.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.
 
 
 UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
-                        const Reference< XMultiServiceFactory >& rxSMgr )
-: m_xSMgr( rxSMgr )
+                        const Reference< XComponentContext >& rxContext )
+: UcbContentProviderProxyFactory_Base(m_aMutex), m_xContext( rxContext )
 {
 }
 
@@ -47,18 +50,25 @@ UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
 {
 }
 
+// XComponent
+void SAL_CALL UcbContentProviderProxyFactory::dispose()
+{
+    UcbContentProviderProxyFactory_Base::dispose();
+    osl::MutexGuard aGuard(g_InstanceGuard);
+    g_Instance.clear();
+}
+
 // XServiceInfo methods.
 
-XSERVICEINFO_COMMOM_IMPL( UcbContentProviderProxyFactory,
-                          "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" )
-/// @throws css::uno::Exception
-static css::uno::Reference< css::uno::XInterface >
-UcbContentProviderProxyFactory_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
+OUString SAL_CALL UcbContentProviderProxyFactory::getImplementationName()
 {
-    return static_cast<css::lang::XServiceInfo*>(new UcbContentProviderProxyFactory(rSMgr));
+    return "com.sun.star.comp.ucb.UcbContentProviderProxyFactory";
+}
+sal_Bool SAL_CALL UcbContentProviderProxyFactory::supportsService( const OUString& ServiceName )
+{
+    return cppu::supportsService( this, ServiceName );
 }
-css::uno::Sequence< OUString >
-UcbContentProviderProxyFactory::getSupportedServiceNames_Static()
+css::uno::Sequence< OUString > SAL_CALL UcbContentProviderProxyFactory::getSupportedServiceNames()
 {
     return { "com.sun.star.ucb.ContentProviderProxyFactory" };
 }
@@ -66,14 +76,15 @@ UcbContentProviderProxyFactory::getSupportedServiceNames_Static()
 // Service factory implementation.
 
 
-css::uno::Reference< css::lang::XSingleServiceFactory >
-UcbContentProviderProxyFactory::createServiceFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& rxServiceMgr )
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+ucb_UcbContentProviderProxyFactory_get_implementation(
+    css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
 {
-    return cppu::createOneInstanceFactory(
-                rxServiceMgr,
-                UcbContentProviderProxyFactory::getImplementationName_Static(),
-                UcbContentProviderProxyFactory_CreateInstance,
-                UcbContentProviderProxyFactory::getSupportedServiceNames_Static() );
+    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());
 }
 
 
@@ -86,7 +97,7 @@ UcbContentProviderProxyFactory::createContentProvider(
                                                 const OUString& Service )
 {
     return Reference< XContentProvider >(
-                        new UcbContentProviderProxy( m_xSMgr, Service ) );
+                        new UcbContentProviderProxy( m_xContext, Service ) );
 }
 
 
@@ -94,12 +105,12 @@ UcbContentProviderProxyFactory::createContentProvider(
 
 
 UcbContentProviderProxy::UcbContentProviderProxy(
-                        const Reference< XMultiServiceFactory >& rxSMgr,
+                        const Reference< XComponentContext >& rxContext,
                         const OUString& Service )
 : m_aService( Service ),
   m_bReplace( false ),
   m_bRegister( false ),
-  m_xSMgr( rxSMgr )
+  m_xContext( rxContext )
 {
 }
 
@@ -305,7 +316,7 @@ UcbContentProviderProxy::getContentProvider()
     {
         try
         {
-            m_xProvider.set( m_xSMgr->createInstance( m_aService ), UNO_QUERY );
+            m_xProvider.set( m_xContext->getServiceManager()->createInstanceWithContext( m_aService,m_xContext ), UNO_QUERY );
             if ( m_aArguments == "NoConfig" )
             {
                 Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
diff --git a/ucb/source/core/provprox.hxx b/ucb/source/core/provprox.hxx
index dea286b10639..0e607abafe94 100644
--- a/ucb/source/core/provprox.hxx
+++ b/ucb/source/core/provprox.hxx
@@ -29,36 +29,33 @@
 #include <com/sun/star/ucb/XContentProvider.hpp>
 #include <com/sun/star/ucb/XParameterizedContentProvider.hpp>
 #include <com/sun/star/ucb/XContentProviderSupplier.hpp>
+#include <com/sun/star/uno/XComponentContext.hpp>
+#include <cppuhelper/compbase.hxx>
 #include <cppuhelper/weak.hxx>
-#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/basemutex.hxx>
 
 
 
-
-class UcbContentProviderProxyFactory : public cppu::WeakImplHelper <
-    css::lang::XServiceInfo,
-    css::ucb::XContentProviderFactory >
+using UcbContentProviderProxyFactory_Base = cppu::WeakComponentImplHelper <
+                                                css::lang::XServiceInfo,
+                                                css::ucb::XContentProviderFactory >;
+class UcbContentProviderProxyFactory : public cppu::BaseMutex, public UcbContentProviderProxyFactory_Base
 {
-    css::uno::Reference< css::lang::XMultiServiceFactory >
-                                m_xSMgr;
+    css::uno::Reference< css::uno::XComponentContext > m_xContext;
 
 public:
     explicit UcbContentProviderProxyFactory(
-            const css::uno::Reference< css::lang::XMultiServiceFactory >& rxSMgr );
+            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;
     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
 
-    static OUString getImplementationName_Static();
-    static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
-
-    static css::uno::Reference< css::lang::XSingleServiceFactory >
-    createServiceFactory( const css::uno::Reference<
-                          css::lang::XMultiServiceFactory >& rxServiceMgr );
-
     // XContentProviderFactory
     virtual css::uno::Reference< css::ucb::XContentProvider > SAL_CALL
     createContentProvider( const OUString& Service ) override;
@@ -82,8 +79,8 @@ class UcbContentProviderProxy :
     bool        m_bReplace;
     bool        m_bRegister;
 
-    css::uno::Reference< css::lang::XMultiServiceFactory >
-                                m_xSMgr;
+    css::uno::Reference< css::uno::XComponentContext >
+                                m_xContext;
     css::uno::Reference< css::ucb::XContentProvider >
                                 m_xProvider;
     css::uno::Reference< css::ucb::XContentProvider >
@@ -91,7 +88,7 @@ class UcbContentProviderProxy :
 
 public:
     UcbContentProviderProxy(
-            const css::uno::Reference< css::lang::XMultiServiceFactory >& rxSMgr,
+            const css::uno::Reference< css::uno::XComponentContext >& rxContext,
             const OUString& Service );
     virtual ~UcbContentProviderProxy() override;
 
diff --git a/ucb/source/core/ucb.cxx b/ucb/source/core/ucb.cxx
index 7d4a307ca334..93a8db613bf8 100644
--- a/ucb/source/core/ucb.cxx
+++ b/ucb/source/core/ucb.cxx
@@ -42,6 +42,7 @@
 #include <ucbhelper/cancelcommandexecution.hxx>
 #include <ucbhelper/getcomponentcontext.hxx>
 #include <ucbhelper/macros.hxx>
+#include <rtl/ref.hxx>
 #include "identify.hxx"
 #include "ucbcmds.hxx"
 
@@ -55,6 +56,8 @@ using namespace ucb_impl;
 using namespace com::sun::star;
 using namespace ucbhelper;
 
+static osl::Mutex g_InstanceGuard;
+static rtl::Reference<UniversalContentBroker> g_Instance;
 
 namespace {
 
@@ -252,6 +255,9 @@ void SAL_CALL UniversalContentBroker::dispose()
 
     if ( m_xNotifier.is() )
         m_xNotifier->removeChangesListener( this );
+
+    osl::MutexGuard aGuard(g_InstanceGuard);
+    g_Instance.clear();
 }
 
 
@@ -279,38 +285,32 @@ void SAL_CALL UniversalContentBroker::removeEventListener(
 
 // XServiceInfo methods.
 
-XSERVICEINFO_COMMOM_IMPL( UniversalContentBroker,
-                          "com.sun.star.comp.ucb.UniversalContentBroker" )
-/// @throws css::uno::Exception
-static css::uno::Reference< css::uno::XInterface >
-UniversalContentBroker_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
+OUString SAL_CALL UniversalContentBroker::getImplementationName()
 {
-    css::lang::XServiceInfo* pX = new UniversalContentBroker( ucbhelper::getComponentContext(rSMgr) );
-    return css::uno::Reference< css::uno::XInterface >::query( pX );
+    return "com.sun.star.comp.ucb.UniversalContentBroker";
 }
-
-css::uno::Sequence< OUString >
-UniversalContentBroker::getSupportedServiceNames_Static()
+sal_Bool SAL_CALL UniversalContentBroker::supportsService( const OUString& ServiceName )
 {
-    css::uno::Sequence< OUString > aSNS { UCB_SERVICE_NAME };
-    return aSNS;
+    return cppu::supportsService( this, ServiceName );
+}
+css::uno::Sequence< OUString > SAL_CALL UniversalContentBroker::getSupportedServiceNames()
+{
+    return { "com.sun.star.ucb.UniversalContentBroker" };
 }
-
-// Service factory implementation.
 
 
-css::uno::Reference< css::lang::XSingleServiceFactory >
-UniversalContentBroker::createServiceFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& rxServiceMgr )
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+ucb_UniversalContentBroker_get_implementation(
+    css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
 {
-    return cppu::createOneInstanceFactory(
-                rxServiceMgr,
-                UniversalContentBroker::getImplementationName_Static(),
-                UniversalContentBroker_CreateInstance,
-                UniversalContentBroker::getSupportedServiceNames_Static() );
+    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());
 }
 
 
-
 // XInitialization methods.
 
 
diff --git a/ucb/source/core/ucb.hxx b/ucb/source/core/ucb.hxx
index fc478cb07dc0..cfc245ad863e 100644
--- a/ucb/source/core/ucb.hxx
+++ b/ucb/source/core/ucb.hxx
@@ -38,9 +38,6 @@
 #include <memory>
 
 
-#define UCB_SERVICE_NAME "com.sun.star.ucb.UniversalContentBroker"
-
-
 namespace comphelper { class OInterfaceContainerHelper2; }
 
 namespace com::sun::star::ucb {
@@ -64,13 +61,6 @@ public:
     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
 
-    static OUString getImplementationName_Static();
-    static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
-
-    static css::uno::Reference< css::lang::XSingleServiceFactory >
-    createServiceFactory( const css::uno::Reference<
-                          css::lang::XMultiServiceFactory >& rxServiceMgr );
-
     // XComponent
     virtual void SAL_CALL
     dispose() override;
diff --git a/ucb/source/core/ucb1.component b/ucb/source/core/ucb1.component
index 71dfa7046501..7cfb35264e11 100644
--- a/ucb/source/core/ucb1.component
+++ b/ucb/source/core/ucb1.component
@@ -18,23 +18,39 @@
  -->
 
 <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
-    prefix="ucb" xmlns="http://openoffice.org/2010/uno-components">
-  <implementation name="com.sun.star.comp.ucb.CommandEnvironment">
+    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"/>
     <service name="com.sun.star.ucb.CommandEnvironment"/>
   </implementation>
-  <implementation name="com.sun.star.comp.ucb.UcbContentProviderProxyFactory">
+  <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"/>
     <service name="com.sun.star.ucb.ContentProviderProxyFactory"/>
   </implementation>
-  <implementation name="com.sun.star.comp.ucb.UcbPropertiesManager">
+  <implementation name="com.sun.star.comp.ucb.UcbPropertiesManager"
+    constructor="ucb_UcbPropertiesManager_get_implementation">
     <service name="com.sun.star.ucb.PropertiesManager"/>
   </implementation>
-  <implementation name="com.sun.star.comp.ucb.UcbStore">
+  <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"/>
     <service name="com.sun.star.ucb.Store"/>
   </implementation>
-  <implementation name="com.sun.star.comp.ucb.UniversalContentBroker">
+  <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"/>
     <service name="com.sun.star.ucb.UniversalContentBroker"/>
   </implementation>
-  <implementation name="com.sun.star.comp.ucb.SimpleFileAccess">
+  <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 1a3863c44bde..19a42e653883 100644
--- a/ucb/source/core/ucbprops.cxx
+++ b/ucb/source/core/ucbprops.cxx
@@ -35,6 +35,7 @@
 #include <com/sun/star/ucb/VerificationMode.hpp>
 #include <com/sun/star/ucb/XDataContainer.hpp>
 #include <ucbhelper/macros.hxx>
+#include <rtl/ref.hxx>
 
 #include "ucbprops.hxx"
 
@@ -44,8 +45,12 @@ using namespace com::sun::star::uno;
 
 #define ATTR_DEFAULT ( PropertyAttribute::BOUND | PropertyAttribute::MAYBEVOID | PropertyAttribute::MAYBEDEFAULT )
 
+static osl::Mutex g_InstanceGuard;
+static rtl::Reference<UcbPropertiesManager> g_Instance;
+
 UcbPropertiesManager::UcbPropertiesManager()
-: m_pProps({
+: UcbPropertiesManager_Base(m_aMutex),
+  m_pProps({
     { "Account", -1, cppu::UnoType<OUString>::get(), ATTR_DEFAULT },
     { "AutoUpdateInterval", -1, cppu::UnoType<sal_Int32>::get(), ATTR_DEFAULT },
     { "ConfirmEmpty", -1, cppu::UnoType<bool>::get(), ATTR_DEFAULT },
@@ -192,38 +197,44 @@ UcbPropertiesManager::~UcbPropertiesManager()
 {
 }
 
+// XComponent
+void SAL_CALL UcbPropertiesManager::dispose()
+{
+    UcbPropertiesManager_Base::dispose();
+    osl::MutexGuard aGuard(g_InstanceGuard);
+    g_Instance.clear();
+}
 
 // XServiceInfo methods.
 
-XSERVICEINFO_COMMOM_IMPL( UcbPropertiesManager,
-                          "com.sun.star.comp.ucb.UcbPropertiesManager" )
-/// @throws css::uno::Exception
-static css::uno::Reference< css::uno::XInterface >
-UcbPropertiesManager_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & /*rSMgr*/ )
+OUString SAL_CALL UcbPropertiesManager::getImplementationName()
+{
+    return "com.sun.star.comp.ucb.UcbPropertiesManager";
+}
+sal_Bool SAL_CALL UcbPropertiesManager::supportsService( const OUString& ServiceName )
 {
-    return static_cast<css::lang::XServiceInfo*>(new UcbPropertiesManager);
+    return cppu::supportsService( this, ServiceName );
 }
-css::uno::Sequence< OUString >
-UcbPropertiesManager::getSupportedServiceNames_Static()
+css::uno::Sequence< OUString > SAL_CALL UcbPropertiesManager::getSupportedServiceNames()
 {
-    return { PROPERTIES_MANAGER_SERVICE_NAME };
+    return { "com.sun.star.ucb.PropertiesManager" };
 }
 
-// Service factory implementation.
 
 
-css::uno::Reference< css::lang::XSingleServiceFactory >
-UcbPropertiesManager::createServiceFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& rxServiceMgr )
+// Service factory implementation.
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+ucb_UcbPropertiesManager_get_implementation(
+    css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
 {
-    return cppu::createOneInstanceFactory(
-                rxServiceMgr,
-                UcbPropertiesManager::getImplementationName_Static(),
-                UcbPropertiesManager_CreateInstance,
-                UcbPropertiesManager::getSupportedServiceNames_Static() );
+    osl::MutexGuard aGuard(g_InstanceGuard);
+    if (!g_Instance)
+        g_Instance.set(new UcbPropertiesManager());
+    g_Instance->acquire();
+    return static_cast<cppu::OWeakObject*>(g_Instance.get());
 }
 
-
-
 // XPropertySetInfo methods.
 
 
diff --git a/ucb/source/core/ucbprops.hxx b/ucb/source/core/ucbprops.hxx
index 6de20ec52b87..6ef4e5a5bfcb 100644
--- a/ucb/source/core/ucbprops.hxx
+++ b/ucb/source/core/ucbprops.hxx
@@ -24,17 +24,15 @@
 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/beans/XPropertySetInfo.hpp>
-#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/compbase.hxx>
+#include <cppuhelper/basemutex.hxx>
 
 
-#define PROPERTIES_MANAGER_SERVICE_NAME "com.sun.star.ucb.PropertiesManager"
+using UcbPropertiesManager_Base = cppu::WeakComponentImplHelper <
+                                        css::lang::XServiceInfo,
+                                        css::beans::XPropertySetInfo >;
 
-
-
-
-class UcbPropertiesManager : public cppu::WeakImplHelper <
-    css::lang::XServiceInfo,
-    css::beans::XPropertySetInfo >
+class UcbPropertiesManager : public cppu::BaseMutex, public UcbPropertiesManager_Base
 {
     css::uno::Sequence< css::beans::Property > m_pProps;
 
@@ -46,18 +44,14 @@ public:
     explicit UcbPropertiesManager();
     virtual ~UcbPropertiesManager() 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;
     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
 
-    static OUString getImplementationName_Static();
-    static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
-
-    static css::uno::Reference< css::lang::XSingleServiceFactory >
-    createServiceFactory( const css::uno::Reference<
-                          css::lang::XMultiServiceFactory >& rxServiceMgr );
-
     // XPropertySetInfo
     virtual css::uno::Sequence< css::beans::Property > SAL_CALL
     getProperties() override;
diff --git a/ucb/source/core/ucbserv.cxx b/ucb/source/core/ucbserv.cxx
deleted file mode 100644
index ad9003f26945..000000000000
--- a/ucb/source/core/ucbserv.cxx
+++ /dev/null
@@ -1,111 +0,0 @@
-/* -*- 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 <com/sun/star/lang/XMultiServiceFactory.hpp>
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
-#include <cppuhelper/factory.hxx>
-#include "ucb.hxx"
-#include "ucbstore.hxx"
-#include "ucbprops.hxx"
-#include "provprox.hxx"
-#include "cmdenv.hxx"
-#include "FileAccess.hxx"
-
-using namespace com::sun::star::uno;
-using namespace com::sun::star::lang;
-
-
-extern "C" SAL_DLLPUBLIC_EXPORT void * ucb_component_getFactory(
-    const char * pImplName, void * pServiceManager, void * )
-{
-    void * pRet = nullptr;
-
-    Reference< XMultiServiceFactory > xSMgr(
-            static_cast< XMultiServiceFactory * >( pServiceManager ) );
-    Reference< XSingleServiceFactory > xFactory;
-
-
-    // Universal Content Broker.
-
-
-    if ( UniversalContentBroker::getImplementationName_Static().
-                equalsAscii( pImplName ) )
-    {
-        xFactory = UniversalContentBroker::createServiceFactory( xSMgr );
-    }
-
-
-    // UCB Store.
-
-
-    else if ( UcbStore::getImplementationName_Static().
-                equalsAscii( pImplName ) )
-    {
-        xFactory = UcbStore::createServiceFactory( xSMgr );
-    }
-
-
-    // UCB PropertiesManager.
-
-
-    else if ( UcbPropertiesManager::getImplementationName_Static().
-                equalsAscii( pImplName ) )
-    {
-        xFactory = UcbPropertiesManager::createServiceFactory( xSMgr );
-    }
-
-
-    // UCP Proxy Factory.
-
-
-    else if ( UcbContentProviderProxyFactory::getImplementationName_Static().
-                equalsAscii( pImplName ) )
-    {
-        xFactory = UcbContentProviderProxyFactory::createServiceFactory( xSMgr );
-    }
-
-
-    // Command Environment.
-
-
-    else if ( ucb_cmdenv::UcbCommandEnvironment::getImplementationName_Static().
-                equalsAscii( pImplName ) )
-    {
-        xFactory = ucb_cmdenv::UcbCommandEnvironment::createServiceFactory( xSMgr );
-    }
-
-    // FilePicker
-    else if (pServiceManager && rtl_str_compare( pImplName, IMPLEMENTATION_NAME ) == 0)
-    {
-        xFactory = cppu::createSingleFactory(xSMgr,
-                                             OUString::createFromAscii( pImplName ),
-                                             FileAccess_CreateInstance,
-                                             FileAccess_getSupportedServiceNames() );
-    }
-
-    if ( xFactory.is() )
-    {
-        xFactory->acquire();
-        pRet = xFactory.get();
-    }
-
-    return pRet;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/ucb/source/core/ucbstore.cxx b/ucb/source/core/ucbstore.cxx
index 8720f3da10f6..5dbc1e3557be 100644
--- a/ucb/source/core/ucbstore.cxx
+++ b/ucb/source/core/ucbstore.cxx
@@ -60,6 +60,8 @@ 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  )
 {
@@ -147,7 +149,8 @@ struct UcbStore_Impl
 
 
 UcbStore::UcbStore( const Reference< XComponentContext >& xContext )
-: m_xContext( xContext ),
+: UcbStore_Base(m_aMutex),
+  m_xContext( xContext ),
   m_pImpl( new UcbStore_Impl )
 {
 }
@@ -158,38 +161,41 @@ UcbStore::~UcbStore()
 {
 }
 
-XSERVICEINFO_COMMOM_IMPL( UcbStore,
-                          "com.sun.star.comp.ucb.UcbStore" )
-/// @throws css::uno::Exception
-static css::uno::Reference< css::uno::XInterface >
-UcbStore_CreateInstance( const css::uno::Reference< css::lang::XMultiServiceFactory> & rSMgr )
+// XComponent
+void SAL_CALL UcbStore::dispose()
 {
-    return static_cast<css::lang::XServiceInfo*>(
-        new UcbStore(ucbhelper::getComponentContext(rSMgr)));
+    UcbStore_Base::dispose();
+    osl::MutexGuard aGuard(g_InstanceGuard);
+    g_Instance.clear();
 }
 
-css::uno::Sequence< OUString >
-UcbStore::getSupportedServiceNames_Static()
+OUString SAL_CALL UcbStore::getImplementationName()
+{
+    return "com.sun.star.comp.ucb.UcbStore";
+}
+sal_Bool SAL_CALL UcbStore::supportsService( const OUString& ServiceName )
+{
+    return cppu::supportsService( this, ServiceName );
+}
+css::uno::Sequence< OUString > SAL_CALL UcbStore::getSupportedServiceNames()
 {
-    css::uno::Sequence< OUString > aSNS { STORE_SERVICE_NAME };
-    return aSNS;
+    return { "com.sun.star.ucb.Store" };
 }
 
 // Service factory implementation.
 
-
-css::uno::Reference< css::lang::XSingleServiceFactory >
-UcbStore::createServiceFactory( const css::uno::Reference< css::lang::XMultiServiceFactory >& rxServiceMgr )
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+ucb_UcbStore_get_implementation(
+    css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
 {
-    return cppu::createOneInstanceFactory(
-                rxServiceMgr,
-                UcbStore::getImplementationName_Static(),
-                UcbStore_CreateInstance,
-                UcbStore::getSupportedServiceNames_Static() );
+    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());
 }
 
 
-
 // XPropertySetRegistryFactory methods.
 
 
@@ -278,7 +284,7 @@ sal_Bool SAL_CALL PropertySetRegistry::supportsService( const OUString& ServiceN
 
 css::uno::Sequence< OUString > SAL_CALL PropertySetRegistry::getSupportedServiceNames()
 {
-    return { PROPSET_REG_SERVICE_NAME };
+    return {  "com.sun.star.ucb.PropertySetRegistry" };
 }
 
 
@@ -1111,10 +1117,9 @@ sal_Bool SAL_CALL PersistentPropertySet::supportsService( const OUString& Servic
     return cppu::supportsService( this, ServiceName );
 }
 
-css::uno::Sequence< OUString > SAL_CALL
-PersistentPropertySet::getSupportedServiceNames()
+css::uno::Sequence< OUString > SAL_CALL PersistentPropertySet::getSupportedServiceNames()
 {
-    return { PERS_PROPSET_SERVICE_NAME };
+    return { "com.sun.star.ucb.PersistentPropertySet" };
 }
 
 
diff --git a/ucb/source/core/ucbstore.hxx b/ucb/source/core/ucbstore.hxx
index 6fb87e274327..3c0cdef87649 100644
--- a/ucb/source/core/ucbstore.hxx
+++ b/ucb/source/core/ucbstore.hxx
@@ -34,21 +34,19 @@
 #include <com/sun/star/beans/XPropertyAccess.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 #include <com/sun/star/lang/XInitialization.hpp>
-#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/compbase.hxx>
+#include <cppuhelper/basemutex.hxx>
 #include <memory>
 
 
-#define STORE_SERVICE_NAME          "com.sun.star.ucb.Store"
-#define PROPSET_REG_SERVICE_NAME    "com.sun.star.ucb.PropertySetRegistry"
-#define PERS_PROPSET_SERVICE_NAME   "com.sun.star.ucb.PersistentPropertySet"
-
-
 struct UcbStore_Impl;
 
-class UcbStore : public cppu::WeakImplHelper <
-    css::lang::XServiceInfo,
-    css::ucb::XPropertySetRegistryFactory,
-    css::lang::XInitialization >
+using UcbStore_Base = cppu::WeakComponentImplHelper <
+                        css::lang::XServiceInfo,
+                        css::ucb::XPropertySetRegistryFactory,
+                        css::lang::XInitialization >;
+
+class UcbStore : public cppu::BaseMutex, public UcbStore_Base
 {
     css::uno::Reference< css::uno::XComponentContext > m_xContext;
     std::unique_ptr<UcbStore_Impl> m_pImpl;
@@ -57,18 +55,14 @@ 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;
     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
 
-    static OUString getImplementationName_Static();
-    static css::uno::Sequence< OUString > getSupportedServiceNames_Static();
-
-    static css::uno::Reference< css::lang::XSingleServiceFactory >
-    createServiceFactory( const css::uno::Reference<
-                          css::lang::XMultiServiceFactory >& rxServiceMgr );
-
     // XPropertySetRegistryFactory
     virtual css::uno::Reference< css::ucb::XPropertySetRegistry > SAL_CALL
     createPropertySetRegistry( const OUString& URL ) override;


More information about the Libreoffice-commits mailing list