[Libreoffice-commits] core.git: connectivity/Library_sdbc2.mk connectivity/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 1 11:15:07 UTC 2020


 connectivity/Library_sdbc2.mk                  |    1 
 connectivity/source/manager/mdrivermanager.cxx |   59 +++++++++++++-----------
 connectivity/source/manager/mdrivermanager.hxx |   22 +++------
 connectivity/source/manager/mregistration.cxx  |   61 -------------------------
 connectivity/source/manager/sdbc2.component    |    7 ++
 5 files changed, 45 insertions(+), 105 deletions(-)

New commits:
commit e01f3e8b49843e6ff69fdc83c3b576ba91e992c1
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jul 9 12:05:27 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Sat Aug 1 13:14:25 2020 +0200

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

diff --git a/connectivity/Library_sdbc2.mk b/connectivity/Library_sdbc2.mk
index 494dc4208a09..5685d1af1de1 100644
--- a/connectivity/Library_sdbc2.mk
+++ b/connectivity/Library_sdbc2.mk
@@ -33,7 +33,6 @@ $(eval $(call gb_Library_use_libraries,sdbc2,\
 
 $(eval $(call gb_Library_add_exception_objects,sdbc2,\
 	connectivity/source/manager/mdrivermanager \
-	connectivity/source/manager/mregistration \
 ))
 
 # vim: set noet sw=4 ts=4:
diff --git a/connectivity/source/manager/mdrivermanager.cxx b/connectivity/source/manager/mdrivermanager.cxx
index 3f66e0606baa..fba247ffab1c 100644
--- a/connectivity/source/manager/mdrivermanager.cxx
+++ b/connectivity/source/manager/mdrivermanager.cxx
@@ -31,11 +31,16 @@
 #include <cppuhelper/implbase.hxx>
 #include <cppuhelper/supportsservice.hxx>
 #include <osl/diagnose.h>
+#include <rtl/ref.hxx>
 
 #include <algorithm>
 #include <iterator>
 #include <vector>
 
+static osl::Mutex g_InstanceGuard;
+static rtl::Reference<drivermanager::OSDBCDriverManager> g_Instance;
+static bool g_Disposed = false;
+
 namespace drivermanager
 {
 
@@ -237,7 +242,8 @@ Any SAL_CALL ODriverEnumeration::nextElement(  )
     }
 
 OSDBCDriverManager::OSDBCDriverManager( const Reference< XComponentContext >& _rxContext )
-    :m_xContext( _rxContext )
+    :OSDBCDriverManager_Base(m_aMutex)
+    ,m_xContext( _rxContext )
     ,m_aEventLogger( _rxContext, "org.openoffice.logging.sdbc.DriverManager" )
     ,m_aDriverConfig(m_xContext)
     ,m_nLoginTimeout(0)
@@ -254,6 +260,15 @@ OSDBCDriverManager::~OSDBCDriverManager()
 {
 }
 
+// XComponent
+void SAL_CALL OSDBCDriverManager::dispose()
+{
+    OSDBCDriverManager_Base::dispose();
+    osl::MutexGuard aGuard(g_InstanceGuard);
+    g_Instance.clear();
+    g_Disposed = true;
+}
+
 void OSDBCDriverManager::bootstrapDrivers()
 {
     Reference< XContentEnumerationAccess > xEnumAccess( m_xContext->getServiceManager(), UNO_QUERY );
@@ -507,7 +522,7 @@ sal_Bool SAL_CALL OSDBCDriverManager::hasElements(  )
 
 OUString SAL_CALL OSDBCDriverManager::getImplementationName(  )
 {
-    return getImplementationName_static();
+    return "com.sun.star.comp.sdbc.OSDBCDriverManager";
 }
 
 sal_Bool SAL_CALL OSDBCDriverManager::supportsService( const OUString& _rServiceName )
@@ -518,31 +533,7 @@ sal_Bool SAL_CALL OSDBCDriverManager::supportsService( const OUString& _rService
 
 Sequence< OUString > SAL_CALL OSDBCDriverManager::getSupportedServiceNames(  )
 {
-    return getSupportedServiceNames_static();
-}
-
-
-Reference< XInterface > OSDBCDriverManager::Create( const Reference< XMultiServiceFactory >& _rxFactory )
-{
-    return *( new OSDBCDriverManager( comphelper::getComponentContext(_rxFactory) ) );
-}
-
-
-OUString OSDBCDriverManager::getImplementationName_static(  )
-{
-    return "com.sun.star.comp.sdbc.OSDBCDriverManager";
-}
-
-
-Sequence< OUString > OSDBCDriverManager::getSupportedServiceNames_static(  )
-{
-    return { getSingletonName_static() };
-}
-
-
-OUString OSDBCDriverManager::getSingletonName_static(  )
-{
-    return "com.sun.star.sdbc.DriverManager";
+    return { "com.sun.star.sdbc.DriverManager" };
 }
 
 
@@ -677,4 +668,18 @@ Reference< XDriver > OSDBCDriverManager::implGetDriverForURL(const OUString& _rU
 
 }   // namespace drivermanager
 
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
+connectivity_OSDBCDriverManager_get_implementation(
+    css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
+{
+    osl::MutexGuard aGuard(g_InstanceGuard);
+    if (g_Disposed)
+        return nullptr;
+    if (!g_Instance)
+        g_Instance.set(new drivermanager::OSDBCDriverManager(context));
+    g_Instance->acquire();
+    return static_cast<cppu::OWeakObject*>(g_Instance.get());
+}
+
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/manager/mdrivermanager.hxx b/connectivity/source/manager/mdrivermanager.hxx
index 21e7bb5df7ac..20fc0a72df7b 100644
--- a/connectivity/source/manager/mdrivermanager.hxx
+++ b/connectivity/source/manager/mdrivermanager.hxx
@@ -31,7 +31,8 @@
 #include <com/sun/star/lang/XServiceInfo.hpp>
 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
 
-#include <cppuhelper/implbase.hxx>
+#include <cppuhelper/basemutex.hxx>
+#include <cppuhelper/compbase.hxx>
 #include <comphelper/logging.hxx>
 #include <osl/mutex.hxx>
 #include <connectivity/DriversConfig.hxx>
@@ -51,16 +52,15 @@ namespace drivermanager
 
     // OSDBCDriverManager - the one-instance service for managing SDBC drivers
 
-    typedef ::cppu::WeakImplHelper<   css::sdbc::XDriverManager2
+    typedef ::cppu::WeakComponentImplHelper<   css::sdbc::XDriverManager2
                                   ,   css::lang::XServiceInfo
                                   ,   css::uno::XNamingService
                                   >   OSDBCDriverManager_Base;
 
-    class OSDBCDriverManager final : public OSDBCDriverManager_Base
+    class OSDBCDriverManager final : public cppu::BaseMutex, public OSDBCDriverManager_Base
     {
         friend class ODriverEnumeration;
 
-        ::osl::Mutex                    m_aMutex;
         css::uno::Reference<css::uno::XComponentContext>  m_xContext;
         ::comphelper::EventLogger       m_aEventLogger;
 
@@ -75,11 +75,14 @@ namespace drivermanager
         ::connectivity::DriversConfig   m_aDriverConfig;
         sal_Int32                       m_nLoginTimeout;
 
+    public:
+
         explicit OSDBCDriverManager(
             const css::uno::Reference< css::uno::XComponentContext >& _rxContext );
         virtual ~OSDBCDriverManager() override;
 
-    public:
+    // XComponent
+        virtual void SAL_CALL dispose() override;
 
     // XDriverManager
         virtual css::uno::Reference< css::sdbc::XConnection > SAL_CALL getConnection( const OUString& url ) override;
@@ -102,15 +105,6 @@ namespace drivermanager
         virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
         virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) override;
 
-    // XServiceInfo - static methods
-        /// @throws css::uno::RuntimeException
-        static OUString getImplementationName_static(  );
-        /// @throws css::uno::RuntimeException
-        static css::uno::Sequence< OUString > getSupportedServiceNames_static(  );
-        /// @throws css::uno::RuntimeException
-        static OUString getSingletonName_static(  );
-        static css::uno::Reference< css::uno::XInterface > Create( const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxContext );
-
     // XNamingService
         virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getRegisteredObject( const OUString& Name ) override;
         virtual void SAL_CALL registerObject( const OUString& Name, const css::uno::Reference< css::uno::XInterface >& Object ) override;
diff --git a/connectivity/source/manager/mregistration.cxx b/connectivity/source/manager/mregistration.cxx
deleted file mode 100644
index c78d3ec6d786..000000000000
--- a/connectivity/source/manager/mregistration.cxx
+++ /dev/null
@@ -1,61 +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 "mdrivermanager.hxx"
-
-#include <cppuhelper/factory.hxx>
-#include <com/sun/star/lang/XSingleServiceFactory.hpp>
-
-using namespace ::com::sun::star::uno;
-using namespace ::com::sun::star::lang;
-
-extern "C"
-{
-
-
-SAL_DLLPUBLIC_EXPORT void* sdbc2_component_getFactory(const char* _pImplName, void * _pServiceManager, void* /*_pRegistryKey*/)
-{
-    void* pRet = nullptr;
-
-    if (::drivermanager::OSDBCDriverManager::getImplementationName_static().equalsAscii(_pImplName))
-    {
-        Reference< XSingleServiceFactory > xFactory(
-            ::cppu::createOneInstanceFactory(
-                static_cast<css::lang::XMultiServiceFactory *>(
-                    _pServiceManager),
-                ::drivermanager::OSDBCDriverManager::getImplementationName_static(),
-                ::drivermanager::OSDBCDriverManager::Create,
-                ::drivermanager::OSDBCDriverManager::getSupportedServiceNames_static()
-            )
-        );
-        if (xFactory.is())
-        {
-            xFactory->acquire();
-            pRet = xFactory.get();
-        }
-    }
-
-    return pRet;
-}
-
-}   // extern "C"
-
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/manager/sdbc2.component b/connectivity/source/manager/sdbc2.component
index b192bebad89d..8797ec80a27c 100644
--- a/connectivity/source/manager/sdbc2.component
+++ b/connectivity/source/manager/sdbc2.component
@@ -18,8 +18,11 @@
  -->
 
 <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@"
-    prefix="sdbc2" xmlns="http://openoffice.org/2010/uno-components">
-  <implementation name="com.sun.star.comp.sdbc.OSDBCDriverManager">
+    xmlns="http://openoffice.org/2010/uno-components">
+  <implementation name="com.sun.star.comp.sdbc.OSDBCDriverManager"
+    constructor="connectivity_OSDBCDriverManager_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.sdbc.theOSDBCDriverManager"/>
     <service name="com.sun.star.sdbc.DriverManager"/>
   </implementation>
 </component>


More information about the Libreoffice-commits mailing list