Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <osl/diagnose.h>
22 : #include <osl/module.h>
23 :
24 : #include <uno/environment.hxx>
25 : #include <uno/mapping.hxx>
26 :
27 : #include <cppuhelper/factory.hxx>
28 :
29 : #include <com/sun/star/beans/XPropertySet.hpp>
30 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 : #include <com/sun/star/lang/XServiceInfo.hpp>
32 : #include <com/sun/star/registry/XRegistryKey.hpp>
33 :
34 : #include "jni.h"
35 : #include "jvmaccess/virtualmachine.hxx"
36 : #include "jvmaccess/unovirtualmachine.hxx"
37 :
38 : #include "vm.hxx"
39 :
40 : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
41 :
42 :
43 : using namespace ::com::sun::star;
44 : using namespace ::com::sun::star::uno;
45 : using ::rtl::OString;
46 : using ::rtl::OUString;
47 :
48 : /*
49 : * Class: com_sun_star_comp_helper_SharedLibraryLoader
50 : * Method: component_writeInfo
51 : * Signature: (Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Z
52 : */
53 : extern "C" SAL_JNI_EXPORT jboolean JNICALL
54 0 : Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
55 : JNIEnv * pJEnv, SAL_UNUSED_PARAMETER jclass, jstring jLibName, jobject jSMgr,
56 : jobject jRegKey, jobject loader )
57 : {
58 0 : sal_Bool bRet = sal_False;
59 :
60 0 : const jchar* pJLibName = pJEnv->GetStringChars( jLibName, NULL );
61 0 : OUString aLibName( pJLibName );
62 0 : pJEnv->ReleaseStringChars( jLibName, pJLibName);
63 :
64 : #ifdef DISABLE_DYNLOADING
65 : (void) jSMgr;
66 : (void) jRegKey;
67 : (void) loader;
68 :
69 : fprintf(stderr, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__, ::rtl::OUStringToOString(pJLibName, RTL_TEXTENCODING_JAVA_UTF8).getStr());
70 : #else
71 0 : oslModule lib = osl_loadModule( aLibName.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL );
72 0 : if (lib)
73 : {
74 : // ========================= LATEST VERSION =========================
75 0 : OUString aGetEnvName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETENV) );
76 : oslGenericFunction pSym =
77 0 : osl_getFunctionSymbol( lib, aGetEnvName.pData );
78 0 : if (pSym)
79 : {
80 0 : Environment java_env, loader_env;
81 :
82 0 : const sal_Char * pEnvTypeName = 0;
83 : (*((component_getImplementationEnvironmentFunc)pSym))(
84 0 : &pEnvTypeName, (uno_Environment **)&loader_env );
85 0 : if (! loader_env.is())
86 : {
87 0 : OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
88 0 : uno_getEnvironment( (uno_Environment **)&loader_env, aEnvTypeName.pData, 0 );
89 : }
90 :
91 : // create vm access
92 : ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access(
93 0 : ::javaunohelper::create_vm_access( pJEnv, loader ) );
94 0 : OUString java_env_name = OUSTR(UNO_LB_JAVA);
95 : uno_getEnvironment(
96 0 : (uno_Environment **)&java_env, java_env_name.pData, vm_access.get() );
97 :
98 0 : OUString aWriteInfoName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_WRITEINFO) );
99 0 : pSym = osl_getFunctionSymbol( lib, aWriteInfoName.pData );
100 0 : if (pSym)
101 : {
102 0 : if (loader_env.is() && java_env.is())
103 : {
104 0 : Mapping java2dest(java_env.get(), loader_env.get());
105 :
106 0 : if ( java2dest.is() )
107 : {
108 : void * pSMgr =
109 : java2dest.mapInterface(
110 0 : jSMgr, getCppuType((Reference< lang::XMultiServiceFactory > *) 0) );
111 : void * pKey =
112 : java2dest.mapInterface(
113 0 : jRegKey, getCppuType((Reference< registry::XRegistryKey > *) 0) );
114 :
115 0 : uno_ExtEnvironment * env = loader_env.get()->pExtEnv;
116 0 : if (pKey)
117 : {
118 0 : bRet = (*((component_writeInfoFunc)pSym))( pSMgr, pKey );
119 :
120 0 : if (env)
121 0 : (*env->releaseInterface)( env, pKey );
122 : }
123 :
124 0 : if (pSMgr && env)
125 0 : (*env->releaseInterface)( env, pSMgr );
126 0 : }
127 : }
128 0 : }
129 0 : }
130 : }
131 : #endif
132 0 : return bRet == sal_False? JNI_FALSE : JNI_TRUE;
133 : }
134 :
135 : /*
136 : * Class: com_sun_star_comp_helper_SharedLibraryLoader
137 : * Method: component_getFactory
138 : * Signature: (Ljava/lang/String;Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Ljava/lang/Object;
139 : */
140 : extern "C" SAL_JNI_EXPORT jobject JNICALL
141 0 : Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
142 : JNIEnv * pJEnv, SAL_UNUSED_PARAMETER jclass, jstring jLibName, jstring jImplName,
143 : jobject jSMgr, jobject jRegKey, jobject loader )
144 : {
145 0 : const jchar* pJLibName = pJEnv->GetStringChars(jLibName, NULL);
146 :
147 : #ifdef DISABLE_DYNLOADING
148 : (void) jImplName;
149 : (void) jSMgr;
150 : (void) jRegKey;
151 : (void) loader;
152 :
153 : fprintf(stderr, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__, ::rtl::OUStringToOString(pJLibName, RTL_TEXTENCODING_JAVA_UTF8).getStr());
154 : #endif
155 :
156 0 : OUString aLibName( pJLibName );
157 0 : pJEnv->ReleaseStringChars( jLibName, pJLibName);
158 :
159 0 : aLibName += OUString( RTL_CONSTASCII_USTRINGPARAM(SAL_DLLEXTENSION) );
160 :
161 0 : jobject joSLL_cpp = 0;
162 :
163 : #ifndef DISABLE_DYNLOADING
164 0 : oslModule lib = osl_loadModule( aLibName.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL );
165 0 : if (lib)
166 : {
167 : // ========================= LATEST VERSION =========================
168 0 : OUString aGetEnvName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETENV) );
169 : oslGenericFunction pSym =
170 0 : osl_getFunctionSymbol( lib, aGetEnvName.pData );
171 0 : if (pSym)
172 : {
173 0 : Environment java_env, loader_env;
174 :
175 0 : const sal_Char * pEnvTypeName = 0;
176 : (*((component_getImplementationEnvironmentFunc)pSym))(
177 0 : &pEnvTypeName, (uno_Environment **)&loader_env );
178 :
179 0 : if (! loader_env.is())
180 : {
181 0 : OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
182 0 : uno_getEnvironment( (uno_Environment **)&loader_env, aEnvTypeName.pData, 0 );
183 : }
184 :
185 : // create vm access
186 : ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access(
187 0 : ::javaunohelper::create_vm_access( pJEnv, loader ) );
188 0 : OUString java_env_name = OUSTR(UNO_LB_JAVA);
189 : uno_getEnvironment(
190 0 : (uno_Environment **)&java_env, java_env_name.pData, vm_access.get() );
191 :
192 0 : OUString aGetFactoryName( RTL_CONSTASCII_USTRINGPARAM(COMPONENT_GETFACTORY) );
193 0 : pSym = osl_getFunctionSymbol( lib, aGetFactoryName.pData );
194 0 : if (pSym)
195 : {
196 0 : if (loader_env.is() && java_env.is())
197 : {
198 0 : Mapping java2dest( java_env.get(), loader_env.get() );
199 0 : Mapping dest2java( loader_env.get(), java_env.get() );
200 :
201 0 : if (dest2java.is() && java2dest.is())
202 : {
203 : void * pSMgr =
204 : java2dest.mapInterface(
205 0 : jSMgr, ::getCppuType((Reference< lang::XMultiServiceFactory > *) 0) );
206 : void * pKey =
207 : java2dest.mapInterface(
208 0 : jRegKey, ::getCppuType((Reference< registry::XRegistryKey > *) 0) );
209 :
210 0 : const char* pImplName = pJEnv->GetStringUTFChars( jImplName, NULL );
211 :
212 : void * pSSF = (*((component_getFactoryFunc)pSym))(
213 0 : pImplName, pSMgr, pKey );
214 :
215 0 : pJEnv->ReleaseStringUTFChars( jImplName, pImplName );
216 :
217 0 : uno_ExtEnvironment * env = loader_env.get()->pExtEnv;
218 :
219 0 : if (pKey && env)
220 0 : (*env->releaseInterface)( env, pKey );
221 0 : if (pSMgr && env)
222 0 : (*env->releaseInterface)( env, pSMgr );
223 :
224 0 : if (pSSF)
225 : {
226 : jobject jglobal = (jobject) dest2java.mapInterface(
227 0 : pSSF, getCppuType((Reference< XInterface > *) 0) );
228 0 : joSLL_cpp = pJEnv->NewLocalRef( jglobal );
229 0 : pJEnv->DeleteGlobalRef( jglobal );
230 0 : if (env)
231 0 : (*env->releaseInterface)( env, pSSF );
232 : }
233 0 : }
234 : }
235 0 : }
236 0 : }
237 : }
238 : #endif
239 0 : return joSLL_cpp;
240 : }
241 :
242 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|