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

Generated by: LCOV version 1.10