1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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
;
55 class DllComponentLoader
56 : public WeakImplHelper
< XImplementationLoader
,
61 explicit DllComponentLoader( const Reference
<XComponentContext
> & xCtx
);
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
;
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
;
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" };
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 )
107 // throw IllegalArgumentException();
110 // Reference< XMultiServiceFactory > rServiceManager;
112 // if( aArgs.getConstArray()[0].getValueType().getTypeClass() == TypeClass_INTERFACE )
114 // aArgs.getConstArray()[0] >>= rServiceManager;
117 // if( !rServiceManager.is() )
119 // throw IllegalArgumentException();
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
142 OSL_FAIL( "DllComponentLoader::writeRegistryInfo() should not be called I think?" );
145 writeSharedLibComponentInfo(
146 cppu::bootstrap_expandUri(rLibName
), OUString(), m_xSMgr
, xKey
);
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: */