[Libreoffice-commits] core.git: Branch 'feature/lok_sofficemain' - 12 commits - desktop/Library_sofficeapp.mk desktop/source libreofficekit/CppunitTest_libreofficekit_tiledrendering.mk libreofficekit/Executable_lokconf_init.mk libreofficekit/Module_libreofficekit.mk libreofficekit/qa Repository.mk sd/source solenv/gbuild

Andrzej Hunt andrzej.hunt at collabora.com
Sat Jul 26 07:06:25 PDT 2014


Rebased ref, commits from common ancestor:
commit f412bf91a5f3c60197168b7baef1a8f058f6236b
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Fri Jul 25 21:03:19 2014 +0200

    Make sure LOK is actually headless.
    
    This prevents e.g. the document recovery dialog from trying to be shown.
    
    Change-Id: I253720f7fa1abd1c053670434f8394473517b670

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 567f5ae..b73e4e2 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -626,13 +626,24 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
 
     try
     {
+        // We specifically need to make sure we have the "headless"
+        // command arg set (various code specifically checks via
+        // CommandLineArgs). We could alternatively add some other
+        // flag elsewhere to indicate headlessness, which would
+        // then be set from here or via CommandLineArgs.
+        // (The first argument is treated specially by osl_setCommandArgs
+        // however it is valid to make it \0 instead.)
+        char sName[] = "";
+        char sHeadless[] = "--headless";
+        char* pArgs[2] = { sName, sHeadless };
+
         // If we've set up the command args elsewhere then we cannot do it
         // again (as an assert will fire), this will be the case e.g.
         // for unit tests (and possibly if UNO is being used in addition
         // to LOK in an external program).
         if (!osl_areCommandArgsSet())
         {
-            osl_setCommandArgs(0, NULL);
+            osl_setCommandArgs(2, pArgs);
         }
         initialize_uno(aAppURL);
         force_c_locale();
commit ceda3f60f3ba92b4e99651d0ba9da310e0cb081c
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Fri Jul 25 20:56:18 2014 +0200

    Don't fail on --protector.
    
    If we have any "unknown" command line arguments Desktop init will fail,
    however our LOK Tiled Rendering test uses Desktop (via soffice_main).
    (Other unit tests don't use soffice_main hence this check never
    comes into play.) It looks like it's most reliable simply to ignore
    --protector here, rather than try to filter it out elsewhere (which
    is difficult as it is passed to osl via SAL_IMPLEMENT_MAIN).
    
    Change-Id: I95d047892851ba2cf9edd2e26bacc6efa0320f71

diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx
index 5f98e07..a0eefbe 100644
--- a/desktop/source/app/cmdlineargs.cxx
+++ b/desktop/source/app/cmdlineargs.cxx
@@ -252,6 +252,18 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier )
             {
                 m_helpmath = true;
             }
+            else if ( oArg == "protector" )
+            {
+                // Not relevant for us here, but can be used in unit tests.
+                // Usually unit tests would not end up here, but e.g. the
+                // LOK Tiled Rendering tests end up running a full soffice
+                // process, and we can't bail on the use of --protector.
+
+                // We specifically need to consume the following 2 arguments
+                // for --protector
+                assert( supplier.next( &aArg ) );
+                assert( supplier.next( &aArg ) );
+            }
             else if ( oArg == "version" )
             {
                 m_version = true;
commit d62e9fa1df9b948b3583ce6b7f6508f15215a31a
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Mon Jul 21 21:16:09 2014 +0200

    Don't start Impress Remote server in headless mode.
    
    Change-Id: Ibafe57413a60745e949dc3146fbc843c52c029d6

diff --git a/sd/source/ui/remotecontrol/Server.cxx b/sd/source/ui/remotecontrol/Server.cxx
index 5ec1184..69e5292 100644
--- a/sd/source/ui/remotecontrol/Server.cxx
+++ b/sd/source/ui/remotecontrol/Server.cxx
@@ -360,6 +360,21 @@ void RemoteServer::deauthoriseClient( ::boost::shared_ptr< ClientInfo > pClient
 void SdDLL::RegisterRemotes()
 {
     SAL_INFO( "sdremote", "SdDLL::RegisterRemotes called" );
+
+    // The remote server is likely of no use in headless mode. And as only
+    // one instance of the server can actually own the appropriate ports its
+    // probably best to not even try to do so from our headless instance
+    // (i.e. as to avoid blocking expected usage).
+    // It could perhaps be argued that we would still need the remote
+    // server for tiled rendering of presentations, but even then this
+    // implementation would not be of much use, i.e. would be controlling
+    // the purely imaginary headless presentation -- instead we'd need
+    // to have some sort of mechanism of plugging in our tiled rendering
+    // client to be controlled by the remote server, or provide an
+    // alternative implementation.
+    if ( Application::IsHeadlessModeEnabled() )
+        return;
+
     uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
     if ( xContext.is()  && !officecfg::Office::Impress::Misc::Start::EnableSdremote::get( xContext ) )
         return;
commit 8ce73d21b69eda11de619cad8a87df2c14eb95ac
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Mon Jul 21 19:36:11 2014 +0200

    Use gb_CppunitTest_use_confpreinit for LOK tiled rendering.
    
    Now that we use the event loop for LOK we need to make sure that
    it is able to run successfully first time, as unit tests start
    with a completely clean config.
    
    Change-Id: If9ddcb75fe8286381d71ecdc76ac7eb3697960d0

diff --git a/libreofficekit/CppunitTest_libreofficekit_tiledrendering.mk b/libreofficekit/CppunitTest_libreofficekit_tiledrendering.mk
index 4b77fbf..9159a24 100644
--- a/libreofficekit/CppunitTest_libreofficekit_tiledrendering.mk
+++ b/libreofficekit/CppunitTest_libreofficekit_tiledrendering.mk
@@ -29,7 +29,6 @@ $(eval $(call gb_CppunitTest_use_libraries,libreofficekit_tiledrendering, \
 	$(gb_UWINAPI) \
 ))
 
-
 # 	unotest \
 
 ifeq ($(OS),LINUX)
@@ -54,4 +53,6 @@ $(eval $(call gb_CppunitTest_use_rdb,libreofficekit_tiledrendering,services))
 
 $(eval $(call gb_CppunitTest_use_configuration,libreofficekit_tiledrendering))
 
+$(eval $(call gb_CppunitTest_use_confpreinit,libreofficekit_tiledrendering))
+
 # vim: set noet sw=4 ts=4:
commit 3e6c1dd9fcac00c0d4366cd4774fb1ee81dbe3cd
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Mon Jul 21 19:35:13 2014 +0200

    Add gb_CppunitTest_use_confpreinit:
    
    For unit tests that use the VCL event loop we can use this to
    avoid the otherwise required restart.
    
    Change-Id: I48265d7e7188a4efaa6f87432c762320331c0c78

diff --git a/solenv/gbuild/CppunitTest.mk b/solenv/gbuild/CppunitTest.mk
index df5c61b..66dcb05 100644
--- a/solenv/gbuild/CppunitTest.mk
+++ b/solenv/gbuild/CppunitTest.mk
@@ -75,6 +75,8 @@ $(call gb_CppunitTest_get_target,%) :| $(gb_CppunitTest_CPPTESTDEPS)
 	$(call gb_Helper_abbreviate_dirs,\
 		mkdir -p $(dir $@) && \
 		rm -fr $@.user && mkdir $@.user && \
+		$(if $(gb_CppunitTest__use_confpreinit), \
+		    $(INSTDIR)/program/lokconf_init $(call gb_CppunitTest__make_args) &&) \
 		$(if $(gb_CppunitTest__interactive),, \
 			$(if $(value gb_CppunitTest_postprocess), \
 				rm -fr $@.core && mkdir $@.core && cd $@.core &&)) \
@@ -166,6 +168,12 @@ endif
 
 endef
 
+define gb_CppunitTest_use_confpreinit
+$(call gb_CppunitTest_use_executable,$(1),lokconf_init)
+$(call gb_CppunitTest_get_target,$(1)) : gb_CppunitTest__use_confpreinit := TRUE
+
+endef
+
 define gb_CppunitTest_use_vcl
 $(call gb_CppunitTest__use_vcl,$(1),$(true))
 
commit c632efde58625a2644a33666d5e8e04833a43e80
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Mon Jul 21 19:34:09 2014 +0200

    Implement lokconf_init.
    
    This is a simple executable which can be used to ensure there is a
    pe-pared configuration for unit-tests to avoid the usually required
    re-start on the first run.
    
    Change-Id: I49b706e8daa93bc34db508a24615b63b9babddba

diff --git a/Repository.mk b/Repository.mk
index 10c8f62..e678db5 100644
--- a/Repository.mk
+++ b/Repository.mk
@@ -101,6 +101,7 @@ $(eval $(call gb_Helper_register_executables,OOO, \
 	uri-encode \
 	ui-previewer \
 	tiledrendering \
+	$(if $(filter LINUX,$(OS)), lokconf_init) \
 	$(if $(and $(ENABLE_GTK), $(filter LINUX,$(OS))), gtktiledviewer) \
 	$(if $(filter DESKTOP,$(BUILD_TYPE)),unopkg_bin) \
 	xpdfimport \
diff --git a/libreofficekit/Executable_lokconf_init.mk b/libreofficekit/Executable_lokconf_init.mk
new file mode 100644
index 0000000..3e25f13
--- /dev/null
+++ b/libreofficekit/Executable_lokconf_init.mk
@@ -0,0 +1,42 @@
+# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
+#
+# This file is part of the LibreOffice project.
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+
+$(eval $(call gb_Executable_Executable,lokconf_init))
+
+$(eval $(call gb_Executable_set_include,lokconf_init,\
+    $$(INCLUDE) \
+))
+
+$(eval $(call gb_Executable_use_libraries,lokconf_init, \
+	cppu \
+	sal \
+))
+
+$(eval $(call gb_Executable_use_static_libraries,lokconf_init,\
+    libreofficekit \
+))
+
+$(eval $(call gb_Executable_add_libs,lokconf_init,\
+    -lSM \
+    -lICE \
+))
+
+ifeq ($(OS),LINUX)
+$(eval $(call gb_Executable_add_libs,lokconf_init,\
+    -lm \
+    -ldl \
+    -lpthread \
+))
+endif
+
+$(eval $(call gb_Executable_add_exception_objects,lokconf_init,\
+    libreofficekit/qa/lokconf_init/lokconf_init \
+))
+
+# vim: set noet sw=4 ts=4:
diff --git a/libreofficekit/Module_libreofficekit.mk b/libreofficekit/Module_libreofficekit.mk
index 1f0771c..8523b1a 100644
--- a/libreofficekit/Module_libreofficekit.mk
+++ b/libreofficekit/Module_libreofficekit.mk
@@ -13,6 +13,7 @@ ifeq ($(OS),LINUX)
 
 $(eval $(call gb_Module_add_targets,libreofficekit,\
     StaticLibrary_libreofficekit \
+    Executable_lokconf_init \
 ))
 
 # $(eval $(call gb_Module_add_check_targets,libreofficekit,\
diff --git a/libreofficekit/qa/lokconf_init/lokconf_init.cxx b/libreofficekit/qa/lokconf_init/lokconf_init.cxx
new file mode 100644
index 0000000..9677159
--- /dev/null
+++ b/libreofficekit/qa/lokconf_init/lokconf_init.cxx
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <stdio.h>
+#include <string>
+#include <string.h>
+
+#include <sal/main.h>
+
+#include <LibreOfficeKit/LibreOfficeKit.h>
+
+using namespace std;
+
+// Using SAL_IMPLEMENT_MAIN means that we can directly use the same
+// arguments as would be provided to cppunittester, i.e. ensuring
+// that we're operating with the correct directories etc.
+SAL_IMPLEMENT_MAIN()
+{
+    string sPath( getenv("INSTDIR") );
+    sPath += "/program";
+
+    LibreOfficeKit* pOffice = lok_init( sPath.c_str() );
+
+    // As this is the first init, pOffice should be NULL.
+    // However there's no reason we shouldn't be able to operate
+    // even if it isn't the first init.
+    if ( pOffice )
+    {
+        pOffice->pClass->destroy( pOffice );
+        pOffice = 0;
+    }
+    return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
commit abbb40ffedc3a102573d412cf3c706be4612a5f3
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Fri Jul 18 13:12:25 2014 +0200

    Fail LOK initialisation if restart is required.
    
    Change-Id: Ia13a3523666147f002b5a5177fd6962d55556f56

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 76d05f3..567f5ae 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -661,6 +661,15 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
         pthread_create(&thread, 0, lo_startmain, NULL);
         OfficeIPCThread::WaitForReady();
 
+        // 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;
+        }
+
         Application::EnableHeadlessMode(true);
 
         ErrorHandler::RegisterDisplay(aBasicErrorFunc);
commit eea31395bb68bc57c69147a2870d0e59e11c6756
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Fri Jul 18 13:10:14 2014 +0200

    Add OfficeIPCThread::IsEnabled.
    
    This lets us easily check whether Desktop::Main has shut down,
    i.e. which happens on the first restart-requiring initialisation.
    
    Change-Id: I7fe5699a4bf59e2c3b891ac73abd9b147773d22e

diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index 93cd339..eaacf81 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -681,6 +681,11 @@ void OfficeIPCThread::WaitForReady(
     }
 }
 
+bool OfficeIPCThread::IsEnabled()
+{
+    return pGlobalOfficeIPCThread.is();
+}
+
 void OfficeIPCThread::execute()
 {
 #if HAVE_FEATURE_DESKTOP
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index 9c1d751..8ed40fd 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -128,6 +128,7 @@ class OfficeIPCThread : public salhelper::Thread
     static void                 WaitForReady(
         rtl::Reference< OfficeIPCThread > const & pThread =
             rtl::Reference< OfficeIPCThread >());
+    static bool                 IsEnabled();
 
     bool                        AreRequestsEnabled() const { return mbRequestsEnabled && ! mbDowning; }
 };
commit d5360279be56da750c1e9890340e8c62df073f08
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Fri Jul 18 10:02:48 2014 +0200

    Use OfficeIPCThread::WaitForReady rather than sleeping.
    
    This way we actually continue when we're ready to, rather than
    dumbly hoping we wait for long enough.
    
    This isn't entirely unproblematic though -- if we have no config
    pre-prepared (i.e. first-run), then we just end up hanging on this
    since soffice_main exits without doing anything to the OfficeIPCThread.
    (Which is especially problematic for unit tests which specifically run
     on an empty config.)
    
    Change-Id: I064fb500a224cfe37a0d3ba24b6154ffd72a71a3

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 0be5f8d..76d05f3 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -60,8 +60,10 @@
 
 // We also need to hackily be able to start the main libreoffice thread
 #include "../app/sofficemain.h"
+#include "../app/officeipcthread.hxx"
 
 using namespace css;
+using namespace desktop;
 using namespace utl;
 
 using namespace boost;
@@ -637,22 +639,27 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
 
         // Force headless -- this is only for bitmap rendering.
         rtl::Bootstrap::set("SAL_USE_VCLPLUGIN", "svp");
-//         InitVCL();
-        // InitVCL() happens in soffice_main for us -- and we can't call InitVCL twice
-        // unfortunately -- which is annoying since (see below)
 
+        // We could use InitVCL() here -- and used to before using soffice_main,
+        // however that now deals with the initialisation for us (and it's not
+        // possible to try to set up VCL twice.
+
+        // Instead VCL init is done for us by soffice_main in a separate thread,
+        // however we specifically can't proceed until this setup is complete
+        // (or you get segfaults trying to use VCL and/or deadlocks due to other
+        //  setup within soffice_main). Specifically the various Application::
+        // functions depend on VCL being ready -- the deadlocks would happen
+        // if you try to use loadDocument too early.
+
+        // The OfficeIPCThread is specifically set to be read when all the other
+        // init in Desktop::Main (run from soffice_main) is done. We can "enable"
+        // 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.
+
+        OfficeIPCThread::EnableOfficeIPCThread();
         pthread_t thread;
         pthread_create(&thread, 0, lo_startmain, NULL);
-        sleep(10);
-        // We'll segfault trying to access Application if we're too fast...
-        // Specifically pImplSVData doesn't exist until InitVCL has been called,
-        // and that won't be immediate, but we can't call InitVCL ourselves
-        // as soffice_main already does so, but InitVCL would then fail
-        // within soffice_main if we have already called it earlier.
-        //
-        // And there's also a chance of deadlock if we try to open documents
-        // too early -- when running in a debugger we therefore need quite
-        // a large delay here (for now).
+        OfficeIPCThread::WaitForReady();
 
         Application::EnableHeadlessMode(true);
 
commit 484084bad2e12caeefd38f6bdd0cfc0e094e668b
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Fri Jul 18 10:00:42 2014 +0200

    Bin outdated / incorrect comment.
    
    Change-Id: I7b8f97377b9606a2228f172f772d8051a64703d2

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index e9a1eed..0be5f8d 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -635,10 +635,7 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
         initialize_uno(aAppURL);
         force_c_locale();
 
-        // Force headless
-        // the "svp" headless vcl backend isn't able to do tiled rendering for
-        // us -- we need to use a full featured backend, i.e. "gen" or "gtk",
-        // gtk seems to be somewhat better.
+        // Force headless -- this is only for bitmap rendering.
         rtl::Bootstrap::set("SAL_USE_VCLPLUGIN", "svp");
 //         InitVCL();
         // InitVCL() happens in soffice_main for us -- and we can't call InitVCL twice
commit a3f17741188eeac728d14f564c8d64e00a48041d
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Fri Jul 18 09:48:47 2014 +0200

    Add OfficeIPCThread::WaitForReady.
    
    For LibreOfficeKit we need to start up the event loop, and can't continue
    initialisation until all the related (VCL etc.) setup is complete -- the
    OfficeIPCThread is also enabled as one of the last items, and can be
    used to indicate whether or not we can start actually working with VCL.
    
    Change-Id: I0450b65584ddf6e8d02ce0c6e66e06f47841d1b7

diff --git a/desktop/source/app/officeipcthread.cxx b/desktop/source/app/officeipcthread.cxx
index aed17b9..93cd339 100644
--- a/desktop/source/app/officeipcthread.cxx
+++ b/desktop/source/app/officeipcthread.cxx
@@ -669,6 +669,18 @@ void OfficeIPCThread::SetReady(
     }
 }
 
+void OfficeIPCThread::WaitForReady(
+    rtl::Reference< OfficeIPCThread > const & pThread)
+
+{
+    rtl::Reference< OfficeIPCThread > const & t(
+        pThread.is() ? pThread : pGlobalOfficeIPCThread);
+    if (t.is())
+    {
+        t->cReady.wait();
+    }
+}
+
 void OfficeIPCThread::execute()
 {
 #if HAVE_FEATURE_DESKTOP
diff --git a/desktop/source/app/officeipcthread.hxx b/desktop/source/app/officeipcthread.hxx
index 4628eca..9c1d751 100644
--- a/desktop/source/app/officeipcthread.hxx
+++ b/desktop/source/app/officeipcthread.hxx
@@ -125,6 +125,9 @@ class OfficeIPCThread : public salhelper::Thread
     static void                 SetReady(
         rtl::Reference< OfficeIPCThread > const & pThread =
             rtl::Reference< OfficeIPCThread >());
+    static void                 WaitForReady(
+        rtl::Reference< OfficeIPCThread > const & pThread =
+            rtl::Reference< OfficeIPCThread >());
 
     bool                        AreRequestsEnabled() const { return mbRequestsEnabled && ! mbDowning; }
 };
commit ec721f5cd397b0e2ad8f69ce27844e9177ecf96e
Author: Andrzej Hunt <andrzej.hunt at collabora.com>
Date:   Sat Jul 26 16:06:04 2014 +0200

    Hack soffice_main into LOK.
    
    Change-Id: I86e13192ddb5904afabca38d3a201f17f145de09

diff --git a/desktop/Library_sofficeapp.mk b/desktop/Library_sofficeapp.mk
index be86dd1..a90bcd1 100644
--- a/desktop/Library_sofficeapp.mk
+++ b/desktop/Library_sofficeapp.mk
@@ -17,6 +17,13 @@ $(eval $(call gb_Library_set_include,sofficeapp,\
     -I$(SRCDIR)/vcl/inc \
 ))
 
+$(eval $(call gb_Library_add_libs,sofficeapp,\
+    $(if $(filter $(OS),LINUX), \
+        -ldl \
+        -lpthread \
+    ) \
+))
+
 $(eval $(call gb_Library_use_external,sofficeapp,boost_headers))
 
 $(eval $(call gb_Library_use_custom_headers,sofficeapp,\
@@ -47,6 +54,7 @@ $(eval $(call gb_Library_use_libraries,sofficeapp,\
     sfx \
     svl \
     svt \
+    sw \
     tk \
     tl \
     ucbhelper \
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 6c4d5cc..e9a1eed 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -58,6 +58,9 @@
 #include <basebmp/bitmapdevice.hxx>
 #endif
 
+// We also need to hackily be able to start the main libreoffice thread
+#include "../app/sofficemain.h"
+
 using namespace css;
 using namespace utl;
 
@@ -587,6 +590,12 @@ static void initialize_uno(const OUString &aAppProgramURL)
     // configmgr setup ?
 }
 
+static void* lo_startmain(void*)
+{
+    soffice_main();
+    return 0;
+}
+
 static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
 {
     (void) pThis;
@@ -627,8 +636,27 @@ static int lo_initialize(LibreOfficeKit* pThis, const char* pAppPath)
         force_c_locale();
 
         // Force headless
+        // the "svp" headless vcl backend isn't able to do tiled rendering for
+        // us -- we need to use a full featured backend, i.e. "gen" or "gtk",
+        // gtk seems to be somewhat better.
         rtl::Bootstrap::set("SAL_USE_VCLPLUGIN", "svp");
-        InitVCL();
+//         InitVCL();
+        // InitVCL() happens in soffice_main for us -- and we can't call InitVCL twice
+        // unfortunately -- which is annoying since (see below)
+
+        pthread_t thread;
+        pthread_create(&thread, 0, lo_startmain, NULL);
+        sleep(10);
+        // We'll segfault trying to access Application if we're too fast...
+        // Specifically pImplSVData doesn't exist until InitVCL has been called,
+        // and that won't be immediate, but we can't call InitVCL ourselves
+        // as soffice_main already does so, but InitVCL would then fail
+        // within soffice_main if we have already called it earlier.
+        //
+        // And there's also a chance of deadlock if we try to open documents
+        // too early -- when running in a debugger we therefore need quite
+        // a large delay here (for now).
+
         Application::EnableHeadlessMode(true);
 
         ErrorHandler::RegisterDisplay(aBasicErrorFunc);


More information about the Libreoffice-commits mailing list