LCOV - code coverage report
Current view: top level - libreoffice/comphelper/source/property - propmultiplex.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 54 66 81.8 %
Date: 2012-12-27 Functions: 10 14 71.4 %
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           5 : OPropertyChangeListener::~OPropertyChangeListener()
      37             : {
      38           5 :     if (m_pAdapter)
      39           0 :         m_pAdapter->dispose();
      40           5 : }
      41             : 
      42             : //------------------------------------------------------------------
      43           8 : void OPropertyChangeListener::_disposing(const EventObject&) throw( RuntimeException)
      44             : {
      45             :     // nothing to do here
      46           8 : }
      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          20 : void OPropertyChangeListener::setAdapter(OPropertyChangeMultiplexer* pAdapter)
      60             : {
      61          20 :     if (m_pAdapter)
      62             :     {
      63          10 :         ::osl::MutexGuard aGuard(m_rMutex);
      64          10 :         m_pAdapter->release();
      65          10 :         m_pAdapter = NULL;
      66             :     }
      67             : 
      68          20 :     if (pAdapter)
      69             :     {
      70          10 :         ::osl::MutexGuard aGuard(m_rMutex);
      71          10 :         m_pAdapter = pAdapter;
      72          10 :         m_pAdapter->acquire();
      73             :     }
      74          20 : }
      75             : 
      76             : //========================================================================
      77             : //= OPropertyChangeMultiplexer
      78             : //========================================================================
      79             : //------------------------------------------------------------------
      80          10 : 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          10 :             ,m_bAutoSetRelease(_bAutoReleaseSet)
      86             : {
      87          10 :     m_pListener->setAdapter(this);
      88          10 : }
      89             : 
      90             : //------------------------------------------------------------------
      91          10 : OPropertyChangeMultiplexer::~OPropertyChangeMultiplexer()
      92             : {
      93          10 : }
      94             : 
      95             : //------------------------------------------------------------------
      96           0 : void OPropertyChangeMultiplexer::lock()
      97             : {
      98           0 :     ++m_nLockCount;
      99           0 : }
     100             : 
     101             : //------------------------------------------------------------------
     102           0 : void OPropertyChangeMultiplexer::unlock()
     103             : {
     104           0 :     --m_nLockCount;
     105           0 : }
     106             : 
     107             : //------------------------------------------------------------------
     108           9 : void OPropertyChangeMultiplexer::dispose()
     109             : {
     110           9 :     if (m_bListening)
     111             :     {
     112           2 :         Reference< XPropertyChangeListener> xPreventDelete(this);
     113             : 
     114           2 :         const ::rtl::OUString* pProperties = m_aProperties.getConstArray();
     115           6 :         for (sal_Int32 i = 0; i < m_aProperties.getLength(); ++i, ++pProperties)
     116           4 :             m_xSet->removePropertyChangeListener(*pProperties, static_cast< XPropertyChangeListener*>(this));
     117             : 
     118           2 :         m_pListener->setAdapter(NULL);
     119             : 
     120           2 :         m_pListener = NULL;
     121           2 :         m_bListening = sal_False;
     122             : 
     123           2 :         if (m_bAutoSetRelease)
     124           0 :             m_xSet = NULL;
     125             :     }
     126           9 : }
     127             : 
     128             : // XEventListener
     129             : //------------------------------------------------------------------
     130          12 : void SAL_CALL OPropertyChangeMultiplexer::disposing( const  EventObject& _rSource) throw( RuntimeException)
     131             : {
     132          12 :     if (m_pListener)
     133             :     {
     134             :          // tell the listener
     135           8 :         if (!locked())
     136           8 :             m_pListener->_disposing(_rSource);
     137             :         // disconnect the listener
     138           8 :         if (m_pListener)    // may have been reset whilest calling into _disposing
     139           8 :             m_pListener->setAdapter(NULL);
     140             :     }
     141             : 
     142          12 :     m_pListener = NULL;
     143          12 :     m_bListening = sal_False;
     144             : 
     145          12 :     if (m_bAutoSetRelease)
     146           3 :         m_xSet = NULL;
     147          12 : }
     148             : 
     149             : // XPropertyChangeListener
     150             : //------------------------------------------------------------------
     151           6 : void SAL_CALL OPropertyChangeMultiplexer::propertyChange( const  PropertyChangeEvent& _rEvent ) throw( RuntimeException)
     152             : {
     153           6 :     if (m_pListener && !locked())
     154           6 :         m_pListener->_propertyChanged(_rEvent);
     155           6 : }
     156             : 
     157             : //------------------------------------------------------------------
     158          16 : void OPropertyChangeMultiplexer::addProperty(const ::rtl::OUString& _sPropertyName)
     159             : {
     160          16 :     if (m_xSet.is())
     161             :     {
     162          16 :         m_xSet->addPropertyChangeListener(_sPropertyName, static_cast< XPropertyChangeListener*>(this));
     163          16 :         m_aProperties.realloc(m_aProperties.getLength() + 1);
     164          16 :         m_aProperties.getArray()[m_aProperties.getLength()-1] = _sPropertyName;
     165          16 :         m_bListening = sal_True;
     166             :     }
     167          16 : }
     168             : 
     169             : //.........................................................................
     170             : }
     171             : //.........................................................................
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10