summaryrefslogtreecommitdiff
path: root/cppuhelper
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2016-02-12 11:46:37 -0500
committerTor Lillqvist <tml@collabora.com>2016-02-15 16:17:53 +0200
commitdf5f7c6abab820070771c5304514faf2a07bc588 (patch)
tree274fd4813096c4db8911eaf84d0124ad08208be8 /cppuhelper
parent5b0c551b9b35f7075d210c9a23e7721e46a66bf9 (diff)
Introduce lok_preinit() to preload all registered UNO implementations
Intended to be used from an application like the LibreOffice On-Line server so that it can be called in a process that then will call fork() several times, and much space consuming data will end up being shared. Change-Id: I65341c57d00308d246ec90deab8050b2c4bb3e61
Diffstat (limited to 'cppuhelper')
-rw-r--r--cppuhelper/source/defaultbootstrap.cxx16
-rw-r--r--cppuhelper/source/gcc3.map5
-rw-r--r--cppuhelper/source/servicemanager.cxx35
-rw-r--r--cppuhelper/source/servicemanager.hxx2
4 files changed, 58 insertions, 0 deletions
diff --git a/cppuhelper/source/defaultbootstrap.cxx b/cppuhelper/source/defaultbootstrap.cxx
index bede6b518af0..c0a2c2edc6f7 100644
--- a/cppuhelper/source/defaultbootstrap.cxx
+++ b/cppuhelper/source/defaultbootstrap.cxx
@@ -18,6 +18,7 @@
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/lang/XSingleComponentFactory.hpp>
#include <cppuhelper/bootstrap.hxx>
+#include <cppuhelper/detail/preinit.hxx>
#include <cppuhelper/component_context.hxx>
#include <rtl/bootstrap.hxx>
#include <rtl/ref.hxx>
@@ -107,4 +108,19 @@ cppu::defaultBootstrap_InitialComponentContext()
return defaultBootstrap_InitialComponentContext(getUnoIniUri());
}
+void
+cppu::preInitBootstrap()
+{
+ rtl::OUString iniUri(getUnoIniUri());
+ rtl::Bootstrap bs(iniUri);
+ if (bs.getHandle() == nullptr)
+ throw css::uno::DeploymentException("Cannot open uno ini " + iniUri);
+
+ // create the service manager
+ rtl::Reference< cppuhelper::ServiceManager > aManager(new cppuhelper::ServiceManager);
+ // read rdb files
+ aManager->init(getBootstrapVariable(bs, "UNO_SERVICES"));
+ aManager->loadAllImplementations();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cppuhelper/source/gcc3.map b/cppuhelper/source/gcc3.map
index 12c29834ab16..20d0e137eef6 100644
--- a/cppuhelper/source/gcc3.map
+++ b/cppuhelper/source/gcc3.map
@@ -436,3 +436,8 @@ GLIBCXX_3.4 {
_ZGVNSt7num_put*; _ZNSt7num_put*;
_ZNSs4_Rep20_S_empty_rep_storageE;
};
+
+PRIVATE_1.0 { # LibO 5.2
+ global:
+ _ZN4cppu16preInitBootstrapEv;
+};
diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx
index 2d824d4aaa3f..d89289a165a4 100644
--- a/cppuhelper/source/servicemanager.cxx
+++ b/cppuhelper/source/servicemanager.cxx
@@ -34,6 +34,7 @@
#include <cppuhelper/implbase3.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <osl/file.hxx>
+#include <osl/module.hxx>
#include <rtl/ref.hxx>
#include <rtl/uri.hxx>
#include <rtl/ustring.hxx>
@@ -875,6 +876,40 @@ void cppuhelper::ServiceManager::loadImplementation(
}
}
+void cppuhelper::ServiceManager::loadAllImplementations()
+{
+ rtl::OUString aUri;
+ osl::MutexGuard g(rBHelper.rMutex);
+
+ for (Data::NamedImplementations::const_iterator iterator(
+ data_.namedImplementations.begin());
+ iterator != data_.namedImplementations.end(); ++iterator)
+ {
+ try
+ {
+ 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)
+ {
+ oslModule aModule = osl_loadModule( aUri.pData, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL );
+ SAL_INFO("lok", "loaded component library " << aUri << ( aModule ? " ok" : " no"));
+
+ // leak aModule
+ // osl_unloadModule(aModule);
+ if ( aModule )
+ iterator->second->status = Data::Implementation::STATUS_LOADED;
+ }
+ }
+}
+
void cppuhelper::ServiceManager::disposing() {
std::vector< css::uno::Reference<css::lang::XComponent> > sngls;
std::vector< css::uno::Reference< css::lang::XComponent > > comps;
diff --git a/cppuhelper/source/servicemanager.hxx b/cppuhelper/source/servicemanager.hxx
index c217cbce39f5..7e8f4e66e7e6 100644
--- a/cppuhelper/source/servicemanager.hxx
+++ b/cppuhelper/source/servicemanager.hxx
@@ -203,6 +203,8 @@ public:
css::uno::Reference< css::uno::XComponentContext > const & context,
std::shared_ptr< Data::Implementation > & implementation);
+ void loadAllImplementations();
+
private:
virtual ~ServiceManager();