1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
32 #include "rtl/ustring.hxx"
33 #include "osl/module.h"
35 // In retrospect, the reason to create a juh wrapper around the juhx library was
36 // probably because java.lang.System.loadLibrary uses RTLD_LOCAL, so uniqueness
37 // of GCC RTTI symbols needed for exception handling would not be guaranteed.
39 #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
41 #if ! defined SAL_DLLPREFIX
42 #define SAL_DLLPREFIX ""
45 using ::rtl::OUString
;
49 typedef jboolean (JNICALL
* fptr_writeInfo
)(
50 JNIEnv
*, jclass
, jstring
, jobject
, jobject
, jobject
);
51 typedef jobject (JNICALL
* fptr_getFactory
)(
52 JNIEnv
*, jclass
, jstring
, jstring
, jobject
, jobject
, jobject
);
53 typedef jobject (JNICALL
* fptr_createRegistryServiceFactory
)(
54 JNIEnv
*, jclass
, jstring
, jstring
, jboolean
, jobject
);
55 typedef jobject (JNICALL
* fptr_bootstrap
)(
56 JNIEnv
*_env
, jclass
, jstring
, jobjectArray
, jobject
);
58 static fptr_writeInfo s_writeInfo
;
59 static fptr_getFactory s_getFactory
;
60 static fptr_createRegistryServiceFactory s_createRegistryServiceFactory
;
61 static fptr_bootstrap s_bootstrap
;
62 static bool s_inited
= false;
64 extern "C" { static void SAL_CALL
thisModule() {} }
66 //--------------------------------------------------------------------------------------------------
67 static bool inited_juhx( JNIEnv
* jni_env
)
71 OUString lib_name
= OUSTR(SAL_DLLPREFIX
"juhx" SAL_DLLEXTENSION
);
73 osl_loadModuleRelative( &thisModule
, lib_name
.pData
, SAL_LOADMODULE_LAZY
| SAL_LOADMODULE_GLOBAL
);
76 jclass c
= jni_env
->FindClass( "java/lang/RuntimeException" );
78 c
, "error loading " SAL_DLLPREFIX
"juhx" SAL_DLLEXTENSION
"!" );
84 OUSTR("Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo");
85 s_writeInfo
= (fptr_writeInfo
)osl_getFunctionSymbol(
86 hModule
, symbol
.pData
);
88 OUSTR("Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory");
89 s_getFactory
= (fptr_getFactory
)osl_getFunctionSymbol(
90 hModule
, symbol
.pData
);
92 OUSTR("Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory");
93 s_createRegistryServiceFactory
=
94 (fptr_createRegistryServiceFactory
)osl_getFunctionSymbol(
95 hModule
, symbol
.pData
);
97 OUSTR("Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap");
99 (fptr_bootstrap
)osl_getFunctionSymbol( hModule
, symbol
.pData
);
101 if (0 == s_writeInfo
||
103 0 == s_createRegistryServiceFactory
||
106 jclass c
= jni_env
->FindClass( "java/lang/RuntimeException" );
108 c
, "error resolving symbols of " SAL_DLLPREFIX
"juhx" SAL_DLLEXTENSION
"!" );
116 //==================================================================================================
117 JNIEXPORT jboolean JNICALL
118 Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
119 JNIEnv
* pJEnv
, jclass jClass
, jstring jLibName
, jobject jSMgr
,
120 jobject jRegKey
, jobject loader
)
122 if (inited_juhx( pJEnv
))
123 return (*s_writeInfo
)(
124 pJEnv
, jClass
, jLibName
, jSMgr
, jRegKey
, loader
);
127 //==================================================================================================
128 JNIEXPORT jobject JNICALL
129 Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
130 JNIEnv
* pJEnv
, jclass jClass
, jstring jLibName
, jstring jImplName
,
131 jobject jSMgr
, jobject jRegKey
, jobject loader
)
133 if (inited_juhx( pJEnv
))
134 return (*s_getFactory
)(
135 pJEnv
, jClass
, jLibName
, jImplName
, jSMgr
, jRegKey
, loader
);
138 //==================================================================================================
139 JNIEXPORT jobject JNICALL
140 Java_com_sun_star_comp_helper_RegistryServiceFactory_createRegistryServiceFactory(
141 JNIEnv
* pJEnv
, jclass jClass
, jstring jWriteRegFile
,
142 jstring jReadRegFile
, jboolean jbReadOnly
, jobject loader
)
144 if (inited_juhx( pJEnv
))
146 return (*s_createRegistryServiceFactory
)(
147 pJEnv
, jClass
, jWriteRegFile
, jReadRegFile
, jbReadOnly
, loader
);
151 //==================================================================================================
152 JNIEXPORT jobject JNICALL
153 Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap(
154 JNIEnv
* jni_env
, jclass jClass
, jstring juno_rc
, jobjectArray jpairs
,
157 if (inited_juhx( jni_env
))
158 return (*s_bootstrap
)( jni_env
, jClass
, juno_rc
, jpairs
, loader
);
163 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */