LCOV - code coverage report
Current view: top level - libreoffice/bridges/source/cpp_uno/shared - unointerfaceproxy.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 37 94.6 %
Date: 2012-12-27 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        1861 : void freeUnoInterfaceProxy(uno_ExtEnvironment * pEnv, void * pProxy)
      33             : {
      34             :     UnoInterfaceProxy * pThis =
      35             :         static_cast< UnoInterfaceProxy * >(
      36        1861 :             reinterpret_cast< uno_Interface * >( pProxy ) );
      37        1861 :     if (pEnv != pThis->pBridge->getUnoEnv()) {
      38             :         OSL_ASSERT(false);
      39             :     }
      40             : 
      41        1861 :     (*pThis->pBridge->getCppEnv()->revokeInterface)(
      42        1861 :         pThis->pBridge->getCppEnv(), pThis->pCppI );
      43        1861 :     pThis->pCppI->release();
      44             :     ::typelib_typedescription_release(
      45        1861 :         (typelib_TypeDescription *)pThis->pTypeDescr );
      46        1861 :     pThis->pBridge->release();
      47             : 
      48             : #if OSL_DEBUG_LEVEL > 1
      49             :     *(int *)pProxy = 0xdeadbabe;
      50             : #endif
      51        1861 :     delete pThis;
      52        1861 : }
      53             : 
      54        1863 : void acquireProxy(uno_Interface * pUnoI)
      55             : {
      56        1863 :     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           0 :         (*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           0 :              static_cast< UnoInterfaceProxy * >( pUnoI )->pTypeDescr );
      70             : #if OSL_DEBUG_LEVEL > 1
      71             :         OSL_ASSERT( pThis == pUnoI );
      72             : #endif
      73             :     }
      74        1863 : }
      75             : 
      76        3724 : void releaseProxy(uno_Interface * pUnoI)
      77             : {
      78        3724 :     if (! osl_atomic_decrement(
      79             :             & static_cast< UnoInterfaceProxy * >( pUnoI )->nRef ))
      80             :     {
      81             :         // revoke from uno env on last release
      82        1861 :         (*static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv()->
      83             :          revokeInterface)(
      84             :              static_cast< UnoInterfaceProxy * >( pUnoI )->pBridge->getUnoEnv(),
      85        1861 :              pUnoI );
      86             :     }
      87        3724 : }
      88             : 
      89        1861 : 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        1861 :     return new UnoInterfaceProxy(pBridge, pCppI, pTypeDescr, rOId);
      96             : }
      97             : 
      98        1861 : 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        1861 :     , oid( rOId_ )
     108             : {
     109        1861 :     pBridge->acquire();
     110        1861 :     ::typelib_typedescription_acquire( (typelib_TypeDescription *)pTypeDescr );
     111        1861 :     if (! ((typelib_TypeDescription *)pTypeDescr)->bComplete)
     112             :         ::typelib_typedescription_complete(
     113           9 :             (typelib_TypeDescription **)&pTypeDescr );
     114             :     OSL_ENSURE(
     115             :         ((typelib_TypeDescription *)pTypeDescr)->bComplete,
     116             :         "### type is incomplete!" );
     117        1861 :     pCppI->acquire();
     118        1861 :     (*pBridge->getCppEnv()->registerInterface)(
     119             :         pBridge->getCppEnv(), reinterpret_cast< void ** >( &pCppI ), oid.pData,
     120        1861 :         pTypeDescr );
     121             : 
     122             :     // uno_Interface
     123        1861 :     acquire = acquireProxy;
     124        1861 :     release = releaseProxy;
     125        1861 :     pDispatcher = unoInterfaceProxyDispatch;
     126        1861 : }
     127             : 
     128        1861 : UnoInterfaceProxy::~UnoInterfaceProxy()
     129        1861 : {}
     130             : 
     131             : } } }
     132             : 
     133             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10