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 "jni.h"
22 :
23 : #include "rtl/ustring.hxx"
24 : #include "osl/module.h"
25 :
26 : // In retrospect, the reason to create a juh wrapper around the juhx library was
27 : // probably because java.lang.System.loadLibrary uses RTLD_LOCAL, so uniqueness
28 : // of GCC RTTI symbols needed for exception handling would not be guaranteed.
29 :
30 : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
31 :
32 : #if ! defined SAL_DLLPREFIX
33 : #define SAL_DLLPREFIX ""
34 : #endif
35 :
36 : using ::rtl::OUString;
37 :
38 : extern "C"
39 : {
40 : typedef jboolean (JNICALL * fptr_writeInfo)(
41 : JNIEnv *, jclass, jstring, jobject, jobject, jobject );
42 : typedef jobject (JNICALL * fptr_getFactory)(
43 : JNIEnv *, jclass, jstring, jstring, jobject, jobject, jobject );
44 : typedef jobject (JNICALL * fptr_createRegistryServiceFactory)(
45 : JNIEnv *, jclass, jstring, jstring, jboolean, jobject );
46 : typedef jobject (JNICALL * fptr_bootstrap)(
47 : JNIEnv *_env, jclass, jstring, jobjectArray, jobject );
48 :
49 : static fptr_writeInfo s_writeInfo;
50 : static fptr_getFactory s_getFactory;
51 : static fptr_createRegistryServiceFactory s_createRegistryServiceFactory;
52 : static fptr_bootstrap s_bootstrap;
53 : static bool s_inited = false;
54 :
55 0 : extern "C" { static void SAL_CALL thisModule() {} }
56 :
57 : //--------------------------------------------------------------------------------------------------
58 0 : static bool inited_juhx( JNIEnv * jni_env )
59 : {
60 0 : if (s_inited)
61 0 : return true;
62 0 : OUString lib_name = OUSTR(SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION);
63 : oslModule hModule =
64 0 : osl_loadModuleRelative( &thisModule, lib_name.pData, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL );
65 0 : if (0 == hModule)
66 : {
67 0 : jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
68 : jni_env->ThrowNew(
69 0 : c, "error loading " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
70 0 : return false;
71 : }
72 : else
73 : {
74 : OUString symbol =
75 0 : OUSTR("Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo");
76 : s_writeInfo = (fptr_writeInfo)osl_getFunctionSymbol(
77 0 : hModule, symbol.pData );
78 : symbol =
79 0 : OUSTR("Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory");
80 : s_getFactory = (fptr_getFactory)osl_getFunctionSymbol(
81 0 : hModule, symbol.pData );
82 : symbol =
83 0 : OUSTR("Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory");
84 : s_createRegistryServiceFactory =
85 : (fptr_createRegistryServiceFactory)osl_getFunctionSymbol(
86 0 : hModule, symbol.pData );
87 : symbol =
88 0 : OUSTR("Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap");
89 : s_bootstrap =
90 0 : (fptr_bootstrap)osl_getFunctionSymbol( hModule, symbol.pData );
91 :
92 0 : if (0 == s_writeInfo ||
93 : 0 == s_getFactory ||
94 : 0 == s_createRegistryServiceFactory ||
95 : 0 == s_bootstrap)
96 : {
97 0 : jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
98 : jni_env->ThrowNew(
99 0 : c, "error resolving symbols of " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
100 0 : return false;
101 0 : }
102 : }
103 0 : s_inited = true;
104 0 : return true;
105 : }
106 :
107 : //==================================================================================================
108 : SAL_DLLPUBLIC_EXPORT jboolean JNICALL
109 0 : Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
110 : JNIEnv * pJEnv, jclass jClass, jstring jLibName, jobject jSMgr,
111 : jobject jRegKey, jobject loader )
112 : {
113 0 : if (inited_juhx( pJEnv ))
114 : return (*s_writeInfo)(
115 0 : pJEnv, jClass, jLibName, jSMgr, jRegKey, loader );
116 0 : return JNI_FALSE;
117 : }
118 : //==================================================================================================
119 : SAL_DLLPUBLIC_EXPORT jobject JNICALL
120 0 : Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
121 : JNIEnv * pJEnv, jclass jClass, jstring jLibName, jstring jImplName,
122 : jobject jSMgr, jobject jRegKey, jobject loader )
123 : {
124 0 : if (inited_juhx( pJEnv ))
125 : return (*s_getFactory)(
126 0 : pJEnv, jClass, jLibName, jImplName, jSMgr, jRegKey, loader );
127 0 : return 0;
128 : }
129 : //==================================================================================================
130 : SAL_DLLPUBLIC_EXPORT jobject JNICALL
131 0 : Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory(
132 : JNIEnv * pJEnv, jclass jClass, jstring jWriteRegFile,
133 : jstring jReadRegFile, jboolean jbReadOnly, jobject loader )
134 : {
135 0 : if (inited_juhx( pJEnv ))
136 : {
137 : return (*s_createRegistryServiceFactory)(
138 0 : pJEnv, jClass, jWriteRegFile, jReadRegFile, jbReadOnly, loader );
139 : }
140 0 : return 0;
141 : }
142 : //==================================================================================================
143 : SAL_DLLPUBLIC_EXPORT jobject JNICALL
144 0 : Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap(
145 : JNIEnv * jni_env, jclass jClass, jstring juno_rc, jobjectArray jpairs,
146 : jobject loader )
147 : {
148 0 : if (inited_juhx( jni_env ))
149 0 : return (*s_bootstrap)( jni_env, jClass, juno_rc, jpairs, loader );
150 0 : return 0;
151 : }
152 : }
153 :
154 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|