tdf#156866 use mSize instead of mPixelSize for inverted surface
[LibreOffice.git] / javaunohelper / source / preload.cxx
blobf73b44b346474bc9116e09bf1a96b41052c11d4a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #if defined __clang__
23 #pragma clang diagnostic push
24 #pragma clang diagnostic ignored "-Wunknown-attributes"
25 #endif
26 #include <jni.h>
27 #if defined __clang__
28 #pragma clang diagnostic pop
29 #endif
31 #include <rtl/ustring.hxx>
32 #include <osl/module.hxx>
34 #include "juhx-export-types.hxx"
36 // In retrospect, the reason to create a juh wrapper around the juhx library was
37 // probably because java.lang.System.loadLibrary uses RTLD_LOCAL, so uniqueness
38 // of GCC RTTI symbols needed for exception handling would not be guaranteed.
40 #if ! defined SAL_DLLPREFIX
41 #define SAL_DLLPREFIX ""
42 #endif
45 extern "C"
48 static javaunohelper::detail::Func_writeInfo * s_writeInfo;
49 static javaunohelper::detail::Func_getFactory * s_getFactory;
50 static javaunohelper::detail::Func_bootstrap * s_bootstrap;
51 static bool s_inited = false;
53 extern "C" { static void thisModule() {} }
56 static bool inited_juhx( JNIEnv * jni_env )
58 if (s_inited)
59 return true;
60 osl::Module aModule;
61 if (!aModule.loadRelative(&thisModule, SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL))
63 jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
64 jni_env->ThrowNew(
65 c, "error loading " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
66 return false;
68 else
70 OUString symbol =
71 "Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo";
72 s_writeInfo = reinterpret_cast<javaunohelper::detail::Func_writeInfo *>(aModule.getFunctionSymbol(symbol));
73 symbol =
74 "Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory";
75 s_getFactory = reinterpret_cast<javaunohelper::detail::Func_getFactory *>(aModule.getFunctionSymbol(symbol));
76 symbol =
77 "Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap";
78 s_bootstrap =
79 reinterpret_cast<javaunohelper::detail::Func_bootstrap *>(aModule.getFunctionSymbol(symbol));
81 if (nullptr == s_writeInfo ||
82 nullptr == s_getFactory ||
83 nullptr == s_bootstrap)
85 jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
86 jni_env->ThrowNew(
87 c, "error resolving symbols of " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
88 return false;
90 aModule.release();
92 s_inited = true;
93 return true;
97 SAL_DLLPUBLIC_EXPORT jboolean JNICALL
98 Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
99 JNIEnv * pJEnv, jclass jClass, jstring jLibName, jobject jSMgr,
100 jobject jRegKey, jobject loader )
102 if (inited_juhx( pJEnv ))
103 return (*s_writeInfo)(
104 pJEnv, jClass, jLibName, jSMgr, jRegKey, loader );
105 return JNI_FALSE;
108 SAL_DLLPUBLIC_EXPORT jobject JNICALL
109 Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
110 JNIEnv * pJEnv, jclass jClass, jstring jLibName, jstring jImplName,
111 jobject jSMgr, jobject jRegKey, jobject loader )
113 if (inited_juhx( pJEnv ))
114 return (*s_getFactory)(
115 pJEnv, jClass, jLibName, jImplName, jSMgr, jRegKey, loader );
116 return nullptr;
119 SAL_DLLPUBLIC_EXPORT jobject JNICALL
120 Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap(
121 JNIEnv * jni_env, jclass jClass, jstring juno_rc, jobjectArray jpairs,
122 jobject loader )
124 if (inited_juhx( jni_env ))
125 return (*s_bootstrap)( jni_env, jClass, juno_rc, jpairs, loader );
126 return nullptr;
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */