1*61f28c9eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*61f28c9eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*61f28c9eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*61f28c9eSAndrew Rist  * distributed with this work for additional information
6*61f28c9eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*61f28c9eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*61f28c9eSAndrew Rist  * "License"); you may not use this file except in compliance
9*61f28c9eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*61f28c9eSAndrew Rist  *
11*61f28c9eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*61f28c9eSAndrew Rist  *
13*61f28c9eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*61f28c9eSAndrew Rist  * software distributed under the License is distributed on an
15*61f28c9eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*61f28c9eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*61f28c9eSAndrew Rist  * specific language governing permissions and limitations
18*61f28c9eSAndrew Rist  * under the License.
19*61f28c9eSAndrew Rist  *
20*61f28c9eSAndrew Rist  *************************************************************/
21*61f28c9eSAndrew Rist 
22*61f28c9eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_javaunohelper.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "jni.h"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "rtl/ustring.hxx"
30cdf0e10cSrcweir #include "osl/module.h"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #if ! defined SAL_DLLPREFIX
35cdf0e10cSrcweir #define SAL_DLLPREFIX ""
36cdf0e10cSrcweir #endif
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using ::rtl::OUString;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir extern "C"
41cdf0e10cSrcweir {
42cdf0e10cSrcweir typedef jboolean (JNICALL * fptr_writeInfo)(
43cdf0e10cSrcweir     JNIEnv *, jclass, jstring, jobject, jobject, jobject );
44cdf0e10cSrcweir typedef jobject (JNICALL * fptr_getFactory)(
45cdf0e10cSrcweir     JNIEnv *, jclass, jstring, jstring, jobject, jobject, jobject );
46cdf0e10cSrcweir typedef jobject (JNICALL * fptr_createRegistryServiceFactory)(
47cdf0e10cSrcweir     JNIEnv *, jclass, jstring, jstring, jboolean, jobject );
48cdf0e10cSrcweir typedef jobject (JNICALL * fptr_bootstrap)(
49cdf0e10cSrcweir     JNIEnv *_env, jclass, jstring, jobjectArray, jobject );
50cdf0e10cSrcweir 
51cdf0e10cSrcweir static fptr_writeInfo s_writeInfo;
52cdf0e10cSrcweir static fptr_getFactory s_getFactory;
53cdf0e10cSrcweir static fptr_createRegistryServiceFactory s_createRegistryServiceFactory;
54cdf0e10cSrcweir static fptr_bootstrap s_bootstrap;
55cdf0e10cSrcweir static bool s_inited = false;
56cdf0e10cSrcweir 
thisModule()57cdf0e10cSrcweir extern "C" { static void SAL_CALL thisModule() {} }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
inited_juhx(JNIEnv * jni_env)60cdf0e10cSrcweir static bool inited_juhx( JNIEnv * jni_env )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     if (s_inited)
63cdf0e10cSrcweir         return true;
64cdf0e10cSrcweir     OUString lib_name = OUSTR(SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION);
65cdf0e10cSrcweir     oslModule hModule =
66cdf0e10cSrcweir         osl_loadModuleRelative( &thisModule, lib_name.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL );
67cdf0e10cSrcweir     if (0 == hModule)
68cdf0e10cSrcweir     {
69cdf0e10cSrcweir         jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
70cdf0e10cSrcweir         jni_env->ThrowNew(
71cdf0e10cSrcweir             c, "error loading " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
72cdf0e10cSrcweir         return false;
73cdf0e10cSrcweir     }
74cdf0e10cSrcweir     else
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         OUString symbol =
77cdf0e10cSrcweir               OUSTR("Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo");
78cdf0e10cSrcweir         s_writeInfo = (fptr_writeInfo)osl_getFunctionSymbol(
79cdf0e10cSrcweir             hModule, symbol.pData );
80cdf0e10cSrcweir         symbol =
81cdf0e10cSrcweir             OUSTR("Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory");
82cdf0e10cSrcweir         s_getFactory = (fptr_getFactory)osl_getFunctionSymbol(
83cdf0e10cSrcweir             hModule, symbol.pData );
84cdf0e10cSrcweir         symbol =
85cdf0e10cSrcweir             OUSTR("Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory");
86cdf0e10cSrcweir         s_createRegistryServiceFactory =
87cdf0e10cSrcweir             (fptr_createRegistryServiceFactory)osl_getFunctionSymbol(
88cdf0e10cSrcweir                 hModule, symbol.pData );
89cdf0e10cSrcweir         symbol =
90cdf0e10cSrcweir             OUSTR("Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap");
91cdf0e10cSrcweir         s_bootstrap =
92cdf0e10cSrcweir             (fptr_bootstrap)osl_getFunctionSymbol( hModule, symbol.pData );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         if (0 == s_writeInfo ||
95cdf0e10cSrcweir             0 == s_getFactory ||
96cdf0e10cSrcweir             0 == s_createRegistryServiceFactory ||
97cdf0e10cSrcweir             0 == s_bootstrap)
98cdf0e10cSrcweir         {
99cdf0e10cSrcweir             jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
100cdf0e10cSrcweir             jni_env->ThrowNew(
101cdf0e10cSrcweir                 c, "error resolving symbols of " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
102cdf0e10cSrcweir             return false;
103cdf0e10cSrcweir         }
104cdf0e10cSrcweir     }
105cdf0e10cSrcweir     s_inited = true;
106cdf0e10cSrcweir     return true;
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir //==================================================================================================
110cdf0e10cSrcweir JNIEXPORT jboolean JNICALL
Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(JNIEnv * pJEnv,jclass jClass,jstring jLibName,jobject jSMgr,jobject jRegKey,jobject loader)111cdf0e10cSrcweir Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
112cdf0e10cSrcweir     JNIEnv * pJEnv, jclass jClass, jstring jLibName, jobject jSMgr,
113cdf0e10cSrcweir     jobject jRegKey, jobject loader )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     if (inited_juhx( pJEnv ))
116cdf0e10cSrcweir         return (*s_writeInfo)(
117cdf0e10cSrcweir             pJEnv, jClass, jLibName, jSMgr, jRegKey, loader );
118cdf0e10cSrcweir     return JNI_FALSE;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir //==================================================================================================
121cdf0e10cSrcweir JNIEXPORT jobject JNICALL
Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(JNIEnv * pJEnv,jclass jClass,jstring jLibName,jstring jImplName,jobject jSMgr,jobject jRegKey,jobject loader)122cdf0e10cSrcweir Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
123cdf0e10cSrcweir     JNIEnv * pJEnv, jclass jClass, jstring jLibName, jstring jImplName,
124cdf0e10cSrcweir     jobject jSMgr, jobject jRegKey, jobject loader )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     if (inited_juhx( pJEnv ))
127cdf0e10cSrcweir         return (*s_getFactory)(
128cdf0e10cSrcweir             pJEnv, jClass, jLibName, jImplName, jSMgr, jRegKey, loader );
129cdf0e10cSrcweir     return 0;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir //==================================================================================================
132cdf0e10cSrcweir JNIEXPORT jobject JNICALL
Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory(JNIEnv * pJEnv,jclass jClass,jstring jWriteRegFile,jstring jReadRegFile,jboolean jbReadOnly,jobject loader)133cdf0e10cSrcweir Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory(
134cdf0e10cSrcweir     JNIEnv * pJEnv, jclass jClass, jstring jWriteRegFile,
135cdf0e10cSrcweir     jstring jReadRegFile, jboolean jbReadOnly, jobject loader )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir     if (inited_juhx( pJEnv ))
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         return (*s_createRegistryServiceFactory)(
140cdf0e10cSrcweir             pJEnv, jClass, jWriteRegFile, jReadRegFile, jbReadOnly, loader );
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir     return 0;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir //==================================================================================================
145cdf0e10cSrcweir JNIEXPORT jobject JNICALL
Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap(JNIEnv * jni_env,jclass jClass,jstring juno_rc,jobjectArray jpairs,jobject loader)146cdf0e10cSrcweir Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap(
147cdf0e10cSrcweir     JNIEnv * jni_env, jclass jClass, jstring juno_rc, jobjectArray jpairs,
148cdf0e10cSrcweir     jobject loader )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     if (inited_juhx( jni_env ))
151cdf0e10cSrcweir         return (*s_bootstrap)( jni_env, jClass, juno_rc, jpairs, loader );
152cdf0e10cSrcweir     return 0;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir }
155