LCOV - code coverage report
Current view: top level - comphelper/source/misc - listenernotification.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 30 53.3 %
Date: 2012-08-25 Functions: 5 8 62.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 6 38 15.8 %

           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/listenernotification.hxx>
      21                 :            : 
      22                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      23                 :            : 
      24                 :            : //........................................................................
      25                 :            : namespace comphelper
      26                 :            : {
      27                 :            : //........................................................................
      28                 :            : 
      29                 :            :     using namespace ::com::sun::star::uno;
      30                 :            :     using namespace ::com::sun::star::lang;
      31                 :            : 
      32                 :            :     //====================================================================
      33                 :            :     //= OListenerContainer
      34                 :            :     //====================================================================
      35                 :            :     //--------------------------------------------------------------------
      36                 :       1877 :     OListenerContainer::OListenerContainer( ::osl::Mutex& _rMutex )
      37                 :       1877 :         :m_aListeners( _rMutex )
      38                 :            :     {
      39                 :       1877 :     }
      40                 :            : 
      41         [ -  + ]:       1729 :     OListenerContainer::~OListenerContainer() {}
      42                 :            : 
      43                 :            :     //--------------------------------------------------------------------
      44                 :          2 :     void OListenerContainer::impl_addListener( const Reference< XEventListener >& _rxListener )
      45                 :            :     {
      46                 :            :         OSL_PRECOND( _rxListener.is(), "OListenerContainer::impl_addListener: a NULL listener?!" );
      47         [ +  - ]:          2 :         if ( _rxListener.is() )
      48                 :          2 :             m_aListeners.addInterface( _rxListener );
      49                 :          2 :     }
      50                 :            : 
      51                 :            :     //--------------------------------------------------------------------
      52                 :          0 :     void OListenerContainer::impl_removeListener( const Reference< XEventListener >& _rxListener )
      53                 :            :     {
      54                 :            : #if OSL_DEBUG_LEVEL > 0
      55                 :            :         ::cppu::OInterfaceIteratorHelper aIter( m_aListeners );
      56                 :            :         bool bFound = false;
      57                 :            :         while ( aIter.hasMoreElements() && !bFound )
      58                 :            :         {
      59                 :            :             bFound = ( Reference< XInterface >( aIter.next() ) == _rxListener );
      60                 :            :         }
      61                 :            :         OSL_ENSURE( bFound, "OListenerContainer::impl_removeListener: sure your listener handling is correct? The given listener is not registered!" );
      62                 :            : #endif
      63                 :          0 :         m_aListeners.removeInterface( _rxListener );
      64                 :          0 :     }
      65                 :            : 
      66                 :            :     //--------------------------------------------------------------------
      67                 :       1732 :     void OListenerContainer::disposing( const EventObject& _rEventSource )
      68                 :            :     {
      69                 :       1732 :         m_aListeners.disposeAndClear( _rEventSource );
      70                 :       1732 :     }
      71                 :            : 
      72                 :            :     //--------------------------------------------------------------------
      73                 :          0 :     void OListenerContainer::clear()
      74                 :            :     {
      75                 :          0 :         m_aListeners.clear();
      76                 :          0 :     }
      77                 :            : 
      78                 :            :     //--------------------------------------------------------------------
      79                 :          8 :     bool OListenerContainer::impl_notify( const EventObject& _rEvent ) SAL_THROW(( Exception ))
      80                 :            :     {
      81         [ +  - ]:          8 :         ::cppu::OInterfaceIteratorHelper aIter( m_aListeners );
      82                 :          8 :         bool bCancelled = false;
      83 [ -  + ][ #  # ]:          8 :         while ( aIter.hasMoreElements() && !bCancelled )
                 [ -  + ]
      84                 :            :         {
      85 [ #  # ][ #  # ]:          0 :             Reference< XEventListener > xListener( static_cast< XEventListener* >( aIter.next() ) );
      86         [ #  # ]:          0 :             if ( !xListener.is() )
      87                 :          0 :                 continue;
      88                 :            : 
      89                 :            :             try
      90                 :            :             {
      91         [ #  # ]:          0 :                 bCancelled = !implNotify( xListener, _rEvent );
      92                 :            :             }
      93   [ #  #  #  # ]:          0 :             catch( const DisposedException& e )
      94                 :            :             {
      95                 :            :                 // DisposedExceptions from the listener might indicate a
      96                 :            :                 // broken connection to a different environment.
      97                 :            : 
      98                 :            :                 OSL_ENSURE( e.Context.is(), "OListenerContainer::impl_notify: caught dispose exception with empty Context field" );
      99                 :            : 
     100                 :            :                 // If the exception stems from the listener then remove it
     101                 :            :                 // from the list of listeners.  If the Context field of the
     102                 :            :                 // exception is empty this is interpreted to indicate the
     103                 :            :                 // listener as well.
     104   [ #  #  #  #  :          0 :                 if ( e.Context == xListener || !e.Context.is() )
             #  #  #  # ]
     105         [ #  # ]:          0 :                     aIter.remove();
     106                 :            :             }
     107         [ #  # ]:          0 :         }
     108                 :            : 
     109         [ +  - ]:          8 :         return !bCancelled;
     110                 :            :     }
     111                 :            : 
     112                 :            : //........................................................................
     113                 :            : }   // namespace comphelper
     114                 :            : //........................................................................
     115                 :            : 
     116                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10