From 255d96a3e1f4e77ed6444a21c1c9c24b3dc9d194 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Sat, 11 Jul 2020 18:57:16 +0200 Subject: connectivity: create instances with uno constructors See tdf#74608 for motivation. Change-Id: Id678e4c51459429dd3953c0e54558d2c36e85eee Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98562 Tested-by: Jenkins Reviewed-by: Noel Grandin --- connectivity/source/drivers/calc/CDriver.cxx | 27 +++--- connectivity/source/drivers/calc/Cservices.cxx | 106 --------------------- connectivity/source/drivers/calc/calc.component | 4 +- connectivity/source/drivers/dbase/DDriver.cxx | 22 +++-- connectivity/source/drivers/dbase/Dservices.cxx | 106 --------------------- connectivity/source/drivers/dbase/dbase.component | 5 +- connectivity/source/drivers/file/FDriver.cxx | 17 +--- connectivity/source/drivers/flat/EDriver.cxx | 23 +++-- connectivity/source/drivers/flat/Eservices.cxx | 106 --------------------- connectivity/source/drivers/flat/flat.component | 5 +- connectivity/source/drivers/writer/WDriver.cxx | 24 +++-- connectivity/source/drivers/writer/Wservices.cxx | 90 ----------------- .../source/drivers/writer/writer.component | 4 +- 13 files changed, 72 insertions(+), 467 deletions(-) delete mode 100644 connectivity/source/drivers/calc/Cservices.cxx delete mode 100644 connectivity/source/drivers/dbase/Dservices.cxx delete mode 100644 connectivity/source/drivers/flat/Eservices.cxx delete mode 100644 connectivity/source/drivers/writer/Wservices.cxx (limited to 'connectivity/source/drivers') diff --git a/connectivity/source/drivers/calc/CDriver.cxx b/connectivity/source/drivers/calc/CDriver.cxx index 3b53ebccd0b8..5a59515bb2d6 100644 --- a/connectivity/source/drivers/calc/CDriver.cxx +++ b/connectivity/source/drivers/calc/CDriver.cxx @@ -34,28 +34,31 @@ using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::lang; -// static ServiceInfo - -OUString ODriver::getImplementationName_Static( ) -{ - return "com.sun.star.comp.sdbc.calc.ODriver"; -} +// ServiceInfo OUString SAL_CALL ODriver::getImplementationName( ) { - return getImplementationName_Static(); + return "com.sun.star.comp.sdbc.calc.ODriver"; } // service names from file::OFileDriver - -css::uno::Reference< css::uno::XInterface > - connectivity::calc::ODriver_CreateInstance(const css::uno::Reference< - css::lang::XMultiServiceFactory >& _rxFactory) +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_calc_ODriver( + css::uno::XComponentContext* context, css::uno::Sequence const&) { - return *(new ODriver( comphelper::getComponentContext(_rxFactory) )); + rtl::Reference ret; + try { + ret = new ODriver(context); + } catch (...) { + } + if (ret) + ret->acquire(); + return static_cast(ret.get()); } + + Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) { diff --git a/connectivity/source/drivers/calc/Cservices.cxx b/connectivity/source/drivers/calc/Cservices.cxx deleted file mode 100644 index 06a516ddc119..000000000000 --- a/connectivity/source/drivers/calc/Cservices.cxx +++ /dev/null @@ -1,106 +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 -#include -#include - -using namespace connectivity::calc; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::lang::XSingleServiceFactory; -using ::com::sun::star::lang::XMultiServiceFactory; - -typedef Reference< XSingleServiceFactory > (*createFactoryFunc) - ( - const Reference< XMultiServiceFactory > & rServiceManager, - const OUString & rComponentName, - ::cppu::ComponentInstantiation pCreateFunction, - const Sequence< OUString > & rServiceNames, - rtl_ModuleCount* - ); - -namespace { - -struct ProviderRequest -{ - Reference< XSingleServiceFactory > xRet; - Reference< XMultiServiceFactory > const xServiceManager; - OUString const sImplementationName; - - ProviderRequest( - void* pServiceManager, - char const* pImplementationName - ) - : xServiceManager(static_cast(pServiceManager)) - , sImplementationName(OUString::createFromAscii(pImplementationName)) - { - } - - bool CREATE_PROVIDER( - const OUString& Implname, - const Sequence< OUString > & Services, - ::cppu::ComponentInstantiation Factory, - createFactoryFunc creator - ) - { - if (!xRet.is() && (Implname == sImplementationName)) - { - try - { - xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr); - } - catch(...) - { - } - } - return xRet.is(); - } - - void* getProvider() const { return xRet.get(); } -}; - -} - -extern "C" SAL_DLLPUBLIC_EXPORT void* connectivity_calc_component_getFactory( - const char* pImplementationName, - void* pServiceManager, - void* /*pRegistryKey*/) -{ - void* pRet = nullptr; - if (pServiceManager) - { - ProviderRequest aReq(pServiceManager,pImplementationName); - - aReq.CREATE_PROVIDER( - ODriver::getImplementationName_Static(), - ODriver::getSupportedServiceNames_Static(), - ODriver_CreateInstance, ::cppu::createSingleFactory) - ; - - if(aReq.xRet.is()) - aReq.xRet->acquire(); - - pRet = aReq.getProvider(); - } - - return pRet; -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/calc/calc.component b/connectivity/source/drivers/calc/calc.component index ffbddfa34c6d..a4fc7d8f119f 100644 --- a/connectivity/source/drivers/calc/calc.component +++ b/connectivity/source/drivers/calc/calc.component @@ -18,9 +18,9 @@ --> - + diff --git a/connectivity/source/drivers/dbase/DDriver.cxx b/connectivity/source/drivers/dbase/DDriver.cxx index ab2d52413e06..6d3af175241b 100644 --- a/connectivity/source/drivers/dbase/DDriver.cxx +++ b/connectivity/source/drivers/dbase/DDriver.cxx @@ -33,25 +33,29 @@ using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::lang; -// static ServiceInfo +// XServiceInfo -OUString ODriver::getImplementationName_Static( ) +OUString SAL_CALL ODriver::getImplementationName( ) { return "com.sun.star.comp.sdbc.dbase.ODriver"; } -OUString SAL_CALL ODriver::getImplementationName( ) +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_dbase_ODriver( + css::uno::XComponentContext* context, css::uno::Sequence const&) { - return getImplementationName_Static(); + rtl::Reference ret; + try { + ret = new ODriver(context); + } catch (...) { + } + if (ret) + ret->acquire(); + return static_cast(ret.get()); } -css::uno::Reference< css::uno::XInterface > connectivity::dbase::ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory) -{ - return *(new ODriver( comphelper::getComponentContext(_rxFactory) )); -} - Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) { ::osl::MutexGuard aGuard( m_aMutex ); diff --git a/connectivity/source/drivers/dbase/Dservices.cxx b/connectivity/source/drivers/dbase/Dservices.cxx deleted file mode 100644 index e2d09d6c0478..000000000000 --- a/connectivity/source/drivers/dbase/Dservices.cxx +++ /dev/null @@ -1,106 +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 -#include -#include - -using namespace connectivity::dbase; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::lang::XSingleServiceFactory; -using ::com::sun::star::lang::XMultiServiceFactory; - -typedef Reference< XSingleServiceFactory > (*createFactoryFunc) - ( - const Reference< XMultiServiceFactory > & rServiceManager, - const OUString & rComponentName, - ::cppu::ComponentInstantiation pCreateFunction, - const Sequence< OUString > & rServiceNames, - rtl_ModuleCount* - ); - -namespace { - -struct ProviderRequest -{ - Reference< XSingleServiceFactory > xRet; - Reference< XMultiServiceFactory > const xServiceManager; - OUString const sImplementationName; - - ProviderRequest( - void* pServiceManager, - char const* pImplementationName - ) - : xServiceManager(static_cast(pServiceManager)) - , sImplementationName(OUString::createFromAscii(pImplementationName)) - { - } - - bool CREATE_PROVIDER( - const OUString& Implname, - const Sequence< OUString > & Services, - ::cppu::ComponentInstantiation Factory, - createFactoryFunc creator - ) - { - if (!xRet.is() && (Implname == sImplementationName)) - { - try - { - xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr); - } - catch(...) - { - } - } - return xRet.is(); - } - - void* getProvider() const { return xRet.get(); } -}; - -} - -extern "C" SAL_DLLPUBLIC_EXPORT void* dbase_component_getFactory( - const char* pImplementationName, - void* pServiceManager, - void* /*pRegistryKey*/) -{ - void* pRet = nullptr; - if (pServiceManager) - { - ProviderRequest aReq(pServiceManager,pImplementationName); - - aReq.CREATE_PROVIDER( - ODriver::getImplementationName_Static(), - ODriver::getSupportedServiceNames_Static(), - ODriver_CreateInstance, ::cppu::createSingleFactory) - ; - - if(aReq.xRet.is()) - aReq.xRet->acquire(); - - pRet = aReq.getProvider(); - } - - return pRet; -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/dbase/dbase.component b/connectivity/source/drivers/dbase/dbase.component index 3f2cea66b783..b078a765d80c 100644 --- a/connectivity/source/drivers/dbase/dbase.component +++ b/connectivity/source/drivers/dbase/dbase.component @@ -18,8 +18,9 @@ --> - + xmlns="http://openoffice.org/2010/uno-components"> + diff --git a/connectivity/source/drivers/file/FDriver.cxx b/connectivity/source/drivers/file/FDriver.cxx index c2956adc279b..16cf60e02cb4 100644 --- a/connectivity/source/drivers/file/FDriver.cxx +++ b/connectivity/source/drivers/file/FDriver.cxx @@ -57,22 +57,11 @@ void OFileDriver::disposing() ODriver_BASE::disposing(); } -// static ServiceInfo - -OUString OFileDriver::getImplementationName_Static( ) -{ - return "com.sun.star.sdbc.driver.file.Driver"; -} - -Sequence< OUString > OFileDriver::getSupportedServiceNames_Static( ) -{ - return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" }; -} - +// XServiceInfo OUString SAL_CALL OFileDriver::getImplementationName( ) { - return getImplementationName_Static(); + return "com.sun.star.sdbc.driver.file.Driver"; } sal_Bool SAL_CALL OFileDriver::supportsService( const OUString& _rServiceName ) @@ -83,7 +72,7 @@ sal_Bool SAL_CALL OFileDriver::supportsService( const OUString& _rServiceName ) Sequence< OUString > SAL_CALL OFileDriver::getSupportedServiceNames( ) { - return getSupportedServiceNames_Static(); + return { "com.sun.star.sdbc.Driver", "com.sun.star.sdbcx.Driver" }; } diff --git a/connectivity/source/drivers/flat/EDriver.cxx b/connectivity/source/drivers/flat/EDriver.cxx index e10f29da7f6d..0e1767870859 100644 --- a/connectivity/source/drivers/flat/EDriver.cxx +++ b/connectivity/source/drivers/flat/EDriver.cxx @@ -36,23 +36,26 @@ using namespace css::sdbc; using namespace css::lang; -// static ServiceInfo - -OUString ODriver::getImplementationName_Static( ) -{ - return "com.sun.star.comp.sdbc.flat.ODriver"; -} - +// XServiceInfo OUString SAL_CALL ODriver::getImplementationName( ) { - return getImplementationName_Static(); + return "com.sun.star.comp.sdbc.flat.ODriver"; } -css::uno::Reference< css::uno::XInterface > connectivity::flat::ODriver_CreateInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& _rxFactory) +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_flat_ODriver( + css::uno::XComponentContext* context, css::uno::Sequence const&) { - return *(new ODriver( comphelper::getComponentContext(_rxFactory) )); + rtl::Reference ret; + try { + ret = new ODriver(context); + } catch (...) { + } + if (ret) + ret->acquire(); + return static_cast(ret.get()); } Reference< XConnection > SAL_CALL ODriver::connect( const OUString& url, const Sequence< PropertyValue >& info ) diff --git a/connectivity/source/drivers/flat/Eservices.cxx b/connectivity/source/drivers/flat/Eservices.cxx deleted file mode 100644 index e74db8791843..000000000000 --- a/connectivity/source/drivers/flat/Eservices.cxx +++ /dev/null @@ -1,106 +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 -#include -#include - -using namespace connectivity::flat; -using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::Sequence; -using ::com::sun::star::lang::XSingleServiceFactory; -using ::com::sun::star::lang::XMultiServiceFactory; - -typedef Reference< XSingleServiceFactory > (*createFactoryFunc) - ( - const Reference< XMultiServiceFactory > & rServiceManager, - const OUString & rComponentName, - ::cppu::ComponentInstantiation pCreateFunction, - const Sequence< OUString > & rServiceNames, - rtl_ModuleCount* - ); - -namespace { - -struct ProviderRequest -{ - Reference< XSingleServiceFactory > xRet; - Reference< XMultiServiceFactory > const xServiceManager; - OUString const sImplementationName; - - ProviderRequest( - void* pServiceManager, - char const* pImplementationName - ) - : xServiceManager(static_cast(pServiceManager)) - , sImplementationName(OUString::createFromAscii(pImplementationName)) - { - } - - bool CREATE_PROVIDER( - const OUString& Implname, - const Sequence< OUString > & Services, - ::cppu::ComponentInstantiation Factory, - createFactoryFunc creator - ) - { - if (!xRet.is() && (Implname == sImplementationName)) - { - try - { - xRet = creator( xServiceManager, sImplementationName,Factory, Services,nullptr); - } - catch(...) - { - } - } - return xRet.is(); - } - - void* getProvider() const { return xRet.get(); } -}; - -} - -extern "C" SAL_DLLPUBLIC_EXPORT void* flat_component_getFactory( - const char* pImplementationName, - void* pServiceManager, - void* /*pRegistryKey*/) -{ - void* pRet = nullptr; - if (pServiceManager) - { - ProviderRequest aReq(pServiceManager,pImplementationName); - - aReq.CREATE_PROVIDER( - ODriver::getImplementationName_Static(), - ODriver::getSupportedServiceNames_Static(), - ODriver_CreateInstance, ::cppu::createSingleFactory) - ; - - if(aReq.xRet.is()) - aReq.xRet->acquire(); - - pRet = aReq.getProvider(); - } - - return pRet; -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/flat/flat.component b/connectivity/source/drivers/flat/flat.component index 6fa7fb8e6262..715fbecd89dc 100644 --- a/connectivity/source/drivers/flat/flat.component +++ b/connectivity/source/drivers/flat/flat.component @@ -18,8 +18,9 @@ --> - + xmlns="http://openoffice.org/2010/uno-components"> + diff --git a/connectivity/source/drivers/writer/WDriver.cxx b/connectivity/source/drivers/writer/WDriver.cxx index 63dc1f3f483d..3d30c00fb571 100644 --- a/connectivity/source/drivers/writer/WDriver.cxx +++ b/connectivity/source/drivers/writer/WDriver.cxx @@ -30,14 +30,26 @@ using namespace ::com::sun::star; namespace connectivity::writer { -OUString ODriver::getImplementationName_Static() { return "com.sun.star.comp.sdbc.writer.ODriver"; } - -OUString SAL_CALL ODriver::getImplementationName() { return getImplementationName_Static(); } +OUString SAL_CALL ODriver::getImplementationName() +{ + return "com.sun.star.comp.sdbc.writer.ODriver"; +} -uno::Reference -ODriver_CreateInstance(const uno::Reference& _rxFactory) +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +connectivity_writer_ODriver(css::uno::XComponentContext* context, + css::uno::Sequence const&) { - return *(new ODriver(comphelper::getComponentContext(_rxFactory))); + rtl::Reference ret; + try + { + ret = new ODriver(context); + } + catch (...) + { + } + if (ret) + ret->acquire(); + return static_cast(ret.get()); } uno::Reference diff --git a/connectivity/source/drivers/writer/Wservices.cxx b/connectivity/source/drivers/writer/Wservices.cxx deleted file mode 100644 index 7f997d7d110d..000000000000 --- a/connectivity/source/drivers/writer/Wservices.cxx +++ /dev/null @@ -1,90 +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 -#include -#include - -using namespace com::sun::star; - -using createFactoryFunc = uno::Reference (*)( - const uno::Reference& rServiceManager, - const OUString& rComponentName, ::cppu::ComponentInstantiation pCreateFunction, - const uno::Sequence& rServiceNames, rtl_ModuleCount*); - -namespace -{ -struct ProviderRequest -{ -private: - uno::Reference xRet; - uno::Reference const xServiceManager; - OUString const sImplementationName; - -public: - ProviderRequest(void* pServiceManager, char const* pImplementationName) - : xServiceManager(static_cast(pServiceManager)) - , sImplementationName(OUString::createFromAscii(pImplementationName)) - { - } - - bool CREATE_PROVIDER(const OUString& Implname, const uno::Sequence& Services, - ::cppu::ComponentInstantiation Factory, createFactoryFunc creator) - { - if (!xRet.is() && (Implname == sImplementationName)) - { - try - { - xRet = creator(xServiceManager, sImplementationName, Factory, Services, nullptr); - } - catch (...) - { - } - } - return xRet.is(); - } - - uno::XInterface* getProvider() const { return xRet.get(); } -}; -} - -extern "C" SAL_DLLPUBLIC_EXPORT void* -connectivity_writer_component_getFactory(const char* pImplementationName, void* pServiceManager, - void* /*pRegistryKey*/) -{ - void* pRet = nullptr; - if (pServiceManager) - { - ProviderRequest aReq(pServiceManager, pImplementationName); - - aReq.CREATE_PROVIDER(connectivity::writer::ODriver::getImplementationName_Static(), - connectivity::writer::ODriver::getSupportedServiceNames_Static(), - connectivity::writer::ODriver_CreateInstance, - ::cppu::createSingleFactory); - - if (aReq.getProvider()) - aReq.getProvider()->acquire(); - - pRet = aReq.getProvider(); - } - - return pRet; -}; - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/writer/writer.component b/connectivity/source/drivers/writer/writer.component index 3bf9d6e79292..3a0432412b54 100644 --- a/connectivity/source/drivers/writer/writer.component +++ b/connectivity/source/drivers/writer/writer.component @@ -8,9 +8,9 @@ --> - + -- cgit