LCOV - code coverage report
Current view: top level - libreoffice/stoc/source/loader - dllcomponentloader.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 54 11.1 %
Date: 2012-12-27 Functions: 2 13 15.4 %
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             : 
      21             : #include <stdlib.h>
      22             : #include <osl/file.h>
      23             : #include <vector>
      24             : #include <osl/mutex.hxx>
      25             : #include <osl/diagnose.h>
      26             : #include <osl/module.h>
      27             : #include <rtl/ustring.hxx>
      28             : #include <uno/environment.h>
      29             : #include <uno/mapping.hxx>
      30             : #include <cppuhelper/queryinterface.hxx>
      31             : #include <cppuhelper/weak.hxx>
      32             : #include <cppuhelper/factory.hxx>
      33             : #include <cppuhelper/shlib.hxx>
      34             : #include <cppuhelper/implbase3.hxx>
      35             : #include <cppuhelper/implementationentry.hxx>
      36             : #include <cppuhelper/bootstrap.hxx>
      37             : 
      38             : #include <com/sun/star/loader/XImplementationLoader.hpp>
      39             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      40             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      41             : #include <com/sun/star/lang/XServiceInfo.hpp>
      42             : #include <com/sun/star/lang/XInitialization.hpp>
      43             : #include <com/sun/star/registry/XRegistryKey.hpp>
      44             : 
      45             : #define SERVICENAME "com.sun.star.loader.SharedLibrary"
      46             : #define IMPLNAME    "com.sun.star.comp.stoc.DLLComponentLoader"
      47             : 
      48             : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
      49             : 
      50             : 
      51             : using namespace com::sun::star;
      52             : using namespace com::sun::star::uno;
      53             : using namespace com::sun::star::loader;
      54             : using namespace com::sun::star::lang;
      55             : using namespace com::sun::star::registry;
      56             : using namespace cppu;
      57             : using namespace osl;
      58             : using ::rtl::OUString;
      59             : extern rtl_StandardModuleCount g_moduleCount;
      60             : 
      61             : namespace stoc_bootstrap
      62             : {
      63         259 : Sequence< OUString > loader_getSupportedServiceNames()
      64             : {
      65         259 :     Sequence< OUString > seqNames(1);
      66         259 :     seqNames.getArray()[0] = OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICENAME));
      67         259 :     return seqNames;
      68             : }
      69             : 
      70        3368 : OUString loader_getImplementationName()
      71             : {
      72        3368 :     return OUString(RTL_CONSTASCII_USTRINGPARAM(IMPLNAME));
      73             : }
      74             : }
      75             : 
      76             : namespace stoc_loader
      77             : {
      78             : //*************************************************************************
      79             : // DllComponentLoader
      80             : //*************************************************************************
      81             : class DllComponentLoader
      82             :     : public WeakImplHelper3< XImplementationLoader,
      83             :                               XInitialization,
      84             :                               XServiceInfo >
      85             : {
      86             : public:
      87             :     DllComponentLoader( const Reference<XComponentContext> & xCtx );
      88             :     ~DllComponentLoader();
      89             : 
      90             :     // XServiceInfo
      91             :     virtual OUString SAL_CALL getImplementationName(  ) throw(::com::sun::star::uno::RuntimeException);
      92             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(::com::sun::star::uno::RuntimeException);
      93             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw(::com::sun::star::uno::RuntimeException);
      94             : 
      95             :     // XInitialization
      96             :     virtual void SAL_CALL initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
      97             : 
      98             :     // XImplementationLoader
      99             :     virtual Reference<XInterface> SAL_CALL activate( const OUString& implementationName, const OUString& implementationLoaderUrl, const OUString& locationUrl, const Reference<XRegistryKey>& xKey ) throw(CannotActivateFactoryException, RuntimeException);
     100             :     virtual sal_Bool SAL_CALL writeRegistryInfo( const Reference<XRegistryKey>& xKey, const OUString& implementationLoaderUrl, const OUString& locationUrl ) throw(CannotRegisterImplementationException, RuntimeException);
     101             : 
     102             : private:
     103             :     OUString expand_url( OUString const & url )
     104             :         SAL_THROW( (RuntimeException) );
     105             : 
     106             :     Reference<XMultiServiceFactory> m_xSMgr;
     107             : };
     108             : 
     109             : //*************************************************************************
     110           0 : DllComponentLoader::DllComponentLoader( const Reference<XComponentContext> & xCtx )
     111             : {
     112           0 :     g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt );
     113           0 :     m_xSMgr.set( xCtx->getServiceManager(), UNO_QUERY );
     114           0 : }
     115             : 
     116             : //*************************************************************************
     117           0 : DllComponentLoader::~DllComponentLoader()
     118             : {
     119           0 :     g_moduleCount.modCnt.release( &g_moduleCount.modCnt );
     120           0 : }
     121             : 
     122             : //*************************************************************************
     123           0 : OUString SAL_CALL DllComponentLoader::getImplementationName(  )
     124             :     throw(::com::sun::star::uno::RuntimeException)
     125             : {
     126           0 :     return stoc_bootstrap::loader_getImplementationName();
     127             : }
     128             : 
     129             : //*************************************************************************
     130           0 : sal_Bool SAL_CALL DllComponentLoader::supportsService( const OUString& ServiceName )
     131             :     throw(::com::sun::star::uno::RuntimeException)
     132             : {
     133           0 :     Sequence< OUString > aSNL = getSupportedServiceNames();
     134           0 :     const OUString * pArray = aSNL.getArray();
     135           0 :     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
     136           0 :         if( pArray[i] == ServiceName )
     137           0 :             return sal_True;
     138           0 :     return sal_False;
     139             : }
     140             : 
     141             : //*************************************************************************
     142           0 : Sequence<OUString> SAL_CALL DllComponentLoader::getSupportedServiceNames(  )
     143             :     throw(::com::sun::star::uno::RuntimeException)
     144             : {
     145           0 :     return stoc_bootstrap::loader_getSupportedServiceNames();
     146             : }
     147             : 
     148             : //*************************************************************************
     149           0 : void DllComponentLoader::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& )
     150             :     throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
     151             : {
     152             :     OSL_FAIL( "dllcomponentloader::initialize should not be called !" );
     153             : //      if( aArgs.getLength() != 1 )
     154             : //      {
     155             : //          throw IllegalArgumentException();
     156             : //      }
     157             : 
     158             : //      Reference< XMultiServiceFactory > rServiceManager;
     159             : 
     160             : //      if( aArgs.getConstArray()[0].getValueType().getTypeClass() == TypeClass_INTERFACE )
     161             : //      {
     162             : //          aArgs.getConstArray()[0] >>= rServiceManager;
     163             : //      }
     164             : 
     165             : //      if( !rServiceManager.is() )
     166             : //      {
     167             : //          throw IllegalArgumentException();
     168             : //      }
     169             : 
     170             : //      m_xSMgr = rServiceManager;
     171           0 : }
     172             : 
     173             : //==================================================================================================
     174           0 : OUString DllComponentLoader::expand_url( OUString const & url )
     175             :     SAL_THROW( (RuntimeException) )
     176             : {
     177             :     try
     178             :     {
     179           0 :         return cppu::bootstrap_expandUri( url );
     180             :     }
     181           0 :     catch ( const IllegalArgumentException & e )
     182             :     {
     183           0 :         throw RuntimeException( e.Message, e.Context );
     184             :     }
     185             : }
     186             : 
     187             : //*************************************************************************
     188           0 : Reference<XInterface> SAL_CALL DllComponentLoader::activate(
     189             :     const OUString & rImplName, const OUString &, const OUString & rLibName,
     190             :     const Reference< XRegistryKey > & xKey )
     191             : 
     192             :     throw(CannotActivateFactoryException, RuntimeException)
     193             : {
     194           0 :     rtl::OUString aPrefix;
     195           0 :     if( xKey.is() )
     196             :     {
     197           0 :         Reference<XRegistryKey > xActivatorKey = xKey->openKey(
     198           0 :                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/ACTIVATOR") ) );
     199           0 :         if (xActivatorKey.is() && xActivatorKey->getValueType() == RegistryValueType_ASCII )
     200             :         {
     201           0 :             Reference<XRegistryKey > xPrefixKey = xKey->openKey(
     202           0 :                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("/UNO/PREFIX") ) );
     203           0 :             if( xPrefixKey.is() && xPrefixKey->getValueType() == RegistryValueType_ASCII )
     204             :             {
     205           0 :                 aPrefix = xPrefixKey->getAsciiValue();
     206           0 :                 if( !aPrefix.isEmpty() )
     207           0 :                     aPrefix = aPrefix + OUSTR("_");
     208           0 :             }
     209           0 :         }
     210             :     }
     211             : 
     212             :     return loadSharedLibComponentFactory(
     213           0 :         expand_url( rLibName ), OUString(), rImplName, m_xSMgr, xKey, aPrefix );
     214             : }
     215             : 
     216             : 
     217             : //*************************************************************************
     218           0 : sal_Bool SAL_CALL DllComponentLoader::writeRegistryInfo(
     219             :     const Reference< XRegistryKey > & xKey, const OUString &, const OUString & rLibName )
     220             : 
     221             :     throw(CannotRegisterImplementationException, RuntimeException)
     222             : {
     223             : #ifdef DISABLE_DYNLOADING
     224             :     (void) xKey;
     225             :     (void) rLibName;
     226             :     OSL_FAIL( "DllComponentLoader::writeRegistryInfo() should not be called I think?" );
     227             :     return sal_False;
     228             : #else
     229             :     writeSharedLibComponentInfo(
     230           0 :         expand_url( rLibName ), OUString(), m_xSMgr, xKey );
     231           0 :     return sal_True;
     232             : #endif
     233             : }
     234             : }
     235             : 
     236             : namespace stoc_bootstrap
     237             : {
     238             : //*************************************************************************
     239           0 : Reference<XInterface> SAL_CALL DllComponentLoader_CreateInstance( const Reference<XComponentContext> & xCtx ) throw(Exception)
     240             : {
     241           0 :     Reference<XInterface> xRet;
     242             : 
     243           0 :     XImplementationLoader *pXLoader = (XImplementationLoader *)new stoc_loader::DllComponentLoader(xCtx);
     244             : 
     245           0 :     if (pXLoader)
     246             :     {
     247           0 :         xRet = Reference<XInterface>::query(pXLoader);
     248             :     }
     249             : 
     250           0 :     return xRet;
     251             : }
     252             : 
     253             : }
     254             : 
     255             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10