LCOV - code coverage report
Current view: top level - libreoffice/bridges/source/cpp_uno/shared - component.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 80 86 93.0 %
Date: 2012-12-27 Functions: 10 11 90.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "component.hxx"
      22             : 
      23             : #include "bridges/cpp_uno/shared/bridge.hxx"
      24             : 
      25             : #include "com/sun/star/uno/Reference.hxx"
      26             : #include "com/sun/star/uno/RuntimeException.hpp"
      27             : #include "com/sun/star/uno/XInterface.hpp"
      28             : #include "osl/diagnose.h"
      29             : #include "osl/mutex.hxx"
      30             : #include "osl/time.h"
      31             : #include "rtl/process.h"
      32             : #include "rtl/unload.h"
      33             : #include "rtl/ustrbuf.hxx"
      34             : #include "rtl/ustring.h"
      35             : #include "rtl/ustring.hxx"
      36             : #include "sal/types.h"
      37             : #include "uno/environment.h"
      38             : #include "uno/lbnames.h"
      39             : #include "uno/mapping.h"
      40             : #include "cppu/EnvDcp.hxx"
      41             : 
      42             : namespace bridges { namespace cpp_uno { namespace shared {
      43             : 
      44             : rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
      45             : 
      46             : } } }
      47             : 
      48             : namespace {
      49             : 
      50             : #if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) \
      51             :     || (defined(__GNUC__) && defined(__APPLE__))
      52             : static OUString * s_pStaticOidPart = 0;
      53             : #endif
      54             : 
      55        1857 : const OUString & SAL_CALL cppu_cppenv_getStaticOIdPart() SAL_THROW(())
      56             : {
      57             : #if ! ((defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) \
      58             :     || (defined(__GNUC__) && defined(__APPLE__)))
      59             :     static OUString * s_pStaticOidPart = 0;
      60             : #endif
      61        1857 :     if (! s_pStaticOidPart)
      62             :     {
      63          18 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
      64          18 :         if (! s_pStaticOidPart)
      65             :         {
      66          18 :             OUStringBuffer aRet( 64 );
      67          18 :             aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM("];") );
      68             :             // good guid
      69             :             sal_uInt8 ar[16];
      70          18 :             ::rtl_getGlobalProcessId( ar );
      71         306 :             for ( sal_Int32 i = 0; i < 16; ++i )
      72             :             {
      73         288 :                 aRet.append( (sal_Int32)ar[i], 16 );
      74             :             }
      75             : #if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) \
      76             :     || (defined(__GNUC__) && defined(__APPLE__))
      77             :             s_pStaticOidPart = new OUString( aRet.makeStringAndClear() );
      78             : #else
      79             :             static OUString s_aStaticOidPart(
      80          18 :                 aRet.makeStringAndClear() );
      81          18 :             s_pStaticOidPart = &s_aStaticOidPart;
      82             : #endif
      83          18 :         }
      84             :     }
      85        1857 :     return *s_pStaticOidPart;
      86             : }
      87             : 
      88             : }
      89             : 
      90             : extern "C" {
      91             : 
      92        1857 : static void s_stub_computeObjectIdentifier(va_list * pParam)
      93             :     SAL_THROW(())
      94             : {
      95        1857 :     uno_ExtEnvironment  * pEnv       = va_arg(*pParam, uno_ExtEnvironment *);
      96        1857 :     rtl_uString        ** ppOId      = va_arg(*pParam, rtl_uString **);
      97        1857 :     void                * pInterface = va_arg(*pParam, void *);
      98             : 
      99             : 
     100             :     OSL_ENSURE( pEnv && ppOId && pInterface, "### null ptr!" );
     101        1857 :     if (pEnv && ppOId && pInterface)
     102             :     {
     103        1857 :         if (*ppOId)
     104             :         {
     105           0 :             rtl_uString_release( *ppOId );
     106           0 :             *ppOId = 0;
     107             :         }
     108             : 
     109             :         try
     110             :         {
     111             :             ::com::sun::star::uno::Reference<
     112             :                   ::com::sun::star::uno::XInterface > xHome(
     113             :                       reinterpret_cast< ::com::sun::star::uno::XInterface * >(
     114             :                           pInterface ),
     115        1857 :                       ::com::sun::star::uno::UNO_QUERY );
     116             :             OSL_ENSURE( xHome.is(), "### query to XInterface failed!" );
     117        1857 :             if (xHome.is())
     118             :             {
     119             :                 // interface
     120        1857 :                 OUStringBuffer oid( 64 );
     121        1857 :                 oid.append( reinterpret_cast< sal_Int64 >(xHome.get()), 16 );
     122        1857 :                 oid.append( (sal_Unicode)';' );
     123             :                 // ;environment[context]
     124             :                 oid.append(
     125             :                     *reinterpret_cast< OUString const * >(
     126        1857 :                         &((uno_Environment *) pEnv)->pTypeName ) );
     127        1857 :                 oid.append( (sal_Unicode)'[' );
     128             :                 oid.append(
     129             :                     reinterpret_cast< sal_Int64 >(
     130             :                         ((uno_Environment *)pEnv)->pContext),
     131        1857 :                     16 );
     132             :                 // ];good guid
     133        1857 :                 oid.append( cppu_cppenv_getStaticOIdPart() );
     134        1857 :                 OUString aRet( oid.makeStringAndClear() );
     135        1857 :                 ::rtl_uString_acquire( *ppOId = aRet.pData );
     136        1857 :             }
     137             :         }
     138           0 :         catch (const ::com::sun::star::uno::RuntimeException &)
     139             :         {
     140             :             OSL_FAIL(
     141             :                 "### RuntimeException occurred during queryInterface()!" );
     142             :         }
     143             :     }
     144        1857 : }
     145             : 
     146        1857 : static void SAL_CALL computeObjectIdentifier(
     147             :     uno_ExtEnvironment * pExtEnv, rtl_uString ** ppOId, void * pInterface )
     148             :     SAL_THROW(())
     149             : {
     150        1857 :     uno_Environment_invoke(&pExtEnv->aBase, s_stub_computeObjectIdentifier, pExtEnv, ppOId, pInterface);
     151        1857 : }
     152             : 
     153       14298 : static void s_stub_acquireInterface(va_list * pParam)
     154             :     SAL_THROW(())
     155             : {
     156       14298 :     /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
     157       14298 :     void               * pCppI   = va_arg(*pParam, void *);
     158             : 
     159       14298 :     reinterpret_cast< ::com::sun::star::uno::XInterface * >( pCppI )->acquire();
     160       14298 : }
     161             : 
     162       14298 : static void SAL_CALL acquireInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
     163             :     SAL_THROW(())
     164             : {
     165       14298 :     uno_Environment_invoke(&pExtEnv->aBase, s_stub_acquireInterface, pExtEnv, pCppI);
     166       14298 : }
     167             : 
     168       11009 : static void s_stub_releaseInterface(va_list * pParam)
     169             :     SAL_THROW(())
     170             : {
     171       11009 :     /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
     172       11009 :     void               * pCppI   = va_arg(*pParam, void *);
     173             : 
     174       11009 :     reinterpret_cast< ::com::sun::star::uno::XInterface * >( pCppI )->release();
     175       11009 : }
     176             : 
     177       11009 : static void SAL_CALL releaseInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
     178             :     SAL_THROW(())
     179             : {
     180       11009 :     uno_Environment_invoke(&pExtEnv->aBase, s_stub_releaseInterface, pExtEnv, pCppI);
     181       11009 : }
     182             : 
     183        4394 : static void SAL_CALL environmentDisposing(
     184             :     SAL_UNUSED_PARAMETER uno_Environment * ) SAL_THROW(())
     185             : {
     186             :     bridges::cpp_uno::shared::g_moduleCount.modCnt.release(
     187        4394 :         &bridges::cpp_uno::shared::g_moduleCount.modCnt );
     188        4394 : }
     189             : 
     190             : #ifndef DISABLE_DYNLOADING
     191             : 
     192           0 : SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_canUnload(TimeValue * pTime) SAL_THROW_EXTERN_C() {
     193             :     return bridges::cpp_uno::shared::g_moduleCount.canUnload(
     194           0 :         &bridges::cpp_uno::shared::g_moduleCount, pTime);
     195             : }
     196             : 
     197             : #endif
     198             : 
     199             : #ifdef DISABLE_DYNLOADING
     200             : #define uno_initEnvironment CPPU_ENV_uno_initEnvironment
     201             : #endif
     202             : 
     203        4425 : SAL_DLLPUBLIC_EXPORT void SAL_CALL uno_initEnvironment(uno_Environment * pCppEnv)
     204             :     SAL_THROW_EXTERN_C()
     205             : {
     206             :     OSL_ENSURE( pCppEnv->pExtEnv, "### expected extended environment!" );
     207             :     OSL_ENSURE(
     208             :         ::rtl_ustr_ascii_compare_WithLength(
     209             :              pCppEnv->pTypeName->buffer, rtl_str_getLength(CPPU_CURRENT_LANGUAGE_BINDING_NAME), CPPU_CURRENT_LANGUAGE_BINDING_NAME )
     210             :         == 0,
     211             :         "### wrong environment type!" );
     212             :     bridges::cpp_uno::shared::g_moduleCount.modCnt.acquire(
     213        4425 :         &bridges::cpp_uno::shared::g_moduleCount.modCnt );
     214             :     ((uno_ExtEnvironment *)pCppEnv)->computeObjectIdentifier
     215        4425 :         = computeObjectIdentifier;
     216        4425 :     ((uno_ExtEnvironment *)pCppEnv)->acquireInterface = acquireInterface;
     217        4425 :     ((uno_ExtEnvironment *)pCppEnv)->releaseInterface = releaseInterface;
     218        4425 :     pCppEnv->environmentDisposing = environmentDisposing;
     219        4425 : }
     220             : 
     221             : #ifdef DISABLE_DYNLOADING
     222             : #define uno_ext_getMapping CPPU_ENV_uno_ext_getMapping
     223             : #endif
     224             : 
     225        1838 : SAL_DLLPUBLIC_EXPORT void SAL_CALL uno_ext_getMapping(
     226             :     uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo)
     227             :     SAL_THROW_EXTERN_C()
     228             : {
     229             :     OSL_ASSERT( ppMapping && pFrom && pTo );
     230        1838 :     if (ppMapping && pFrom && pTo && pFrom->pExtEnv && pTo->pExtEnv)
     231             :     {
     232        1838 :         uno_Mapping * pMapping = 0;
     233             : 
     234        1838 :         OUString from_envTypeName(cppu::EnvDcp::getTypeName(pFrom->pTypeName));
     235        1838 :         OUString to_envTypeName(cppu::EnvDcp::getTypeName(pTo->pTypeName));
     236             : 
     237        1926 :         if (0 == rtl_ustr_ascii_compare(
     238             :                 from_envTypeName.pData->buffer,
     239        1838 :                 CPPU_CURRENT_LANGUAGE_BINDING_NAME ) &&
     240             :             0 == rtl_ustr_ascii_compare(
     241          88 :                 to_envTypeName.pData->buffer, UNO_LB_UNO ))
     242             :         {
     243             :             // ref count initially 1
     244             :             pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
     245          88 :                 pFrom->pExtEnv, pTo->pExtEnv, sal_True );
     246             :             ::uno_registerMapping(
     247             :                 &pMapping, bridges::cpp_uno::shared::freeMapping,
     248             :                 (uno_Environment *)pFrom->pExtEnv,
     249          88 :                 (uno_Environment *)pTo->pExtEnv, 0 );
     250             :         }
     251        3500 :         else if (0 == rtl_ustr_ascii_compare(
     252             :                      to_envTypeName.pData->buffer,
     253        1750 :                      CPPU_CURRENT_LANGUAGE_BINDING_NAME ) &&
     254             :                  0 == rtl_ustr_ascii_compare(
     255        1750 :                      from_envTypeName.pData->buffer, UNO_LB_UNO ))
     256             :         {
     257             :             // ref count initially 1
     258             :             pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
     259        1750 :                 pTo->pExtEnv, pFrom->pExtEnv, sal_False );
     260             :             ::uno_registerMapping(
     261             :                 &pMapping, bridges::cpp_uno::shared::freeMapping,
     262             :                 (uno_Environment *)pFrom->pExtEnv,
     263        1750 :                 (uno_Environment *)pTo->pExtEnv, 0 );
     264             :         }
     265             : 
     266        1838 :         if (*ppMapping)
     267             :         {
     268           0 :             (*(*ppMapping)->release)( *ppMapping );
     269             :         }
     270        1838 :         if (pMapping)
     271        1838 :         *ppMapping = pMapping;
     272             :     }
     273        1838 : }
     274             : 
     275             : }
     276             : 
     277             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10