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

Generated by: LCOV version 1.10