LCOV - code coverage report
Current view: top level - ucb/source/core - provprox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 52 97 53.6 %
Date: 2012-08-25 Functions: 21 34 61.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 53 281 18.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <osl/diagnose.h>
      30                 :            : #include <osl/thread.h>
      31                 :            : #include <rtl/strbuf.hxx>
      32                 :            : #include "provprox.hxx"
      33                 :            : #include <com/sun/star/lang/XInitialization.hpp>
      34                 :            : 
      35                 :            : using namespace com::sun::star::lang;
      36                 :            : using namespace com::sun::star::ucb;
      37                 :            : using namespace com::sun::star::uno;
      38                 :            : 
      39                 :            : using ::rtl::OUString;
      40                 :            : 
      41                 :            : //=========================================================================
      42                 :            : //=========================================================================
      43                 :            : //
      44                 :            : // UcbContentProviderProxyFactory Implementation.
      45                 :            : //
      46                 :            : //=========================================================================
      47                 :            : //=========================================================================
      48                 :            : 
      49                 :        248 : UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
      50                 :            :                         const Reference< XMultiServiceFactory >& rxSMgr )
      51                 :        248 : : m_xSMgr( rxSMgr )
      52                 :            : {
      53                 :        248 : }
      54                 :            : 
      55                 :            : //=========================================================================
      56                 :            : // virtual
      57                 :        248 : UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
      58                 :            : {
      59         [ -  + ]:        496 : }
      60                 :            : 
      61                 :            : //=========================================================================
      62                 :            : //
      63                 :            : // XInterface methods.
      64                 :            : //
      65                 :            : //=========================================================================
      66                 :            : 
      67 [ +  - ][ +  + ]:      42871 : XINTERFACE_IMPL_3( UcbContentProviderProxyFactory,
                 [ +  - ]
      68                 :            :                    XTypeProvider,
      69                 :            :                    XServiceInfo,
      70                 :            :                    XContentProviderFactory );
      71                 :            : 
      72                 :            : //=========================================================================
      73                 :            : //
      74                 :            : // XTypeProvider methods.
      75                 :            : //
      76                 :            : //=========================================================================
      77                 :            : 
      78 [ #  # ][ #  # ]:          0 : XTYPEPROVIDER_IMPL_3( UcbContentProviderProxyFactory,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      79                 :            :                           XTypeProvider,
      80                 :            :                       XServiceInfo,
      81                 :            :                           XContentProviderFactory );
      82                 :            : 
      83                 :            : //=========================================================================
      84                 :            : //
      85                 :            : // XServiceInfo methods.
      86                 :            : //
      87                 :            : //=========================================================================
      88                 :            : 
      89 [ +  - ][ +  - ]:        998 : XSERVICEINFO_IMPL_1( UcbContentProviderProxyFactory,
         [ +  - ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      90                 :            :                      OUString( "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" ),
      91                 :        248 :                      OUString( PROVIDER_FACTORY_SERVICE_NAME ) );
      92                 :            : 
      93                 :            : //=========================================================================
      94                 :            : //
      95                 :            : // Service factory implementation.
      96                 :            : //
      97                 :            : //=========================================================================
      98                 :            : 
      99 [ +  - ][ +  - ]:        248 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory );
     100                 :            : 
     101                 :            : //=========================================================================
     102                 :            : //
     103                 :            : // XContentProviderFactory methods.
     104                 :            : //
     105                 :            : //=========================================================================
     106                 :            : 
     107                 :            : // virtual
     108                 :            : Reference< XContentProvider > SAL_CALL
     109                 :       3713 : UcbContentProviderProxyFactory::createContentProvider(
     110                 :            :                                                 const OUString& Service )
     111                 :            :     throw( RuntimeException )
     112                 :            : {
     113                 :            :     return Reference< XContentProvider >(
     114 [ +  - ][ +  - ]:       3713 :                         new UcbContentProviderProxy( m_xSMgr, Service ) );
     115                 :            : }
     116                 :            : 
     117                 :            : //=========================================================================
     118                 :            : //=========================================================================
     119                 :            : //
     120                 :            : // UcbContentProviderProxy Implementation.
     121                 :            : //
     122                 :            : //=========================================================================
     123                 :            : //=========================================================================
     124                 :            : 
     125                 :       3713 : UcbContentProviderProxy::UcbContentProviderProxy(
     126                 :            :                         const Reference< XMultiServiceFactory >& rxSMgr,
     127                 :            :                         const OUString& Service )
     128                 :            : : m_aService( Service ),
     129                 :            :   m_bReplace( sal_False ),
     130                 :            :   m_bRegister( sal_False ),
     131         [ +  - ]:       3713 :   m_xSMgr( rxSMgr )
     132                 :            : {
     133                 :       3713 : }
     134                 :            : 
     135                 :            : //=========================================================================
     136                 :            : // virtual
     137         [ +  - ]:       3713 : UcbContentProviderProxy::~UcbContentProviderProxy()
     138                 :            : {
     139         [ -  + ]:       7426 : }
     140                 :            : 
     141                 :            : //=========================================================================
     142                 :            : //
     143                 :            : // XInterface methods.
     144                 :            : //
     145                 :            : //=========================================================================
     146                 :            : 
     147                 :     111208 : XINTERFACE_COMMON_IMPL( UcbContentProviderProxy );
     148                 :            : 
     149                 :            : //============================================================================
     150                 :            : // virtual
     151                 :            : Any SAL_CALL
     152                 :      16681 : UcbContentProviderProxy::queryInterface( const Type & rType )
     153                 :            :     throw ( RuntimeException )
     154                 :            : {
     155                 :            :     Any aRet = cppu::queryInterface( rType,
     156                 :            :                 static_cast< XTypeProvider * >( this ),
     157                 :            :                 static_cast< XServiceInfo * >( this ),
     158                 :            :                 static_cast< XContentProvider * >( this ),
     159                 :            :                 static_cast< XParameterizedContentProvider * >( this ),
     160                 :      16681 :                 static_cast< XContentProviderSupplier * >( this ) );
     161                 :            : 
     162         [ +  + ]:      16681 :     if ( !aRet.hasValue() )
     163         [ +  - ]:      12430 :         aRet = OWeakObject::queryInterface( rType );
     164                 :            : 
     165         [ +  + ]:      16681 :     if ( !aRet.hasValue() )
     166                 :            :     {
     167                 :            :         // Get original provider an forward the call...
     168         [ +  - ]:      12398 :         osl::Guard< osl::Mutex > aGuard( m_aMutex );
     169         [ +  - ]:      12398 :         Reference< XContentProvider > xProvider = getContentProvider();
     170         [ +  + ]:      12398 :         if ( xProvider.is() )
     171 [ +  - ][ +  - ]:      12398 :             aRet = xProvider->queryInterface( rType );
                 [ +  - ]
     172                 :            :     }
     173                 :            : 
     174                 :      16681 :     return aRet;
     175                 :            : }
     176                 :            : 
     177                 :            : //=========================================================================
     178                 :            : //
     179                 :            : // XTypeProvider methods.
     180                 :            : //
     181                 :            : //=========================================================================
     182                 :            : 
     183 [ #  # ][ #  # ]:          0 : XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     184                 :            : 
     185                 :            : //=========================================================================
     186                 :            : 
     187                 :          0 : Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes()                                                           \
     188                 :            :     throw( RuntimeException )
     189                 :            : {
     190                 :            :     // Get original provider an forward the call...
     191         [ #  # ]:          0 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     192 [ #  # ][ #  # ]:          0 :     Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY );
     193         [ #  # ]:          0 :     if ( xProvider.is() )
     194                 :            :     {
     195 [ #  # ][ #  # ]:          0 :         return xProvider->getTypes();
     196                 :            :     }
     197                 :            :     else
     198                 :            :     {
     199                 :            :         static cppu::OTypeCollection collection(
     200         [ #  # ]:          0 :             CPPU_TYPE_REF( XTypeProvider ),
     201         [ #  # ]:          0 :             CPPU_TYPE_REF( XServiceInfo ),
     202         [ #  # ]:          0 :             CPPU_TYPE_REF( XContentProvider ),
     203         [ #  # ]:          0 :             CPPU_TYPE_REF( XParameterizedContentProvider ),
     204 [ #  # ][ #  # ]:          0 :             CPPU_TYPE_REF( XContentProviderSupplier ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     205         [ #  # ]:          0 :         return collection.getTypes();
     206         [ #  # ]:          0 :     }
     207                 :            : }
     208                 :            : 
     209                 :            : //=========================================================================
     210                 :            : //
     211                 :            : // XServiceInfo methods.
     212                 :            : //
     213                 :            : //=========================================================================
     214                 :            : 
     215 [ #  # ][ #  # ]:          0 : XSERVICEINFO_NOFACTORY_IMPL_1( UcbContentProviderProxy,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     216                 :            :                             OUString( "com.sun.star.comp.ucb.UcbContentProviderProxy" ),
     217                 :            :                             OUString( PROVIDER_PROXY_SERVICE_NAME ) );
     218                 :            : 
     219                 :            : //=========================================================================
     220                 :            : //
     221                 :            : // XContentProvider methods.
     222                 :            : //
     223                 :            : //=========================================================================
     224                 :            : 
     225                 :            : // virtual
     226                 :        609 : Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent(
     227                 :            :                         const Reference< XContentIdentifier >& Identifier )
     228                 :            :     throw( IllegalIdentifierException,
     229                 :            :            RuntimeException )
     230                 :            : {
     231                 :            :     // Get original provider an forward the call...
     232                 :            : 
     233         [ +  - ]:        609 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     234                 :            : 
     235         [ +  - ]:        609 :     Reference< XContentProvider > xProvider = getContentProvider();
     236         [ -  + ]:        609 :     if ( xProvider.is() )
     237 [ #  # ][ #  # ]:          0 :         return xProvider->queryContent( Identifier );
     238                 :            : 
     239         [ +  - ]:        609 :     return Reference< XContent >();
     240                 :            : }
     241                 :            : 
     242                 :            : //=========================================================================
     243                 :            : // virtual
     244                 :          0 : sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds(
     245                 :            :                        const Reference< XContentIdentifier >& Id1,
     246                 :            :                        const Reference< XContentIdentifier >& Id2 )
     247                 :            :     throw( RuntimeException )
     248                 :            : {
     249                 :            :     // Get original provider an forward the call...
     250                 :            : 
     251         [ #  # ]:          0 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     252         [ #  # ]:          0 :     Reference< XContentProvider > xProvider = getContentProvider();
     253         [ #  # ]:          0 :     if ( xProvider.is() )
     254 [ #  # ][ #  # ]:          0 :         return xProvider->compareContentIds( Id1, Id2 );
     255                 :            : 
     256                 :            :     // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
     257                 :            : 
     258                 :            :     // @@@ What else?
     259         [ #  # ]:          0 :     return 0;
     260                 :            : }
     261                 :            : 
     262                 :            : //=========================================================================
     263                 :            : //
     264                 :            : // XParameterizedContentProvider methods.
     265                 :            : //
     266                 :            : //=========================================================================
     267                 :            : 
     268                 :            : // virtual
     269                 :            : Reference< XContentProvider > SAL_CALL
     270                 :       3711 : UcbContentProviderProxy::registerInstance( const OUString& Template,
     271                 :            :                                              const OUString& Arguments,
     272                 :            :                                              sal_Bool ReplaceExisting )
     273                 :            :     throw( IllegalArgumentException,
     274                 :            :            RuntimeException )
     275                 :            : {
     276                 :            :     // Just remember that this method was called ( and the params ).
     277                 :            : 
     278         [ +  - ]:       3711 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     279                 :            : 
     280         [ +  - ]:       3711 :     if ( !m_bRegister )
     281                 :            :     {
     282                 :            : //      m_xTargetProvider = 0;
     283                 :       3711 :         m_aTemplate  = Template;
     284                 :       3711 :         m_aArguments = Arguments;
     285                 :       3711 :         m_bReplace   = ReplaceExisting;
     286                 :            : 
     287                 :       3711 :         m_bRegister  = sal_True;
     288                 :            :     }
     289 [ +  - ][ +  - ]:       3711 :     return this;
     290                 :            : }
     291                 :            : 
     292                 :            : //=========================================================================
     293                 :            : // virtual
     294                 :            : Reference< XContentProvider > SAL_CALL
     295                 :          0 : UcbContentProviderProxy::deregisterInstance( const OUString& Template,
     296                 :            :                                              const OUString& Arguments )
     297                 :            :     throw( IllegalArgumentException,
     298                 :            :            RuntimeException )
     299                 :            : {
     300         [ #  # ]:          0 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     301                 :            : 
     302                 :            :     // registerInstance called at proxy and at original?
     303 [ #  # ][ #  # ]:          0 :     if ( m_bRegister && m_xTargetProvider.is() )
                 [ #  # ]
     304                 :            :     {
     305                 :          0 :         m_bRegister       = sal_False;
     306         [ #  # ]:          0 :         m_xTargetProvider = 0;
     307                 :            : 
     308                 :            :         Reference< XParameterizedContentProvider >
     309         [ #  # ]:          0 :                                 xParamProvider( m_xProvider, UNO_QUERY );
     310         [ #  # ]:          0 :         if ( xParamProvider.is() )
     311                 :            :         {
     312                 :            :             try
     313                 :            :             {
     314 [ #  # ][ #  # ]:          0 :                 xParamProvider->deregisterInstance( Template, Arguments );
     315                 :            :             }
     316         [ #  # ]:          0 :             catch ( IllegalIdentifierException const & )
     317                 :            :             {
     318                 :            :                 OSL_FAIL( "UcbContentProviderProxy::deregisterInstance - "
     319                 :            :                     "Caught IllegalIdentifierException!" );
     320                 :            :             }
     321                 :          0 :         }
     322                 :            :     }
     323                 :            : 
     324 [ #  # ][ #  # ]:          0 :     return this;
                 [ #  # ]
     325                 :            : }
     326                 :            : 
     327                 :            : //=========================================================================
     328                 :            : //
     329                 :            : // XContentProviderSupplier methods.
     330                 :            : //
     331                 :            : //=========================================================================
     332                 :            : 
     333                 :            : // virtual
     334                 :            : Reference< XContentProvider > SAL_CALL
     335                 :      13547 : UcbContentProviderProxy::getContentProvider()
     336                 :            :     throw( RuntimeException )
     337                 :            : {
     338         [ +  - ]:      13547 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     339         [ +  + ]:      13547 :     if ( !m_xProvider.is() )
     340                 :            :     {
     341                 :            :         try
     342                 :            :         {
     343                 :            :             m_xProvider
     344                 :            :                 = Reference< XContentProvider >(
     345 [ +  - ][ +  - ]:       1758 :                       m_xSMgr->createInstance( m_aService ), UNO_QUERY );
         [ +  - ][ +  - ]
     346         [ -  + ]:       1758 :             if ( m_aArguments == "NoConfig" )
     347                 :            :             {
     348         [ #  # ]:          0 :                 Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
     349         [ #  # ]:          0 :                 if(xInit.is()) {
     350         [ #  # ]:          0 :                     Sequence<Any> aArgs(1);
     351 [ #  # ][ #  # ]:          0 :                     aArgs[0] <<= m_aArguments;
     352 [ #  # ][ #  # ]:          0 :                     xInit->initialize(aArgs);
                 [ #  # ]
     353                 :          0 :                 }
     354                 :            :             }
     355                 :            :         }
     356      [ #  #  # ]:          0 :         catch ( RuntimeException const & )
     357                 :            :         {
     358                 :          0 :             throw;
     359                 :            :         }
     360         [ #  # ]:          0 :         catch ( Exception const & )
     361                 :            :         {
     362                 :            :         }
     363                 :            : 
     364                 :            :         // registerInstance called at proxy, but not yet at original?
     365 [ +  + ][ +  - ]:       1758 :         if ( m_xProvider.is() && m_bRegister )
                 [ +  + ]
     366                 :            :         {
     367                 :            :             Reference< XParameterizedContentProvider >
     368         [ +  - ]:        403 :                 xParamProvider( m_xProvider, UNO_QUERY );
     369         [ -  + ]:        403 :             if ( xParamProvider.is() )
     370                 :            :             {
     371                 :            :                 try
     372                 :            :                 {
     373                 :            :                     m_xTargetProvider
     374         [ #  # ]:          0 :                         = xParamProvider->registerInstance( m_aTemplate,
     375                 :            :                                                             m_aArguments,
     376 [ #  # ][ #  # ]:          0 :                                                             m_bReplace );
                 [ #  # ]
     377                 :            :                 }
     378         [ #  # ]:          0 :                 catch ( IllegalIdentifierException const & )
     379                 :            :                 {
     380                 :            :                     OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
     381                 :            :                         "Caught IllegalIdentifierException!" );
     382                 :            :                 }
     383                 :            : 
     384                 :            :                 OSL_ENSURE( m_xTargetProvider.is(),
     385                 :            :                     "UcbContentProviderProxy::getContentProvider - "
     386                 :            :                     "No provider!" );
     387                 :        403 :             }
     388                 :            :         }
     389         [ +  - ]:       1758 :         if ( !m_xTargetProvider.is() )
     390         [ +  - ]:       1758 :             m_xTargetProvider = m_xProvider;
     391                 :            :     }
     392                 :            : 
     393                 :            :     OSL_ENSURE( m_xProvider.is(),
     394                 :            :         rtl::OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '").append(rtl::OUStringToOString(m_aService, osl_getThreadTextEncoding())).append(".").getStr() );
     395         [ +  - ]:      13547 :     return m_xTargetProvider;
     396                 :            : }
     397                 :            : 
     398                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10