diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-16 12:19:14 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-17 08:47:55 +0200 |
commit | 2fc112e98ddcb46038eaff341734331a8558934f (patch) | |
tree | e0d8424193b925b4fbfbb82afbdcfdf83b2fd869 /package | |
parent | c33f3ede4a5e5336972aab2cb13714624d479b0a (diff) |
package: create instances with uno constructors
See tdf#74608 for motivation.
Change-Id: I17627bdd2f4f595343ad9bf524dc57cd03170b2a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98921
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'package')
-rw-r--r-- | package/Library_package2.mk | 1 | ||||
-rw-r--r-- | package/inc/ZipPackage.hxx | 5 | ||||
-rw-r--r-- | package/inc/zipfileaccess.hxx | 7 | ||||
-rw-r--r-- | package/source/manifest/ManifestReader.cxx | 30 | ||||
-rw-r--r-- | package/source/manifest/ManifestReader.hxx | 5 | ||||
-rw-r--r-- | package/source/manifest/ManifestWriter.cxx | 32 | ||||
-rw-r--r-- | package/source/manifest/ManifestWriter.hxx | 5 | ||||
-rw-r--r-- | package/source/manifest/UnoRegister.cxx | 70 | ||||
-rw-r--r-- | package/source/zippackage/ZipPackage.cxx | 38 | ||||
-rw-r--r-- | package/source/zippackage/zipfileaccess.cxx | 31 | ||||
-rw-r--r-- | package/util/package2.component | 14 |
11 files changed, 46 insertions, 192 deletions
diff --git a/package/Library_package2.mk b/package/Library_package2.mk index adca76fba2ed..9bb7e3194b98 100644 --- a/package/Library_package2.mk +++ b/package/Library_package2.mk @@ -46,7 +46,6 @@ $(eval $(call gb_Library_add_exception_objects,package2,\ package/source/manifest/ManifestImport \ package/source/manifest/ManifestReader \ package/source/manifest/ManifestWriter \ - package/source/manifest/UnoRegister \ package/source/zipapi/blowfishcontext \ package/source/zipapi/ByteChucker \ package/source/zipapi/ByteGrabber \ diff --git a/package/inc/ZipPackage.hxx b/package/inc/ZipPackage.hxx index 779e5cd7ed41..ec39666fbbb1 100644 --- a/package/inc/ZipPackage.hxx +++ b/package/inc/ZipPackage.hxx @@ -161,11 +161,6 @@ public: 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; - - // Uno componentiseralation - static OUString static_getImplementationName(); - static css::uno::Sequence < OUString > static_getSupportedServiceNames(); - static css::uno::Reference < css::lang::XSingleServiceFactory > createServiceFactory( css::uno::Reference < css::lang::XMultiServiceFactory > const & rServiceFactory ); }; #endif diff --git a/package/inc/zipfileaccess.hxx b/package/inc/zipfileaccess.hxx index 2cd403d54545..a3f96346d6ec 100644 --- a/package/inc/zipfileaccess.hxx +++ b/package/inc/zipfileaccess.hxx @@ -61,13 +61,6 @@ public: static bool StringGoodForPattern_Impl( const OUString& aString, const css::uno::Sequence< OUString >& aPattern ); - static css::uno::Sequence< OUString > impl_staticGetSupportedServiceNames(); - - static OUString impl_staticGetImplementationName(); - - static css::uno::Reference< css::uno::XInterface > impl_staticCreateSelfInstance( - const css::uno::Reference< css::lang::XMultiServiceFactory >& rxMSF ); - // XInitialization virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override; diff --git a/package/source/manifest/ManifestReader.cxx b/package/source/manifest/ManifestReader.cxx index 50fd851b31b8..dcb296d7e6f0 100644 --- a/package/source/manifest/ManifestReader.cxx +++ b/package/source/manifest/ManifestReader.cxx @@ -81,24 +81,10 @@ Sequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSeque } // Component functions -static Reference < XInterface > ManifestReader_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory ) -{ - return *new ManifestReader( comphelper::getComponentContext(rServiceFactory) ); -} -OUString ManifestReader::static_getImplementationName() -{ - return "com.sun.star.packages.manifest.comp.ManifestReader"; -} - -Sequence < OUString > ManifestReader::static_getSupportedServiceNames() -{ - Sequence < OUString > aNames { "com.sun.star.packages.manifest.ManifestReader" }; - return aNames; -} OUString ManifestReader::getImplementationName() { - return static_getImplementationName(); + return "com.sun.star.packages.manifest.comp.ManifestReader"; } sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName) @@ -108,14 +94,16 @@ sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName) Sequence < OUString > ManifestReader::getSupportedServiceNames() { - return static_getSupportedServiceNames(); + return { "com.sun.star.packages.manifest.ManifestReader" }; } -Reference < XSingleServiceFactory > ManifestReader::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory ) + + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +package_ManifestReader_get_implementation( + css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) { - return cppu::createSingleFactory (rServiceFactory, - static_getImplementationName(), - ManifestReader_createInstance, - static_getSupportedServiceNames()); + return cppu::acquire(new ManifestReader(context)); } + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestReader.hxx b/package/source/manifest/ManifestReader.hxx index e30884424f77..d9546cd30ddf 100644 --- a/package/source/manifest/ManifestReader.hxx +++ b/package/source/manifest/ManifestReader.hxx @@ -49,11 +49,6 @@ public: 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; - - // Component constructor - static OUString static_getImplementationName(); - static css::uno::Sequence < OUString > static_getSupportedServiceNames(); - static css::uno::Reference < css::lang::XSingleServiceFactory > createServiceFactory( css::uno::Reference < css::lang::XMultiServiceFactory > const & rServiceFactory ); }; #endif diff --git a/package/source/manifest/ManifestWriter.cxx b/package/source/manifest/ManifestWriter.cxx index 8fbb9bd6a177..08c12510afee 100644 --- a/package/source/manifest/ManifestWriter.cxx +++ b/package/source/manifest/ManifestWriter.cxx @@ -72,26 +72,9 @@ void SAL_CALL ManifestWriter::writeManifestSequence( const Reference< XOutputStr } } -// Component methods -static Reference < XInterface > ManifestWriter_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory ) -{ - return *new ManifestWriter( comphelper::getComponentContext(rServiceFactory) ); -} - -OUString ManifestWriter::static_getImplementationName() -{ - return "com.sun.star.packages.manifest.comp.ManifestWriter"; -} - -Sequence < OUString > ManifestWriter::static_getSupportedServiceNames() -{ - Sequence<OUString> aNames { "com.sun.star.packages.manifest.ManifestWriter" }; - return aNames; -} - OUString ManifestWriter::getImplementationName() { - return static_getImplementationName(); + return "com.sun.star.packages.manifest.comp.ManifestWriter"; } sal_Bool SAL_CALL ManifestWriter::supportsService(OUString const & rServiceName) @@ -100,14 +83,15 @@ sal_Bool SAL_CALL ManifestWriter::supportsService(OUString const & rServiceName) } Sequence < OUString > ManifestWriter::getSupportedServiceNames() { - return static_getSupportedServiceNames(); + return { "com.sun.star.packages.manifest.ManifestWriter" }; } -Reference < XSingleServiceFactory > ManifestWriter::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory ) + + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +package_ManifestWriter_get_implementation( + css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) { - return cppu::createSingleFactory (rServiceFactory, - static_getImplementationName(), - ManifestWriter_createInstance, - static_getSupportedServiceNames()); + return cppu::acquire(new ManifestWriter(context)); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/manifest/ManifestWriter.hxx b/package/source/manifest/ManifestWriter.hxx index 7d83a7383bc9..1378ebf8edd7 100644 --- a/package/source/manifest/ManifestWriter.hxx +++ b/package/source/manifest/ManifestWriter.hxx @@ -49,11 +49,6 @@ public: 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; - - // Component constructor - static OUString static_getImplementationName(); - static css::uno::Sequence < OUString > static_getSupportedServiceNames(); - static css::uno::Reference < css::lang::XSingleServiceFactory > createServiceFactory( css::uno::Reference < css::lang::XMultiServiceFactory > const & rServiceFactory ); }; #endif diff --git a/package/source/manifest/UnoRegister.cxx b/package/source/manifest/UnoRegister.cxx deleted file mode 100644 index aa14db7d7c6f..000000000000 --- a/package/source/manifest/UnoRegister.cxx +++ /dev/null @@ -1,70 +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 "ManifestReader.hxx" -#include "ManifestWriter.hxx" -#include <cppuhelper/factory.hxx> -#include <com/sun/star/registry/XRegistryKey.hpp> -#include <ZipPackage.hxx> - -#include <zipfileaccess.hxx> - -using namespace ::com::sun::star; -using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::beans; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::registry; -using namespace ::com::sun::star::packages; - -/** - * This function is called to get service factories for an implementation. - * @param pImplName name of implementation - * @param pServiceManager generic uno interface providing a service manager to instantiate components - * @param pRegistryKey registry data key to read and write component persistent data - * @return a component factory (generic uno interface) - */ -extern "C" SAL_DLLPUBLIC_EXPORT void * package2_component_getFactory( - const char * pImplName, void * pServiceManager, void * /*pRegistryKey*/ ) -{ - void * pRet = nullptr; - uno::Reference< XMultiServiceFactory > xSMgr( - static_cast< XMultiServiceFactory * >( pServiceManager ) ); - uno::Reference< XSingleServiceFactory > xFactory; - - if (ManifestReader::static_getImplementationName().equalsAscii( pImplName ) ) - xFactory = ManifestReader::createServiceFactory ( xSMgr ); - else if (ManifestWriter::static_getImplementationName().equalsAscii( pImplName ) ) - xFactory = ManifestWriter::createServiceFactory ( xSMgr ); - else if (ZipPackage::static_getImplementationName().equalsAscii( pImplName ) ) - xFactory = ZipPackage::createServiceFactory ( xSMgr ); - else if ( OZipFileAccess::impl_staticGetImplementationName().equalsAscii( pImplName ) ) - xFactory = ::cppu::createSingleFactory( xSMgr, - OZipFileAccess::impl_staticGetImplementationName(), - OZipFileAccess::impl_staticCreateSelfInstance, - OZipFileAccess::impl_staticGetSupportedServiceNames() ); - - if ( xFactory.is() ) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - return pRet; -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 02aed7a66a2e..4e113e91d3bb 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -1661,34 +1661,15 @@ Sequence< ElementChange > SAL_CALL ZipPackage::getPendingChanges() return uno::Sequence < ElementChange > (); } -/** - * Function to create a new component instance; is needed by factory helper implementation. - * @param xMgr service manager to if the components needs other component instances - */ -static uno::Reference < XInterface > ZipPackage_createInstance( - const uno::Reference< XMultiServiceFactory > & xMgr ) -{ - return uno::Reference< XInterface >( *new ZipPackage( comphelper::getComponentContext(xMgr) ) ); -} - -OUString ZipPackage::static_getImplementationName() -{ - return "com.sun.star.packages.comp.ZipPackage"; -} - -Sequence< OUString > ZipPackage::static_getSupportedServiceNames() -{ - return { "com.sun.star.packages.Package" }; -} OUString ZipPackage::getImplementationName() { - return static_getImplementationName(); + return "com.sun.star.packages.comp.ZipPackage"; } Sequence< OUString > ZipPackage::getSupportedServiceNames() { - return static_getSupportedServiceNames(); + return { "com.sun.star.packages.Package" }; } sal_Bool SAL_CALL ZipPackage::supportsService( OUString const & rServiceName ) @@ -1696,14 +1677,6 @@ sal_Bool SAL_CALL ZipPackage::supportsService( OUString const & rServiceName ) return cppu::supportsService(this, rServiceName); } -uno::Reference < XSingleServiceFactory > ZipPackage::createServiceFactory( uno::Reference < XMultiServiceFactory > const & rServiceFactory ) -{ - return cppu::createSingleFactory ( rServiceFactory, - static_getImplementationName(), - ZipPackage_createInstance, - static_getSupportedServiceNames() ); -} - Sequence< sal_Int8 > ZipPackage::getUnoTunnelId() { static ::cppu::OImplementationId implId; @@ -1872,4 +1845,11 @@ void SAL_CALL ZipPackage::removeVetoableChangeListener( const OUString& /*Proper { } +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +package_ZipPackage_get_implementation( + css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new ZipPackage(context)); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/source/zippackage/zipfileaccess.cxx b/package/source/zippackage/zipfileaccess.cxx index 31e38aff1dcd..b813c165d46e 100644 --- a/package/source/zippackage/zipfileaccess.cxx +++ b/package/source/zippackage/zipfileaccess.cxx @@ -449,38 +449,29 @@ void SAL_CALL OZipFileAccess::removeEventListener( const uno::Reference< lang::X m_pListenersContainer->removeInterface( xListener ); } -uno::Sequence< OUString > OZipFileAccess::impl_staticGetSupportedServiceNames() -{ - uno::Sequence< OUString > aRet(2); - aRet[0] = "com.sun.star.packages.zip.ZipFileAccess"; - aRet[1] = "com.sun.star.comp.packages.zip.ZipFileAccess"; - return aRet; -} - -OUString OZipFileAccess::impl_staticGetImplementationName() +OUString SAL_CALL OZipFileAccess::getImplementationName() { return "com.sun.star.comp.package.zip.ZipFileAccess"; } -uno::Reference< uno::XInterface > OZipFileAccess::impl_staticCreateSelfInstance( - const uno::Reference< lang::XMultiServiceFactory >& rxMSF ) +sal_Bool SAL_CALL OZipFileAccess::supportsService( const OUString& ServiceName ) { - return uno::Reference< uno::XInterface >( *new OZipFileAccess( comphelper::getComponentContext(rxMSF) ) ); + return cppu::supportsService(this, ServiceName); } -OUString SAL_CALL OZipFileAccess::getImplementationName() +uno::Sequence< OUString > SAL_CALL OZipFileAccess::getSupportedServiceNames() { - return impl_staticGetImplementationName(); + return { "com.sun.star.packages.zip.ZipFileAccess", + "com.sun.star.comp.packages.zip.ZipFileAccess" }; } -sal_Bool SAL_CALL OZipFileAccess::supportsService( const OUString& ServiceName ) -{ - return cppu::supportsService(this, ServiceName); -} -uno::Sequence< OUString > SAL_CALL OZipFileAccess::getSupportedServiceNames() +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +package_OZipFileAccess_get_implementation( + css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&) { - return impl_staticGetSupportedServiceNames(); + return cppu::acquire(new OZipFileAccess(context)); } + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/package/util/package2.component b/package/util/package2.component index 6691a0173bbe..d436d9a35a81 100644 --- a/package/util/package2.component +++ b/package/util/package2.component @@ -18,18 +18,22 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="package2" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.package.zip.ZipFileAccess"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.package.zip.ZipFileAccess" + constructor="package_OZipFileAccess_get_implementation"> <service name="com.sun.star.comp.packages.zip.ZipFileAccess"/> <service name="com.sun.star.packages.zip.ZipFileAccess"/> </implementation> - <implementation name="com.sun.star.packages.comp.ZipPackage"> + <implementation name="com.sun.star.packages.comp.ZipPackage" + constructor="package_ZipPackage_get_implementation"> <service name="com.sun.star.packages.Package"/> </implementation> - <implementation name="com.sun.star.packages.manifest.comp.ManifestReader"> + <implementation name="com.sun.star.packages.manifest.comp.ManifestReader" + constructor="package_ManifestReader_get_implementation"> <service name="com.sun.star.packages.manifest.ManifestReader"/> </implementation> - <implementation name="com.sun.star.packages.manifest.comp.ManifestWriter"> + <implementation name="com.sun.star.packages.manifest.comp.ManifestWriter" + constructor="package_ManifestWriter_get_implementation"> <service name="com.sun.star.packages.manifest.ManifestWriter"/> </implementation> </component> |