LCOV - code coverage report
Current view: top level - comphelper/source/misc - proxyaggregation.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 78 94 83.0 %
Date: 2012-08-25 Functions: 19 26 73.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 58 134 43.3 %

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

Generated by: LCOV version 1.10