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

Generated by: LCOV version 1.11