LCOV - code coverage report
Current view: top level - bridges/source/cpp_uno/shared - unointerfaceproxy.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 37 37 100.0 %
Date: 2014-04-11 Functions: 6 6 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/unointerfaceproxy.hxx"
      21             : 
      22             : #include "bridges/cpp_uno/shared/bridge.hxx"
      23             : 
      24             : #include "com/sun/star/uno/XInterface.hpp"
      25             : #include "osl/diagnose.h"
      26             : #include "osl/interlck.h"
      27             : #include "typelib/typedescription.h"
      28             : #include "uno/dispatcher.h"
      29             : 
      30             : namespace bridges { namespace cpp_uno { namespace shared {
      31             : 
      32       81938 : void freeUnoInterfaceProxy(uno_ExtEnvironment * pEnv, void * pProxy)
      33             : {
      34             :     UnoInterfaceProxy * pThis =
      35             :         static_cast< UnoInterfaceProxy * >(
      36       81938 :             reinterpret_cast< uno_Interface * >( pProxy ) );
      37       81938 :     if (pEnv != pThis->pBridge->getUnoEnv()) {
      38             :         OSL_ASSERT(false);
      39             :     }
      40             : 
      41       81938 :     (*pThis->pBridge->getCppEnv()->revokeInterface)(
      42       81938 :         pThis->pBridge->getCppEnv(), pThis->pCppI );
      43       81938 :     pThis->pCppI->release();
      44             :     ::typelib_typedescription_release(
      45       81938 :         (typelib_TypeDescription *)pThis->pTypeDescr );
      46       81938 :     pThis->pBridge->release();
      47             : 
      48             : #if OSL_DEBUG_LEVEL > 1
      49             :     *(int *)pProxy = 0xdeadbabe;
      50             : #endif
      51       81938 :     delete pThis;
      52       81938 : }
      53             : 
      54     1196840 : void acquireProxy(uno_Interface * pUnoI)
      55             : {
      56     1196840 :     if (1 == osl_atomic_increment(
      57             :             & static_cast< UnoInterfaceProxy * >( pUnoI )->nRef ))
      58             :     {
      59             :         // rebirth of proxy zombie
      60             :         // register at uno env
      61             : #if OSL_DEBUG_LEVEL > 1
      62             :         void * pThis = pUnoI;
      63             : #endif
      64        2557 :         (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
      65             :          registerProxyInterface)(
      66             :              static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
      67             :              reinterpret_cast< void ** >( &pUnoI ), freeUnoInterfaceProxy,
      68             :              static_cast< UnoInterfaceProxy * >( pUnoI )->oid.pData,
      69        2557 :              static_cast< UnoInterfaceProxy * >( pUnoI )->pTypeDescr );
      70             : #if OSL_DEBUG_LEVEL > 1
      71             :         OSL_ASSERT( pThis == pUnoI );
      72             : #endif
      73             :     }
      74     1196840 : }
      75             : 
      76     1278905 : void releaseProxy(uno_Interface * pUnoI)
      77             : {
      78     1278905 :     if (! osl_atomic_decrement(
      79             :             & static_cast< UnoInterfaceProxy * >( pUnoI )->nRef ))
      80             :     {
      81             :         // revoke from uno env on last release
      82       84859 :         (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
      83             :          revokeInterface)(
      84             :              static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
      85       84859 :              pUnoI );
      86             :     }
      87     1278905 : }
      88             : 
      89       82756 : UnoInterfaceProxy * UnoInterfaceProxy::create(
      90             :     bridges::cpp_uno::shared::Bridge * pBridge,
      91             :     com::sun::star::uno::XInterface * pCppI,
      92             :     typelib_InterfaceTypeDescription * pTypeDescr,
      93             :     OUString const & rOId) SAL_THROW(())
      94             : {
      95       82756 :     return new UnoInterfaceProxy(pBridge, pCppI, pTypeDescr, rOId);
      96             : }
      97             : 
      98       82756 : UnoInterfaceProxy::UnoInterfaceProxy(
      99             :     bridges::cpp_uno::shared::Bridge * pBridge_,
     100             :     com::sun::star::uno::XInterface * pCppI_,
     101             :     typelib_InterfaceTypeDescription * pTypeDescr_, OUString const & rOId_)
     102             :     SAL_THROW(())
     103             :     : nRef( 1 )
     104             :     , pBridge( pBridge_ )
     105             :     , pCppI( pCppI_ )
     106             :     , pTypeDescr( pTypeDescr_ )
     107       82756 :     , oid( rOId_ )
     108             : {
     109       82756 :     pBridge->acquire();
     110       82756 :     ::typelib_typedescription_acquire( (typelib_TypeDescription *)pTypeDescr );
     111       82756 :     if (! ((typelib_TypeDescription *)pTypeDescr)->bComplete)
     112             :         ::typelib_typedescription_complete(
     113        1291 :             (typelib_TypeDescription **)&pTypeDescr );
     114             :     OSL_ENSURE(
     115             :         ((typelib_TypeDescription *)pTypeDescr)->bComplete,
     116             :         "### type is incomplete!" );
     117       82756 :     pCppI->acquire();
     118       82756 :     (*pBridge->getCppEnv()->registerInterface)(
     119             :         pBridge->getCppEnv(), reinterpret_cast< void ** >( &pCppI ), oid.pData,
     120       82756 :         pTypeDescr );
     121             : 
     122             :     // uno_Interface
     123       82756 :     acquire = acquireProxy;
     124       82756 :     release = releaseProxy;
     125       82756 :     pDispatcher = unoInterfaceProxyDispatch;
     126       82756 : }
     127             : 
     128       81938 : UnoInterfaceProxy::~UnoInterfaceProxy()
     129       81938 : {}
     130             : 
     131             : } } }
     132             : 
     133             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10