LCOV - code coverage report
Current view: top level - comphelper/source/misc - proxyaggregation.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 75 91 82.4 %
Date: 2014-11-03 Functions: 19 26 73.1 %
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 <sal/config.h>
      21             : 
      22             : #include <cassert>
      23             : 
      24             : #include <comphelper/proxyaggregation.hxx>
      25             : #include <com/sun/star/reflection/ProxyFactory.hpp>
      26             : 
      27             : 
      28             : namespace comphelper
      29             : {
      30             : 
      31             : 
      32             :     using namespace ::com::sun::star::uno;
      33             :     using namespace ::com::sun::star::lang;
      34             :     using namespace ::com::sun::star::reflection;
      35             : 
      36             : 
      37             :     //= OProxyAggregation
      38             : 
      39             : 
      40         800 :     OProxyAggregation::OProxyAggregation( const Reference< XComponentContext >& _rxContext )
      41         800 :         :m_xContext( _rxContext )
      42             :     {
      43         800 :     }
      44             : 
      45             : 
      46         800 :     void OProxyAggregation::baseAggregateProxyFor( const Reference< XInterface >& _rxComponent, oslInterlockedCount& _rRefCount,
      47             :             ::cppu::OWeakObject& _rDelegator )
      48             :     {
      49             :         // first a factory for the proxy
      50         800 :         Reference< XProxyFactory > xFactory = ProxyFactory::create( m_xContext );
      51             : 
      52             :         // then the proxy itself
      53             :         { // i36686 OJ: achieve the desctruction of the temporary -> otherwise it leads to _rRefCount -= 2
      54         800 :             m_xProxyAggregate = xFactory->createProxy( _rxComponent );
      55             :         }
      56         800 :         if ( m_xProxyAggregate.is() )
      57         800 :             m_xProxyAggregate->queryAggregation( ::getCppuType( &m_xProxyTypeAccess ) ) >>= m_xProxyTypeAccess;
      58             : 
      59             :         // aggregate the proxy
      60         800 :         osl_atomic_increment( &_rRefCount );
      61         800 :         if ( m_xProxyAggregate.is() )
      62             :         {
      63             :             // At this point in time, the proxy has a ref count of exactly two - in m_xControlContextProxy,
      64             :             // and in m_xProxyTypeAccess.
      65             :             // Remember to _not_ reset these members unless the delegator of the proxy has been reset, too!
      66         800 :             m_xProxyAggregate->setDelegator( _rDelegator );
      67             :         }
      68         800 :         osl_atomic_decrement( &_rRefCount );
      69         800 :     }
      70             : 
      71             : 
      72          18 :     Any SAL_CALL OProxyAggregation::queryAggregation( const Type& _rType ) throw (RuntimeException)
      73             :     {
      74          18 :         return m_xProxyAggregate.is() ? m_xProxyAggregate->queryAggregation( _rType ) : Any();
      75             :     }
      76             : 
      77             : 
      78           0 :     Sequence< Type > SAL_CALL OProxyAggregation::getTypes(  ) throw (RuntimeException)
      79             :     {
      80           0 :         Sequence< Type > aTypes;
      81           0 :         if ( m_xProxyAggregate.is() )
      82             :         {
      83           0 :             if ( m_xProxyTypeAccess.is() )
      84           0 :                 aTypes = m_xProxyTypeAccess->getTypes();
      85             :         }
      86           0 :         return aTypes;
      87             :     }
      88             : 
      89             : 
      90         160 :     OProxyAggregation::~OProxyAggregation()
      91             :     {
      92          80 :         if ( m_xProxyAggregate.is() )
      93          80 :             m_xProxyAggregate->setDelegator( NULL );
      94          80 :         m_xProxyAggregate.clear();
      95          80 :         m_xProxyTypeAccess.clear();
      96             :             // this should remove the _two_only_ "real" references (means not delegated to
      97             :             // ourself) to this proxy, and thus delete it
      98          80 :     }
      99             : 
     100             : 
     101             :     //= OComponentProxyAggregationHelper
     102             : 
     103             : 
     104         800 :     OComponentProxyAggregationHelper::OComponentProxyAggregationHelper( const Reference< XComponentContext >& _rxContext,
     105             :         ::cppu::OBroadcastHelper& _rBHelper )
     106             :         :OProxyAggregation( _rxContext )
     107         800 :         ,m_rBHelper( _rBHelper )
     108             :     {
     109             :         OSL_ENSURE( _rxContext.is(), "OComponentProxyAggregationHelper::OComponentProxyAggregationHelper: invalid arguments!" );
     110         800 :     }
     111             : 
     112             : 
     113         800 :     void OComponentProxyAggregationHelper::componentAggregateProxyFor(
     114             :         const Reference< XComponent >& _rxComponent, oslInterlockedCount& _rRefCount,
     115             :         ::cppu::OWeakObject& _rDelegator )
     116             :     {
     117             :         OSL_ENSURE( _rxComponent.is(), "OComponentProxyAggregationHelper::componentAggregateProxyFor: invalid inner component!" );
     118         800 :         m_xInner = _rxComponent;
     119             : 
     120             :         // aggregate a proxy for the object
     121         800 :         baseAggregateProxyFor( m_xInner.get(), _rRefCount, _rDelegator );
     122             : 
     123             :         // add as event listener to the inner context, because we want to be notified of disposals
     124         800 :         osl_atomic_increment( &_rRefCount );
     125             :         {
     126         800 :             if ( m_xInner.is() )
     127         800 :                 m_xInner->addEventListener( this );
     128             :         }
     129         800 :         osl_atomic_decrement( &_rRefCount );
     130         800 :     }
     131             : 
     132             : 
     133         180 :     Any SAL_CALL OComponentProxyAggregationHelper::queryInterface( const Type& _rType ) throw (RuntimeException, std::exception)
     134             :     {
     135         180 :         Any aReturn( BASE::queryInterface( _rType ) );
     136         180 :         if ( !aReturn.hasValue() )
     137          18 :             aReturn = OProxyAggregation::queryAggregation( _rType );
     138         180 :         return aReturn;
     139             :     }
     140             : 
     141             : 
     142           0 :     IMPLEMENT_FORWARD_XTYPEPROVIDER2( OComponentProxyAggregationHelper, BASE, OProxyAggregation )
     143             : 
     144             : 
     145         160 :     OComponentProxyAggregationHelper::~OComponentProxyAggregationHelper( )
     146             :     {
     147             :         OSL_ENSURE( m_rBHelper.bDisposed, "OComponentProxyAggregationHelper::~OComponentProxyAggregationHelper: you should dispose your derived class in the dtor, if necessary!" );
     148             :             // if this asserts, add the following to your derived class dtor:
     149             : 
     150             :             // if ( !m_rBHelper.bDisposed )
     151             :             // {
     152             :             //   acquire(); // to prevent duplicate dtor calls
     153             :             //   dispose();
     154             :             // }
     155             : 
     156          80 :         m_xInner.clear();
     157          80 :     }
     158             : 
     159             : 
     160         162 :     void SAL_CALL OComponentProxyAggregationHelper::disposing( const EventObject& _rSource ) throw (RuntimeException, std::exception)
     161             :     {
     162         162 :         if ( _rSource.Source == m_xInner )
     163             :         {   // it's our inner context which is dying -> dispose ourself
     164         162 :             if ( !m_rBHelper.bDisposed && !m_rBHelper.bInDispose )
     165             :             {   // (if necessary only, of course)
     166         114 :                 dispose();
     167             :             }
     168             :         }
     169         162 :     }
     170             : 
     171             : 
     172         114 :     void SAL_CALL OComponentProxyAggregationHelper::dispose() throw( RuntimeException, std::exception )
     173             :     {
     174         114 :         ::osl::MutexGuard aGuard( m_rBHelper.rMutex );
     175             : 
     176             :         // dispose our inner context
     177             :         // before we do this, remove ourself as listener - else in disposing( EventObject ), we
     178             :         // would dispose ourself a second time
     179         228 :         Reference< XComponent > xComp( m_xInner, UNO_QUERY );
     180         114 :         if ( xComp.is() )
     181             :         {
     182         114 :             xComp->removeEventListener( this );
     183         114 :             xComp->dispose();
     184         114 :             xComp.clear();
     185         114 :         }
     186         114 :     }
     187             : 
     188             : 
     189             :     //= OComponentProxyAggregation
     190             : 
     191             : 
     192         412 :     OComponentProxyAggregation::OComponentProxyAggregation( const Reference< XComponentContext >& _rxContext,
     193             :             const Reference< XComponent >& _rxComponent )
     194             :         :WeakComponentImplHelperBase( m_aMutex )
     195         412 :         ,OComponentProxyAggregationHelper( _rxContext, rBHelper )
     196             :     {
     197             :         OSL_ENSURE( _rxComponent.is(), "OComponentProxyAggregation::OComponentProxyAggregation: accessible is no XComponent!" );
     198         412 :         if ( _rxComponent.is() )
     199         412 :             componentAggregateProxyFor( _rxComponent, m_refCount, *this );
     200         412 :     }
     201             : 
     202             : 
     203          64 :     OComponentProxyAggregation::~OComponentProxyAggregation()
     204             :     {
     205          32 :         implEnsureDisposeInDtor( );
     206          32 :     }
     207             : 
     208             : 
     209       18656 :     IMPLEMENT_FORWARD_XINTERFACE2( OComponentProxyAggregation, WeakComponentImplHelperBase, OComponentProxyAggregationHelper )
     210             : 
     211             : 
     212           0 :     IMPLEMENT_GET_IMPLEMENTATION_ID( OComponentProxyAggregation )
     213             : 
     214             : 
     215           0 :     Sequence< Type > SAL_CALL OComponentProxyAggregation::getTypes(  ) throw (RuntimeException, std::exception)
     216             :     {
     217           0 :         Sequence< Type > aTypes( OComponentProxyAggregationHelper::getTypes() );
     218             : 
     219             :         // append XComponent, coming from WeakComponentImplHelperBase
     220           0 :         sal_Int32 nLen = aTypes.getLength();
     221           0 :         aTypes.realloc( nLen + 1 );
     222           0 :         aTypes[ nLen ] = cppu::UnoType<XComponent>::get();
     223             : 
     224           0 :         return aTypes;
     225             :     }
     226             : 
     227             : 
     228          32 :     void OComponentProxyAggregation::implEnsureDisposeInDtor( )
     229             :     {
     230          32 :         if ( !rBHelper.bDisposed )
     231             :         {
     232           0 :             acquire();  // to prevent duplicate dtor calls
     233           0 :             dispose();
     234             :         }
     235          32 :     }
     236             : 
     237             : 
     238          66 :     void SAL_CALL OComponentProxyAggregation::disposing( const EventObject& _rSource ) throw (RuntimeException, std::exception)
     239             :     {
     240             :         // Simply disambiguate---this is necessary for MSVC to distinguish
     241             :         // "disposing(EventObject)" from "disposing()"; but it is also a good
     242             :         // place to check for recursive calls that would be caused by an object
     243             :         // being registered as an XEventListener at itself (cf. rhbz#928568):
     244             :         assert(_rSource.Source != static_cast< cppu::OWeakObject * >(this));
     245          66 :         OComponentProxyAggregationHelper::disposing( _rSource );
     246          66 :     }
     247             : 
     248             : 
     249          66 :     void SAL_CALL OComponentProxyAggregation::disposing()  throw (RuntimeException)
     250             :     {
     251             :         // call the dispose-functionality of the base, which will dispose our aggregated component
     252          66 :         OComponentProxyAggregationHelper::dispose();
     253          66 :     }
     254             : 
     255             : 
     256          90 :     void SAL_CALL OComponentProxyAggregation::dispose() throw( RuntimeException, std::exception )
     257             :     {
     258             :         // simply disambiguate
     259          90 :         WeakComponentImplHelperBase::dispose();
     260          90 :     }
     261             : 
     262             : 
     263             : 
     264             : }   // namespace comphelper
     265             : 
     266             : 
     267             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10