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 .
21 #include <osl/diagnose.h>
22 #include <rtl/ustring.hxx>
23 #include <cppuhelper/weak.hxx>
24 #include <cppuhelper/shlib.hxx>
25 #include <cppuhelper/implbase.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <cppuhelper/bootstrap.hxx>
29 #include <com/sun/star/loader/XImplementationLoader.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/uno/XComponentContext.hpp>
35 namespace com::sun::star::registry
{ class XRegistryKey
; }
37 using namespace com::sun::star
;
38 using namespace css::uno
;
39 using namespace css::loader
;
40 using namespace css::lang
;
41 using namespace css::registry
;
46 class DllComponentLoader
47 : public WeakImplHelper
< XImplementationLoader
,
52 explicit DllComponentLoader( const Reference
<XComponentContext
> & xCtx
);
55 virtual OUString SAL_CALL
getImplementationName( ) override
;
56 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
57 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) override
;
60 virtual void SAL_CALL
initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
62 // XImplementationLoader
63 virtual Reference
<XInterface
> SAL_CALL
activate( const OUString
& implementationName
, const OUString
& implementationLoaderUrl
, const OUString
& locationUrl
, const Reference
<XRegistryKey
>& xKey
) override
;
64 virtual sal_Bool SAL_CALL
writeRegistryInfo( const Reference
<XRegistryKey
>& xKey
, const OUString
& implementationLoaderUrl
, const OUString
& locationUrl
) override
;
67 Reference
<XMultiServiceFactory
> m_xSMgr
;
71 DllComponentLoader::DllComponentLoader( const Reference
<XComponentContext
> & xCtx
)
73 m_xSMgr
.set( xCtx
->getServiceManager(), UNO_QUERY
);
76 OUString SAL_CALL
DllComponentLoader::getImplementationName( )
78 return u
"com.sun.star.comp.stoc.DLLComponentLoader"_ustr
;
81 sal_Bool SAL_CALL
DllComponentLoader::supportsService( const OUString
& ServiceName
)
83 return cppu::supportsService(this, ServiceName
);
86 Sequence
<OUString
> SAL_CALL
DllComponentLoader::getSupportedServiceNames( )
88 return { u
"com.sun.star.loader.SharedLibrary"_ustr
};
92 void DllComponentLoader::initialize( const css::uno::Sequence
< css::uno::Any
>& )
94 OSL_FAIL( "dllcomponentloader::initialize should not be called !" );
95 // if( aArgs.getLength() != 1 )
97 // throw IllegalArgumentException();
100 // Reference< XMultiServiceFactory > rServiceManager;
102 // if( aArgs.getConstArray()[0].getValueTypeClass() == TypeClass_INTERFACE )
104 // aArgs.getConstArray()[0] >>= rServiceManager;
107 // if( !rServiceManager.is() )
109 // throw IllegalArgumentException();
112 // m_xSMgr = rServiceManager;
116 Reference
<XInterface
> SAL_CALL
DllComponentLoader::activate(
117 const OUString
& rImplName
, const OUString
&, const OUString
& rLibName
,
118 const Reference
< XRegistryKey
> & )
120 return loadSharedLibComponentFactory(
121 cppu::bootstrap_expandUri(rLibName
), OUString(), rImplName
, m_xSMgr
,
122 css::uno::Reference
<css::registry::XRegistryKey
>());
126 sal_Bool SAL_CALL
DllComponentLoader::writeRegistryInfo(
127 const Reference
< XRegistryKey
> & xKey
, const OUString
&, const OUString
& rLibName
)
129 #ifdef DISABLE_DYNLOADING
132 OSL_FAIL( "DllComponentLoader::writeRegistryInfo() should not be called I think?" );
135 writeSharedLibComponentInfo(
136 cppu::bootstrap_expandUri(rLibName
), OUString(), m_xSMgr
, xKey
);
143 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
144 com_sun_star_comp_stoc_DLLComponentLoader_get_implementation(
145 css::uno::XComponentContext
*context
,
146 css::uno::Sequence
<css::uno::Any
> const &)
148 return cppu::acquire(new DllComponentLoader(context
));
151 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */