LCOV - code coverage report
Current view: top level - libreoffice/comphelper/source/property - genericpropertyset.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 45 110 40.9 %
Date: 2012-12-27 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 <com/sun/star/lang/XServiceInfo.hpp>
      21             : #include <com/sun/star/lang/XTypeProvider.hpp>
      22             : #include <cppuhelper/weakagg.hxx>
      23             : #include <cppuhelper/interfacecontainer.hxx>
      24             : #include <comphelper/propertysethelper.hxx>
      25             : #include <osl/mutex.hxx>
      26             : #include <comphelper/genericpropertyset.hxx>
      27             : #include <comphelper/propertysetinfo.hxx>
      28             : #include <comphelper/stl_types.hxx>
      29             : #include <comphelper/servicehelper.hxx>
      30             : #include <rtl/uuid.h>
      31             : 
      32             : ///////////////////////////////////////////////////////////////////////
      33             : 
      34             : using namespace ::rtl;
      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             : DECLARE_STL_USTRINGACCESS_MAP( Any, GenericAnyMapImpl );
      44             : 
      45             : namespace comphelper
      46             : {
      47         422 :     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< ::rtl::OUString, ::rtl::OUStringHash,UStringEqual> m_aListener;
      61             : 
      62             :     protected:
      63             :         virtual void _setPropertyValues( const PropertyMapEntry** ppEntries, const  Any* pValues ) throw( UnknownPropertyException,  PropertyVetoException,  IllegalArgumentException,  WrappedTargetException );
      64             :         virtual void _getPropertyValues( const PropertyMapEntry** ppEntries,  Any* pValue ) throw( UnknownPropertyException,  WrappedTargetException );
      65             : 
      66             :     public:
      67             :         GenericPropertySet( PropertySetInfo* pInfo ) throw();
      68             :         virtual ~GenericPropertySet() throw();
      69             : 
      70             :         // XInterface
      71             :         virtual  Any SAL_CALL queryAggregation( const  Type & rType ) throw( RuntimeException);
      72             :         virtual  Any SAL_CALL queryInterface( const  Type & rType ) throw( RuntimeException);
      73             :         virtual void SAL_CALL acquire() throw();
      74             :         virtual void SAL_CALL release() throw();
      75             : 
      76             :         // XTypeProvider
      77             :         virtual  Sequence<  Type > SAL_CALL getTypes(  ) throw( RuntimeException);
      78             :         virtual  Sequence< sal_Int8 > SAL_CALL getImplementationId(  ) throw( RuntimeException);
      79             : 
      80             :         // XServiceInfo
      81             :         virtual rtl::OUString SAL_CALL getImplementationName() throw(  RuntimeException );
      82             :         virtual sal_Bool SAL_CALL supportsService( const rtl::OUString& ServiceName ) throw(  RuntimeException );
      83             :         virtual  Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw(  RuntimeException );
      84             : 
      85             :         // XPropertySet
      86             :         virtual void SAL_CALL addPropertyChangeListener( const ::rtl::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);
      87             :         virtual void SAL_CALL removePropertyChangeListener( const ::rtl::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);
      88             :     };
      89             : 
      90             : }
      91             : 
      92             : ///////////////////////////////////////////////////////////////////////
      93             : 
      94         211 : GenericPropertySet::GenericPropertySet( PropertySetInfo* pInfo ) throw()
      95             : : PropertySetHelper( pInfo )
      96         211 : ,m_aListener(maMutex)
      97             : {
      98         211 : }
      99             : 
     100         422 : GenericPropertySet::~GenericPropertySet() throw()
     101             : {
     102         422 : }
     103           0 : void SAL_CALL GenericPropertySet::addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     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 ::rtl::OUString& aPropertyName, const Reference< XPropertyChangeListener >& xListener ) throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
     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        1591 : void GenericPropertySet::_setPropertyValues( const PropertyMapEntry** ppEntries, const Any* pValues )
     150             :     throw(UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException )
     151             : {
     152        1591 :     ResettableMutexGuard aGuard( maMutex );
     153             : 
     154        4773 :     while( *ppEntries )
     155             :     {
     156        1591 :         const OUString aPropertyName( (*ppEntries)->mpName, (*ppEntries)->mnNameLen, RTL_TEXTENCODING_ASCII_US );
     157        1591 :         OInterfaceContainerHelper * pHelper = m_aListener.getContainer(aPropertyName);
     158             : 
     159        1591 :         maAnyMap[ aPropertyName ] = *pValues;
     160             : 
     161        1591 :         if ( pHelper )
     162             :         {
     163           0 :             PropertyChangeEvent aEvt;
     164           0 :             aEvt.PropertyName = aPropertyName;
     165           0 :             aEvt.NewValue = *pValues;
     166           0 :             aGuard.clear();
     167           0 :             pHelper->notifyEach( &XPropertyChangeListener::propertyChange, aEvt );
     168           0 :             aGuard.reset();
     169             :         }
     170             : 
     171        1591 :         ppEntries++;
     172        1591 :         pValues++;
     173        3182 :     }
     174        1591 : }
     175             : 
     176        3546 : void GenericPropertySet::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, Any* pValue )
     177             :     throw( UnknownPropertyException, WrappedTargetException )
     178             : {
     179        3546 :     MutexGuard aGuard( maMutex );
     180             : 
     181       10638 :     while( *ppEntries )
     182             :     {
     183        3546 :         const OUString aPropertyName( (*ppEntries)->mpName, (*ppEntries)->mnNameLen, RTL_TEXTENCODING_ASCII_US );
     184        3546 :         *pValue = maAnyMap[ aPropertyName ];
     185             : 
     186        3546 :         ppEntries++;
     187        3546 :         pValue++;
     188        7092 :     }
     189        3546 : }
     190             : 
     191             : // XInterface
     192             : 
     193        2874 : Any SAL_CALL GenericPropertySet::queryInterface( const Type & rType )
     194             :     throw( RuntimeException )
     195             : {
     196        2874 :     return OWeakAggObject::queryInterface( rType );
     197             : }
     198             : 
     199        2874 : Any SAL_CALL GenericPropertySet::queryAggregation( const Type & rType )
     200             :     throw(RuntimeException)
     201             : {
     202        2874 :     Any aAny;
     203             : 
     204        2874 :     if( rType == ::getCppuType((const Reference< XServiceInfo >*)0) )
     205           0 :         aAny <<= Reference< XServiceInfo >(this);
     206        2874 :     else if( rType == ::getCppuType((const Reference< XTypeProvider >*)0) )
     207           0 :         aAny <<= Reference< XTypeProvider >(this);
     208        2874 :     else if( rType == ::getCppuType((const Reference< XPropertySet >*)0) )
     209         506 :         aAny <<= Reference< XPropertySet >(this);
     210        2368 :     else if( rType == ::getCppuType((const Reference< XMultiPropertySet >*)0) )
     211           0 :         aAny <<= Reference< XMultiPropertySet >(this);
     212             :     else
     213        2368 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     214             : 
     215        2874 :     return aAny;
     216             : }
     217             : 
     218        3678 : void SAL_CALL GenericPropertySet::acquire() throw()
     219             : {
     220        3678 :     OWeakAggObject::acquire();
     221        3678 : }
     222             : 
     223        3678 : void SAL_CALL GenericPropertySet::release() throw()
     224             : {
     225        3678 :     OWeakAggObject::release();
     226        3678 : }
     227             : 
     228           0 : uno::Sequence< uno::Type > SAL_CALL GenericPropertySet::getTypes()
     229             :     throw (uno::RuntimeException)
     230             : {
     231           0 :     uno::Sequence< uno::Type > aTypes( 5 );
     232           0 :     uno::Type* pTypes = aTypes.getArray();
     233             : 
     234           0 :     *pTypes++ = ::getCppuType((const uno::Reference< XAggregation>*)0);
     235           0 :     *pTypes++ = ::getCppuType((const uno::Reference< XServiceInfo>*)0);
     236           0 :     *pTypes++ = ::getCppuType((const uno::Reference< XTypeProvider>*)0);
     237           0 :     *pTypes++ = ::getCppuType((const uno::Reference< XPropertySet>*)0);
     238           0 :     *pTypes++ = ::getCppuType((const uno::Reference< XMultiPropertySet>*)0);
     239             : 
     240           0 :     return aTypes;
     241             : }
     242             : 
     243             : namespace
     244             : {
     245             :     class theGenericPropertySetImplmentationId : public rtl::Static< UnoTunnelIdInit, theGenericPropertySetImplmentationId > {};
     246             : }
     247             : 
     248           0 : uno::Sequence< sal_Int8 > SAL_CALL GenericPropertySet::getImplementationId()
     249             :     throw (uno::RuntimeException)
     250             : {
     251           0 :     return theGenericPropertySetImplmentationId::get().getSeq();
     252             : }
     253             : 
     254             : // XServiceInfo
     255             : 
     256           0 : sal_Bool SAL_CALL GenericPropertySet::supportsService( const  OUString& ServiceName ) throw(RuntimeException)
     257             : {
     258           0 :     Sequence< OUString > aSNL( getSupportedServiceNames() );
     259           0 :     const OUString * pArray = aSNL.getConstArray();
     260             : 
     261           0 :     for( sal_Int32 i = 0; i < aSNL.getLength(); ++i )
     262           0 :         if( pArray[i] == ServiceName )
     263           0 :             return sal_True;
     264             : 
     265           0 :     return sal_False;
     266             : }
     267             : 
     268           0 : OUString SAL_CALL GenericPropertySet::getImplementationName() throw( RuntimeException )
     269             : {
     270           0 :     return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.comphelper.GenericPropertySet") );
     271             : }
     272             : 
     273           0 : Sequence< OUString > SAL_CALL GenericPropertySet::getSupportedServiceNames(  )
     274             :     throw( RuntimeException )
     275             : {
     276           0 :     Sequence< OUString > aSNS( 1 );
     277           0 :     aSNS.getArray()[0] = OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.beans.XPropertySet" ));
     278           0 :     return aSNS;
     279             : }
     280             : 
     281         211 : ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > comphelper::GenericPropertySet_CreateInstance( comphelper::PropertySetInfo* pInfo )
     282             : {
     283         211 :     return (XPropertySet*)new GenericPropertySet( pInfo );
     284             : }
     285             : 
     286             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10