LCOV - code coverage report
Current view: top level - comphelper/source/property - genericpropertyset.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 43 103 41.7 %
Date: 2015-06-13 12:38:46 Functions: 12 19 63.2 %
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 <map>
      23             : 
      24             : #include <com/sun/star/lang/XServiceInfo.hpp>
      25             : #include <com/sun/star/lang/XTypeProvider.hpp>
      26             : #include <cppuhelper/weakagg.hxx>
      27             : #include <cppuhelper/interfacecontainer.hxx>
      28             : #include <cppuhelper/supportsservice.hxx>
      29             : #include <comphelper/propertysethelper.hxx>
      30             : #include <osl/mutex.hxx>
      31             : #include <comphelper/genericpropertyset.hxx>
      32             : #include <comphelper/propertysetinfo.hxx>
      33             : #include <comphelper/servicehelper.hxx>
      34             : 
      35             : using namespace ::osl;
      36             : using namespace ::cppu;
      37             : using namespace ::comphelper;
      38             : using namespace ::com::sun::star;
      39             : using namespace ::com::sun::star::uno;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::lang;
      42             : 
      43             : typedef std::map<OUString, Any> GenericAnyMapImpl;
      44             : 
      45             : namespace comphelper
      46             : {
      47        3338 :     struct IMPL_GenericPropertySet_MutexContainer
      48             :     {
      49             :         Mutex maMutex ;
      50             :     } ;
      51             : 
      52             :     class GenericPropertySet :  public OWeakAggObject,
      53             :                                 public XServiceInfo,
      54             :                                 public XTypeProvider,
      55             :                                 public PropertySetHelper,
      56             :                                 private IMPL_GenericPropertySet_MutexContainer
      57             :     {
      58             :     private:
      59             :         GenericAnyMapImpl   maAnyMap;
      60             :         cppu::OMultiTypeInterfaceContainerHelperVar<OUString> m_aListener;
      61             : 
      62             :     protected:
      63             :         virtual void _setPropertyValues( const PropertyMapEntry** ppEntries, const  Any* pValues ) throw( UnknownPropertyException,  PropertyVetoException,  IllegalArgumentException,  WrappedTargetException ) SAL_OVERRIDE;
      64             :         virtual void _getPropertyValues( const PropertyMapEntry** ppEntries,  Any* pValue ) throw( UnknownPropertyException,  WrappedTargetException ) SAL_OVERRIDE;
      65             : 
      66             :     public:
      67             :         explicit GenericPropertySet( PropertySetInfo* pInfo ) throw();
      68             :         virtual ~GenericPropertySet() throw();
      69             : 
      70             :         // XInterface
      71             :         virtual  Any SAL_CALL queryAggregation( const  Type & rType ) throw( RuntimeException, std::exception) SAL_OVERRIDE;
      72             :         virtual  Any SAL_CALL queryInterface( const  Type & rType ) throw( RuntimeException, std::exception) SAL_OVERRIDE;
      73             :         virtual void SAL_CALL acquire() throw() SAL_OVERRIDE;
      74             :         virtual void SAL_CALL release() throw() SAL_OVERRIDE;
      75             : 
      76             :         // XTypeProvider
      77             :         virtual  Sequence<  Type > SAL_CALL getTypes(  ) throw( RuntimeException, std::exception) SAL_OVERRIDE;
      78             :         virtual  Sequence< sal_Int8 > SAL_CALL getImplementationId(  ) throw( RuntimeException, std::exception) SAL_OVERRIDE;
      79             : 
      80             :         // XServiceInfo
      81             :         virtual OUString SAL_CALL getImplementationName() throw(  RuntimeException, std::exception ) SAL_OVERRIDE;
      82             :         virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(  RuntimeException, std::exception ) SAL_OVERRIDE;
      83             :         virtual  Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(  RuntimeException, std::exception ) SAL_OVERRIDE;
      84             : 
      85             :         // XPropertySet
      86             :         virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      87             :         virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      88             :     };
      89             : 
      90             : }
      91             : 
      92             : 
      93             : 
      94        1669 : GenericPropertySet::GenericPropertySet( PropertySetInfo* pInfo ) throw()
      95             : : PropertySetHelper( pInfo )
      96        1669 : ,m_aListener(maMutex)
      97             : {
      98        1669 : }
      99             : 
     100        3338 : GenericPropertySet::~GenericPropertySet() throw()
     101             : {
     102        3338 : }
     103           0 : void SAL_CALL GenericPropertySet::addPropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     104             : {
     105           0 :     Reference < XPropertySetInfo > xInfo = getPropertySetInfo(  );
     106           0 :     if ( xInfo.is() )
     107             :     {
     108           0 :         if ( aPropertyName.isEmpty() )
     109             :         {
     110           0 :             Sequence< Property> aSeq = xInfo->getProperties();
     111           0 :             const Property* pIter = aSeq.getConstArray();
     112           0 :             const Property* pEnd  = pIter + aSeq.getLength();
     113           0 :             for( ; pIter != pEnd ; ++pIter)
     114             :             {
     115           0 :                 m_aListener.addInterface(pIter->Name,xListener);
     116           0 :             }
     117             :         }
     118           0 :         else if ( xInfo->hasPropertyByName(aPropertyName) )
     119           0 :             m_aListener.addInterface(aPropertyName,xListener);
     120             :         else
     121           0 :             throw UnknownPropertyException( aPropertyName, *this );
     122           0 :     }
     123           0 : }
     124             : 
     125           0 : void SAL_CALL GenericPropertySet::removePropertyChangeListener( const OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
     126             : {
     127           0 :     ResettableMutexGuard aGuard( maMutex );
     128           0 :     Reference < XPropertySetInfo > xInfo = getPropertySetInfo(  );
     129           0 :     aGuard.clear();
     130           0 :     if ( xInfo.is() )
     131             :     {
     132           0 :         if ( aPropertyName.isEmpty() )
     133             :         {
     134           0 :             Sequence< Property> aSeq = xInfo->getProperties();
     135           0 :             const Property* pIter = aSeq.getConstArray();
     136           0 :             const Property* pEnd  = pIter + aSeq.getLength();
     137           0 :             for( ; pIter != pEnd ; ++pIter)
     138             :             {
     139           0 :                 m_aListener.removeInterface(pIter->Name,xListener);
     140           0 :             }
     141             :         }
     142           0 :         else if ( xInfo->hasPropertyByName(aPropertyName) )
     143           0 :             m_aListener.removeInterface(aPropertyName,xListener);
     144             :         else
     145           0 :             throw UnknownPropertyException( aPropertyName, *this );
     146           0 :     }
     147           0 : }
     148             : 
     149       19436 : void GenericPropertySet::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues )
     150             :     throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
     151             : {
     152       19436 :     ResettableMutexGuard aGuard( maMutex );
     153             : 
     154       58308 :     while( *ppEntries )
     155             :     {
     156       19436 :         OInterfaceContainerHelper * pHelper = m_aListener.getContainer((*ppEntries)->maName);
     157             : 
     158       19436 :         maAnyMap[ (*ppEntries)->maName ] = *pValues;
     159             : 
     160       19436 :         if ( pHelper )
     161             :         {
     162           0 :             PropertyChangeEvent aEvt;
     163           0 :             aEvt.PropertyName = (*ppEntries)->maName;
     164           0 :             aEvt.NewValue = *pValues;
     165           0 :             aGuard.clear();
     166           0 :             pHelper->notifyEach( &XPropertyChangeListener::propertyChange, aEvt );
     167           0 :             aGuard.reset();
     168             :         }
     169             : 
     170       19436 :         ppEntries++;
     171       19436 :         pValues++;
     172       19436 :     }
     173       19436 : }
     174             : 
     175       48727 : void GenericPropertySet::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, Any* pValue )
     176             :     throw( UnknownPropertyException, WrappedTargetException )
     177             : {
     178       48727 :     MutexGuard aGuard( maMutex );
     179             : 
     180      146181 :     while( *ppEntries )
     181             :     {
     182       48727 :         *pValue = maAnyMap[ (*ppEntries)->maName ];
     183             : 
     184       48727 :         ppEntries++;
     185       48727 :         pValue++;
     186       48727 :     }
     187       48727 : }
     188             : 
     189             : // XInterface
     190             : 
     191       26523 : Any SAL_CALL GenericPropertySet::queryInterface( const Type & rType )
     192             :     throw( RuntimeException, std::exception )
     193             : {
     194       26523 :     return OWeakAggObject::queryInterface( rType );
     195             : }
     196             : 
     197       26523 : Any SAL_CALL GenericPropertySet::queryAggregation( const Type & rType )
     198             :     throw(RuntimeException, std::exception)
     199             : {
     200       26523 :     Any aAny;
     201             : 
     202       26523 :     if( rType == cppu::UnoType<XServiceInfo>::get())
     203           0 :         aAny <<= Reference< XServiceInfo >(this);
     204       26523 :     else if( rType == cppu::UnoType<XTypeProvider>::get())
     205           0 :         aAny <<= Reference< XTypeProvider >(this);
     206       26523 :     else if( rType == cppu::UnoType<XPropertySet>::get())
     207        4833 :         aAny <<= Reference< XPropertySet >(this);
     208       21690 :     else if( rType == cppu::UnoType<XMultiPropertySet>::get())
     209           0 :         aAny <<= Reference< XMultiPropertySet >(this);
     210             :     else
     211       21690 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     212             : 
     213       26523 :     return aAny;
     214             : }
     215             : 
     216       39381 : void SAL_CALL GenericPropertySet::acquire() throw()
     217             : {
     218       39381 :     OWeakAggObject::acquire();
     219       39381 : }
     220             : 
     221       39381 : void SAL_CALL GenericPropertySet::release() throw()
     222             : {
     223       39381 :     OWeakAggObject::release();
     224       39381 : }
     225             : 
     226           0 : uno::Sequence< uno::Type > SAL_CALL GenericPropertySet::getTypes()
     227             :     throw (uno::RuntimeException, std::exception)
     228             : {
     229           0 :     uno::Sequence< uno::Type > aTypes( 5 );
     230           0 :     uno::Type* pTypes = aTypes.getArray();
     231             : 
     232           0 :     *pTypes++ = cppu::UnoType<XAggregation>::get();
     233           0 :     *pTypes++ = cppu::UnoType<XServiceInfo>::get();
     234           0 :     *pTypes++ = cppu::UnoType<XTypeProvider>::get();
     235           0 :     *pTypes++ = cppu::UnoType<XPropertySet>::get();
     236           0 :     *pTypes++ = cppu::UnoType<XMultiPropertySet>::get();
     237             : 
     238           0 :     return aTypes;
     239             : }
     240             : 
     241           0 : uno::Sequence< sal_Int8 > SAL_CALL GenericPropertySet::getImplementationId()
     242             :     throw (uno::RuntimeException, std::exception)
     243             : {
     244           0 :     return css::uno::Sequence<sal_Int8>();
     245             : }
     246             : 
     247             : // XServiceInfo
     248           0 : sal_Bool SAL_CALL GenericPropertySet::supportsService( const  OUString& ServiceName ) throw(RuntimeException, std::exception)
     249             : {
     250           0 :     return cppu::supportsService(this, ServiceName);
     251             : }
     252             : 
     253           0 : OUString SAL_CALL GenericPropertySet::getImplementationName() throw( RuntimeException, std::exception )
     254             : {
     255           0 :     return OUString( "com.sun.star.comp.comphelper.GenericPropertySet" );
     256             : }
     257             : 
     258           0 : Sequence< OUString > SAL_CALL GenericPropertySet::getSupportedServiceNames(  )
     259             :     throw( RuntimeException, std::exception )
     260             : {
     261           0 :     Sequence< OUString > aSNS( 1 );
     262           0 :     aSNS.getArray()[0] = "com.sun.star.beans.XPropertySet";
     263           0 :     return aSNS;
     264             : }
     265             : 
     266        1669 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > comphelper::GenericPropertySet_CreateInstance( comphelper::PropertySetInfo* pInfo )
     267             : {
     268        1669 :     return static_cast<XPropertySet*>(new GenericPropertySet( pInfo ));
     269             : }
     270             : 
     271             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11