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
, NULL
);
59 OUString
aLibName(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 OUString
aGetEnvName( COMPONENT_GETENV
);
74 oslGenericFunction pSym
= lib
.getFunctionSymbol(aGetEnvName
);
77 Environment java_env
, loader_env
;
79 const sal_Char
* pEnvTypeName
= 0;
80 (*reinterpret_cast<component_getImplementationEnvironmentFunc
>(pSym
))(
81 &pEnvTypeName
, reinterpret_cast<uno_Environment
**>(&loader_env
) );
82 if (! loader_env
.is())
84 OUString
aEnvTypeName( OUString::createFromAscii( pEnvTypeName
) );
85 uno_getEnvironment( reinterpret_cast<uno_Environment
**>(&loader_env
), aEnvTypeName
.pData
, 0 );
89 ::rtl::Reference
< ::jvmaccess::UnoVirtualMachine
> vm_access(
90 ::javaunohelper::create_vm_access( pJEnv
, loader
) );
91 OUString java_env_name
= UNO_LB_JAVA
;
93 reinterpret_cast<uno_Environment
**>(&java_env
), java_env_name
.pData
, vm_access
.get() );
95 OUString
aWriteInfoName( COMPONENT_WRITEINFO
);
96 pSym
= lib
.getFunctionSymbol(aWriteInfoName
);
99 if (loader_env
.is() && java_env
.is())
101 Mapping
java2dest(java_env
.get(), loader_env
.get());
103 if ( java2dest
.is() )
106 java2dest
.mapInterface(
107 jSMgr
, cppu::UnoType
<lang::XMultiServiceFactory
>::get());
109 java2dest
.mapInterface(
110 jRegKey
, cppu::UnoType
<registry::XRegistryKey
>::get());
112 uno_ExtEnvironment
* env
= loader_env
.get()->pExtEnv
;
115 bRet
= (*reinterpret_cast<component_writeInfoFunc
>(pSym
))( pSMgr
, pKey
);
118 (*env
->releaseInterface
)( env
, pKey
);
122 (*env
->releaseInterface
)( env
, pSMgr
);
130 return bRet
? JNI_TRUE
: JNI_FALSE
;
134 * Class: com_sun_star_comp_helper_SharedLibraryLoader
135 * Method: component_getFactory
136 * Signature: (Ljava/lang/String;Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Ljava/lang/Object;
138 jobject
Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
139 JNIEnv
* pJEnv
, SAL_UNUSED_PARAMETER jclass
, jstring jLibName
, jstring jImplName
,
140 jobject jSMgr
, jobject jRegKey
, jobject loader
)
142 const jchar
* pJLibName
= pJEnv
->GetStringChars(jLibName
, NULL
);
143 OUString
aLibName(pJLibName
);
144 pJEnv
->ReleaseStringChars(jLibName
, pJLibName
);
146 #ifdef DISABLE_DYNLOADING
152 fprintf(stderr
, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__
, OUStringToOString(aLibName
, osl_getThreadTextEncoding()).getStr());
155 aLibName
+= OUString( SAL_DLLEXTENSION
);
157 jobject joSLL_cpp
= 0;
159 #ifndef DISABLE_DYNLOADING
160 osl::Module
lib(aLibName
, SAL_LOADMODULE_LAZY
| SAL_LOADMODULE_GLOBAL
);
163 // ========================= LATEST VERSION =========================
164 OUString
aGetEnvName( COMPONENT_GETENV
);
165 oslGenericFunction pSym
= lib
.getFunctionSymbol(aGetEnvName
);
168 Environment java_env
, loader_env
;
170 const sal_Char
* pEnvTypeName
= 0;
171 (*reinterpret_cast<component_getImplementationEnvironmentFunc
>(pSym
))(
172 &pEnvTypeName
, reinterpret_cast<uno_Environment
**>(&loader_env
) );
174 if (! loader_env
.is())
176 OUString
aEnvTypeName( OUString::createFromAscii( pEnvTypeName
) );
177 uno_getEnvironment( reinterpret_cast<uno_Environment
**>(&loader_env
), aEnvTypeName
.pData
, 0 );
181 ::rtl::Reference
< ::jvmaccess::UnoVirtualMachine
> vm_access(
182 ::javaunohelper::create_vm_access( pJEnv
, loader
) );
183 OUString java_env_name
= UNO_LB_JAVA
;
185 reinterpret_cast<uno_Environment
**>(&java_env
), java_env_name
.pData
, vm_access
.get() );
187 OUString
aGetFactoryName( COMPONENT_GETFACTORY
);
188 pSym
= lib
.getFunctionSymbol(aGetFactoryName
);
191 if (loader_env
.is() && java_env
.is())
193 Mapping
java2dest( java_env
.get(), loader_env
.get() );
194 Mapping
dest2java( loader_env
.get(), java_env
.get() );
196 if (dest2java
.is() && java2dest
.is())
199 java2dest
.mapInterface(
200 jSMgr
, cppu::UnoType
<lang::XMultiServiceFactory
>::get());
202 java2dest
.mapInterface(
203 jRegKey
, cppu::UnoType
<registry::XRegistryKey
>::get());
205 const char* pImplName
= pJEnv
->GetStringUTFChars( jImplName
, NULL
);
207 void * pSSF
= (*reinterpret_cast<component_getFactoryFunc
>(pSym
))(
208 pImplName
, pSMgr
, pKey
);
210 pJEnv
->ReleaseStringUTFChars( jImplName
, pImplName
);
212 uno_ExtEnvironment
* env
= loader_env
.get()->pExtEnv
;
215 (*env
->releaseInterface
)( env
, pKey
);
217 (*env
->releaseInterface
)( env
, pSMgr
);
221 jobject jglobal
= static_cast<jobject
>(dest2java
.mapInterface(
222 pSSF
, cppu::UnoType
<XInterface
>::get()));
223 joSLL_cpp
= pJEnv
->NewLocalRef( jglobal
);
224 pJEnv
->DeleteGlobalRef( jglobal
);
226 (*env
->releaseInterface
)( env
, pSSF
);
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */