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/diagnose.h>
23 #include <osl/module.hxx>
24 #include <osl/thread.h>
26 #include <uno/environment.hxx>
27 #include <uno/lbnames.h>
28 #include <uno/mapping.hxx>
30 #include <cppuhelper/factory.hxx>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/registry/XRegistryKey.hpp>
38 #include "jvmaccess/virtualmachine.hxx"
39 #include "jvmaccess/unovirtualmachine.hxx"
41 #include "juhx-export-functions.hxx"
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::uno
;
48 * Class: com_sun_star_comp_helper_SharedLibraryLoader
49 * Method: component_writeInfo
50 * Signature: (Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Z
52 jboolean
Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
53 JNIEnv
* pJEnv
, SAL_UNUSED_PARAMETER jclass
, jstring jLibName
, jobject jSMgr
,
54 jobject jRegKey
, jobject loader
)
58 const jchar
* pJLibName
= pJEnv
->GetStringChars(jLibName
, nullptr);
59 OUString
aLibName(reinterpret_cast<sal_Unicode
const *>(pJLibName
));
60 pJEnv
->ReleaseStringChars(jLibName
, pJLibName
);
62 #ifdef DISABLE_DYNLOADING
67 fprintf(stderr
, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__
, OUStringToOString(aLibName
, osl_getThreadTextEncoding()).getStr());
69 osl::Module
lib(aLibName
, SAL_LOADMODULE_LAZY
| SAL_LOADMODULE_GLOBAL
);
72 // ========================= LATEST VERSION =========================
73 oslGenericFunction pSym
= lib
.getFunctionSymbol(COMPONENT_GETENV
);
76 Environment java_env
, loader_env
;
78 const sal_Char
* pEnvTypeName
= nullptr;
79 (*reinterpret_cast<component_getImplementationEnvironmentFunc
>(pSym
))(
80 &pEnvTypeName
, reinterpret_cast<uno_Environment
**>(&loader_env
) );
81 if (! loader_env
.is())
83 OUString
aEnvTypeName( OUString::createFromAscii( pEnvTypeName
) );
84 uno_getEnvironment( reinterpret_cast<uno_Environment
**>(&loader_env
), aEnvTypeName
.pData
, nullptr );
88 ::rtl::Reference
< ::jvmaccess::UnoVirtualMachine
> vm_access(
89 ::javaunohelper::create_vm_access( pJEnv
, loader
) );
90 OUString java_env_name
= UNO_LB_JAVA
;
92 reinterpret_cast<uno_Environment
**>(&java_env
), java_env_name
.pData
, vm_access
.get() );
94 pSym
= lib
.getFunctionSymbol(COMPONENT_WRITEINFO
);
97 if (loader_env
.is() && java_env
.is())
99 Mapping
java2dest(java_env
.get(), loader_env
.get());
101 if ( java2dest
.is() )
104 java2dest
.mapInterface(
105 jSMgr
, cppu::UnoType
<lang::XMultiServiceFactory
>::get());
107 java2dest
.mapInterface(
108 jRegKey
, cppu::UnoType
<registry::XRegistryKey
>::get());
110 uno_ExtEnvironment
* env
= loader_env
.get()->pExtEnv
;
113 bRet
= (*reinterpret_cast<component_writeInfoFunc
>(pSym
))( pSMgr
, pKey
);
116 (*env
->releaseInterface
)( env
, pKey
);
120 (*env
->releaseInterface
)( env
, pSMgr
);
128 return bRet
? JNI_TRUE
: JNI_FALSE
;
132 * Class: com_sun_star_comp_helper_SharedLibraryLoader
133 * Method: component_getFactory
134 * Signature: (Ljava/lang/String;Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Ljava/lang/Object;
136 jobject
Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
137 JNIEnv
* pJEnv
, SAL_UNUSED_PARAMETER jclass
, jstring jLibName
, jstring jImplName
,
138 jobject jSMgr
, jobject jRegKey
, jobject loader
)
140 const jchar
* pJLibName
= pJEnv
->GetStringChars(jLibName
, nullptr);
141 OUString
aLibName(reinterpret_cast<sal_Unicode
const *>(pJLibName
));
142 pJEnv
->ReleaseStringChars(jLibName
, pJLibName
);
144 #ifdef DISABLE_DYNLOADING
150 fprintf(stderr
, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__
, OUStringToOString(aLibName
, osl_getThreadTextEncoding()).getStr());
153 aLibName
+= SAL_DLLEXTENSION
;
155 jobject joSLL_cpp
= nullptr;
157 #ifndef DISABLE_DYNLOADING
158 osl::Module
lib(aLibName
, SAL_LOADMODULE_LAZY
| SAL_LOADMODULE_GLOBAL
);
161 // ========================= LATEST VERSION =========================
162 oslGenericFunction pSym
= lib
.getFunctionSymbol(COMPONENT_GETENV
);
165 Environment java_env
, loader_env
;
167 const sal_Char
* pEnvTypeName
= nullptr;
168 (*reinterpret_cast<component_getImplementationEnvironmentFunc
>(pSym
))(
169 &pEnvTypeName
, reinterpret_cast<uno_Environment
**>(&loader_env
) );
171 if (! loader_env
.is())
173 OUString
aEnvTypeName( OUString::createFromAscii( pEnvTypeName
) );
174 uno_getEnvironment( reinterpret_cast<uno_Environment
**>(&loader_env
), aEnvTypeName
.pData
, nullptr );
178 ::rtl::Reference
< ::jvmaccess::UnoVirtualMachine
> vm_access(
179 ::javaunohelper::create_vm_access( pJEnv
, loader
) );
180 OUString java_env_name
= UNO_LB_JAVA
;
182 reinterpret_cast<uno_Environment
**>(&java_env
), java_env_name
.pData
, vm_access
.get() );
184 pSym
= lib
.getFunctionSymbol(COMPONENT_GETFACTORY
);
187 if (loader_env
.is() && java_env
.is())
189 Mapping
java2dest( java_env
.get(), loader_env
.get() );
190 Mapping
dest2java( loader_env
.get(), java_env
.get() );
192 if (dest2java
.is() && java2dest
.is())
195 java2dest
.mapInterface(
196 jSMgr
, cppu::UnoType
<lang::XMultiServiceFactory
>::get());
198 java2dest
.mapInterface(
199 jRegKey
, cppu::UnoType
<registry::XRegistryKey
>::get());
201 const char* pImplName
= pJEnv
->GetStringUTFChars( jImplName
, nullptr );
203 void * pSSF
= (*reinterpret_cast<component_getFactoryFunc
>(pSym
))(
204 pImplName
, pSMgr
, pKey
);
206 pJEnv
->ReleaseStringUTFChars( jImplName
, pImplName
);
208 uno_ExtEnvironment
* env
= loader_env
.get()->pExtEnv
;
211 (*env
->releaseInterface
)( env
, pKey
);
213 (*env
->releaseInterface
)( env
, pSMgr
);
217 jobject jglobal
= static_cast<jobject
>(dest2java
.mapInterface(
218 pSSF
, cppu::UnoType
<XInterface
>::get()));
219 joSLL_cpp
= pJEnv
->NewLocalRef( jglobal
);
220 pJEnv
->DeleteGlobalRef( jglobal
);
222 (*env
->releaseInterface
)( env
, pSSF
);
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */