LCOV - code coverage report
Current view: top level - libreoffice/ucb/source/core - provprox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 48 97 49.5 %
Date: 2012-12-27 Functions: 20 34 58.8 %
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 <osl/diagnose.h>
      21             : #include <osl/thread.h>
      22             : #include <rtl/strbuf.hxx>
      23             : #include "provprox.hxx"
      24             : #include <com/sun/star/lang/XInitialization.hpp>
      25             : 
      26             : using namespace com::sun::star::lang;
      27             : using namespace com::sun::star::ucb;
      28             : using namespace com::sun::star::uno;
      29             : 
      30             : using ::rtl::OUString;
      31             : 
      32             : //=========================================================================
      33             : //=========================================================================
      34             : //
      35             : // UcbContentProviderProxyFactory Implementation.
      36             : //
      37             : //=========================================================================
      38             : //=========================================================================
      39             : 
      40           2 : UcbContentProviderProxyFactory::UcbContentProviderProxyFactory(
      41             :                         const Reference< XMultiServiceFactory >& rxSMgr )
      42           2 : : m_xSMgr( rxSMgr )
      43             : {
      44           2 : }
      45             : 
      46             : //=========================================================================
      47             : // virtual
      48           4 : UcbContentProviderProxyFactory::~UcbContentProviderProxyFactory()
      49             : {
      50           4 : }
      51             : 
      52             : //=========================================================================
      53             : //
      54             : // XInterface methods.
      55             : //
      56             : //=========================================================================
      57             : 
      58         236 : XINTERFACE_IMPL_3( UcbContentProviderProxyFactory,
      59             :                    XTypeProvider,
      60             :                    XServiceInfo,
      61             :                    XContentProviderFactory );
      62             : 
      63             : //=========================================================================
      64             : //
      65             : // XTypeProvider methods.
      66             : //
      67             : //=========================================================================
      68             : 
      69           0 : XTYPEPROVIDER_IMPL_3( UcbContentProviderProxyFactory,
      70             :                           XTypeProvider,
      71             :                       XServiceInfo,
      72             :                           XContentProviderFactory );
      73             : 
      74             : //=========================================================================
      75             : //
      76             : // XServiceInfo methods.
      77             : //
      78             : //=========================================================================
      79             : 
      80           8 : XSERVICEINFO_IMPL_1( UcbContentProviderProxyFactory,
      81             :                      OUString( "com.sun.star.comp.ucb.UcbContentProviderProxyFactory" ),
      82           2 :                      OUString( PROVIDER_FACTORY_SERVICE_NAME ) );
      83             : 
      84             : //=========================================================================
      85             : //
      86             : // Service factory implementation.
      87             : //
      88             : //=========================================================================
      89             : 
      90           2 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( UcbContentProviderProxyFactory );
      91             : 
      92             : //=========================================================================
      93             : //
      94             : // XContentProviderFactory methods.
      95             : //
      96             : //=========================================================================
      97             : 
      98             : // virtual
      99             : Reference< XContentProvider > SAL_CALL
     100          20 : UcbContentProviderProxyFactory::createContentProvider(
     101             :                                                 const OUString& Service )
     102             :     throw( RuntimeException )
     103             : {
     104             :     return Reference< XContentProvider >(
     105          20 :                         new UcbContentProviderProxy( m_xSMgr, Service ) );
     106             : }
     107             : 
     108             : //=========================================================================
     109             : //=========================================================================
     110             : //
     111             : // UcbContentProviderProxy Implementation.
     112             : //
     113             : //=========================================================================
     114             : //=========================================================================
     115             : 
     116          20 : UcbContentProviderProxy::UcbContentProviderProxy(
     117             :                         const Reference< XMultiServiceFactory >& rxSMgr,
     118             :                         const OUString& Service )
     119             : : m_aService( Service ),
     120             :   m_bReplace( sal_False ),
     121             :   m_bRegister( sal_False ),
     122          20 :   m_xSMgr( rxSMgr )
     123             : {
     124          20 : }
     125             : 
     126             : //=========================================================================
     127             : // virtual
     128          40 : UcbContentProviderProxy::~UcbContentProviderProxy()
     129             : {
     130          40 : }
     131             : 
     132             : //=========================================================================
     133             : //
     134             : // XInterface methods.
     135             : //
     136             : //=========================================================================
     137             : 
     138         506 : XINTERFACE_COMMON_IMPL( UcbContentProviderProxy );
     139             : 
     140             : //============================================================================
     141             : // virtual
     142             : Any SAL_CALL
     143          47 : UcbContentProviderProxy::queryInterface( const Type & rType )
     144             :     throw ( RuntimeException )
     145             : {
     146             :     Any aRet = cppu::queryInterface( rType,
     147             :                 static_cast< XTypeProvider * >( this ),
     148             :                 static_cast< XServiceInfo * >( this ),
     149             :                 static_cast< XContentProvider * >( this ),
     150             :                 static_cast< XParameterizedContentProvider * >( this ),
     151          47 :                 static_cast< XContentProviderSupplier * >( this ) );
     152             : 
     153          47 :     if ( !aRet.hasValue() )
     154          25 :         aRet = OWeakObject::queryInterface( rType );
     155             : 
     156          47 :     if ( !aRet.hasValue() )
     157             :     {
     158             :         // Get original provider an forward the call...
     159          25 :         osl::Guard< osl::Mutex > aGuard( m_aMutex );
     160          25 :         Reference< XContentProvider > xProvider = getContentProvider();
     161          25 :         if ( xProvider.is() )
     162           0 :             aRet = xProvider->queryInterface( rType );
     163             :     }
     164             : 
     165          47 :     return aRet;
     166             : }
     167             : 
     168             : //=========================================================================
     169             : //
     170             : // XTypeProvider methods.
     171             : //
     172             : //=========================================================================
     173             : 
     174           0 : XTYPEPROVIDER_COMMON_IMPL( UcbContentProviderProxy );
     175             : 
     176             : //=========================================================================
     177             : 
     178           0 : Sequence< Type > SAL_CALL UcbContentProviderProxy::getTypes()                                                           \
     179             :     throw( RuntimeException )
     180             : {
     181             :     // Get original provider an forward the call...
     182           0 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     183           0 :     Reference< XTypeProvider > xProvider( getContentProvider(), UNO_QUERY );
     184           0 :     if ( xProvider.is() )
     185             :     {
     186           0 :         return xProvider->getTypes();
     187             :     }
     188             :     else
     189             :     {
     190             :         static cppu::OTypeCollection collection(
     191           0 :             CPPU_TYPE_REF( XTypeProvider ),
     192           0 :             CPPU_TYPE_REF( XServiceInfo ),
     193           0 :             CPPU_TYPE_REF( XContentProvider ),
     194           0 :             CPPU_TYPE_REF( XParameterizedContentProvider ),
     195           0 :             CPPU_TYPE_REF( XContentProviderSupplier ) );
     196           0 :         return collection.getTypes();
     197           0 :     }
     198             : }
     199             : 
     200             : //=========================================================================
     201             : //
     202             : // XServiceInfo methods.
     203             : //
     204             : //=========================================================================
     205             : 
     206           0 : XSERVICEINFO_NOFACTORY_IMPL_1( UcbContentProviderProxy,
     207             :                             OUString( "com.sun.star.comp.ucb.UcbContentProviderProxy" ),
     208             :                             OUString( PROVIDER_PROXY_SERVICE_NAME ) );
     209             : 
     210             : //=========================================================================
     211             : //
     212             : // XContentProvider methods.
     213             : //
     214             : //=========================================================================
     215             : 
     216             : // virtual
     217           2 : Reference< XContent > SAL_CALL UcbContentProviderProxy::queryContent(
     218             :                         const Reference< XContentIdentifier >& Identifier )
     219             :     throw( IllegalIdentifierException,
     220             :            RuntimeException )
     221             : {
     222             :     // Get original provider an forward the call...
     223             : 
     224           2 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     225             : 
     226           2 :     Reference< XContentProvider > xProvider = getContentProvider();
     227           2 :     if ( xProvider.is() )
     228           0 :         return xProvider->queryContent( Identifier );
     229             : 
     230           2 :     return Reference< XContent >();
     231             : }
     232             : 
     233             : //=========================================================================
     234             : // virtual
     235           0 : sal_Int32 SAL_CALL UcbContentProviderProxy::compareContentIds(
     236             :                        const Reference< XContentIdentifier >& Id1,
     237             :                        const Reference< XContentIdentifier >& Id2 )
     238             :     throw( RuntimeException )
     239             : {
     240             :     // Get original provider an forward the call...
     241             : 
     242           0 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     243           0 :     Reference< XContentProvider > xProvider = getContentProvider();
     244           0 :     if ( xProvider.is() )
     245           0 :         return xProvider->compareContentIds( Id1, Id2 );
     246             : 
     247             :     // OSL_FAIL( // "UcbContentProviderProxy::compareContentIds - No provider!" );
     248             : 
     249             :     // @@@ What else?
     250           0 :     return 0;
     251             : }
     252             : 
     253             : //=========================================================================
     254             : //
     255             : // XParameterizedContentProvider methods.
     256             : //
     257             : //=========================================================================
     258             : 
     259             : // virtual
     260             : Reference< XContentProvider > SAL_CALL
     261          20 : UcbContentProviderProxy::registerInstance( const OUString& Template,
     262             :                                              const OUString& Arguments,
     263             :                                              sal_Bool ReplaceExisting )
     264             :     throw( IllegalArgumentException,
     265             :            RuntimeException )
     266             : {
     267             :     // Just remember that this method was called ( and the params ).
     268             : 
     269          20 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     270             : 
     271          20 :     if ( !m_bRegister )
     272             :     {
     273             : //      m_xTargetProvider = 0;
     274          20 :         m_aTemplate  = Template;
     275          20 :         m_aArguments = Arguments;
     276          20 :         m_bReplace   = ReplaceExisting;
     277             : 
     278          20 :         m_bRegister  = sal_True;
     279             :     }
     280          20 :     return this;
     281             : }
     282             : 
     283             : //=========================================================================
     284             : // virtual
     285             : Reference< XContentProvider > SAL_CALL
     286           0 : UcbContentProviderProxy::deregisterInstance( const OUString& Template,
     287             :                                              const OUString& Arguments )
     288             :     throw( IllegalArgumentException,
     289             :            RuntimeException )
     290             : {
     291           0 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     292             : 
     293             :     // registerInstance called at proxy and at original?
     294           0 :     if ( m_bRegister && m_xTargetProvider.is() )
     295             :     {
     296           0 :         m_bRegister       = sal_False;
     297           0 :         m_xTargetProvider = 0;
     298             : 
     299             :         Reference< XParameterizedContentProvider >
     300           0 :                                 xParamProvider( m_xProvider, UNO_QUERY );
     301           0 :         if ( xParamProvider.is() )
     302             :         {
     303             :             try
     304             :             {
     305           0 :                 xParamProvider->deregisterInstance( Template, Arguments );
     306             :             }
     307           0 :             catch ( IllegalIdentifierException const & )
     308             :             {
     309             :                 OSL_FAIL( "UcbContentProviderProxy::deregisterInstance - "
     310             :                     "Caught IllegalIdentifierException!" );
     311             :             }
     312           0 :         }
     313             :     }
     314             : 
     315           0 :     return this;
     316             : }
     317             : 
     318             : //=========================================================================
     319             : //
     320             : // XContentProviderSupplier methods.
     321             : //
     322             : //=========================================================================
     323             : 
     324             : // virtual
     325             : Reference< XContentProvider > SAL_CALL
     326          29 : UcbContentProviderProxy::getContentProvider()
     327             :     throw( RuntimeException )
     328             : {
     329          29 :     osl::Guard< osl::Mutex > aGuard( m_aMutex );
     330          29 :     if ( !m_xProvider.is() )
     331             :     {
     332             :         try
     333             :         {
     334             :             m_xProvider
     335             :                 = Reference< XContentProvider >(
     336          29 :                       m_xSMgr->createInstance( m_aService ), UNO_QUERY );
     337          29 :             if ( m_aArguments == "NoConfig" )
     338             :             {
     339           0 :                 Reference<XInitialization> xInit(m_xProvider,UNO_QUERY);
     340           0 :                 if(xInit.is()) {
     341           0 :                     Sequence<Any> aArgs(1);
     342           0 :                     aArgs[0] <<= m_aArguments;
     343           0 :                     xInit->initialize(aArgs);
     344           0 :                 }
     345             :             }
     346             :         }
     347           0 :         catch ( RuntimeException const & )
     348             :         {
     349           0 :             throw;
     350             :         }
     351           0 :         catch ( Exception const & )
     352             :         {
     353             :         }
     354             : 
     355             :         // registerInstance called at proxy, but not yet at original?
     356          29 :         if ( m_xProvider.is() && m_bRegister )
     357             :         {
     358             :             Reference< XParameterizedContentProvider >
     359           0 :                 xParamProvider( m_xProvider, UNO_QUERY );
     360           0 :             if ( xParamProvider.is() )
     361             :             {
     362             :                 try
     363             :                 {
     364             :                     m_xTargetProvider
     365           0 :                         = xParamProvider->registerInstance( m_aTemplate,
     366             :                                                             m_aArguments,
     367           0 :                                                             m_bReplace );
     368             :                 }
     369           0 :                 catch ( IllegalIdentifierException const & )
     370             :                 {
     371             :                     OSL_FAIL( "UcbContentProviderProxy::getContentProvider - "
     372             :                         "Caught IllegalIdentifierException!" );
     373             :                 }
     374             : 
     375             :                 OSL_ENSURE( m_xTargetProvider.is(),
     376             :                     "UcbContentProviderProxy::getContentProvider - "
     377             :                     "No provider!" );
     378           0 :             }
     379             :         }
     380          29 :         if ( !m_xTargetProvider.is() )
     381          29 :             m_xTargetProvider = m_xProvider;
     382             :     }
     383             : 
     384             :     OSL_ENSURE( m_xProvider.is(),
     385             :         rtl::OStringBuffer("UcbContentProviderProxy::getContentProvider - No provider for '").append(rtl::OUStringToOString(m_aService, osl_getThreadTextEncoding())).append(".").getStr() );
     386          29 :     return m_xTargetProvider;
     387             : }
     388             : 
     389             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10