LCOV - code coverage report
Current view: top level - vcl/unx/generic/plugadapt - salplug.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 74 117 63.2 %
Date: 2012-08-25 Functions: 11 15 73.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 58 164 35.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "officecfg/Office/Common.hxx"
      30                 :            : 
      31                 :            : #include "comphelper/processfactory.hxx"
      32                 :            : 
      33                 :            : #include "osl/module.h"
      34                 :            : #include "osl/process.h"
      35                 :            : 
      36                 :            : #include "rtl/ustrbuf.hxx"
      37                 :            : 
      38                 :            : #include "salinst.hxx"
      39                 :            : #include "generic/gensys.h"
      40                 :            : #include "generic/gendata.hxx"
      41                 :            : #include "unx/desktops.hxx"
      42                 :            : #include "vcl/printerinfomanager.hxx"
      43                 :            : 
      44                 :            : #include <cstdio>
      45                 :            : #include <unistd.h>
      46                 :            : 
      47                 :            : using ::rtl::OUString;
      48                 :            : using ::rtl::OUStringBuffer;
      49                 :            : extern "C" {
      50                 :            : typedef SalInstance*(*salFactoryProc)( oslModule pModule);
      51                 :            : }
      52                 :            : 
      53                 :            : static oslModule pCloseModule = NULL;
      54                 :            : 
      55                 :        266 : static SalInstance* tryInstance( const OUString& rModuleBase, bool bForce = false )
      56                 :            : {
      57                 :        266 :     SalInstance* pInst = NULL;
      58                 :            : #if !defined(ANDROID)
      59 [ +  - ][ -  + ]:        266 :     if (!bForce && rModuleBase.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("gtk3")))
                 [ -  + ]
      60                 :            :     {
      61                 :            :         // Disable gtk3 plugin load except in experimental mode for now.
      62                 :            :         using namespace com::sun::star;
      63         [ #  # ]:          0 :         uno::Reference< uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
      64 [ #  # ][ #  # ]:          0 :         if (!xContext.is() || !officecfg::Office::Common::Misc::ExperimentalMode::get(xContext))
         [ #  # ][ #  # ]
      65         [ #  # ]:          0 :             return NULL;
      66                 :            :     }
      67                 :            : #endif
      68                 :        266 :     OUStringBuffer aModName( 128 );
      69         [ +  - ]:        266 :     aModName.appendAscii( SAL_DLLPREFIX"vclplug_" );
      70         [ +  - ]:        266 :     aModName.append( rModuleBase );
      71         [ +  - ]:        266 :     aModName.appendAscii( SAL_DLLPOSTFIX );
      72         [ +  - ]:        266 :     OUString aModule = aModName.makeStringAndClear();
      73                 :            : 
      74                 :            :     oslModule aMod = osl_loadModuleRelative(
      75                 :            :         reinterpret_cast< oslGenericFunction >( &tryInstance ), aModule.pData,
      76         [ +  - ]:        266 :         SAL_LOADMODULE_DEFAULT );
      77         [ +  - ]:        266 :     if( aMod )
      78                 :            :     {
      79         [ +  - ]:        266 :         salFactoryProc aProc = (salFactoryProc)osl_getAsciiFunctionSymbol( aMod, "create_SalInstance" );
      80         [ +  - ]:        266 :         if( aProc )
      81                 :            :         {
      82         [ +  - ]:        266 :             pInst = aProc( aMod );
      83                 :            : #if OSL_DEBUG_LEVEL > 1
      84                 :            :             std::fprintf( stderr, "sal plugin %s produced instance %p\n",
      85                 :            :                      OUStringToOString( aModule, RTL_TEXTENCODING_ASCII_US ).getStr(),
      86                 :            :                      pInst );
      87                 :            : #endif
      88         [ +  - ]:        266 :             if( pInst )
      89                 :            :             {
      90                 :        266 :                 pCloseModule = aMod;
      91                 :            : 
      92                 :            : #ifndef ANDROID
      93                 :            :                 /*
      94                 :            :                  * Recent GTK+ versions load their modules with RTLD_LOCAL, so we can
      95                 :            :                  * not access the 'gnome_accessibility_module_shutdown' anymore.
      96                 :            :                  * So make sure libgtk+ & co are still mapped into memory when
      97                 :            :                  * atk-bridge's atexit handler gets called.
      98                 :            :                  * #i109007# KDE3 seems to have the same problem.
      99                 :            :                  * And same applies for KDE4.
     100                 :            :                  */
     101 [ +  - ][ +  - ]:        266 :                 if( rModuleBase == "gtk" || rModuleBase == "gtk3" || rModuleBase == "tde" || rModuleBase == "kde" || rModuleBase == "kde4" )
         [ +  - ][ +  - ]
         [ -  + ][ -  + ]
     102                 :            :                 {
     103                 :          0 :                     pCloseModule = NULL;
     104                 :            :                 }
     105                 :            : #endif
     106         [ +  - ]:        266 :                 GetSalData()->m_pPlugin = aMod;
     107                 :            :             }
     108                 :            :             else
     109         [ #  # ]:          0 :                 osl_unloadModule( aMod );
     110                 :            :         }
     111                 :            :         else
     112                 :            :         {
     113                 :            : #if OSL_DEBUG_LEVEL > 1
     114                 :            :             std::fprintf( stderr, "could not load symbol %s from shared object %s\n",
     115                 :            :                      "create_SalInstance",
     116                 :            :                      OUStringToOString( aModule, RTL_TEXTENCODING_ASCII_US ).getStr() );
     117                 :            : #endif
     118         [ #  # ]:          0 :             osl_unloadModule( aMod );
     119                 :            :         }
     120                 :            :     }
     121                 :            : #if OSL_DEBUG_LEVEL > 1
     122                 :            :     else
     123                 :            :         std::fprintf( stderr, "could not load shared object %s\n",
     124                 :            :                  OUStringToOString( aModule, RTL_TEXTENCODING_ASCII_US ).getStr() );
     125                 :            : #endif
     126                 :            : 
     127                 :        266 :     return pInst;
     128                 :            : }
     129                 :            : 
     130                 :            : #if !defined(ANDROID)
     131                 :            : 
     132                 :        212 : static DesktopType get_desktop_environment()
     133                 :            : {
     134                 :        212 :     OUStringBuffer aModName( 128 );
     135         [ +  - ]:        212 :     aModName.appendAscii( SAL_DLLPREFIX"desktop_detector" );
     136         [ +  - ]:        212 :     aModName.appendAscii( SAL_DLLPOSTFIX );
     137         [ +  - ]:        212 :     OUString aModule = aModName.makeStringAndClear();
     138                 :            : 
     139                 :            :     oslModule aMod = osl_loadModuleRelative(
     140                 :            :         reinterpret_cast< oslGenericFunction >( &tryInstance ), aModule.pData,
     141         [ +  - ]:        212 :         SAL_LOADMODULE_DEFAULT );
     142                 :        212 :     DesktopType ret = DESKTOP_UNKNOWN;
     143         [ +  - ]:        212 :     if( aMod )
     144                 :            :     {
     145                 :            :         DesktopType (*pSym)() = (DesktopType(*)())
     146         [ +  - ]:        212 :             osl_getAsciiFunctionSymbol( aMod, "get_desktop_environment" );
     147         [ +  - ]:        212 :         if( pSym )
     148         [ +  - ]:        212 :             ret = pSym();
     149                 :            :     }
     150         [ +  - ]:        212 :     osl_unloadModule( aMod );
     151                 :        212 :     return ret;
     152                 :            : }
     153                 :            : 
     154                 :            : #else
     155                 :            : 
     156                 :            : #define get_desktop_environment() DESKTOP_NONE // For now...
     157                 :            : 
     158                 :            : #endif
     159                 :            : 
     160                 :          0 : static SalInstance* autodetect_plugin()
     161                 :            : {
     162                 :            :     static const char* pTDEFallbackList[] =
     163                 :            :     {
     164                 :            :         "tde", "kde4", "kde", "gtk3", "gtk", "gen", 0
     165                 :            :     };
     166                 :            : 
     167                 :            :     static const char* pKDEFallbackList[] =
     168                 :            :     {
     169                 :            :         "kde4", "kde", "gtk3", "gtk", "gen", 0
     170                 :            :     };
     171                 :            : 
     172                 :            :     static const char* pStandardFallbackList[] =
     173                 :            :     {
     174                 :            :         "gtk3", "gtk", "gen", 0
     175                 :            :     };
     176                 :            : 
     177                 :            :     static const char* pHeadlessFallbackList[] =
     178                 :            :     {
     179                 :            :         "svp", 0
     180                 :            :     };
     181                 :            : 
     182                 :          0 :     DesktopType desktop = get_desktop_environment();
     183                 :          0 :     const char ** pList = pStandardFallbackList;
     184                 :          0 :     int nListEntry = 0;
     185                 :            : 
     186                 :            :     // no server at all: dummy plugin
     187         [ #  # ]:          0 :     if ( desktop == DESKTOP_NONE )
     188                 :          0 :         pList = pHeadlessFallbackList;
     189         [ #  # ]:          0 :     else if ( desktop == DESKTOP_GNOME )
     190                 :          0 :         pList = pStandardFallbackList;
     191         [ #  # ]:          0 :     else if( desktop == DESKTOP_TDE )
     192                 :          0 :         pList = pTDEFallbackList;
     193         [ #  # ]:          0 :     else if( desktop == DESKTOP_KDE )
     194                 :            :     {
     195                 :          0 :         pList = pKDEFallbackList;
     196                 :          0 :         nListEntry = 1;
     197                 :            :     }
     198         [ #  # ]:          0 :     else if( desktop == DESKTOP_KDE4 )
     199                 :          0 :         pList = pKDEFallbackList;
     200                 :            : 
     201                 :          0 :     SalInstance* pInst = NULL;
     202 [ #  # ][ #  # ]:          0 :     while( pList[nListEntry] && pInst == NULL )
                 [ #  # ]
     203                 :            :     {
     204                 :          0 :         rtl::OUString aTry( rtl::OUString::createFromAscii( pList[nListEntry] ) );
     205         [ #  # ]:          0 :         pInst = tryInstance( aTry );
     206                 :            :         #if OSL_DEBUG_LEVEL > 1
     207                 :            :         if( pInst )
     208                 :            :             std::fprintf( stderr, "plugin autodetection: %s\n", pList[nListEntry] );
     209                 :            :         #endif
     210                 :          0 :         nListEntry++;
     211                 :          0 :     }
     212                 :            : 
     213                 :          0 :     return pInst;
     214                 :            : }
     215                 :            : 
     216                 :        266 : static SalInstance* check_headless_plugin()
     217                 :            : {
     218         [ +  - ]:        266 :     int nParams = osl_getCommandArgCount();
     219                 :        266 :     OUString aParam;
     220         [ +  - ]:       1326 :     for( int i = 0; i < nParams; i++ )
     221                 :            :     {
     222         [ +  - ]:       1326 :         osl_getCommandArg( i, &aParam.pData );
     223 [ +  - ][ +  + ]:       1326 :         if( aParam == "-headless" || aParam == "--headless" )
                 [ +  + ]
     224                 :            :         {
     225 [ +  - ][ +  - ]:        266 :             return tryInstance( OUString( RTL_CONSTASCII_USTRINGPARAM( "svp" ) ) );
     226                 :            :         }
     227                 :            :     }
     228                 :        266 :     return NULL;
     229                 :            : }
     230                 :            : 
     231                 :        266 : SalInstance *CreateSalInstance()
     232                 :            : {
     233                 :        266 :     SalInstance*    pInst = NULL;
     234                 :            : 
     235 [ +  - ][ +  - ]:        266 :     static const char* pUsePlugin = getenv( "SAL_USE_VCLPLUGIN" );
     236                 :            : 
     237         [ +  - ]:        266 :     pInst = check_headless_plugin();
     238                 :            : 
     239 [ -  + ][ #  # ]:        266 :     if( !pInst && pUsePlugin && *pUsePlugin )
                 [ #  # ]
     240         [ #  # ]:          0 :         pInst = tryInstance( OUString::createFromAscii( pUsePlugin ), true );
     241                 :            : 
     242         [ -  + ]:        266 :     if( ! pInst )
     243         [ #  # ]:          0 :         pInst = autodetect_plugin();
     244                 :            : 
     245                 :            :     // fallback, try everything
     246                 :        266 :     const char* pPlugin[] = { "gtk3", "gtk", "kde4", "kde", "tde", "gen", 0 };
     247                 :            : 
     248 [ -  + ][ #  # ]:        266 :     for ( int i = 0; !pInst && pPlugin[ i ]; ++i )
                 [ -  + ]
     249         [ #  # ]:          0 :         pInst = tryInstance( OUString::createFromAscii( pPlugin[ i ] ) );
     250                 :            : 
     251         [ -  + ]:        266 :     if( ! pInst )
     252                 :            :     {
     253         [ #  # ]:          0 :         std::fprintf( stderr, "no suitable windowing system found, exiting.\n" );
     254                 :          0 :         _exit( 1 );
     255                 :            :     }
     256                 :            : 
     257                 :            :     // acquire SolarMutex
     258         [ +  - ]:        266 :     pInst->AcquireYieldMutex( 1 );
     259                 :            : 
     260                 :        266 :     return pInst;
     261                 :            : }
     262                 :            : 
     263                 :        158 : void DestroySalInstance( SalInstance *pInst )
     264                 :            : {
     265                 :            :     // release SolarMutex
     266                 :        158 :     pInst->ReleaseYieldMutex();
     267                 :            : 
     268         [ +  - ]:        158 :     delete pInst;
     269         [ +  - ]:        158 :     if( pCloseModule )
     270                 :        158 :         osl_unloadModule( pCloseModule );
     271                 :        158 : }
     272                 :            : 
     273                 :        266 : void InitSalData()
     274                 :            : {
     275                 :        266 : }
     276                 :            : 
     277                 :        158 : void DeInitSalData()
     278                 :            : {
     279                 :        158 : }
     280                 :            : 
     281                 :        266 : void InitSalMain()
     282                 :            : {
     283                 :        266 : }
     284                 :            : 
     285                 :        158 : void DeInitSalMain()
     286                 :            : {
     287                 :        158 : }
     288                 :            : 
     289                 :          0 : void SalAbort( const rtl::OUString& rErrorText, bool bDumpCore )
     290                 :            : {
     291         [ #  # ]:          0 :     if( rErrorText.isEmpty() )
     292                 :          0 :         std::fprintf( stderr, "Application Error\n" );
     293                 :            :     else
     294         [ #  # ]:          0 :         std::fprintf( stderr, "%s\n", rtl::OUStringToOString(rErrorText, osl_getThreadTextEncoding()).getStr() );
     295         [ #  # ]:          0 :     if( bDumpCore )
     296                 :          0 :         abort();
     297                 :            :     else
     298                 :          0 :         _exit(1);
     299                 :            : }
     300                 :            : 
     301                 :            : static const char * desktop_strings[] = { "none", "unknown", "GNOME", "TDE", "KDE", "KDE4" };
     302                 :            : 
     303                 :        434 : const OUString& SalGetDesktopEnvironment()
     304                 :            : {
     305 [ +  + ][ +  - ]:        434 :     static rtl::OUString aRet;
     306         [ +  + ]:        434 :     if( aRet.isEmpty())
     307                 :            :     {
     308                 :        212 :         rtl::OUStringBuffer buf( 8 );
     309 [ +  - ][ +  - ]:        212 :         buf.appendAscii( desktop_strings[ get_desktop_environment() ] );
     310         [ +  - ]:        212 :         aRet = buf.makeStringAndClear();
     311                 :            :     }
     312                 :        434 :     return aRet;
     313                 :            : }
     314                 :            : 
     315                 :        266 : SalData::SalData() :
     316                 :            :     m_pInstance(NULL),
     317                 :            :     m_pPlugin(NULL),
     318                 :        266 :     m_pPIManager(NULL)
     319                 :            : {
     320                 :        266 : }
     321                 :            : 
     322                 :          0 : SalData::~SalData()
     323                 :            : {
     324                 :          0 :     psp::PrinterInfoManager::release();
     325         [ #  # ]:          0 : }
     326                 :            : 
     327                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10