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

Generated by: LCOV version 1.10