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 #pragma clang diagnostic push
35 #pragma clang diagnostic ignored "-Wunknown-attributes"
39 #pragma clang diagnostic pop
42 #include <jvmaccess/unovirtualmachine.hxx>
44 #include "juhx-export-functions.hxx"
47 #ifdef DISABLE_DYNLOADING
48 #include <osl/thread.h>
51 using namespace ::com::sun::star
;
52 using namespace ::com::sun::star::uno
;
55 * Class: com_sun_star_comp_helper_SharedLibraryLoader
56 * Method: component_writeInfo
57 * Signature: (Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Z
59 jboolean
Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
60 JNIEnv
* pJEnv
, SAL_UNUSED_PARAMETER jclass
, jstring jLibName
, jobject jSMgr
,
61 jobject jRegKey
, jobject loader
)
65 const jchar
* pJLibName
= pJEnv
->GetStringChars(jLibName
, nullptr);
66 OUString
aLibName(reinterpret_cast<sal_Unicode
const *>(pJLibName
));
67 pJEnv
->ReleaseStringChars(jLibName
, pJLibName
);
69 #ifdef DISABLE_DYNLOADING
74 fprintf(stderr
, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__
, OUStringToOString(aLibName
, osl_getThreadTextEncoding()).getStr());
76 osl::Module
lib(aLibName
, SAL_LOADMODULE_LAZY
| SAL_LOADMODULE_GLOBAL
);
79 // ========================= LATEST VERSION =========================
80 oslGenericFunction pSym
= lib
.getFunctionSymbol(COMPONENT_GETENV
);
83 Environment java_env
, loader_env
;
85 const char * pEnvTypeName
= nullptr;
86 (*reinterpret_cast<component_getImplementationEnvironmentFunc
>(pSym
))(
87 &pEnvTypeName
, reinterpret_cast<uno_Environment
**>(&loader_env
) );
88 if (! loader_env
.is())
90 OUString
aEnvTypeName( OUString::createFromAscii( pEnvTypeName
) );
91 uno_getEnvironment( reinterpret_cast<uno_Environment
**>(&loader_env
), aEnvTypeName
.pData
, nullptr );
95 ::rtl::Reference
< ::jvmaccess::UnoVirtualMachine
> vm_access(
96 ::javaunohelper::create_vm_access( pJEnv
, loader
) );
97 OUString java_env_name
= u
"" UNO_LB_JAVA
""_ustr
;
99 reinterpret_cast<uno_Environment
**>(&java_env
), java_env_name
.pData
, vm_access
.get() );
101 pSym
= lib
.getFunctionSymbol(COMPONENT_WRITEINFO
);
104 if (loader_env
.is() && java_env
.is())
106 Mapping
java2dest(java_env
.get(), loader_env
.get());
108 if ( java2dest
.is() )
111 java2dest
.mapInterface(
112 jSMgr
, cppu::UnoType
<lang::XMultiServiceFactory
>::get());
114 java2dest
.mapInterface(
115 jRegKey
, cppu::UnoType
<registry::XRegistryKey
>::get());
117 uno_ExtEnvironment
* env
= loader_env
.get()->pExtEnv
;
120 bRet
= (*reinterpret_cast<component_writeInfoFunc
>(pSym
))( pSMgr
, pKey
);
123 (*env
->releaseInterface
)( env
, pKey
);
127 (*env
->releaseInterface
)( env
, pSMgr
);
139 * Class: com_sun_star_comp_helper_SharedLibraryLoader
140 * Method: component_getFactory
141 * Signature: (Ljava/lang/String;Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Ljava/lang/Object;
143 jobject
Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
144 JNIEnv
* pJEnv
, SAL_UNUSED_PARAMETER jclass
, jstring jLibName
, jstring jImplName
,
145 jobject jSMgr
, jobject jRegKey
, jobject loader
)
147 const jchar
* pJLibName
= pJEnv
->GetStringChars(jLibName
, nullptr);
148 OUString
aLibName(reinterpret_cast<sal_Unicode
const *>(pJLibName
));
149 pJEnv
->ReleaseStringChars(jLibName
, pJLibName
);
151 #ifdef DISABLE_DYNLOADING
157 fprintf(stderr
, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__
, OUStringToOString(aLibName
, osl_getThreadTextEncoding()).getStr());
160 aLibName
+= SAL_DLLEXTENSION
;
162 jobject joSLL_cpp
= nullptr;
164 #ifndef DISABLE_DYNLOADING
165 osl::Module
lib(aLibName
, SAL_LOADMODULE_LAZY
| SAL_LOADMODULE_GLOBAL
);
168 // ========================= LATEST VERSION =========================
169 oslGenericFunction pSym
= lib
.getFunctionSymbol(COMPONENT_GETENV
);
172 Environment java_env
, loader_env
;
174 const char * pEnvTypeName
= nullptr;
175 (*reinterpret_cast<component_getImplementationEnvironmentFunc
>(pSym
))(
176 &pEnvTypeName
, reinterpret_cast<uno_Environment
**>(&loader_env
) );
178 if (! loader_env
.is())
180 OUString
aEnvTypeName( OUString::createFromAscii( pEnvTypeName
) );
181 uno_getEnvironment( reinterpret_cast<uno_Environment
**>(&loader_env
), aEnvTypeName
.pData
, nullptr );
185 ::rtl::Reference
< ::jvmaccess::UnoVirtualMachine
> vm_access(
186 ::javaunohelper::create_vm_access( pJEnv
, loader
) );
187 OUString java_env_name
= u
"" UNO_LB_JAVA
""_ustr
;
189 reinterpret_cast<uno_Environment
**>(&java_env
), java_env_name
.pData
, vm_access
.get() );
191 pSym
= lib
.getFunctionSymbol(COMPONENT_GETFACTORY
);
194 if (loader_env
.is() && java_env
.is())
196 Mapping
java2dest( java_env
.get(), loader_env
.get() );
197 Mapping
dest2java( loader_env
.get(), java_env
.get() );
199 if (dest2java
.is() && java2dest
.is())
202 java2dest
.mapInterface(
203 jSMgr
, cppu::UnoType
<lang::XMultiServiceFactory
>::get());
205 java2dest
.mapInterface(
206 jRegKey
, cppu::UnoType
<registry::XRegistryKey
>::get());
208 const char* pImplName
= pJEnv
->GetStringUTFChars( jImplName
, nullptr );
210 void * pSSF
= (*reinterpret_cast<component_getFactoryFunc
>(pSym
))(
211 pImplName
, pSMgr
, pKey
);
213 pJEnv
->ReleaseStringUTFChars( jImplName
, pImplName
);
215 uno_ExtEnvironment
* env
= loader_env
.get()->pExtEnv
;
218 (*env
->releaseInterface
)( env
, pKey
);
220 (*env
->releaseInterface
)( env
, pSMgr
);
224 jobject jglobal
= static_cast<jobject
>(dest2java
.mapInterface(
225 pSSF
, cppu::UnoType
<XInterface
>::get()));
226 joSLL_cpp
= pJEnv
->NewLocalRef( jglobal
);
227 pJEnv
->DeleteGlobalRef( jglobal
);
229 (*env
->releaseInterface
)( env
, pSSF
);
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */