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

Stub initial pre-init phase.

Change-Id: I92d172a166606189ce386826eee566623ec4a83c
üst c35958c5
......@@ -42,6 +42,8 @@
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/ucb/XContentProvider.hpp>
#include <com/sun/star/ucb/XUniversalContentBroker.hpp>
#include <com/sun/star/container/XContentEnumerationAccess.hpp>
#include <com/sun/star/container/XHierarchicalNameAccess.hpp>
#include <vcl/svapp.hxx>
#include <vcl/svpforlokit.hxx>
......@@ -964,17 +966,69 @@ static void lo_status_indicator_callback(void *data, comphelper::LibreOfficeKit:
}
}
/// pre-load all C++ component factories and leak references to them.
static void forceLoadAllNativeComponents()
{
// FIXME: we need to inject RTLD_NOW into here, either by a
// putenv("LD_BIND_NOW=1") in parent process or ... (?).
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)
{
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.
}
} catch (const uno::Exception &) {
}
}
/// pre-load and parse all filter XML
static void forceLoadFilterXML()
{
}
static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char* pUserProfilePath)
{
enum {
PRE_INIT, // setup shared data in master process
SECOND_INIT, // complete init. after fork
FULL_INIT // do a standard complete init.
} eStage;
// Did we do a pre-initialize
static bool bPreInited = false;
// What stage are we at ?
if (pThis == NULL)
eStage = PRE_INIT;
else if (bPreInited)
eStage = SECOND_INIT;
else
eStage = FULL_INIT;
LibLibreOffice_Impl* pLib = static_cast<LibLibreOffice_Impl*>(pThis);
if (bInitialized)
return 1;
comphelper::LibreOfficeKit::setActive();
comphelper::LibreOfficeKit::setStatusIndicatorCallback(lo_status_indicator_callback, pLib);
if (eStage != SECOND_INIT)
comphelper::LibreOfficeKit::setActive();
if (eStage != PRE_INIT)
comphelper::LibreOfficeKit::setStatusIndicatorCallback(lo_status_indicator_callback, pLib);
if (pUserProfilePath)
if (eStage != SECOND_INIT && pUserProfilePath)
rtl::Bootstrap::set(OUString("UserInstallation"), OUString(pUserProfilePath, strlen(pUserProfilePath), RTL_TEXTENCODING_UTF8));
OUString aAppPath;
......@@ -997,22 +1051,30 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
try
{
SAL_INFO("lok", "Attempting to initalize UNO");
if (!initialize_uno(aAppURL))
if (eStage != SECOND_INIT)
{
return false;
}
force_c_locale();
SAL_INFO("lok", "Attempting to initalize UNO");
// Force headless -- this is only for bitmap rendering.
rtl::Bootstrap::set("SAL_USE_VCLPLUGIN", "svp");
if (!initialize_uno(aAppURL))
return false;
force_c_locale();
// We specifically need to make sure we have the "headless"
// command arg set (various code specifically checks via
// CommandLineArgs):
desktop::Desktop::GetCommandLineArgs().setHeadless();
// Force headless -- this is only for bitmap rendering.
rtl::Bootstrap::set("SAL_USE_VCLPLUGIN", "svp");
Application::EnableHeadlessMode(true);
// We specifically need to make sure we have the "headless"
// command arg set (various code specifically checks via
// CommandLineArgs):
desktop::Desktop::GetCommandLineArgs().setHeadless();
Application::EnableHeadlessMode(true);
}
if (eStage == PRE_INIT)
{
forceLoadAllNativeComponents();
forceLoadFilterXML();
}
// This is horrible crack. I really would want to go back to simply just call
// InitVCL() here. The OfficeIPCThread thing is just horrible.
......@@ -1033,27 +1095,34 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath, const char
// the Thread from wherever (it's done again in Desktop::Main), and can
// then use it to wait until we're definitely ready to continue.
SAL_INFO("lok", "Enabling OfficeIPCThread");
OfficeIPCThread::EnableOfficeIPCThread();
SAL_INFO("lok", "Starting soffice_main");
pLib->maThread = osl_createThread(lo_startmain, NULL);
SAL_INFO("lok", "Waiting for OfficeIPCThread");
OfficeIPCThread::WaitForReady();
SAL_INFO("lok", "OfficeIPCThread ready -- continuing");
// If the Thread has been disabled again that indicates that a
// restart is required (or in any case we don't have a useable
// process around).
if (!OfficeIPCThread::IsEnabled())
if (eStage != PRE_INIT)
{
fprintf(stderr, "LOK init failed -- restart required\n");
return false;
SAL_INFO("lok", "Enabling OfficeIPCThread");
OfficeIPCThread::EnableOfficeIPCThread();
SAL_INFO("lok", "Starting soffice_main");
pLib->maThread = osl_createThread(lo_startmain, NULL);
SAL_INFO("lok", "Waiting for OfficeIPCThread");
OfficeIPCThread::WaitForReady();
SAL_INFO("lok", "OfficeIPCThread ready -- continuing");
// If the Thread has been disabled again that indicates that a
// restart is required (or in any case we don't have a useable
// process around).
if (!OfficeIPCThread::IsEnabled())
{
fprintf(stderr, "LOK init failed -- restart required\n");
return false;
}
}
ErrorHandler::RegisterDisplay(aBasicErrorFunc);
if (eStage != SECOND_INIT)
ErrorHandler::RegisterDisplay(aBasicErrorFunc);
SAL_INFO("lok", "LOK Initialized");
bInitialized = true;
if (eStage == PRE_INIT)
bPreInited = true;
else
bInitialized = true;
}
catch (css::uno::Exception& exception)
{
......@@ -1088,10 +1157,10 @@ LibreOfficeKit *libreofficekit_hook(const char* install_path)
}
SAL_JNI_EXPORT
int lok_preinit()
int lok_preinit(const char* install_path, const char* user_profile_path)
{
SAL_INFO("lok", "Hello World");
return 0;
return lo_initialize(NULL, install_path, user_profile_path);
}
static void lo_destroy(LibreOfficeKit* pThis)
......
......@@ -83,7 +83,29 @@ int main (int argc, char **argv)
return 1;
// coverity[tainted_string] - build time test tool
Office *pOffice = lok_cpp_init( argv[1] );
char *install_path = argv[1];
if( argc > 4 )
{
fprintf( stderr, "testing preinit\n");
char *imp_lib;
void *dlhandle;
dlhandle = lok_dlopen( install_path, &imp_lib );
if( !dlhandle )
{
fprintf( stderr, "Failed to link '%s'\n", lok_dlerror() );
return -1;
}
LokHookPreInit *preinit = (LokHookPreInit *) lok_dlsym( dlhandle, "lok_preinit" );
if( !preinit )
{
fprintf( stderr, "Failed to find pre-init symbol: %s\n", lok_dlerror() );
return -1;
}
preinit( install_path, NULL );
}
Office *pOffice = lok_cpp_init( install_path );
if( !pOffice )
{
fprintf( stderr, "Failed to initialize\n" );
......
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