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

Generated by: LCOV version 1.10