desktop/Library_sofficeapp.mk | 1 desktop/source/lib/init.cxx | 137 +++++++++++++++++++++++++++++++++++------- 2 files changed, 117 insertions(+), 21 deletions(-)
New commits: commit 91dc9f3bde55627ca06993b710048fda9dacbf44 Author: Henry Castro <[email protected]> Date: Thu Aug 20 15:09:46 2015 -0400 lok: load component library Change-Id: I7fd048e9d3ccd1679bf4a3593be3efd61b5e3c3f diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk index 467fecc..4093c3a 100644 --- a/desktop/Library_sofficeapp.mk +++ b/desktop/Library_sofficeapp.mk @@ -58,6 +58,7 @@ $(eval $(call gb_Library_use_libraries,sofficeapp,\ ucbhelper \ utl \ vcl \ + xmlreader \ $(gb_UWINAPI) \ )) diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index a435b7ef..3bc5824 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -57,6 +57,7 @@ #include <unotools/mediadescriptor.hxx> #include <osl/module.hxx> #include <comphelper/sequence.hxx> +#include <xmlreader/xmlreader.hxx> #include <app.hxx> @@ -966,31 +967,125 @@ static void lo_status_indicator_callback(void *data, comphelper::LibreOfficeKit: } } +static void loadSharedLibrary(const OUString & aUriRdb) +{ + int nsId; + int nUcNsId; + + OUString sAttrUri; + OUString sAttrLoader; + + xmlreader::Span aName; + xmlreader::XmlReader::Result aItem = xmlreader::XmlReader::RESULT_BEGIN; + + xmlreader::XmlReader aRdbReader(aUriRdb); + nUcNsId = aRdbReader.registerNamespaceIri(xmlreader::Span(RTL_CONSTASCII_STRINGPARAM("http://openoffice.org/2010/uno-components"))); + + while( aItem != xmlreader::XmlReader::RESULT_DONE ) + { + aItem = aRdbReader.nextItem(xmlreader::XmlReader::TEXT_NONE, &aName, &nsId ); + if (nsId == nUcNsId && + aName.equals(RTL_CONSTASCII_STRINGPARAM("component"))) + { + sAttrLoader = OUString(); + sAttrUri = OUString(); + + while (aRdbReader.nextAttribute(&nsId, &aName)) + { + if (nsId == xmlreader::XmlReader::NAMESPACE_NONE && + aName.equals(RTL_CONSTASCII_STRINGPARAM("loader"))) + sAttrLoader = aRdbReader.getAttributeValue(false).convertFromUtf8(); + else if (nsId == xmlreader::XmlReader::NAMESPACE_NONE && + aName.equals(RTL_CONSTASCII_STRINGPARAM("uri"))) + sAttrUri = aRdbReader.getAttributeValue(false).convertFromUtf8(); + } + + try + { + sAttrUri = cppu::bootstrap_expandUri(sAttrUri); + } + catch(css::lang::IllegalArgumentException) + { + fprintf(stderr, "Cannot expand URI '%s'\n", + OUStringToOString(sAttrUri, RTL_TEXTENCODING_UTF8).getStr()); + } + + if (sAttrLoader == "com.sun.star.loader.SharedLibrary") + { + oslModule aModule = osl_loadModule( sAttrUri.pData, SAL_LOADMODULE_NOW | SAL_LOADMODULE_GLOBAL ); + SAL_INFO("lok", "loaded component library " << sAttrUri << ( aModule ? " ok" : " no")); + + // leak aModule + // osl_unloadModule(aModule); + aModule = 0; + } + } + } +} + /// pre-load all C++ component factories and leak references to them. -static void forceLoadAllNativeComponents() +static void forceLoadAllNativeComponents(const OUString & aAppURL) { - // FIXME: we need to inject RTLD_NOW into here, either by a - // putenv("LD_BIND_NOW=1") in parent process or ... (?). + sal_Int32 nIndex = 0; - try { - uno::Reference<container::XContentEnumerationAccess> xEnumAcc( - xContext->getServiceManager(), css::uno::UNO_QUERY_THROW); - uno::Reference<container::XHierarchicalNameAccess> xTypeMgr( - xContext->getValueByName( - "/singletons/com.sun.star.reflection.theTypeDescriptionManager"), - css::uno::UNO_QUERY_THROW); - uno::Sequence<OUString> aServiceNames( - xContext->getServiceManager()->getAvailableServiceNames()); - - for (sal_Int32 i = 0; i != aServiceNames.getLength(); ++i) + rtl::Bootstrap bs(aAppURL + "/" + SAL_CONFIGFILE("uno")); + if (bs.getHandle() == 0) + { + fprintf(stderr, "Cannot open uno ini '%s'\n", + OUStringToOString(aAppURL + "/" + SAL_CONFIGFILE("uno"), RTL_TEXTENCODING_UTF8).getStr()); + return; + } + + OUString aRdbFiles; + if (!bs.getFrom("UNO_SERVICES", aRdbFiles)) + { + fprintf(stderr, "Cannot obtain UNO_SERVICES from uno ini\n"); + return; + } + + while (nIndex != -1) + { + OUString aUriRdb(aRdbFiles.getToken(0, ' ', nIndex)); + + if (aUriRdb.isEmpty()) + continue; + + if (aUriRdb[0] == '?') + aUriRdb = aUriRdb.copy(1); + + if (aUriRdb.startsWith("<") && aUriRdb.endsWith(">*")) + { + aUriRdb = aUriRdb.copy(1, aUriRdb.getLength() - 3); + osl::Directory aDir(aUriRdb); + + if ( aDir.open() == osl::FileBase::E_None ) + { + while(true) + { + osl::DirectoryItem aDirItem; + + if ( aDir.getNextItem(aDirItem, SAL_MAX_UINT32) != osl::FileBase::E_None) + break; + + osl::FileStatus stat(osl_FileStatus_Mask_Type | + osl_FileStatus_Mask_FileName | + osl_FileStatus_Mask_FileURL); + + if (aDirItem.getFileStatus(stat) == osl::FileBase::E_None) + loadSharedLibrary(stat.getFileURL()); + } + } + else + { + fprintf(stderr, "Cannot open directory '%s'\n", + OUStringToOString(aUriRdb, RTL_TEXTENCODING_UTF8).getStr()); + } + + } + else { - css::uno::Reference<css::container::XEnumeration> xServiceImpls( - xEnumAcc->createContentEnumeration(aServiceNames[i]), - css::uno::UNO_SET_THROW); - SAL_INFO("lok", "service " << aServiceNames[i]); - // FIXME: need to actually load and link each native DSO. + loadSharedLibrary(aUriRdb); } - } catch (const uno::Exception &) { } } @@ -1072,7 +1167,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char if (eStage == PRE_INIT) { - forceLoadAllNativeComponents(); + forceLoadAllNativeComponents(aAppURL); forceLoadFilterXML(); } _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
