diff options
author | Michael Meeks <michael.meeks@suse.com> | 2013-03-05 13:16:36 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2013-03-12 15:35:33 +0000 |
commit | 8887de72c184bec6225a952ec90433ae1b7a5b26 (patch) | |
tree | f3d90d221b5eba49aa14ff713c7d11216935b233 /desktop/source | |
parent | 6ea685090806a2a2f39b8d5ec6a749eaf9b1856e (diff) |
liblibo: create initial liblibreoffice.
bootstrap libreoffice, start a dummy test-harness: can't use CppUnit
or link to any URE / LibreOffice libraries.
Change-Id: I855b640557f93959749e966a2d8e5e577fd84574
Diffstat (limited to 'desktop/source')
-rw-r--r-- | desktop/source/lib/init.cxx | 139 | ||||
-rw-r--r-- | desktop/source/lib/shim.cxx | 52 |
2 files changed, 191 insertions, 0 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx new file mode 100644 index 000000000000..5aab66bd42d2 --- /dev/null +++ b/desktop/source/lib/init.cxx @@ -0,0 +1,139 @@ +/* -*- 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 <liblibreoffice.h> +#include <tools/errinf.hxx> +#include <osl/file.hxx> +#include <rtl/strbuf.hxx> +#include <rtl/bootstrap.hxx> +#include <cppuhelper/bootstrap.hxx> +#include <comphelper/processfactory.hxx> + +#include <com/sun/star/lang/Locale.hpp> +#include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/ucb/XContentProvider.hpp> +#include <com/sun/star/ucb/XUniversalContentBroker.hpp> + +#include <vcl/svapp.hxx> +#include <tools/resmgr.hxx> +#include <vcl/graphicfilter.hxx> +#include <unotools/syslocaleoptions.hxx> + +using namespace ::com::sun::star; + +// Wonder global state ... +static uno::Reference<css::uno::XComponentContext> xContext; +static uno::Reference<css::lang::XMultiServiceFactory> xSFactory; +static uno::Reference<css::lang::XMultiComponentFactory> xFactory; + +SAL_DLLPUBLIC_EXPORT void +lo_error_free( LOError * ) +{ +} + +SAL_DLLPUBLIC_EXPORT LOError * +lo_error_new( int, const char * ) +{ + return NULL; +} + +SAL_DLLPUBLIC_EXPORT LODocument * +lo_document_load( const char *, LOError ** ) +{ + return NULL; +} + +SAL_DLLPUBLIC_EXPORT loboolean +lo_document_save( const char *, LOError ** ) +{ + return 1; +} + +static void +force_c_locale( void ) +{ + // force locale (and resource files loaded) to en-US + css::lang::Locale aLocale( "en", "US", ""); + ResMgr::SetDefaultLocale( aLocale ); + SvtSysLocaleOptions aLocalOptions; + OUString aLangISO( "en-US" ); + aLocalOptions.SetLocaleConfigString( aLangISO ); + aLocalOptions.SetUILocaleConfigString( aLangISO ); +} + +static void +aBasicErrorFunc( const OUString &rErr, const OUString &rAction ) +{ + OStringBuffer aErr( "Unexpected dialog: " ); + aErr.append( OUStringToOString( rAction, RTL_TEXTENCODING_ASCII_US ) ); + aErr.append( " Error: " ); + aErr.append( OUStringToOString( rErr, RTL_TEXTENCODING_ASCII_US ) ); + fprintf( stderr, "Unexpected basic error dialog '%s'\n", aErr.getStr() ); +} + +static void +initialize_uno( const rtl::OUString &aUserProfileURL ) +{ + // set UserInstallation to user profile dir in test/user-template + rtl::Bootstrap aDefaultVars; + aDefaultVars.set(rtl::OUString("UserInstallation"), aUserProfileURL ); + + xContext = comphelper::getProcessComponentContext(); + xFactory = xContext->getServiceManager(); + xSFactory = uno::Reference<lang::XMultiServiceFactory>(xFactory, uno::UNO_QUERY_THROW); +} + +SAL_DLLPUBLIC_EXPORT loboolean +lo_initialize( const char *app_path ) +{ + static bool bInitialized = false; + if( bInitialized ) + return true; + + if( !app_path ) + return false; + + OUString aAppPath( app_path, strlen( app_path ), RTL_TEXTENCODING_UTF8 ); + OUString aAppURL; + if( osl::FileBase::getFileURLFromSystemPath( aAppPath, aAppURL ) != + osl::FileBase::E_None ) + return false; + + try { + initialize_uno( aAppURL + "../registry" ); + force_c_locale(); + InitVCL(); + if (Application::IsHeadlessModeRequested()) + Application::EnableHeadlessMode(true); + + ErrorHandler::RegisterDisplay( aBasicErrorFunc ); + + fprintf (stderr, "do nothing yet"); + bInitialized = true; + } catch (css::uno::Exception & e) { + fprintf( stderr, "bootstrapping exception '%s'\n", + OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr() ); + } + return bInitialized; +} + +extern "C" { + SAL_DLLPUBLIC_EXPORT LibLibreOffice *liblibreoffice_hook(void); +} + +LibLibreOffice *liblibreoffice_hook(void) +{ + return new LibLibreOffice(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ + diff --git a/desktop/source/lib/shim.cxx b/desktop/source/lib/shim.cxx new file mode 100644 index 000000000000..c57803e588fa --- /dev/null +++ b/desktop/source/lib/shim.cxx @@ -0,0 +1,52 @@ +/* -*- 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/. + */ + +#ifdef LINUX + +#include <sal/types.h> +#include <liblibreoffice.h> + +#include <dlfcn.h> +#ifdef AIX +# include <sys/ldr.h> +#endif + +#define TARGET_LIB SAL_MODULENAME( "sofficeapp" ) + +extern "C" { + typedef LibLibreOffice *(HookFunction)(void); +}; + +extern LibLibreOffice *lo_init( const char *install_path ) +{ + if( !install_path ) + return NULL; + char *impl_lib = malloc( strlen (install_path) + sizeof( TARGET_LIB ) + 2 ); + strcpy( imp_lib, install_path ); + strcat( imp_lib, "/" ); + strcat( imp_lib, TARGET_LIB ); + void *dlhandle = dlopen( imp_lib, RTLD_LAZY ); + if( !dlhandle ) + { + fprintf( stderr, "failed to open library '%s'\n", imp_lib ); + return NULL; + } + free( imp_lib ); + + HookFunction *pSym = dlsym( dlhandle, "liblibreoffice_hook" ); + if( !pSym ) { + fprintf( stderr, "failed to find hook in library '%s'\n", imp_lib ); + return NULL; + } + return pSym(); +} + +#endif // LINUX - port me ! + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |