LCOV - code coverage report
Current view: top level - cppuhelper/source - implbase.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 96 122 78.7 %
Date: 2015-06-13 12:38:46 Functions: 19 21 90.5 %
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 <cppuhelper/compbase_ex.hxx>
      21             : #include <osl/diagnose.h>
      22             : #include <rtl/instance.hxx>
      23             : #include <rtl/string.hxx>
      24             : 
      25             : #include <com/sun/star/lang/XComponent.hpp>
      26             : #include <com/sun/star/uno/RuntimeException.hpp>
      27             : 
      28             : using namespace ::osl;
      29             : using namespace ::com::sun::star;
      30             : using namespace ::com::sun::star::uno;
      31             : 
      32             : using rtl::OUString;
      33             : using rtl::OString;
      34             : 
      35             : namespace cppu
      36             : {
      37             : 
      38             : // WeakComponentImplHelperBase
      39             : 
      40     1215903 : WeakComponentImplHelperBase::WeakComponentImplHelperBase( Mutex & rMutex )
      41     1215903 :     : rBHelper( rMutex )
      42             : {
      43     1215903 : }
      44             : 
      45     1202813 : WeakComponentImplHelperBase::~WeakComponentImplHelperBase()
      46             : {
      47     1202813 : }
      48             : 
      49      965327 : void WeakComponentImplHelperBase::disposing()
      50             : {
      51      965327 : }
      52             : 
      53      660413 : Any WeakComponentImplHelperBase::queryInterface( Type const & rType )
      54             :     throw (RuntimeException, std::exception)
      55             : {
      56      660413 :     if (rType == cppu::UnoType<lang::XComponent>::get())
      57             :     {
      58       65114 :         void * p = static_cast< lang::XComponent * >( this );
      59       65114 :         return Any( &p, rType );
      60             :     }
      61      595299 :     return OWeakObject::queryInterface( rType );
      62             : }
      63             : 
      64  1412239380 : void WeakComponentImplHelperBase::acquire()
      65             :     throw ()
      66             : {
      67  1412239380 :     OWeakObject::acquire();
      68  1412239387 : }
      69             : 
      70  1412194679 : void WeakComponentImplHelperBase::release()
      71             :     throw ()
      72             : {
      73  1412194679 :     if (osl_atomic_decrement( &m_refCount ) == 0) {
      74             :         // ensure no other references are created, via the weak connection point, from now on
      75     1202034 :         disposeWeakConnectionPoint();
      76             :         // restore reference count:
      77     1202034 :         osl_atomic_increment( &m_refCount );
      78     1202034 :         if (! rBHelper.bDisposed) {
      79             :             try {
      80     1116627 :                 dispose();
      81             :             }
      82           0 :             catch (RuntimeException const& exc) { // don't break throw ()
      83             :                 OSL_FAIL(
      84             :                     OUStringToOString(
      85             :                         exc.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
      86             :                 static_cast<void>(exc);
      87             :             }
      88             :             OSL_ASSERT( rBHelper.bDisposed );
      89             :         }
      90     1202034 :         OWeakObject::release();
      91             :     }
      92  1412194679 : }
      93             : 
      94     1206936 : void WeakComponentImplHelperBase::dispose()
      95             :     throw (RuntimeException, std::exception)
      96             : {
      97     1206936 :     ClearableMutexGuard aGuard( rBHelper.rMutex );
      98     1206936 :     if (!rBHelper.bDisposed && !rBHelper.bInDispose)
      99             :     {
     100     1206425 :         rBHelper.bInDispose = sal_True;
     101     1206425 :         aGuard.clear();
     102             :         try
     103             :         {
     104             :             // side effect: keeping a reference to this
     105     1206425 :             lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
     106             :             try
     107             :             {
     108     1206425 :                 rBHelper.aLC.disposeAndClear( aEvt );
     109     1206425 :                 disposing();
     110             :             }
     111           0 :             catch (...)
     112             :             {
     113           0 :                 MutexGuard aGuard2( rBHelper.rMutex );
     114             :                 // bDisposed and bInDispose must be set in this order:
     115           0 :                 rBHelper.bDisposed = sal_True;
     116           0 :                 rBHelper.bInDispose = sal_False;
     117           0 :                 throw;
     118             :             }
     119     2412850 :             MutexGuard aGuard2( rBHelper.rMutex );
     120             :             // bDisposed and bInDispose must be set in this order:
     121     1206425 :             rBHelper.bDisposed = sal_True;
     122     2412850 :             rBHelper.bInDispose = sal_False;
     123             :         }
     124           0 :         catch (RuntimeException &)
     125             :         {
     126           0 :             throw;
     127             :         }
     128           0 :         catch (Exception & exc)
     129             :         {
     130             :             throw RuntimeException(
     131           0 :                 "unexpected UNO exception caught: " + exc.Message );
     132             :         }
     133     1206936 :     }
     134     1206936 : }
     135             : 
     136        3028 : void WeakComponentImplHelperBase::addEventListener(
     137             :     Reference< lang::XEventListener > const & xListener )
     138             :     throw (RuntimeException, std::exception)
     139             : {
     140        3028 :     ClearableMutexGuard aGuard( rBHelper.rMutex );
     141        3028 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     142             :     {
     143           0 :         aGuard.clear();
     144           0 :         lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
     145           0 :         xListener->disposing( aEvt );
     146             :     }
     147             :     else
     148             :     {
     149        3028 :         rBHelper.addListener( cppu::UnoType<decltype(xListener)>::get(), xListener );
     150        3028 :     }
     151        3028 : }
     152             : 
     153         466 : void WeakComponentImplHelperBase::removeEventListener(
     154             :     Reference< lang::XEventListener > const & xListener )
     155             :     throw (RuntimeException, std::exception)
     156             : {
     157         466 :     rBHelper.removeListener( cppu::UnoType<decltype(xListener)>::get(), xListener );
     158         466 : }
     159             : 
     160             : // WeakAggComponentImplHelperBase
     161             : 
     162        4319 : WeakAggComponentImplHelperBase::WeakAggComponentImplHelperBase( Mutex & rMutex )
     163        4319 :     : rBHelper( rMutex )
     164             : {
     165        4319 : }
     166             : 
     167        4098 : WeakAggComponentImplHelperBase::~WeakAggComponentImplHelperBase()
     168             : {
     169        4098 : }
     170             : 
     171         223 : void WeakAggComponentImplHelperBase::disposing()
     172             : {
     173         223 : }
     174             : 
     175       33178 : Any WeakAggComponentImplHelperBase::queryInterface( Type const & rType )
     176             :     throw (RuntimeException, std::exception)
     177             : {
     178       33178 :     return OWeakAggObject::queryInterface( rType );
     179             : }
     180             : 
     181       30036 : Any WeakAggComponentImplHelperBase::queryAggregation( Type const & rType )
     182             :     throw (RuntimeException, std::exception)
     183             : {
     184       30036 :     if (rType == cppu::UnoType<lang::XComponent>::get())
     185             :     {
     186        4863 :         void * p = static_cast< lang::XComponent * >( this );
     187        4863 :         return Any( &p, rType );
     188             :     }
     189       25173 :     return OWeakAggObject::queryAggregation( rType );
     190             : }
     191             : 
     192      382580 : void WeakAggComponentImplHelperBase::acquire()
     193             :     throw ()
     194             : {
     195      382580 :     OWeakAggObject::acquire();
     196      382580 : }
     197             : 
     198      380964 : void WeakAggComponentImplHelperBase::release()
     199             :     throw ()
     200             : {
     201      380964 :     Reference<XInterface> const xDelegator_(xDelegator);
     202      380964 :     if (xDelegator_.is()) {
     203        3016 :         OWeakAggObject::release();
     204             :     }
     205      377948 :     else if (osl_atomic_decrement( &m_refCount ) == 0) {
     206             :         // ensure no other references are created, via the weak connection point, from now on
     207        4098 :         disposeWeakConnectionPoint();
     208             :         // restore reference count:
     209        4098 :         osl_atomic_increment( &m_refCount );
     210        4098 :         if (! rBHelper.bDisposed) {
     211             :             try {
     212         112 :                 dispose();
     213             :             }
     214           0 :             catch (RuntimeException const& exc) { // don't break throw ()
     215             :                 OSL_FAIL(
     216             :                     OUStringToOString(
     217             :                         exc.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
     218             :                 static_cast<void>(exc);
     219             :             }
     220             :             OSL_ASSERT( rBHelper.bDisposed );
     221             :         }
     222        4098 :         OWeakAggObject::release();
     223      380964 :     }
     224      380963 : }
     225             : 
     226        4538 : void WeakAggComponentImplHelperBase::dispose()
     227             :     throw (RuntimeException, std::exception)
     228             : {
     229        4538 :     ClearableMutexGuard aGuard( rBHelper.rMutex );
     230        4538 :     if (!rBHelper.bDisposed && !rBHelper.bInDispose)
     231             :     {
     232        4139 :         rBHelper.bInDispose = sal_True;
     233        4139 :         aGuard.clear();
     234             :         try
     235             :         {
     236             :             // side effect: keeping a reference to this
     237        4139 :             lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
     238             :             try
     239             :             {
     240        4139 :                 rBHelper.aLC.disposeAndClear( aEvt );
     241        4139 :                 disposing();
     242             :             }
     243           0 :             catch (...)
     244             :             {
     245           0 :                 MutexGuard aGuard2( rBHelper.rMutex );
     246             :                 // bDisposed and bInDispose must be set in this order:
     247           0 :                 rBHelper.bDisposed = sal_True;
     248           0 :                 rBHelper.bInDispose = sal_False;
     249           0 :                 throw;
     250             :             }
     251        8278 :             MutexGuard aGuard2( rBHelper.rMutex );
     252             :             // bDisposed and bInDispose must be set in this order:
     253        4139 :             rBHelper.bDisposed = sal_True;
     254        8278 :             rBHelper.bInDispose = sal_False;
     255             :         }
     256           0 :         catch (RuntimeException &)
     257             :         {
     258           0 :             throw;
     259             :         }
     260           0 :         catch (Exception & exc)
     261             :         {
     262             :             throw RuntimeException(
     263           0 :                 "unexpected UNO exception caught: " + exc.Message );
     264             :         }
     265        4538 :     }
     266        4538 : }
     267             : 
     268         562 : void WeakAggComponentImplHelperBase::addEventListener(
     269             :     Reference< lang::XEventListener > const & xListener )
     270             :     throw (RuntimeException, std::exception)
     271             : {
     272         562 :     ClearableMutexGuard aGuard( rBHelper.rMutex );
     273         562 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     274             :     {
     275           0 :         aGuard.clear();
     276           0 :         lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
     277           0 :         xListener->disposing( aEvt );
     278             :     }
     279             :     else
     280             :     {
     281         562 :         rBHelper.addListener( cppu::UnoType<decltype(xListener)>::get(), xListener );
     282         562 :     }
     283         562 : }
     284             : 
     285          92 : void WeakAggComponentImplHelperBase::removeEventListener(
     286             :     Reference< lang::XEventListener > const & xListener )
     287             :     throw (RuntimeException, std::exception)
     288             : {
     289          92 :     rBHelper.removeListener( cppu::UnoType<decltype(xListener)>::get(), xListener );
     290          92 : }
     291             : 
     292             : }
     293             : 
     294             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11