LCOV - code coverage report
Current view: top level - framework/source/fwi/classes - propertysethelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 83 167 49.7 %
Date: 2014-11-03 Functions: 14 22 63.6 %
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        5574 : PropertySetHelper::PropertySetHelper(      osl::Mutex & mutex,
      30             :                                            TransactionManager*                                     pExternalTransactionManager ,
      31             :                                            bool                                                bReleaseLockOnCall          )
      32             :     : m_lSimpleChangeListener(mutex)
      33             :     , m_lVetoChangeListener  (mutex)
      34             :     , m_bReleaseLockOnCall   (bReleaseLockOnCall                   )
      35        5574 :     , m_rTransactionManager  (*pExternalTransactionManager         )
      36             : {
      37        5574 : }
      38             : 
      39        5528 : PropertySetHelper::~PropertySetHelper()
      40             : {
      41        5528 : }
      42             : 
      43        5574 : void PropertySetHelper::impl_setPropertyChangeBroadcaster(const css::uno::Reference< css::uno::XInterface >& xBroadcaster)
      44             : {
      45        5574 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
      46             : 
      47       11148 :     SolarMutexGuard g;
      48       11148 :     m_xBroadcaster = xBroadcaster;
      49        5574 : }
      50             : 
      51       27870 : void SAL_CALL PropertySetHelper::impl_addPropertyInfo(const css::beans::Property& aProperty)
      52             :     throw(css::beans::PropertyExistException,
      53             :           css::uno::Exception               )
      54             : {
      55       27870 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
      56             : 
      57       55740 :     SolarMutexGuard g;
      58             : 
      59       27870 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(aProperty.Name);
      60       27870 :     if (pIt != m_lProps.end())
      61           0 :         throw css::beans::PropertyExistException();
      62             : 
      63       55740 :     m_lProps[aProperty.Name] = aProperty;
      64       27870 : }
      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        5572 : void SAL_CALL PropertySetHelper::impl_enablePropertySet()
      82             : {
      83        5572 : }
      84             : 
      85        5568 : void SAL_CALL PropertySetHelper::impl_disablePropertySet()
      86             : {
      87        5568 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
      88             : 
      89       11136 :     SolarMutexGuard g;
      90             : 
      91       11136 :     css::uno::Reference< css::uno::XInterface > xThis(static_cast< css::beans::XPropertySet* >(this), css::uno::UNO_QUERY);
      92       11136 :     css::lang::EventObject aEvent(xThis);
      93             : 
      94        5568 :     m_lSimpleChangeListener.disposeAndClear(aEvent);
      95        5568 :     m_lVetoChangeListener.disposeAndClear(aEvent);
      96       11136 :     m_lProps.free();
      97        5568 : }
      98             : 
      99           4 : 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           4 :     ::cppu::OInterfaceContainerHelper* pVetoListener = m_lVetoChangeListener.getContainer(aEvent.PropertyName);
     106           4 :     if (! pVetoListener)
     107           4 :         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 :                 static_cast<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           4 : 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           4 :     ::cppu::OInterfaceContainerHelper* pSimpleListener = m_lSimpleChangeListener.getContainer(aEvent.PropertyName);
     135           4 :     if (! pSimpleListener)
     136           8 :         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 :                 static_cast<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           2 : css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL PropertySetHelper::getPropertySetInfo()
     154             :     throw(css::uno::RuntimeException, std::exception)
     155             : {
     156           2 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     157             : 
     158           2 :     css::uno::Reference< css::beans::XPropertySetInfo > xInfo(static_cast< css::beans::XPropertySetInfo* >(this), css::uno::UNO_QUERY_THROW);
     159           2 :     return xInfo;
     160             : }
     161             : 
     162           4 : 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           4 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     173             : 
     174             :     // SAFE ->
     175           8 :     SolarMutexResettableGuard aWriteLock;
     176             : 
     177           4 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     178           4 :     if (pIt == m_lProps.end())
     179           0 :         throw css::beans::UnknownPropertyException();
     180             : 
     181           8 :     css::beans::Property aPropInfo = pIt->second;
     182             : 
     183           4 :     bool bLocked = true;
     184           4 :     if (m_bReleaseLockOnCall)
     185             :     {
     186           0 :         aWriteLock.clear();
     187           0 :         bLocked = false;
     188             :         // <- SAFE
     189             :     }
     190             : 
     191           8 :     css::uno::Any aCurrentValue = impl_getPropertyValue(aPropInfo.Name, aPropInfo.Handle);
     192             : 
     193           4 :     if (! bLocked)
     194             :     {
     195             :         // SAFE ->
     196           0 :         aWriteLock.reset();
     197             :     }
     198             : 
     199           4 :     bool bWillBeChanged = (aCurrentValue != aValue);
     200           4 :     if (! bWillBeChanged)
     201           4 :         return;
     202             : 
     203           8 :     css::beans::PropertyChangeEvent aEvent;
     204           4 :     aEvent.PropertyName   = aPropInfo.Name;
     205           4 :     aEvent.Further        = sal_False;
     206           4 :     aEvent.PropertyHandle = aPropInfo.Handle;
     207           4 :     aEvent.OldValue       = aCurrentValue;
     208           4 :     aEvent.NewValue       = aValue;
     209           4 :     aEvent.Source         = css::uno::Reference< css::uno::XInterface >(m_xBroadcaster.get(), css::uno::UNO_QUERY);
     210             : 
     211           4 :     if (m_bReleaseLockOnCall)
     212             :     {
     213           0 :         aWriteLock.clear();
     214             :         // <- SAFE
     215             :     }
     216             : 
     217           4 :     if (impl_existsVeto(aEvent))
     218           0 :         throw css::beans::PropertyVetoException();
     219             : 
     220           4 :     impl_setPropertyValue(aPropInfo.Name, aPropInfo.Handle, aValue);
     221             : 
     222           8 :     impl_notifyChangeListener(aEvent);
     223             : }
     224             : 
     225      126566 : css::uno::Any SAL_CALL PropertySetHelper::getPropertyValue(const OUString& sProperty)
     226             :     throw(css::beans::UnknownPropertyException,
     227             :           css::lang::WrappedTargetException   ,
     228             :           css::uno::RuntimeException, std::exception          )
     229             : {
     230      126566 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     231             : 
     232             :     // SAFE ->
     233      253132 :     SolarMutexClearableGuard aReadLock;
     234             : 
     235      126566 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     236      126566 :     if (pIt == m_lProps.end())
     237           0 :         throw css::beans::UnknownPropertyException();
     238             : 
     239      253132 :     css::beans::Property aPropInfo = pIt->second;
     240             : 
     241      126566 :     if (m_bReleaseLockOnCall)
     242           0 :         aReadLock.clear();
     243             : 
     244      253132 :     return impl_getPropertyValue(aPropInfo.Name, aPropInfo.Handle);
     245             : }
     246             : 
     247           0 : void SAL_CALL PropertySetHelper::addPropertyChangeListener(const OUString&                                            sProperty,
     248             :                                                            const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener)
     249             :     throw(css::beans::UnknownPropertyException,
     250             :           css::lang::WrappedTargetException   ,
     251             :           css::uno::RuntimeException, std::exception          )
     252             : {
     253           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     254             : 
     255             :     // SAFE ->
     256           0 :     SolarMutexClearableGuard aReadLock;
     257             : 
     258           0 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     259           0 :     if (pIt == m_lProps.end())
     260           0 :         throw css::beans::UnknownPropertyException();
     261             : 
     262           0 :     aReadLock.clear();
     263             :     // <- SAFE
     264             : 
     265           0 :     m_lSimpleChangeListener.addInterface(sProperty, xListener);
     266           0 : }
     267             : 
     268           0 : void SAL_CALL PropertySetHelper::removePropertyChangeListener(const OUString&                                            sProperty,
     269             :                                                               const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener)
     270             :     throw(css::beans::UnknownPropertyException,
     271             :           css::lang::WrappedTargetException   ,
     272             :           css::uno::RuntimeException, std::exception          )
     273             : {
     274           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
     275             : 
     276             :     // SAFE ->
     277           0 :     SolarMutexClearableGuard aReadLock;
     278             : 
     279           0 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     280           0 :     if (pIt == m_lProps.end())
     281           0 :         throw css::beans::UnknownPropertyException();
     282             : 
     283           0 :     aReadLock.clear();
     284             :     // <- SAFE
     285             : 
     286           0 :     m_lSimpleChangeListener.removeInterface(sProperty, xListener);
     287           0 : }
     288             : 
     289           0 : void SAL_CALL PropertySetHelper::addVetoableChangeListener(const OUString&                                            sProperty,
     290             :                                                            const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener)
     291             :     throw(css::beans::UnknownPropertyException,
     292             :           css::lang::WrappedTargetException   ,
     293             :           css::uno::RuntimeException, std::exception          )
     294             : {
     295           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     296             : 
     297             :     // SAFE ->
     298           0 :     SolarMutexClearableGuard aReadLock;
     299             : 
     300           0 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     301           0 :     if (pIt == m_lProps.end())
     302           0 :         throw css::beans::UnknownPropertyException();
     303             : 
     304           0 :     aReadLock.clear();
     305             :     // <- SAFE
     306             : 
     307           0 :     m_lVetoChangeListener.addInterface(sProperty, xListener);
     308           0 : }
     309             : 
     310           0 : void SAL_CALL PropertySetHelper::removeVetoableChangeListener(const OUString&                                            sProperty,
     311             :                                                               const css::uno::Reference< css::beans::XVetoableChangeListener >& xListener)
     312             :     throw(css::beans::UnknownPropertyException,
     313             :           css::lang::WrappedTargetException   ,
     314             :           css::uno::RuntimeException, std::exception          )
     315             : {
     316           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_SOFTEXCEPTIONS);
     317             : 
     318             :     // SAFE ->
     319           0 :     SolarMutexClearableGuard aReadLock;
     320             : 
     321           0 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sProperty);
     322           0 :     if (pIt == m_lProps.end())
     323           0 :         throw css::beans::UnknownPropertyException();
     324             : 
     325           0 :     aReadLock.clear();
     326             :     // <- SAFE
     327             : 
     328           0 :     m_lVetoChangeListener.removeInterface(sProperty, xListener);
     329           0 : }
     330             : 
     331           2 : css::uno::Sequence< css::beans::Property > SAL_CALL PropertySetHelper::getProperties()
     332             :     throw(css::uno::RuntimeException, std::exception)
     333             : {
     334           2 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     335             : 
     336           4 :     SolarMutexGuard g;
     337             : 
     338           2 :     sal_Int32                                        c     = (sal_Int32)m_lProps.size();
     339           2 :     css::uno::Sequence< css::beans::Property >       lProps(c);
     340           2 :     PropertySetHelper::TPropInfoHash::const_iterator pIt;
     341             : 
     342          36 :     for (  pIt  = m_lProps.begin();
     343          24 :            pIt != m_lProps.end();
     344             :          ++pIt                    )
     345             :     {
     346          10 :         lProps[--c] = pIt->second;
     347             :     }
     348             : 
     349           4 :     return lProps;
     350             : }
     351             : 
     352           0 : css::beans::Property SAL_CALL PropertySetHelper::getPropertyByName(const OUString& sName)
     353             :     throw(css::beans::UnknownPropertyException,
     354             :           css::uno::RuntimeException, std::exception          )
     355             : {
     356           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     357             : 
     358           0 :     SolarMutexGuard g;
     359             : 
     360           0 :     PropertySetHelper::TPropInfoHash::const_iterator pIt = m_lProps.find(sName);
     361           0 :     if (pIt == m_lProps.end())
     362           0 :         throw css::beans::UnknownPropertyException();
     363             : 
     364           0 :     return pIt->second;
     365             : }
     366             : 
     367           0 : sal_Bool SAL_CALL PropertySetHelper::hasPropertyByName(const OUString& sName)
     368             :     throw(css::uno::RuntimeException, std::exception)
     369             : {
     370           0 :     TransactionGuard aTransaction(m_rTransactionManager, E_HARDEXCEPTIONS);
     371             : 
     372           0 :     SolarMutexGuard g;
     373             : 
     374           0 :     PropertySetHelper::TPropInfoHash::iterator pIt    = m_lProps.find(sName);
     375           0 :     bool                                   bExist = (pIt != m_lProps.end());
     376             : 
     377           0 :     return bExist;
     378             : }
     379             : 
     380         969 : } // namespace framework
     381             : 
     382             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10