Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / stoc / source / loader / dllcomponentloader.cxx
blob4f9cc2c6a1b4b2d146e6e096f362b406c7048e0f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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/ref.hxx>
28 #include <rtl/ustring.hxx>
29 #include <uno/environment.h>
30 #include <uno/mapping.hxx>
31 #include <cppuhelper/queryinterface.hxx>
32 #include <cppuhelper/weak.hxx>
33 #include <cppuhelper/shlib.hxx>
34 #include <cppuhelper/implbase.hxx>
35 #include <cppuhelper/implementationentry.hxx>
36 #include <cppuhelper/supportsservice.hxx>
37 #include <cppuhelper/bootstrap.hxx>
39 #include <com/sun/star/loader/XImplementationLoader.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>
45 using namespace com::sun::star;
46 using namespace css::uno;
47 using namespace css::loader;
48 using namespace css::lang;
49 using namespace css::registry;
50 using namespace cppu;
51 using namespace osl;
53 namespace {
55 class DllComponentLoader
56 : public WeakImplHelper< XImplementationLoader,
57 XInitialization,
58 XServiceInfo >
60 public:
61 explicit DllComponentLoader( const Reference<XComponentContext> & xCtx );
63 // XServiceInfo
64 virtual OUString SAL_CALL getImplementationName( ) override;
65 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
66 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
68 // XInitialization
69 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
71 // XImplementationLoader
72 virtual Reference<XInterface> SAL_CALL activate( const OUString& implementationName, const OUString& implementationLoaderUrl, const OUString& locationUrl, const Reference<XRegistryKey>& xKey ) override;
73 virtual sal_Bool SAL_CALL writeRegistryInfo( const Reference<XRegistryKey>& xKey, const OUString& implementationLoaderUrl, const OUString& locationUrl ) override;
75 private:
76 Reference<XMultiServiceFactory> m_xSMgr;
80 DllComponentLoader::DllComponentLoader( const Reference<XComponentContext> & xCtx )
82 m_xSMgr.set( xCtx->getServiceManager(), UNO_QUERY );
85 OUString SAL_CALL DllComponentLoader::getImplementationName( )
87 return OUString("com.sun.star.comp.stoc.DLLComponentLoader");
90 sal_Bool SAL_CALL DllComponentLoader::supportsService( const OUString& ServiceName )
92 return cppu::supportsService(this, ServiceName);
95 Sequence<OUString> SAL_CALL DllComponentLoader::getSupportedServiceNames( )
97 Sequence< OUString > seqNames { "com.sun.star.loader.SharedLibrary" };
98 return seqNames;
102 void DllComponentLoader::initialize( const css::uno::Sequence< css::uno::Any >& )
104 OSL_FAIL( "dllcomponentloader::initialize should not be called !" );
105 // if( aArgs.getLength() != 1 )
106 // {
107 // throw IllegalArgumentException();
108 // }
110 // Reference< XMultiServiceFactory > rServiceManager;
112 // if( aArgs.getConstArray()[0].getValueType().getTypeClass() == TypeClass_INTERFACE )
113 // {
114 // aArgs.getConstArray()[0] >>= rServiceManager;
115 // }
117 // if( !rServiceManager.is() )
118 // {
119 // throw IllegalArgumentException();
120 // }
122 // m_xSMgr = rServiceManager;
126 Reference<XInterface> SAL_CALL DllComponentLoader::activate(
127 const OUString & rImplName, const OUString &, const OUString & rLibName,
128 const Reference< XRegistryKey > & )
130 return loadSharedLibComponentFactory(
131 cppu::bootstrap_expandUri(rLibName), OUString(), rImplName, m_xSMgr,
132 css::uno::Reference<css::registry::XRegistryKey>());
136 sal_Bool SAL_CALL DllComponentLoader::writeRegistryInfo(
137 const Reference< XRegistryKey > & xKey, const OUString &, const OUString & rLibName )
139 #ifdef DISABLE_DYNLOADING
140 (void) xKey;
141 (void) rLibName;
142 OSL_FAIL( "DllComponentLoader::writeRegistryInfo() should not be called I think?" );
143 return sal_False;
144 #else
145 writeSharedLibComponentInfo(
146 cppu::bootstrap_expandUri(rLibName), OUString(), m_xSMgr, xKey );
147 return true;
148 #endif
153 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
154 com_sun_star_comp_stoc_DLLComponentLoader_get_implementation(
155 css::uno::XComponentContext *context,
156 css::uno::Sequence<css::uno::Any> const &)
158 return cppu::acquire(new DllComponentLoader(context));
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */