LCOV - code coverage report
Current view: top level - framework/source/fwi/classes - propertysethelper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 82 168 48.8 %
Date: 2014-04-11 Functions: 12 20 60.0 %
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 <sal/config.h>
      21             : 
      22             : #include <vcl/svapp.hxx>
      23             : 
      24             : #include <classes/propertysethelper.hxx>
      25             : #include <threadhelp/transactionguard.hxx>
      26             : 
      27             : namespace framework{
      28             : 
      29        2078 : PropertySetHelper::PropertySetHelper(      osl::Mutex & mutex,
      30             :                                            TransactionManager*                                     pExternalTransactionManager ,
      31             :                                            bool                                                bReleaseLockOnCall          )
      32             :     : m_lSimpleChangeListener(mutex)
      33             :     , m_lVetoChangeListener  (mutex)
      34             :     , m_bReleaseLockOnCall   (bReleaseLockOnCall                   )
      35        2078 :     , m_rTransactionManager  (*pExternalTransactionManager         )
      36             : {
      37        2078 : }
      38             : 
      39        2065 : PropertySetHelper::~PropertySetHelper()
      40             : {
      41        2065 : }
      42             : 
      43        2078 : void PropertySetHelper::impl_setPropertyChangeBroadcaster(const css::uno::Reference< css::uno::XInterface >& xBroadcaster)
      44             : {
      45        2078 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
      46             : 
      47        4156 :     SolarMutexGuard g;
      48        4156 :     m_xBroadcaster = xBroadcaster;
      49        2078 : }
      50             : 
      51       10390 : void SAL_CALL PropertySetHelper::impl_addPropertyInfo(const css::beans::Property& aProperty)
      52             :     throw(css::beans::PropertyExistException,
      53             :           css::uno::Exception               )
      54             : {
      55       10390 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
      56             : 
      57       20780 :     SolarMutexGuard g;
      58             : 
      59       10390 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(aProperty.Name);
      60       10390 :     if (pIt != m_lProps.end())
      61           0 :         throw css::beans::PropertyExistException();
      62             : 
      63       20780 :     m_lProps[aProperty.Name] = aProperty;
      64       10390 : }
      65             : 
      66           0 : void SAL_CALL PropertySetHelper::impl_removePropertyInfo(const OUString& sProperty)
      67             :     throw(css::beans::UnknownPropertyException,
      68             :           css::uno::Exception                 )
      69             : {
      70           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
      71             : 
      72           0 :     SolarMutexGuard g;
      73             : 
      74           0 :     PropertySetHelper::TPropInfoHash::iterator pIt = m_lProps.find(sProperty);
      75           0 :     if (pIt == m_lProps.end())
      76           0 :         throw css::beans::UnknownPropertyException();
      77             : 
      78           0 :     m_lProps.erase(pIt);
      79           0 : }
      80             : 
      81        2077 : void SAL_CALL PropertySetHelper::impl_enablePropertySet()
      82             : {
      83        2077 : }
      84             : 
      85        2064 : void SAL_CALL PropertySetHelper::impl_disablePropertySet()
      86             : {
      87        2064 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
      88             : 
      89        4128 :     SolarMutexGuard g;
      90             : 
      91        4128 :     css::uno::Reference< css::uno::XInterface > xThis(static_cast< css::beans::XPropertySet* >(this), css::uno::UNO_QUERY);
      92        4128 :     css::lang::EventObject aEvent(xThis);
      93             : 
      94        2064 :     m_lSimpleChangeListener.disposeAndClear(aEvent);
      95        2064 :     m_lVetoChangeListener.disposeAndClear(aEvent);
      96        4128 :     m_lProps.free();
      97        2064 : }
      98             : 
      99           2 : bool PropertySetHelper::impl_existsVeto(const css::beans::PropertyChangeEvent& aEvent)
     100             : {
     101             :     /*  Dont use the lock here!
     102             :         The used helper is threadsafe and it lives for the whole lifetime of
     103             :         our own object.
     104             :     */
     105           2 :     ::cppu::OInterfaceContainerHelper* pVetoListener = m_lVetoChangeListener.getContainer(aEvent.PropertyName);
     106           2 :     if (! pVetoListener)
     107           2 :         return false;
     108             : 
     109           0 :     ::cppu::OInterfaceIteratorHelper pListener(*pVetoListener);
     110           0 :     while (pListener.hasMoreElements())
     111             :     {
     112             :         try
     113             :         {
     114             :             css::uno::Reference< css::beans::XVetoableChangeListener > xListener(
     115           0 :                 ((css::beans::XVetoableChangeListener*)pListener.next()),
     116           0 :                 css::uno::UNO_QUERY_THROW);
     117           0 :             xListener->vetoableChange(aEvent);
     118             :         }
     119           0 :         catch(const css::uno::RuntimeException&)
     120           0 :             { pListener.remove(); }
     121           0 :         catch(const css::beans::PropertyVetoException&)
     122           0 :             { return true; }
     123             :     }
     124             : 
     125           0 :     return false;
     126             : }
     127             : 
     128           2 : void PropertySetHelper::impl_notifyChangeListener(const css::beans::PropertyChangeEvent& aEvent)
     129             : {
     130             :     /*  Dont use the lock here!
     131             :         The used helper is threadsafe and it lives for the whole lifetime of
     132             :         our own object.
     133             :     */
     134           2 :     ::cppu::OInterfaceContainerHelper* pSimpleListener = m_lSimpleChangeListener.getContainer(aEvent.PropertyName);
     135           2 :     if (! pSimpleListener)
     136           4 :         return;
     137             : 
     138           0 :     ::cppu::OInterfaceIteratorHelper pListener(*pSimpleListener);
     139           0 :     while (pListener.hasMoreElements())
     140             :     {
     141             :         try
     142             :         {
     143             :             css::uno::Reference< css::beans::XPropertyChangeListener > xListener(
     144           0 :                 ((css::beans::XVetoableChangeListener*)pListener.next()),
     145           0 :                 css::uno::UNO_QUERY_THROW);
     146           0 :             xListener->propertyChange(aEvent);
     147             :         }
     148           0 :         catch(const css::uno::RuntimeException&)
     149           0 :             { pListener.remove(); }
     150           0 :     }
     151             : }
     152             : 
     153           1 : css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo()
     154             :     throw(css::uno::RuntimeException, std::exception)
     155             : {
     156           1 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     157             : 
     158           1 :     css::uno::Reference< css::beans::XPropertySetInfo > xInfo(static_cast< css::beans::XPropertySetInfo* >(this), css::uno::UNO_QUERY_THROW);
     159           1 :     return xInfo;
     160             : }
     161             : 
     162           2 : void SAL_CALL PropertySetHelper::setPropertyValue(const OUString& sProperty,
     163             :                                                   const css::uno::Any&   aValue   )
     164             :     throw(css::beans::UnknownPropertyException,
     165             :           css::beans::PropertyVetoException   ,
     166             :           css::lang::IllegalArgumentException ,
     167             :           css::lang::WrappedTargetException   ,
     168             :           css::uno::RuntimeException, std::exception          )
     169             : {
     170             :     // TODO look for e.g. readonly props and reject setProp() call!
     171             : 
     172           2 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     173             : 
     174             :     // SAFE ->
     175           4 :     SolarMutexResettableGuard aWriteLock;
     176             : 
     177           2 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     178           2 :     if (pIt == m_lProps.end())
     179           0 :         throw css::beans::UnknownPropertyException();
     180             : 
     181           4 :     css::beans::Property aPropInfo = pIt->second;
     182             : 
     183           2 :     bool bLocked = true;
     184           2 :     if (m_bReleaseLockOnCall)
     185             :     {
     186           0 :         aWriteLock.clear();
     187           0 :         bLocked = false;
     188             :         // <- SAFE
     189             :     }
     190             : 
     191           4 :     css::uno::Any aCurrentValue = impl_getPropertyValue(aPropInfo.Name, aPropInfo.Handle);
     192             : 
     193           2 :     if (! bLocked)
     194             :     {
     195             :         // SAFE ->
     196           0 :         aWriteLock.reset();
     197           0 :         bLocked = true;
     198             :     }
     199             : 
     200           2 :     bool bWillBeChanged = (aCurrentValue != aValue);
     201           2 :     if (! bWillBeChanged)
     202           2 :         return;
     203             : 
     204           4 :     css::beans::PropertyChangeEvent aEvent;
     205           2 :     aEvent.PropertyName   = aPropInfo.Name;
     206           2 :     aEvent.Further        = sal_False;
     207           2 :     aEvent.PropertyHandle = aPropInfo.Handle;
     208           2 :     aEvent.OldValue       = aCurrentValue;
     209           2 :     aEvent.NewValue       = aValue;
     210           2 :     aEvent.Source         = css::uno::Reference< css::uno::XInterface >(m_xBroadcaster.get(), css::uno::UNO_QUERY);
     211             : 
     212           2 :     if (m_bReleaseLockOnCall)
     213             :     {
     214           0 :         aWriteLock.clear();
     215           0 :         bLocked = false;
     216             :         // <- SAFE
     217             :     }
     218             : 
     219           2 :     if (impl_existsVeto(aEvent))
     220           0 :         throw css::beans::PropertyVetoException();
     221             : 
     222           2 :     impl_setPropertyValue(aPropInfo.Name, aPropInfo.Handle, aValue);
     223             : 
     224           4 :     impl_notifyChangeListener(aEvent);
     225             : }
     226             : 
     227       47688 : css::uno::Any SAL_CALL PropertySetHelper::getPropertyValue(const OUString& sProperty)
     228             :     throw(css::beans::UnknownPropertyException,
     229             :           css::lang::WrappedTargetException   ,
     230             :           css::uno::RuntimeException, std::exception          )
     231             : {
     232       47688 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     233             : 
     234             :     // SAFE ->
     235       95376 :     SolarMutexClearableGuard aReadLock;
     236             : 
     237       47688 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     238       47688 :     if (pIt == m_lProps.end())
     239           0 :         throw css::beans::UnknownPropertyException();
     240             : 
     241       95376 :     css::beans::Property aPropInfo = pIt->second;
     242             : 
     243       47688 :     if (m_bReleaseLockOnCall)
     244           0 :         aReadLock.clear();
     245             : 
     246       95376 :     return impl_getPropertyValue(aPropInfo.Name, aPropInfo.Handle);
     247             : }
     248             : 
     249           0 : void SAL_CALL PropertySetHelper::addPropertyChangeListener(const OUString&                                            sProperty,
     250             :                                                            const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener)
     251             :     throw(css::beans::UnknownPropertyException,
     252             :           css::lang::WrappedTargetException   ,
     253             :           css::uno::RuntimeException, std::exception          )
     254             : {
     255           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     256             : 
     257             :     // SAFE ->
     258           0 :     SolarMutexClearableGuard aReadLock;
     259             : 
     260           0 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     261           0 :     if (pIt == m_lProps.end())
     262           0 :         throw css::beans::UnknownPropertyException();
     263             : 
     264           0 :     aReadLock.clear();
     265             :     // <- SAFE
     266             : 
     267           0 :     m_lSimpleChangeListener.addInterface(sProperty, xListener);
     268           0 : }
     269             : 
     270           0 : void SAL_CALL PropertySetHelper::removePropertyChangeListener(const OUString&                                            sProperty,
     271             :                                                               const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener)
     272             :     throw(css::beans::UnknownPropertyException,
     273             :           css::lang::WrappedTargetException   ,
     274             :           css::uno::RuntimeException, std::exception          )
     275             : {
     276           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
     277             : 
     278             :     // SAFE ->
     279           0 :     SolarMutexClearableGuard aReadLock;
     280             : 
     281           0 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     282           0 :     if (pIt == m_lProps.end())
     283           0 :         throw css::beans::UnknownPropertyException();
     284             : 
     285           0 :     aReadLock.clear();
     286             :     // <- SAFE
     287             : 
     288           0 :     m_lSimpleChangeListener.removeInterface(sProperty, xListener);
     289           0 : }
     290             : 
     291           0 : void SAL_CALL PropertySetHelper::addVetoableChangeListener(const OUString&                                            sProperty,
     292             :                                                            const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener)
     293             :     throw(css::beans::UnknownPropertyException,
     294             :           css::lang::WrappedTargetException   ,
     295             :           css::uno::RuntimeException, std::exception          )
     296             : {
     297           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     298             : 
     299             :     // SAFE ->
     300           0 :     SolarMutexClearableGuard aReadLock;
     301             : 
     302           0 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     303           0 :     if (pIt == m_lProps.end())
     304           0 :         throw css::beans::UnknownPropertyException();
     305             : 
     306           0 :     aReadLock.clear();
     307             :     // <- SAFE
     308             : 
     309           0 :     m_lVetoChangeListener.addInterface(sProperty, xListener);
     310           0 : }
     311             : 
     312           0 : void SAL_CALL PropertySetHelper::removeVetoableChangeListener(const OUString&                                            sProperty,
     313             :                                                               const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener)
     314             :     throw(css::beans::UnknownPropertyException,
     315             :           css::lang::WrappedTargetException   ,
     316             :           css::uno::RuntimeException, std::exception          )
     317             : {
     318           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
     319             : 
     320             :     // SAFE ->
     321           0 :     SolarMutexClearableGuard aReadLock;
     322             : 
     323           0 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     324           0 :     if (pIt == m_lProps.end())
     325           0 :         throw css::beans::UnknownPropertyException();
     326             : 
     327           0 :     aReadLock.clear();
     328             :     // <- SAFE
     329             : 
     330           0 :     m_lVetoChangeListener.removeInterface(sProperty, xListener);
     331           0 : }
     332             : 
     333           1 : css::uno::Sequence< css::beans::Property > SAL_CALL PropertySetHelper::getProperties()
     334             :     throw(css::uno::RuntimeException, std::exception)
     335             : {
     336           1 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     337             : 
     338           2 :     SolarMutexGuard g;
     339             : 
     340           1 :     sal_Int32                                        c     = (sal_Int32)m_lProps.size();
     341           1 :     css::uno::Sequence< css::beans::Property >       lProps(c);
     342           1 :     PropertySetHelper::TPropInfoHash::const_iterator pIt;
     343             : 
     344          18 :     for (  pIt  = m_lProps.begin();
     345          12 :            pIt != m_lProps.end();
     346             :          ++pIt                    )
     347             :     {
     348           5 :         lProps[--c] = pIt->second;
     349             :     }
     350             : 
     351           2 :     return lProps;
     352             : }
     353             : 
     354           0 : css::beans::Property SAL_CALL PropertySetHelper::getPropertyByName(const OUString& sName)
     355             :     throw(css::beans::UnknownPropertyException,
     356             :           css::uno::RuntimeException, std::exception          )
     357             : {
     358           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     359             : 
     360           0 :     SolarMutexGuard g;
     361             : 
     362           0 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sName);
     363           0 :     if (pIt == m_lProps.end())
     364           0 :         throw css::beans::UnknownPropertyException();
     365             : 
     366           0 :     return pIt->second;
     367             : }
     368             : 
     369           0 : sal_Bool SAL_CALL PropertySetHelper::hasPropertyByName(const OUString& sName)
     370             :     throw(css::uno::RuntimeException, std::exception)
     371             : {
     372           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     373             : 
     374           0 :     SolarMutexGuard g;
     375             : 
     376           0 :     PropertySetHelper::TPropInfoHash::iterator pIt    = m_lProps.find(sName);
     377           0 :     bool                                   bExist = (pIt != m_lProps.end());
     378             : 
     379           0 :     return bExist;
     380             : }
     381             : 
     382             : } // namespace framework
     383             : 
     384             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10