From 79c11bb56ecf9f99250387ee59559f7472028f05 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Thu, 25 Feb 2016 15:33:22 +0100 Subject: Use an XInitialization-based channel to request service mgr pre-init ...instead of private cppu::preInitBootstrap function Change-Id: Id0e6fcf721b697c993e5acffaf7836452cfa9750 Reviewed-on: https://gerrit.libreoffice.org/22699 Tested-by: Jenkins Reviewed-by: Tor Lillqvist Tested-by: Tor Lillqvist --- cppuhelper/source/servicemanager.cxx | 239 +++++++++++++++++++---------------- 1 file changed, 127 insertions(+), 112 deletions(-) (limited to 'cppuhelper/source/servicemanager.cxx') diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx index 0f709ef9190c..2c29bb62fffb 100644 --- a/cppuhelper/source/servicemanager.cxx +++ b/cppuhelper/source/servicemanager.cxx @@ -878,118 +878,6 @@ void cppuhelper::ServiceManager::loadImplementation( } } -void cppuhelper::ServiceManager::loadAllImplementations() -{ -#ifdef DISABLE_DYNLOADING - abort(); -#else - rtl::OUString aUri; - osl::MutexGuard g(rBHelper.rMutex); - css::uno::Environment aSourceEnv(css::uno::Environment::getCurrent()); - - // loop all implementations - for (Data::NamedImplementations::const_iterator iterator( - data_.namedImplementations.begin()); - iterator != data_.namedImplementations.end(); ++iterator) - { - try - { - // expand absolute URI implementation component library - aUri = cppu::bootstrap_expandUri(iterator->second->info->uri); - } - catch (css::lang::IllegalArgumentException& aError) - { - throw css::uno::DeploymentException( - "Cannot expand URI" + iterator->second->info->uri + ": " + aError.Message, - static_cast< cppu::OWeakObject * >(this)); - } - - if (iterator->second->info->loader == "com.sun.star.loader.SharedLibrary" && - iterator->second->status != Data::Implementation::STATUS_LOADED) - { - // load component library - osl::Module aModule(aUri, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL); - SAL_INFO("lok", "loaded component library " << aUri << ( aModule.is() ? " ok" : " no")); - - if (aModule.is() && - !iterator->second->info->environment.isEmpty()) - { - OUString aSymFactory; - oslGenericFunction fpFactory; - css::uno::Environment aTargetEnv; - css::uno::Reference xFactory; - - if(iterator->second->info->constructor.isEmpty()) - { - // expand full name component factory symbol - if (iterator->second->info->prefix == "direct") - aSymFactory = iterator->second->info->name.replace('.', '_') + "_" COMPONENT_GETFACTORY; - else if (!iterator->second->info->prefix.isEmpty()) - aSymFactory = iterator->second->info->prefix + "_" COMPONENT_GETFACTORY; - else - aSymFactory = COMPONENT_GETFACTORY; - - // get function symbol component factory - fpFactory = aModule.getFunctionSymbol(aSymFactory); - if (fpFactory == nullptr) - { - throw css::loader::CannotActivateFactoryException( - ("no factory symbol \"" + aSymFactory + "\" in component library :" + aUri), - css::uno::Reference()); - } - - aTargetEnv = cppuhelper::detail::getEnvironment(iterator->second->info->environment, iterator->second->info->name); - component_getFactoryFunc fpComponentFactory = reinterpret_cast(fpFactory); - - if (aSourceEnv.get() == aTargetEnv.get()) - { - // invoke function component factory - OString aImpl(rtl::OUStringToOString(iterator->second->info->name, RTL_TEXTENCODING_ASCII_US)); - xFactory.set(css::uno::Reference(static_cast( - (*fpComponentFactory)(aImpl.getStr(), this, nullptr)), SAL_NO_ACQUIRE)); - } - } - else - { - // get function symbol component factory - fpFactory = aModule.getFunctionSymbol(iterator->second->info->constructor); - } - - css::uno::Reference xSCFactory; - css::uno::Reference xSSFactory; - - // query interface XSingleComponentFactory or XSingleServiceFactory - if (xFactory.is()) - { - xSCFactory.set(xFactory, css::uno::UNO_QUERY); - if (!xSCFactory.is()) - { - xSSFactory.set(xFactory, css::uno::UNO_QUERY); - if (!xSSFactory.is()) - { - throw css::uno::DeploymentException( - ("Implementation " + iterator->second->info->name - + " does not provide a constructor or factory"), - static_cast< cppu::OWeakObject * >(this)); - } - } - } - - if (!iterator->second->info->constructor.isEmpty() && fpFactory) - iterator->second->constructor = reinterpret_cast(fpFactory); - - iterator->second->factory1 = xSCFactory; - iterator->second->factory2 = xSSFactory; - iterator->second->status = Data::Implementation::STATUS_LOADED; - - } - // leak aModule - aModule.release(); - } - } -#endif -} - void cppuhelper::ServiceManager::disposing() { std::vector< css::uno::Reference > sngls; std::vector< css::uno::Reference< css::lang::XComponent > > comps; @@ -1051,6 +939,22 @@ void cppuhelper::ServiceManager::disposing() { } } +void cppuhelper::ServiceManager::initialize( + css::uno::Sequence const & aArguments) + throw (css::uno::Exception, css::uno::RuntimeException, std::exception) +{ + OUString arg; + if (aArguments.getLength() == 1 && (aArguments[0] >>= arg) + && arg == "preload") + { + preloadImplementations(); + } else { + throw css::lang::IllegalArgumentException( + "invalid ServiceManager::initialize argument", + css::uno::Reference(), 0); + } +} + rtl::OUString cppuhelper::ServiceManager::getImplementationName() throw (css::uno::RuntimeException, std::exception) { @@ -1989,4 +1893,115 @@ cppuhelper::ServiceManager::findServiceImplementation( return impl; } +void cppuhelper::ServiceManager::preloadImplementations() { +#ifdef DISABLE_DYNLOADING + abort(); +#else + rtl::OUString aUri; + osl::MutexGuard g(rBHelper.rMutex); + css::uno::Environment aSourceEnv(css::uno::Environment::getCurrent()); + + // loop all implementations + for (Data::NamedImplementations::const_iterator iterator( + data_.namedImplementations.begin()); + iterator != data_.namedImplementations.end(); ++iterator) + { + try + { + // expand absolute URI implementation component library + aUri = cppu::bootstrap_expandUri(iterator->second->info->uri); + } + catch (css::lang::IllegalArgumentException& aError) + { + throw css::uno::DeploymentException( + "Cannot expand URI" + iterator->second->info->uri + ": " + aError.Message, + static_cast< cppu::OWeakObject * >(this)); + } + + if (iterator->second->info->loader == "com.sun.star.loader.SharedLibrary" && + iterator->second->status != Data::Implementation::STATUS_LOADED) + { + // load component library + osl::Module aModule(aUri, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL); + SAL_INFO("lok", "loaded component library " << aUri << ( aModule.is() ? " ok" : " no")); + + if (aModule.is() && + !iterator->second->info->environment.isEmpty()) + { + OUString aSymFactory; + oslGenericFunction fpFactory; + css::uno::Environment aTargetEnv; + css::uno::Reference xFactory; + + if(iterator->second->info->constructor.isEmpty()) + { + // expand full name component factory symbol + if (iterator->second->info->prefix == "direct") + aSymFactory = iterator->second->info->name.replace('.', '_') + "_" COMPONENT_GETFACTORY; + else if (!iterator->second->info->prefix.isEmpty()) + aSymFactory = iterator->second->info->prefix + "_" COMPONENT_GETFACTORY; + else + aSymFactory = COMPONENT_GETFACTORY; + + // get function symbol component factory + fpFactory = aModule.getFunctionSymbol(aSymFactory); + if (fpFactory == nullptr) + { + throw css::loader::CannotActivateFactoryException( + ("no factory symbol \"" + aSymFactory + "\" in component library :" + aUri), + css::uno::Reference()); + } + + aTargetEnv = cppuhelper::detail::getEnvironment(iterator->second->info->environment, iterator->second->info->name); + component_getFactoryFunc fpComponentFactory = reinterpret_cast(fpFactory); + + if (aSourceEnv.get() == aTargetEnv.get()) + { + // invoke function component factory + OString aImpl(rtl::OUStringToOString(iterator->second->info->name, RTL_TEXTENCODING_ASCII_US)); + xFactory.set(css::uno::Reference(static_cast( + (*fpComponentFactory)(aImpl.getStr(), this, nullptr)), SAL_NO_ACQUIRE)); + } + } + else + { + // get function symbol component factory + fpFactory = aModule.getFunctionSymbol(iterator->second->info->constructor); + } + + css::uno::Reference xSCFactory; + css::uno::Reference xSSFactory; + + // query interface XSingleComponentFactory or XSingleServiceFactory + if (xFactory.is()) + { + xSCFactory.set(xFactory, css::uno::UNO_QUERY); + if (!xSCFactory.is()) + { + xSSFactory.set(xFactory, css::uno::UNO_QUERY); + if (!xSSFactory.is()) + { + throw css::uno::DeploymentException( + ("Implementation " + iterator->second->info->name + + " does not provide a constructor or factory"), + static_cast< cppu::OWeakObject * >(this)); + } + } + } + + if (!iterator->second->info->constructor.isEmpty() && fpFactory) + iterator->second->constructor = reinterpret_cast(fpFactory); + + iterator->second->factory1 = xSCFactory; + iterator->second->factory2 = xSSFactory; + iterator->second->status = Data::Implementation::STATUS_LOADED; + + } + // leak aModule + aModule.release(); + } + } +#endif +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit