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 .
20 #include <sal/config.h>
22 #include <osl/module.hxx>
24 #include <uno/environment.hxx>
25 #include <uno/lbnames.h>
26 #include <uno/mapping.hxx>
28 #include <cppuhelper/factory.hxx>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/registry/XRegistryKey.hpp>
34 #include <jvmaccess/unovirtualmachine.hxx>
36 #include "juhx-export-functions.hxx"
39 #ifdef DISABLE_DYNLOADING
40 #include <osl/thread.h>
43 using namespace ::com::sun::star
;
44 using namespace ::com::sun::star::uno
;
47 * Class: com_sun_star_comp_helper_SharedLibraryLoader
48 * Method: component_writeInfo
49 * Signature: (Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Z
51 jboolean
Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
52 JNIEnv
* pJEnv
, SAL_UNUSED_PARAMETER jclass
, jstring jLibName
, jobject jSMgr
,
53 jobject jRegKey
, jobject loader
)
57 const jchar
* pJLibName
= pJEnv
->GetStringChars(jLibName
, nullptr);
58 OUString
aLibName(reinterpret_cast<sal_Unicode
const *>(pJLibName
));
59 pJEnv
->ReleaseStringChars(jLibName
, pJLibName
);
61 #ifdef DISABLE_DYNLOADING
66 fprintf(stderr
, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__
, OUStringToOString(aLibName
, osl_getThreadTextEncoding()).getStr());
68 osl::Module
lib(aLibName
, SAL_LOADMODULE_LAZY
| SAL_LOADMODULE_GLOBAL
);
71 // ========================= LATEST VERSION =========================
72 oslGenericFunction pSym
= lib
.getFunctionSymbol(COMPONENT_GETENV
);
75 Environment java_env
, loader_env
;
77 const sal_Char
* pEnvTypeName
= nullptr;
78 (*reinterpret_cast<component_getImplementationEnvironmentFunc
>(pSym
))(
79 &pEnvTypeName
, reinterpret_cast<uno_Environment
**>(&loader_env
) );
80 if (! loader_env
.is())
82 OUString
aEnvTypeName( OUString::createFromAscii( pEnvTypeName
) );
83 uno_getEnvironment( reinterpret_cast<uno_Environment
**>(&loader_env
), aEnvTypeName
.pData
, nullptr );
87 ::rtl::Reference
< ::jvmaccess::UnoVirtualMachine
> vm_access(
88 ::javaunohelper::create_vm_access( pJEnv
, loader
) );
89 OUString java_env_name
= UNO_LB_JAVA
;
91 reinterpret_cast<uno_Environment
**>(&java_env
), java_env_name
.pData
, vm_access
.get() );
93 pSym
= lib
.getFunctionSymbol(COMPONENT_WRITEINFO
);
96 if (loader_env
.is() && java_env
.is())
98 Mapping
java2dest(java_env
.get(), loader_env
.get());
100 if ( java2dest
.is() )
103 java2dest
.mapInterface(
104 jSMgr
, cppu::UnoType
<lang::XMultiServiceFactory
>::get());
106 java2dest
.mapInterface(
107 jRegKey
, cppu::UnoType
<registry::XRegistryKey
>::get());
109 uno_ExtEnvironment
* env
= loader_env
.get()->pExtEnv
;
112 bRet
= (*reinterpret_cast<component_writeInfoFunc
>(pSym
))( pSMgr
, pKey
);
115 (*env
->releaseInterface
)( env
, pKey
);
119 (*env
->releaseInterface
)( env
, pSMgr
);
131 * Class: com_sun_star_comp_helper_SharedLibraryLoader
132 * Method: component_getFactory
133 * Signature: (Ljava/lang/String;Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Ljava/lang/Object;
135 jobject
Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
136 JNIEnv
* pJEnv
, SAL_UNUSED_PARAMETER jclass
, jstring jLibName
, jstring jImplName
,
137 jobject jSMgr
, jobject jRegKey
, jobject loader
)
139 const jchar
* pJLibName
= pJEnv
->GetStringChars(jLibName
, nullptr);
140 OUString
aLibName(reinterpret_cast<sal_Unicode
const *>(pJLibName
));
141 pJEnv
->ReleaseStringChars(jLibName
, pJLibName
);
143 #ifdef DISABLE_DYNLOADING
149 fprintf(stderr
, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__
, OUStringToOString(aLibName
, osl_getThreadTextEncoding()).getStr());
152 aLibName
+= SAL_DLLEXTENSION
;
154 jobject joSLL_cpp
= nullptr;
156 #ifndef DISABLE_DYNLOADING
157 osl::Module
lib(aLibName
, SAL_LOADMODULE_LAZY
| SAL_LOADMODULE_GLOBAL
);
160 // ========================= LATEST VERSION =========================
161 oslGenericFunction pSym
= lib
.getFunctionSymbol(COMPONENT_GETENV
);
164 Environment java_env
, loader_env
;
166 const sal_Char
* pEnvTypeName
= nullptr;
167 (*reinterpret_cast<component_getImplementationEnvironmentFunc
>(pSym
))(
168 &pEnvTypeName
, reinterpret_cast<uno_Environment
**>(&loader_env
) );
170 if (! loader_env
.is())
172 OUString
aEnvTypeName( OUString::createFromAscii( pEnvTypeName
) );
173 uno_getEnvironment( reinterpret_cast<uno_Environment
**>(&loader_env
), aEnvTypeName
.pData
, nullptr );
177 ::rtl::Reference
< ::jvmaccess::UnoVirtualMachine
> vm_access(
178 ::javaunohelper::create_vm_access( pJEnv
, loader
) );
179 OUString java_env_name
= UNO_LB_JAVA
;
181 reinterpret_cast<uno_Environment
**>(&java_env
), java_env_name
.pData
, vm_access
.get() );
183 pSym
= lib
.getFunctionSymbol(COMPONENT_GETFACTORY
);
186 if (loader_env
.is() && java_env
.is())
188 Mapping
java2dest( java_env
.get(), loader_env
.get() );
189 Mapping
dest2java( loader_env
.get(), java_env
.get() );
191 if (dest2java
.is() && java2dest
.is())
194 java2dest
.mapInterface(
195 jSMgr
, cppu::UnoType
<lang::XMultiServiceFactory
>::get());
197 java2dest
.mapInterface(
198 jRegKey
, cppu::UnoType
<registry::XRegistryKey
>::get());
200 const char* pImplName
= pJEnv
->GetStringUTFChars( jImplName
, nullptr );
202 void * pSSF
= (*reinterpret_cast<component_getFactoryFunc
>(pSym
))(
203 pImplName
, pSMgr
, pKey
);
205 pJEnv
->ReleaseStringUTFChars( jImplName
, pImplName
);
207 uno_ExtEnvironment
* env
= loader_env
.get()->pExtEnv
;
210 (*env
->releaseInterface
)( env
, pKey
);
212 (*env
->releaseInterface
)( env
, pSMgr
);
216 jobject jglobal
= static_cast<jobject
>(dest2java
.mapInterface(
217 pSSF
, cppu::UnoType
<XInterface
>::get()));
218 joSLL_cpp
= pJEnv
->NewLocalRef( jglobal
);
219 pJEnv
->DeleteGlobalRef( jglobal
);
221 (*env
->releaseInterface
)( env
, pSSF
);
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */