Kaydet (Commit) 799aef2b authored tarafından Michael Meeks's avatar Michael Meeks

preload: cleanup disabled messages and simplify flow.

Change-Id: I249b81afe5ec2fab5e0aaf73a2cde62173fa803e
Reviewed-on: https://gerrit.libreoffice.org/69912
Tested-by: Jenkins
Reviewed-by: 's avatarMichael Meeks <michael.meeks@collabora.com>
üst db76236e
...@@ -1790,7 +1790,7 @@ void cppuhelper::ServiceManager::preloadImplementations() { ...@@ -1790,7 +1790,7 @@ void cppuhelper::ServiceManager::preloadImplementations() {
std::cerr << "preload:"; std::cerr << "preload:";
std::vector<OUString> aReported; std::vector<OUString> aReported;
std::vector<OUString> aDisabled; std::vector<OUString> aDisabled;
OUStringBuffer aDisabledMsg("Disabled: "); OUStringBuffer aDisabledMsg;
/// Allow external callers & testers to disable certain components /// Allow external callers & testers to disable certain components
const char *pDisable = getenv("UNODISABLELIBRARY"); const char *pDisable = getenv("UNODISABLELIBRARY");
...@@ -1809,6 +1809,10 @@ void cppuhelper::ServiceManager::preloadImplementations() { ...@@ -1809,6 +1809,10 @@ void cppuhelper::ServiceManager::preloadImplementations() {
// loop all implementations // loop all implementations
for (const auto& rEntry : data_.namedImplementations) for (const auto& rEntry : data_.namedImplementations)
{ {
if (rEntry.second->info->loader != "com.sun.star.loader.SharedLibrary" ||
rEntry.second->status == Data::Implementation::STATUS_LOADED)
continue;
try try
{ {
const OUString &aLibrary = rEntry.second->info->uri; const OUString &aLibrary = rEntry.second->info->uri;
...@@ -1848,118 +1852,110 @@ void cppuhelper::ServiceManager::preloadImplementations() { ...@@ -1848,118 +1852,110 @@ void cppuhelper::ServiceManager::preloadImplementations() {
static_cast< cppu::OWeakObject * >(this)); static_cast< cppu::OWeakObject * >(this));
} }
if (rEntry.second->info->loader == "com.sun.star.loader.SharedLibrary" && // load component library
rEntry.second->status != Data::Implementation::STATUS_LOADED) osl::Module aModule(aUri, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL);
if (!aModule.is())
{ {
// load component library std::cerr << ":failed" << std::endl;
osl::Module aModule(aUri, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL); std::cerr.flush();
}
if (!aModule.is()) if (aModule.is() &&
{ !rEntry.second->info->environment.isEmpty())
std::cerr << ":failed" << std::endl; {
std::cerr.flush(); OUString aSymFactory;
} oslGenericFunction fpFactory;
css::uno::Environment aTargetEnv;
css::uno::Reference<css::uno::XInterface> xFactory;
if (aModule.is() && if(rEntry.second->info->constructor.isEmpty())
!rEntry.second->info->environment.isEmpty())
{ {
OUString aSymFactory; // expand full name component factory symbol
oslGenericFunction fpFactory; if (rEntry.second->info->prefix == "direct")
css::uno::Environment aTargetEnv; aSymFactory = rEntry.second->info->name.replace('.', '_') + "_" COMPONENT_GETFACTORY;
css::uno::Reference<css::uno::XInterface> xFactory; else if (!rEntry.second->info->prefix.isEmpty())
aSymFactory = rEntry.second->info->prefix + "_" COMPONENT_GETFACTORY;
else
aSymFactory = COMPONENT_GETFACTORY;
if(rEntry.second->info->constructor.isEmpty()) // get function symbol component factory
fpFactory = aModule.getFunctionSymbol(aSymFactory);
if (fpFactory == nullptr)
{ {
// expand full name component factory symbol throw css::loader::CannotActivateFactoryException(
if (rEntry.second->info->prefix == "direct") ("no factory symbol \"" + aSymFactory + "\" in component library :" + aUri),
aSymFactory = rEntry.second->info->name.replace('.', '_') + "_" COMPONENT_GETFACTORY; css::uno::Reference<css::uno::XInterface>());
else if (!rEntry.second->info->prefix.isEmpty())
aSymFactory = rEntry.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(rEntry.second->info->environment, rEntry.second->info->name);
component_getFactoryFunc fpComponentFactory = reinterpret_cast<component_getFactoryFunc>(fpFactory);
if (aSourceEnv.get() == aTargetEnv.get())
{
// invoke function component factory
OString aImpl(OUStringToOString(rEntry.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
aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name);
component_getFactoryFunc fpComponentFactory = reinterpret_cast<component_getFactoryFunc>(fpFactory);
if (aSourceEnv.get() == aTargetEnv.get())
{ {
// get function symbol component factory // invoke function component factory
aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name); OString aImpl(OUStringToOString(rEntry.second->info->name, RTL_TEXTENCODING_ASCII_US));
if (aSourceEnv.get() == aTargetEnv.get()) xFactory.set(css::uno::Reference<css::uno::XInterface>(static_cast<css::uno::XInterface *>(
{ (*fpComponentFactory)(aImpl.getStr(), this, nullptr)), SAL_NO_ACQUIRE));
fpFactory = aModule.getFunctionSymbol(rEntry.second->info->constructor);
}
else
{
fpFactory = nullptr;
}
} }
}
else
{
// get function symbol component factory
aTargetEnv = cppuhelper::detail::getEnvironment(rEntry.second->info->environment, rEntry.second->info->name);
fpFactory = (aSourceEnv.get() == aTargetEnv.get()) ?
aModule.getFunctionSymbol(rEntry.second->info->constructor) : nullptr;
}
css::uno::Reference<css::lang::XSingleComponentFactory> xSCFactory; css::uno::Reference<css::lang::XSingleComponentFactory> xSCFactory;
css::uno::Reference<css::lang::XSingleServiceFactory> xSSFactory; css::uno::Reference<css::lang::XSingleServiceFactory> xSSFactory;
// query interface XSingleComponentFactory or XSingleServiceFactory // query interface XSingleComponentFactory or XSingleServiceFactory
if (xFactory.is()) if (xFactory.is())
{
xSCFactory.set(xFactory, css::uno::UNO_QUERY);
if (!xSCFactory.is())
{ {
xSCFactory.set(xFactory, css::uno::UNO_QUERY); xSSFactory.set(xFactory, css::uno::UNO_QUERY);
if (!xSCFactory.is()) if (!xSSFactory.is())
{ throw css::uno::DeploymentException(
xSSFactory.set(xFactory, css::uno::UNO_QUERY); ("Implementation " + rEntry.second->info->name
if (!xSSFactory.is()) + " does not provide a constructor or factory"),
{ static_cast< cppu::OWeakObject * >(this));
throw css::uno::DeploymentException(
("Implementation " + rEntry.second->info->name
+ " does not provide a constructor or factory"),
static_cast< cppu::OWeakObject * >(this));
}
}
} }
}
if (!rEntry.second->info->constructor.isEmpty() && fpFactory) if (!rEntry.second->info->constructor.isEmpty() && fpFactory)
rEntry.second->constructor = WrapperConstructorFn(reinterpret_cast<ImplementationConstructorFn *>(fpFactory)); rEntry.second->constructor = WrapperConstructorFn(reinterpret_cast<ImplementationConstructorFn *>(fpFactory));
rEntry.second->factory1 = xSCFactory; rEntry.second->factory1 = xSCFactory;
rEntry.second->factory2 = xSSFactory; rEntry.second->factory2 = xSSFactory;
rEntry.second->status = Data::Implementation::STATUS_LOADED; rEntry.second->status = Data::Implementation::STATUS_LOADED;
} }
// Some libraries use other (non-UNO) libraries requiring preinit // Some libraries use other (non-UNO) libraries requiring preinit
oslGenericFunction fpPreload = aModule.getFunctionSymbol( "lok_preload_hook" ); oslGenericFunction fpPreload = aModule.getFunctionSymbol( "lok_preload_hook" );
if (fpPreload) if (fpPreload)
{
static std::vector<oslGenericFunction> aPreloaded;
if (std::find(aPreloaded.begin(), aPreloaded.end(), fpPreload) == aPreloaded.end())
{ {
static std::vector<oslGenericFunction> aPreloaded; aPreloaded.push_back(fpPreload);
if (std::find(aPreloaded.begin(), aPreloaded.end(), fpPreload) == aPreloaded.end()) fpPreload();
{
aPreloaded.push_back(fpPreload);
fpPreload();
}
} }
// leak aModule
aModule.release();
} }
// leak aModule
aModule.release();
} }
std::cerr << std::endl; std::cerr << std::endl;
std::cerr << aDisabledMsg.makeStringAndClear() << "\n"; if (aDisabledMsg.getLength() > 0)
{
OUString aMsg = aDisabledMsg.makeStringAndClear();
std::cerr << "Disabled: " << aMsg << "\n";
}
std::cerr.flush(); std::cerr.flush();
// Various rather important uno mappings. // Various rather important uno mappings.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment