LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/comphelper/source/property - propmultiplex.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 62 66 93.9 %
Date: 2013-07-09 Functions: 12 14 85.7 %
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/propmultiplex.hxx>
      21             : #include <osl/diagnose.h>
      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::beans;
      31             : 
      32             : //========================================================================
      33             : //= OPropertyChangeListener
      34             : //========================================================================
      35             : //------------------------------------------------------------------------
      36         536 : OPropertyChangeListener::~OPropertyChangeListener()
      37             : {
      38         536 :     if (m_pAdapter)
      39          19 :         m_pAdapter->dispose();
      40         536 : }
      41             : 
      42             : //------------------------------------------------------------------
      43         322 : void OPropertyChangeListener::_disposing(const EventObject&) throw( RuntimeException)
      44             : {
      45             :     // nothing to do here
      46         322 : }
      47             : 
      48             : //------------------------------------------------------------------
      49           0 : void OPropertyChangeListener::disposeAdapter()
      50             : {
      51           0 :     if ( m_pAdapter )
      52           0 :         m_pAdapter->dispose();
      53             : 
      54             :     // will automatically set a new adapter
      55             :     OSL_ENSURE( !m_pAdapter, "OPropertyChangeListener::disposeAdapter: what did dispose do?" );
      56           0 : }
      57             : 
      58             : //------------------------------------------------------------------
      59        1128 : void OPropertyChangeListener::setAdapter(OPropertyChangeMultiplexer* pAdapter)
      60             : {
      61        1128 :     if (m_pAdapter)
      62             :     {
      63         543 :         ::osl::MutexGuard aGuard(m_rMutex);
      64         543 :         m_pAdapter->release();
      65         543 :         m_pAdapter = NULL;
      66             :     }
      67             : 
      68        1128 :     if (pAdapter)
      69             :     {
      70         585 :         ::osl::MutexGuard aGuard(m_rMutex);
      71         585 :         m_pAdapter = pAdapter;
      72         585 :         m_pAdapter->acquire();
      73             :     }
      74        1128 : }
      75             : 
      76             : //========================================================================
      77             : //= OPropertyChangeMultiplexer
      78             : //========================================================================
      79             : //------------------------------------------------------------------
      80         585 : OPropertyChangeMultiplexer::OPropertyChangeMultiplexer(OPropertyChangeListener* _pListener, const  Reference< XPropertySet>& _rxSet, sal_Bool _bAutoReleaseSet)
      81             :             :m_xSet(_rxSet)
      82             :             ,m_pListener(_pListener)
      83             :             ,m_nLockCount(0)
      84             :             ,m_bListening(sal_False)
      85         585 :             ,m_bAutoSetRelease(_bAutoReleaseSet)
      86             : {
      87         585 :     m_pListener->setAdapter(this);
      88         585 : }
      89             : 
      90             : //------------------------------------------------------------------
      91        1076 : OPropertyChangeMultiplexer::~OPropertyChangeMultiplexer()
      92             : {
      93        1076 : }
      94             : 
      95             : //------------------------------------------------------------------
      96          20 : void OPropertyChangeMultiplexer::lock()
      97             : {
      98          20 :     ++m_nLockCount;
      99          20 : }
     100             : 
     101             : //------------------------------------------------------------------
     102          20 : void OPropertyChangeMultiplexer::unlock()
     103             : {
     104          20 :     --m_nLockCount;
     105          20 : }
     106             : 
     107             : //------------------------------------------------------------------
     108         936 : void OPropertyChangeMultiplexer::dispose()
     109             : {
     110         936 :     if (m_bListening)
     111             :     {
     112         221 :         Reference< XPropertyChangeListener> xPreventDelete(this);
     113             : 
     114         221 :         const OUString* pProperties = m_aProperties.getConstArray();
     115         722 :         for (sal_Int32 i = 0; i < m_aProperties.getLength(); ++i, ++pProperties)
     116         501 :             m_xSet->removePropertyChangeListener(*pProperties, static_cast< XPropertyChangeListener*>(this));
     117             : 
     118         221 :         m_pListener->setAdapter(NULL);
     119             : 
     120         221 :         m_pListener = NULL;
     121         221 :         m_bListening = sal_False;
     122             : 
     123         221 :         if (m_bAutoSetRelease)
     124          63 :             m_xSet = NULL;
     125             :     }
     126         936 : }
     127             : 
     128             : // XEventListener
     129             : //------------------------------------------------------------------
     130         380 : void SAL_CALL OPropertyChangeMultiplexer::disposing( const  EventObject& _rSource) throw( RuntimeException)
     131             : {
     132         380 :     if (m_pListener)
     133             :     {
     134             :          // tell the listener
     135         322 :         if (!locked())
     136         322 :             m_pListener->_disposing(_rSource);
     137             :         // disconnect the listener
     138         322 :         if (m_pListener)    // may have been reset whilest calling into _disposing
     139         322 :             m_pListener->setAdapter(NULL);
     140             :     }
     141             : 
     142         380 :     m_pListener = NULL;
     143         380 :     m_bListening = sal_False;
     144             : 
     145         380 :     if (m_bAutoSetRelease)
     146          85 :         m_xSet = NULL;
     147         380 : }
     148             : 
     149             : // XPropertyChangeListener
     150             : //------------------------------------------------------------------
     151         605 : void SAL_CALL OPropertyChangeMultiplexer::propertyChange( const  PropertyChangeEvent& _rEvent ) throw( RuntimeException)
     152             : {
     153         605 :     if (m_pListener && !locked())
     154         582 :         m_pListener->_propertyChanged(_rEvent);
     155         605 : }
     156             : 
     157             : //------------------------------------------------------------------
     158         909 : void OPropertyChangeMultiplexer::addProperty(const OUString& _sPropertyName)
     159             : {
     160         909 :     if (m_xSet.is())
     161             :     {
     162         909 :         m_xSet->addPropertyChangeListener(_sPropertyName, static_cast< XPropertyChangeListener*>(this));
     163         909 :         m_aProperties.realloc(m_aProperties.getLength() + 1);
     164         909 :         m_aProperties.getArray()[m_aProperties.getLength()-1] = _sPropertyName;
     165         909 :         m_bListening = sal_True;
     166             :     }
     167         909 : }
     168             : 
     169             : //.........................................................................
     170             : }
     171             : //.........................................................................
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10