cppuhelper/source/defaultbootstrap.cxx | 27 ++++++---- cppuhelper/source/gcc3.map | 2 cppuhelper/source/servicemanager.cxx | 86 +++++++++++++++++++++++++++++++-- desktop/source/lib/init.cxx | 6 +- include/cppuhelper/detail/preinit.hxx | 10 +++ 5 files changed, 111 insertions(+), 20 deletions(-)
New commits: commit 4c251ee490523675211afa0f967de2830067f9bc Author: Tor Lillqvist <t...@collabora.com> Date: Mon Feb 15 22:29:32 2016 +0200 loplugin:nullptr Change-Id: I768b45818eaa0138d033bfcf6fd6e94459e44c0b diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index f69bdd5..75c17b4 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1849,7 +1849,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char static bool bPreInited = false; // What stage are we at ? - if (pThis == NULL) + if (pThis == nullptr) eStage = PRE_INIT; else if (bPreInited) eStage = SECOND_INIT; @@ -2019,7 +2019,7 @@ LibreOfficeKit *libreofficekit_hook(const char* install_path) SAL_JNI_EXPORT int lok_preinit(const char* install_path, const char* user_profile_path) { - return lo_initialize(NULL, install_path, user_profile_path); + return lo_initialize(nullptr, install_path, user_profile_path); } static void lo_destroy(LibreOfficeKit* pThis) commit 8d7f29a933b62ffd754c6a0f05d25e55b8646e74 Author: Henry Castro <hcas...@collabora.com> Date: Mon Sep 7 17:17:22 2015 -0400 Re-work cppu::preInitBootstrap() In the preinit stage, the preInitBootstrap is called to load implementations for each service registered by the service manager. All service requests are: initial Component Context and the process service factory is set. However, some services require that VCL is properly initialized. Change-Id: Ib116e3da172b860f2df4d672f6181b5de0b7e6b2 diff --git a/cppuhelper/source/defaultbootstrap.cxx b/cppuhelper/source/defaultbootstrap.cxx index c0a2c2e..9ff68e1 100644 --- a/cppuhelper/source/defaultbootstrap.cxx +++ b/cppuhelper/source/defaultbootstrap.cxx @@ -109,18 +109,25 @@ cppu::defaultBootstrap_InitialComponentContext() } void -cppu::preInitBootstrap() +cppu::preInitBootstrap(css::uno::Reference< css::uno::XComponentContext > const & xContext) { - rtl::OUString iniUri(getUnoIniUri()); - rtl::Bootstrap bs(iniUri); - if (bs.getHandle() == nullptr) - throw css::uno::DeploymentException("Cannot open uno ini " + iniUri); + if (!xContext.is()) + throw css::uno::DeploymentException("preInit: XComponentContext is not created"); + + css::uno::Reference< css::uno::XInterface > xService; + xContext->getValueByName("/singletons/com.sun.star.lang.theServiceManager") >>= xService; + if (!xService.is()) + throw css::uno::DeploymentException("preInit: XMultiComponentFactory is not created"); + + rtl::Reference<cppuhelper::ServiceManager> aService(reinterpret_cast<cppuhelper::ServiceManager*>(xService.get())); - // create the service manager - rtl::Reference< cppuhelper::ServiceManager > aManager(new cppuhelper::ServiceManager); - // read rdb files - aManager->init(getBootstrapVariable(bs, "UNO_SERVICES")); - aManager->loadAllImplementations(); + // pre-requisites: + // In order to load implementations and invoke + // component factory it is required: + // 1) defaultBootstrap_InitialComponentContext() + // 2) comphelper::setProcessServiceFactory(xSFactory); + // 3) InitVCL() + aService->loadAllImplementations(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/source/gcc3.map b/cppuhelper/source/gcc3.map index 20d0e13..658b3ca 100644 --- a/cppuhelper/source/gcc3.map +++ b/cppuhelper/source/gcc3.map @@ -439,5 +439,5 @@ GLIBCXX_3.4 { PRIVATE_1.0 { # LibO 5.2 global: - _ZN4cppu16preInitBootstrapEv; + _ZN4cppu16preInitBootstrapERKN3com3sun4star3uno9ReferenceINS3_17XComponentContextEEE; }; diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index f24ecd2..f69bdd5 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1914,7 +1914,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char { InitVCL(); // pre-load all component libraries. - cppu::preInitBootstrap(); + cppu::preInitBootstrap(xContext); // Release Solar Mutex, lo_startmain thread should acquire it. Application::ReleaseSolarMutex(); } diff --git a/include/cppuhelper/detail/preinit.hxx b/include/cppuhelper/detail/preinit.hxx index b21929a..d152cf2 100644 --- a/include/cppuhelper/detail/preinit.hxx +++ b/include/cppuhelper/detail/preinit.hxx @@ -17,8 +17,16 @@ namespace cppu #if defined LIBO_INTERNAL_ONLY +/** Preload all shared library components with service manager upon + information from bootstrap variables. + + This function tries to find its parameters via these bootstrap variables: + + - UNO_SERVICES -- a space separated list of file urls of service rdbs + +*/ CPPUHELPER_DLLPUBLIC void SAL_CALL -preInitBootstrap(); +preInitBootstrap(css::uno::Reference< css::uno::XComponentContext > const & xContext); #endif // LIBO_INTERNAL_ONLY commit 6b41b89cc51b65fe3aa69099638ec4432782886a Author: Henry Castro <hcas...@collabora.com> Date: Mon Sep 7 17:11:45 2015 -0400 In loadAllImplementations(), also invoke component factory Change-Id: Ie6f6d769b611c8440ddab802545e6bdc482d1476 diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx index 0c71a04..0f709ef 100644 --- a/cppuhelper/source/servicemanager.cxx +++ b/cppuhelper/source/servicemanager.cxx @@ -33,6 +33,8 @@ #include <cppuhelper/implbase1.hxx> #include <cppuhelper/implbase3.hxx> #include <cppuhelper/supportsservice.hxx> +#include <cppuhelper/factory.hxx> +#include <cppuhelper/shlib.hxx> #include <osl/file.hxx> #include <osl/module.hxx> #include <rtl/ref.hxx> @@ -883,13 +885,16 @@ void cppuhelper::ServiceManager::loadAllImplementations() #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) @@ -902,13 +907,84 @@ void cppuhelper::ServiceManager::loadAllImplementations() if (iterator->second->info->loader == "com.sun.star.loader.SharedLibrary" && iterator->second->status != Data::Implementation::STATUS_LOADED) { - oslModule aModule = osl_loadModule( aUri.pData, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL ); - SAL_INFO("lok", "loaded component library " << aUri << ( aModule ? " ok" : " no")); + // load component library + osl::Module aModule(aUri, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL); + SAL_INFO("lok", "loaded component library " << aUri << ( aModule.is() ? " ok" : " no")); - // leak aModule - // osl_unloadModule(aModule); - if ( aModule ) + if (aModule.is() && + !iterator->second->info->environment.isEmpty()) + { + OUString aSymFactory; + oslGenericFunction fpFactory; + css::uno::Environment aTargetEnv; + css::uno::Reference<css::uno::XInterface> 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<css::uno::XInterface>()); + } + + aTargetEnv = cppuhelper::detail::getEnvironment(iterator->second->info->environment, iterator->second->info->name); + component_getFactoryFunc fpComponentFactory = reinterpret_cast<component_getFactoryFunc>(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<css::uno::XInterface>(static_cast<css::uno::XInterface *>( + (*fpComponentFactory)(aImpl.getStr(), this, nullptr)), SAL_NO_ACQUIRE)); + } + } + else + { + // get function symbol component factory + fpFactory = aModule.getFunctionSymbol(iterator->second->info->constructor); + } + + css::uno::Reference<css::lang::XSingleComponentFactory> xSCFactory; + css::uno::Reference<css::lang::XSingleServiceFactory> 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<ImplementationConstructorFn *>(fpFactory); + + iterator->second->factory1 = xSCFactory; + iterator->second->factory2 = xSSFactory; iterator->second->status = Data::Implementation::STATUS_LOADED; + + } + // leak aModule + aModule.release(); } } #endif _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits