LCOV - code coverage report
Current view: top level - bridges/source/cpp_uno/shared - component.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 78 82 95.1 %
Date: 2014-11-03 Functions: 10 10 100.0 %
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             : #include "bridges/cpp_uno/shared/bridge.hxx"
      21             : 
      22             : #include "com/sun/star/uno/Reference.hxx"
      23             : #include "com/sun/star/uno/RuntimeException.hpp"
      24             : #include "com/sun/star/uno/XInterface.hpp"
      25             : #include "osl/diagnose.h"
      26             : #include "osl/mutex.hxx"
      27             : #include "osl/time.h"
      28             : #include "rtl/process.h"
      29             : #include "rtl/ustrbuf.hxx"
      30             : #include "rtl/ustring.h"
      31             : #include "rtl/ustring.hxx"
      32             : #include "sal/types.h"
      33             : #include "uno/environment.h"
      34             : #include "uno/lbnames.h"
      35             : #include "uno/mapping.h"
      36             : #include "cppu/EnvDcp.hxx"
      37             : 
      38             : namespace bridges { namespace cpp_uno { namespace shared {
      39             : 
      40             : } } }
      41             : 
      42             : namespace {
      43             : 
      44             : #if (defined(__GNUC__) && defined(__APPLE__))
      45             : static OUString * s_pStaticOidPart = 0;
      46             : #endif
      47             : 
      48      165470 : const OUString & SAL_CALL cppu_cppenv_getStaticOIdPart()
      49             : {
      50             : #if ! (defined(__GNUC__) && defined(__APPLE__))
      51             :     static OUString * s_pStaticOidPart = 0;
      52             : #endif
      53      165470 :     if (! s_pStaticOidPart)
      54             :     {
      55         311 :         ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
      56         311 :         if (! s_pStaticOidPart)
      57             :         {
      58         311 :             OUStringBuffer aRet( 64 );
      59         311 :             aRet.append( "];" );
      60             :             // good guid
      61             :             sal_uInt8 ar[16];
      62         311 :             ::rtl_getGlobalProcessId( ar );
      63        5287 :             for ( sal_Int32 i = 0; i < 16; ++i )
      64             :             {
      65        4976 :                 aRet.append( (sal_Int32)ar[i], 16 );
      66             :             }
      67             : #if (defined(__GNUC__) && defined(__APPLE__))
      68             :             s_pStaticOidPart = new OUString( aRet.makeStringAndClear() );
      69             : #else
      70             :             static OUString s_aStaticOidPart(
      71         311 :                 aRet.makeStringAndClear() );
      72         311 :             s_pStaticOidPart = &s_aStaticOidPart;
      73             : #endif
      74         311 :         }
      75             :     }
      76      165470 :     return *s_pStaticOidPart;
      77             : }
      78             : 
      79             : }
      80             : 
      81             : extern "C" {
      82             : 
      83      165470 : static void s_stub_computeObjectIdentifier(va_list * pParam)
      84             : {
      85      165470 :     uno_ExtEnvironment  * pEnv       = va_arg(*pParam, uno_ExtEnvironment *);
      86      165470 :     rtl_uString        ** ppOId      = va_arg(*pParam, rtl_uString **);
      87      165470 :     void                * pInterface = va_arg(*pParam, void *);
      88             : 
      89             : 
      90             :     OSL_ENSURE( pEnv && ppOId && pInterface, "### null ptr!" );
      91      165470 :     if (pEnv && ppOId && pInterface)
      92             :     {
      93      165470 :         if (*ppOId)
      94             :         {
      95           0 :             rtl_uString_release( *ppOId );
      96           0 :             *ppOId = 0;
      97             :         }
      98             : 
      99             :         try
     100             :         {
     101             :             ::com::sun::star::uno::Reference<
     102             :                   ::com::sun::star::uno::XInterface > xHome(
     103             :                       reinterpret_cast< ::com::sun::star::uno::XInterface * >(
     104             :                           pInterface ),
     105      165470 :                       ::com::sun::star::uno::UNO_QUERY );
     106             :             OSL_ENSURE( xHome.is(), "### query to XInterface failed!" );
     107      165470 :             if (xHome.is())
     108             :             {
     109             :                 // interface
     110      165470 :                 OUStringBuffer oid( 64 );
     111      165470 :                 oid.append( reinterpret_cast< sal_Int64 >(xHome.get()), 16 );
     112      165470 :                 oid.append( ';' );
     113             :                 // ;environment[context]
     114             :                 oid.append(
     115             :                     *reinterpret_cast< OUString const * >(
     116      165470 :                         &((uno_Environment *) pEnv)->pTypeName ) );
     117      165470 :                 oid.append( '[' );
     118             :                 oid.append(
     119             :                     reinterpret_cast< sal_Int64 >(
     120             :                         ((uno_Environment *)pEnv)->pContext),
     121      165470 :                     16 );
     122             :                 // ];good guid
     123      165470 :                 oid.append( cppu_cppenv_getStaticOIdPart() );
     124      330940 :                 OUString aRet( oid.makeStringAndClear() );
     125      330940 :                 ::rtl_uString_acquire( *ppOId = aRet.pData );
     126      165470 :             }
     127             :         }
     128           0 :         catch (const ::com::sun::star::uno::RuntimeException &)
     129             :         {
     130             :             OSL_FAIL(
     131             :                 "### RuntimeException occurred during queryInterface()!" );
     132             :         }
     133             :     }
     134      165470 : }
     135             : 
     136      165470 : static void SAL_CALL computeObjectIdentifier(
     137             :     uno_ExtEnvironment * pExtEnv, rtl_uString ** ppOId, void * pInterface )
     138             : {
     139      165470 :     uno_Environment_invoke(&pExtEnv->aBase, s_stub_computeObjectIdentifier, pExtEnv, ppOId, pInterface);
     140      165470 : }
     141             : 
     142      279589 : static void s_stub_acquireInterface(va_list * pParam)
     143             : {
     144      279589 :     /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
     145      279589 :     void               * pCppI   = va_arg(*pParam, void *);
     146             : 
     147      279589 :     reinterpret_cast< ::com::sun::star::uno::XInterface * >( pCppI )->acquire();
     148      279589 : }
     149             : 
     150      279589 : static void SAL_CALL acquireInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
     151             : {
     152      279589 :     uno_Environment_invoke(&pExtEnv->aBase, s_stub_acquireInterface, pExtEnv, pCppI);
     153      279589 : }
     154             : 
     155      164801 : static void s_stub_releaseInterface(va_list * pParam)
     156             : {
     157      164801 :     /*uno_ExtEnvironment * pExtEnv = */va_arg(*pParam, uno_ExtEnvironment *);
     158      164801 :     void               * pCppI   = va_arg(*pParam, void *);
     159             : 
     160      164801 :     reinterpret_cast< ::com::sun::star::uno::XInterface * >( pCppI )->release();
     161      164801 : }
     162             : 
     163      164801 : static void SAL_CALL releaseInterface( uno_ExtEnvironment * pExtEnv, void * pCppI )
     164             : {
     165      164801 :     uno_Environment_invoke(&pExtEnv->aBase, s_stub_releaseInterface, pExtEnv, pCppI);
     166      164801 : }
     167             : 
     168        2606 : static void SAL_CALL environmentDisposing(
     169             :     SAL_UNUSED_PARAMETER uno_Environment * )
     170             : {
     171        2606 : }
     172             : 
     173             : #ifdef DISABLE_DYNLOADING
     174             : #define uno_initEnvironment CPPU_ENV_uno_initEnvironment
     175             : #endif
     176             : 
     177        2985 : SAL_DLLPUBLIC_EXPORT void SAL_CALL uno_initEnvironment(uno_Environment * pCppEnv)
     178             :     SAL_THROW_EXTERN_C()
     179             : {
     180             :     OSL_ENSURE( pCppEnv->pExtEnv, "### expected extended environment!" );
     181             :     OSL_ENSURE(
     182             :         ::rtl_ustr_ascii_compare_WithLength(
     183             :              pCppEnv->pTypeName->buffer, rtl_str_getLength(CPPU_CURRENT_LANGUAGE_BINDING_NAME), CPPU_CURRENT_LANGUAGE_BINDING_NAME )
     184             :         == 0,
     185             :         "### wrong environment type!" );
     186             :     ((uno_ExtEnvironment *)pCppEnv)->computeObjectIdentifier
     187        2985 :         = computeObjectIdentifier;
     188        2985 :     ((uno_ExtEnvironment *)pCppEnv)->acquireInterface = acquireInterface;
     189        2985 :     ((uno_ExtEnvironment *)pCppEnv)->releaseInterface = releaseInterface;
     190        2985 :     pCppEnv->environmentDisposing = environmentDisposing;
     191        2985 : }
     192             : 
     193             : #ifdef DISABLE_DYNLOADING
     194             : #define uno_ext_getMapping CPPU_ENV_uno_ext_getMapping
     195             : #endif
     196             : 
     197       16815 : SAL_DLLPUBLIC_EXPORT void SAL_CALL uno_ext_getMapping(
     198             :     uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo)
     199             :     SAL_THROW_EXTERN_C()
     200             : {
     201             :     OSL_ASSERT( ppMapping && pFrom && pTo );
     202       16815 :     if (ppMapping && pFrom && pTo && pFrom->pExtEnv && pTo->pExtEnv)
     203             :     {
     204       16815 :         uno_Mapping * pMapping = 0;
     205             : 
     206       16815 :         OUString from_envTypeName(cppu::EnvDcp::getTypeName(pFrom->pTypeName));
     207       33630 :         OUString to_envTypeName(cppu::EnvDcp::getTypeName(pTo->pTypeName));
     208             : 
     209       16815 :         if (0 == rtl_ustr_ascii_compare(
     210             :                 from_envTypeName.pData->buffer,
     211       18277 :                 CPPU_CURRENT_LANGUAGE_BINDING_NAME ) &&
     212             :             0 == rtl_ustr_ascii_compare(
     213        1462 :                 to_envTypeName.pData->buffer, UNO_LB_UNO ))
     214             :         {
     215             :             // ref count initially 1
     216             :             pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
     217        1462 :                 pFrom->pExtEnv, pTo->pExtEnv, true );
     218             :             ::uno_registerMapping(
     219             :                 &pMapping, bridges::cpp_uno::shared::freeMapping,
     220             :                 (uno_Environment *)pFrom->pExtEnv,
     221        1462 :                 (uno_Environment *)pTo->pExtEnv, 0 );
     222             :         }
     223       15353 :         else if (0 == rtl_ustr_ascii_compare(
     224             :                      to_envTypeName.pData->buffer,
     225       30706 :                      CPPU_CURRENT_LANGUAGE_BINDING_NAME ) &&
     226             :                  0 == rtl_ustr_ascii_compare(
     227       15353 :                      from_envTypeName.pData->buffer, UNO_LB_UNO ))
     228             :         {
     229             :             // ref count initially 1
     230             :             pMapping = bridges::cpp_uno::shared::Bridge::createMapping(
     231       15353 :                 pTo->pExtEnv, pFrom->pExtEnv, false );
     232             :             ::uno_registerMapping(
     233             :                 &pMapping, bridges::cpp_uno::shared::freeMapping,
     234             :                 (uno_Environment *)pFrom->pExtEnv,
     235       15353 :                 (uno_Environment *)pTo->pExtEnv, 0 );
     236             :         }
     237             : 
     238       16815 :         if (*ppMapping)
     239             :         {
     240           0 :             (*(*ppMapping)->release)( *ppMapping );
     241             :         }
     242       16815 :         if (pMapping)
     243       33630 :         *ppMapping = pMapping;
     244             :     }
     245       16815 : }
     246             : 
     247             : }
     248             : 
     249             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10