diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-09-13 12:23:36 +0200 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2018-10-02 11:24:38 +0200 |
commit | 0f3be2e19fa408d7069d586ccf04cb3f3eccd6b9 (patch) | |
tree | 7cd14806e1098bdc08cfc84f0e00480f8d09dc68 /vcl/unx/generic | |
parent | 3af4e1a0825c5b11ae4ef58fc411378aab669387 (diff) |
Unify sal plugin loaders
Change-Id: Ic099761eaff80349e985ccf62e3f4aa6b2e98022
Reviewed-on: https://gerrit.libreoffice.org/61103
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
Diffstat (limited to 'vcl/unx/generic')
-rw-r--r-- | vcl/unx/generic/plugadapt/salplug.cxx | 319 |
1 files changed, 0 insertions, 319 deletions
diff --git a/vcl/unx/generic/plugadapt/salplug.cxx b/vcl/unx/generic/plugadapt/salplug.cxx deleted file mode 100644 index bce722b6ed6c..000000000000 --- a/vcl/unx/generic/plugadapt/salplug.cxx +++ /dev/null @@ -1,319 +0,0 @@ -/* -*- 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/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <osl/module.hxx> -#include <osl/process.h> - -#include <rtl/bootstrap.hxx> -#include <rtl/process.h> -#include <sal/log.hxx> - -#include <salinst.hxx> -#include <unx/gensys.h> -#include <unx/gendata.hxx> -#include <headless/svpinst.hxx> -#include <unx/desktops.hxx> -#include <printerinfomanager.hxx> -#include <config_vclplug.h> -#include <desktop/crashreport.hxx> - -#include <cstdio> -#include <unistd.h> - -extern "C" { -typedef SalInstance*(*salFactoryProc)(); -} - -namespace { - -// HACK to obtain Application::IsHeadlessModeEnabled early on, before -// Application::EnableHeadlessMode has potentially been called: -bool IsHeadlessModeRequested() -{ - if (Application::IsHeadlessModeEnabled()) { - return true; - } - sal_uInt32 n = rtl_getAppCommandArgCount(); - for (sal_uInt32 i = 0; i < n; ++i) { - OUString arg; - rtl_getAppCommandArg(i, &arg.pData); - if ( arg == "--headless" || arg == "-headless" ) { - return true; - } - } - return false; -} - -} - -static oslModule pCloseModule = nullptr; - -static SalInstance* tryInstance( const OUString& rModuleBase, bool bForce = false ) -{ - if (rModuleBase == "svp") - return svp_create_SalInstance(); - - SalInstance* pInst = nullptr; - OUString aModule( -#ifdef SAL_DLLPREFIX - SAL_DLLPREFIX -#endif - "vclplug_" + rModuleBase + "lo" SAL_DLLEXTENSION ); - - osl::Module aMod; - if (aMod.loadRelative(reinterpret_cast<oslGenericFunction>(&tryInstance), aModule, SAL_LOADMODULE_GLOBAL)) - { - salFactoryProc aProc = reinterpret_cast<salFactoryProc>(aMod.getFunctionSymbol("create_SalInstance")); - if (aProc) - { - pInst = aProc(); - SAL_INFO( - "vcl.plugadapt", - "sal plugin " << aModule << " produced instance " << pInst); - if (pInst) - { - pCloseModule = static_cast<oslModule>(aMod); - aMod.release(); - -#ifndef ANDROID - /* - * Recent GTK+ versions load their modules with RTLD_LOCAL, so we can - * not access the 'gnome_accessibility_module_shutdown' anymore. - * So make sure libgtk+ & co are still mapped into memory when - * atk-bridge's atexit handler gets called. - * #i109007# KDE3 seems to have the same problem. - * And same applies for KDE4. - */ - if( rModuleBase == "gtk" || rModuleBase == "gtk3" || rModuleBase == "kde4" || rModuleBase == "gtk3_kde5") - { - pCloseModule = nullptr; - } -#endif - } - } - else - { - SAL_WARN( - "vcl.plugadapt", - "could not load symbol create_SalInstance from shared object " - << aModule); - } - } - else if (bForce) - { - SAL_WARN("vcl.plugadapt", "could not load shared object " << aModule); - } - else - { - SAL_INFO("vcl.plugadapt", "could not load shared object " << aModule); - } - - // coverity[leaked_storage] - this is on purpose - return pInst; -} - -#if !defined(ANDROID) - -namespace { - -extern "C" typedef DesktopType Fn_get_desktop_environment(); - -} - -static DesktopType get_desktop_environment() -{ - OUString aModule(DESKTOP_DETECTOR_DLL_NAME); - oslModule aMod = osl_loadModuleRelative( - reinterpret_cast< oslGenericFunction >( &tryInstance ), aModule.pData, - SAL_LOADMODULE_DEFAULT ); - DesktopType ret = DESKTOP_UNKNOWN; - if( aMod ) - { - Fn_get_desktop_environment * pSym - = reinterpret_cast<Fn_get_desktop_environment *>( - osl_getAsciiFunctionSymbol(aMod, "get_desktop_environment")); - if( pSym ) - ret = pSym(); - } - osl_unloadModule( aMod ); - return ret; -} - -#else - -#define get_desktop_environment() DESKTOP_NONE // For now... - -#endif - -static SalInstance* autodetect_plugin() -{ - static const char* const pKDEFallbackList[] = - { -#if ENABLE_KDE5 - "kde5", -#endif -#if ENABLE_GTK3_KDE5 - "gtk3_kde5", -#endif -#if ENABLE_KDE4 - "kde4", -#endif - "gtk3", "gtk", "gen", nullptr - }; - - static const char* const pStandardFallbackList[] = - { - "gtk3", "gtk", "gen", nullptr - }; - - static const char* const pHeadlessFallbackList[] = - { - "svp", nullptr - }; - - DesktopType desktop = get_desktop_environment(); - const char * const * pList = pStandardFallbackList; - int nListEntry = 0; - - // no server at all: dummy plugin - if ( desktop == DESKTOP_NONE ) - pList = pHeadlessFallbackList; - else if ( desktop == DESKTOP_GNOME || - desktop == DESKTOP_UNITY || - desktop == DESKTOP_XFCE || - desktop == DESKTOP_MATE ) - pList = pStandardFallbackList; - else if( desktop == DESKTOP_KDE4 || desktop == DESKTOP_KDE5 ) - pList = pKDEFallbackList; - - SalInstance* pInst = nullptr; - while( pList[nListEntry] && pInst == nullptr ) - { - OUString aTry( OUString::createFromAscii( pList[nListEntry] ) ); - pInst = tryInstance( aTry ); - SAL_INFO_IF( - pInst, "vcl.plugadapt", - "plugin autodetection: " << pList[nListEntry]); - nListEntry++; - } - - return pInst; -} - -SalInstance *CreateSalInstance() -{ - SalInstance *pInst = nullptr; - - OUString aUsePlugin; - if( IsHeadlessModeRequested() ) - aUsePlugin = "svp"; - else - { - rtl::Bootstrap::get( "SAL_USE_VCLPLUGIN", aUsePlugin ); - } - - if( !aUsePlugin.isEmpty() ) - pInst = tryInstance( aUsePlugin, true ); - - if( ! pInst ) - pInst = autodetect_plugin(); - - // fallback, try everything - static const char* const pPlugin[] = { - "gtk3", "gtk", "kde5", "kde4", "gen" }; - - for ( int i = 0; !pInst && i != SAL_N_ELEMENTS(pPlugin); ++i ) - pInst = tryInstance( OUString::createFromAscii( pPlugin[ i ] ) ); - - if( ! pInst ) - { - std::fprintf( stderr, "no suitable windowing system found, exiting.\n" ); - _exit( 1 ); - } - - // acquire SolarMutex - pInst->AcquireYieldMutex(); - - return pInst; -} - -void DestroySalInstance( SalInstance *pInst ) -{ - // release SolarMutex - pInst->ReleaseYieldMutexAll(); - - delete pInst; - if( pCloseModule ) - osl_unloadModule( pCloseModule ); -} - -void InitSalData() -{ -} - -void DeInitSalData() -{ -} - -void InitSalMain() -{ -} - -void SalAbort( const OUString& rErrorText, bool bDumpCore ) -{ - if( rErrorText.isEmpty() ) - std::fprintf( stderr, "Application Error\n" ); - else - { - CrashReporter::AddKeyValue("AbortMessage", rErrorText); - std::fprintf( stderr, "%s\n", OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr() ); - } - if( bDumpCore ) - abort(); - else - _exit(1); -} - -const OUString& SalGetDesktopEnvironment() -{ - // Order to match desktops.hxx' DesktopType - static const char * const desktop_strings[] = { - "none", "unknown", "GNOME", "UNITY", - "XFCE", "MATE", "KDE4", "KDE5" }; - static OUString aRet; - if( aRet.isEmpty()) - { - aRet = OUString::createFromAscii( - desktop_strings[get_desktop_environment()]); - } - return aRet; -} - -SalData::SalData() : - m_pInstance(nullptr), - m_pPIManager(nullptr) -{ -} - -SalData::~SalData() COVERITY_NOEXCEPT_FALSE -{ - psp::PrinterInfoManager::release(); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |