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

Generated by: LCOV version 1.10