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

Generated by: LCOV version 1.10