LCOV - code coverage report
Current view: top level - remotebridges/source/unourl_resolver - unourl_resolver.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 39 56 69.6 %
Date: 2012-08-25 Functions: 8 12 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 32 80 40.0 %

           Branch data     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                 :            : //  #define TRACE(x) OSL_TRACE(x)
      21                 :            : #define TRACE(x)
      22                 :            : 
      23                 :            : #include <osl/diagnose.h>
      24                 :            : #include <osl/mutex.hxx>
      25                 :            : #include <cppuhelper/factory.hxx>
      26                 :            : #include <cppuhelper/implbase2.hxx>
      27                 :            : #include <cppuhelper/implementationentry.hxx>
      28                 :            : #include "cppuhelper/unourl.hxx"
      29                 :            : #include "rtl/malformeduriexception.hxx"
      30                 :            : 
      31                 :            : #include <com/sun/star/lang/XServiceInfo.hpp>
      32                 :            : #include <com/sun/star/lang/XComponent.hpp>
      33                 :            : #include <com/sun/star/registry/XRegistryKey.hpp>
      34                 :            : #include <com/sun/star/connection/XConnector.hpp>
      35                 :            : #include <com/sun/star/bridge/XBridgeFactory.hpp>
      36                 :            : #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
      37                 :            : 
      38                 :            : using namespace cppu;
      39                 :            : using namespace osl;
      40                 :            : using namespace com::sun::star::uno;
      41                 :            : using namespace com::sun::star::lang;
      42                 :            : using namespace com::sun::star::connection;
      43                 :            : using namespace com::sun::star::bridge;
      44                 :            : using namespace com::sun::star::registry;
      45                 :            : 
      46                 :            : using ::rtl::OUString;
      47                 :            : 
      48                 :            : #define SERVICENAME     "com.sun.star.bridge.UnoUrlResolver"
      49                 :            : #define IMPLNAME        "com.sun.star.comp.bridge.UnoUrlResolver"
      50                 :            : 
      51                 :            : namespace unourl_resolver
      52                 :            : {
      53                 :            :     rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT;
      54                 :            : //--------------------------------------------------------------------------------------------------
      55                 :          4 : Sequence< OUString > resolver_getSupportedServiceNames()
      56                 :            : {
      57                 :          4 :     Sequence< OUString > seqNames(1);
      58 [ +  - ][ +  - ]:          4 :     seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
      59                 :          4 :     return seqNames;
      60                 :            : }
      61                 :            : 
      62                 :          4 : OUString resolver_getImplementationName()
      63                 :            : {
      64                 :          4 :     return OUString(RTL_CONSTASCII_USTRINGPARAM(IMPLNAME));
      65                 :            : }
      66                 :            : 
      67                 :            : //==================================================================================================
      68                 :            : class ResolverImpl : public WeakImplHelper2< XServiceInfo, XUnoUrlResolver >
      69                 :            : {
      70                 :            :     Reference< XMultiComponentFactory > _xSMgr;
      71                 :            :     Reference< XComponentContext > _xCtx;
      72                 :            : 
      73                 :            : public:
      74                 :            :     ResolverImpl( const Reference< XComponentContext > & xSMgr );
      75                 :            :     virtual ~ResolverImpl();
      76                 :            : 
      77                 :            :     // XServiceInfo
      78                 :            :     virtual OUString SAL_CALL getImplementationName() throw(::com::sun::star::uno::RuntimeException);
      79                 :            :     virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw(::com::sun::star::uno::RuntimeException);
      80                 :            :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
      81                 :            : 
      82                 :            :     // XUnoUrlResolver
      83                 :            :     virtual Reference< XInterface > SAL_CALL resolve( const OUString & rUnoUrl )
      84                 :            :         throw (NoConnectException, ConnectionSetupException, RuntimeException);
      85                 :            : };
      86                 :            : 
      87                 :            : //##################################################################################################
      88                 :            : 
      89                 :            : //__________________________________________________________________________________________________
      90                 :          4 : ResolverImpl::ResolverImpl( const Reference< XComponentContext > & xCtx )
      91         [ +  - ]:          4 :     : _xSMgr( xCtx->getServiceManager() )
      92         [ +  - ]:          8 :     , _xCtx( xCtx )
      93                 :            : {
      94         [ +  - ]:          4 :     g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
      95                 :          4 : }
      96                 :            : //__________________________________________________________________________________________________
      97                 :          4 : ResolverImpl::~ResolverImpl()
      98                 :            : {
      99         [ +  - ]:          4 :     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
     100         [ -  + ]:          8 : }
     101                 :            : 
     102                 :            : // XServiceInfo
     103                 :            : //__________________________________________________________________________________________________
     104                 :          0 : OUString ResolverImpl::getImplementationName()
     105                 :            :     throw(::com::sun::star::uno::RuntimeException)
     106                 :            : {
     107                 :          0 :     return resolver_getImplementationName();
     108                 :            : }
     109                 :            : //__________________________________________________________________________________________________
     110                 :          0 : sal_Bool ResolverImpl::supportsService( const OUString & rServiceName )
     111                 :            :     throw(::com::sun::star::uno::RuntimeException)
     112                 :            : {
     113                 :          0 :     const Sequence< OUString > & rSNL = getSupportedServiceNames();
     114                 :          0 :     const OUString * pArray = rSNL.getConstArray();
     115         [ #  # ]:          0 :     for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
     116                 :            :     {
     117         [ #  # ]:          0 :         if (pArray[nPos] == rServiceName)
     118                 :          0 :             return sal_True;
     119                 :            :     }
     120                 :          0 :     return sal_False;
     121                 :            : }
     122                 :            : //__________________________________________________________________________________________________
     123                 :          0 : Sequence< OUString > ResolverImpl::getSupportedServiceNames()
     124                 :            :     throw(::com::sun::star::uno::RuntimeException)
     125                 :            : {
     126                 :          0 :     return resolver_getSupportedServiceNames();
     127                 :            : }
     128                 :            : 
     129                 :            : // XUnoUrlResolver
     130                 :            : //__________________________________________________________________________________________________
     131                 :         26 : Reference< XInterface > ResolverImpl::resolve( const OUString & rUnoUrl )
     132                 :            :     throw (NoConnectException, ConnectionSetupException, RuntimeException)
     133                 :            : {
     134                 :         26 :     OUString aProtocolDescr;
     135                 :         26 :     OUString aConnectDescr;
     136                 :         26 :     OUString aInstanceName;
     137                 :            :     try
     138                 :            :     {
     139         [ +  - ]:         26 :         cppu::UnoUrl aUrl(rUnoUrl);
     140 [ +  - ][ +  - ]:         26 :         aProtocolDescr = aUrl.getProtocol().getDescriptor();
     141 [ +  - ][ +  - ]:         26 :         aConnectDescr = aUrl.getConnection().getDescriptor();
     142 [ +  - ][ +  - ]:         26 :         aInstanceName = aUrl.getObjectName();
     143                 :            :     }
     144         [ #  # ]:          0 :     catch (const rtl::MalformedUriException & rEx)
     145                 :            :     {
     146   [ #  #  #  # ]:          0 :         throw ConnectionSetupException(rEx.getMessage(), 0);
     147                 :            :     }
     148                 :            : 
     149                 :            :     Reference< XConnector > xConnector(
     150         [ +  - ]:         26 :         _xSMgr->createInstanceWithContext(
     151                 :            :             OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.connection.Connector") ),
     152                 :         26 :             _xCtx ),
     153 [ +  - ][ +  - ]:         26 :         UNO_QUERY );
                 [ +  - ]
     154                 :            : 
     155         [ -  + ]:         26 :     if (! xConnector.is())
     156 [ #  # ][ #  # ]:          0 :         throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("no connector!" ) ), Reference< XInterface >() );
     157                 :            : 
     158 [ +  - ][ +  + ]:         26 :     Reference< XConnection > xConnection( xConnector->connect( aConnectDescr ) );
     159                 :            : 
     160                 :            :     // As soon as singletons are ready, switch to singleton !
     161                 :            :     Reference< XBridgeFactory > xBridgeFactory(
     162         [ +  - ]:          4 :         _xSMgr->createInstanceWithContext(
     163                 :            :             OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.bridge.BridgeFactory") ),
     164                 :          4 :             _xCtx ),
     165 [ +  - ][ +  - ]:          4 :         UNO_QUERY );
                 [ +  - ]
     166                 :            : 
     167         [ -  + ]:          4 :     if (! xBridgeFactory.is())
     168 [ #  # ][ #  # ]:          0 :         throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM("no bridge factory!" ) ), Reference< XInterface >() );
     169                 :            : 
     170                 :            :     // bridge
     171         [ +  - ]:          4 :     Reference< XBridge > xBridge( xBridgeFactory->createBridge(
     172                 :            :         OUString(), aProtocolDescr,
     173         [ +  - ]:          4 :         xConnection, Reference< XInstanceProvider >() ) );
     174                 :            : 
     175 [ +  - ][ +  - ]:          4 :     Reference< XInterface > xRet( xBridge->getInstance( aInstanceName ) );
     176                 :            : 
     177                 :         26 :     return xRet;
     178                 :            : }
     179                 :            : 
     180                 :            : //==================================================================================================
     181                 :          4 : static Reference< XInterface > SAL_CALL ResolverImpl_create( const Reference< XComponentContext > & xCtx )
     182                 :            : {
     183         [ +  - ]:          4 :     return Reference< XInterface >( *new ResolverImpl( xCtx ) );
     184                 :            : }
     185                 :            : 
     186                 :            : 
     187                 :            : }
     188                 :            : 
     189                 :            : using namespace unourl_resolver;
     190                 :            : 
     191                 :            : static struct ImplementationEntry g_entries[] =
     192                 :            : {
     193                 :            :     {
     194                 :            :         ResolverImpl_create, resolver_getImplementationName,
     195                 :            :         resolver_getSupportedServiceNames, createSingleComponentFactory,
     196                 :            :         &g_moduleCount.modCnt , 0
     197                 :            :     },
     198                 :            :     { 0, 0, 0, 0, 0, 0 }
     199                 :            : };
     200                 :            : 
     201                 :            : extern "C"
     202                 :            : {
     203                 :          0 : SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_canUnload( TimeValue *pTime )
     204                 :            : {
     205                 :          0 :     return g_moduleCount.canUnload( &g_moduleCount , pTime );
     206                 :            : }
     207                 :            : 
     208                 :            : //==================================================================================================
     209                 :          4 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
     210                 :            :     const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey )
     211                 :            : {
     212                 :          4 :     return component_getFactoryHelper( pImplName, pServiceManager, pRegistryKey , g_entries );
     213                 :            : }
     214                 :            : }
     215                 :            : 
     216                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10