tdf#156866 use mSize instead of mPixelSize for inverted surface
[LibreOffice.git] / javaunohelper / source / javaunohelper.cxx
blob8db57c5b78f372f8309d4440fdbaa69cb1a66986
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 #include <osl/module.hxx>
24 #include <uno/environment.hxx>
25 #include <uno/lbnames.h>
26 #include <uno/mapping.hxx>
28 #include <cppuhelper/factory.hxx>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/registry/XRegistryKey.hpp>
33 #if defined __clang__
34 #pragma clang diagnostic push
35 #pragma clang diagnostic ignored "-Wunknown-attributes"
36 #endif
37 #include <jni.h>
38 #if defined __clang__
39 #pragma clang diagnostic pop
40 #endif
42 #include <jvmaccess/unovirtualmachine.hxx>
44 #include "juhx-export-functions.hxx"
45 #include "vm.hxx"
47 #ifdef DISABLE_DYNLOADING
48 #include <osl/thread.h>
49 #endif
51 using namespace ::com::sun::star;
52 using namespace ::com::sun::star::uno;
55 * Class: com_sun_star_comp_helper_SharedLibraryLoader
56 * Method: component_writeInfo
57 * Signature: (Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Z
59 jboolean Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
60 JNIEnv * pJEnv, SAL_UNUSED_PARAMETER jclass, jstring jLibName, jobject jSMgr,
61 jobject jRegKey, jobject loader )
63 bool bRet = false;
65 const jchar* pJLibName = pJEnv->GetStringChars(jLibName, nullptr);
66 OUString aLibName(reinterpret_cast<sal_Unicode const *>(pJLibName));
67 pJEnv->ReleaseStringChars(jLibName, pJLibName);
69 #ifdef DISABLE_DYNLOADING
70 (void) jSMgr;
71 (void) jRegKey;
72 (void) loader;
74 fprintf(stderr, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__, OUStringToOString(aLibName, osl_getThreadTextEncoding()).getStr());
75 #else
76 osl::Module lib(aLibName, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL);
77 if (lib.is())
79 // ========================= LATEST VERSION =========================
80 oslGenericFunction pSym = lib.getFunctionSymbol(COMPONENT_GETENV);
81 if (pSym)
83 Environment java_env, loader_env;
85 const char * pEnvTypeName = nullptr;
86 (*reinterpret_cast<component_getImplementationEnvironmentFunc>(pSym))(
87 &pEnvTypeName, reinterpret_cast<uno_Environment **>(&loader_env) );
88 if (! loader_env.is())
90 OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
91 uno_getEnvironment( reinterpret_cast<uno_Environment **>(&loader_env), aEnvTypeName.pData, nullptr );
94 // create vm access
95 ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access(
96 ::javaunohelper::create_vm_access( pJEnv, loader ) );
97 OUString java_env_name = UNO_LB_JAVA;
98 uno_getEnvironment(
99 reinterpret_cast<uno_Environment **>(&java_env), java_env_name.pData, vm_access.get() );
101 pSym = lib.getFunctionSymbol(COMPONENT_WRITEINFO);
102 if (pSym)
104 if (loader_env.is() && java_env.is())
106 Mapping java2dest(java_env.get(), loader_env.get());
108 if ( java2dest.is() )
110 void * pSMgr =
111 java2dest.mapInterface(
112 jSMgr, cppu::UnoType<lang::XMultiServiceFactory>::get());
113 void * pKey =
114 java2dest.mapInterface(
115 jRegKey, cppu::UnoType<registry::XRegistryKey>::get());
117 uno_ExtEnvironment * env = loader_env.get()->pExtEnv;
118 if (pKey)
120 bRet = (*reinterpret_cast<component_writeInfoFunc>(pSym))( pSMgr, pKey );
122 if (env)
123 (*env->releaseInterface)( env, pKey );
126 if (pSMgr && env)
127 (*env->releaseInterface)( env, pSMgr );
132 lib.release();
134 #endif
135 return bRet;
139 * Class: com_sun_star_comp_helper_SharedLibraryLoader
140 * Method: component_getFactory
141 * Signature: (Ljava/lang/String;Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Ljava/lang/Object;
143 jobject Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
144 JNIEnv * pJEnv, SAL_UNUSED_PARAMETER jclass, jstring jLibName, jstring jImplName,
145 jobject jSMgr, jobject jRegKey, jobject loader )
147 const jchar* pJLibName = pJEnv->GetStringChars(jLibName, nullptr);
148 OUString aLibName(reinterpret_cast<sal_Unicode const *>(pJLibName));
149 pJEnv->ReleaseStringChars(jLibName, pJLibName);
151 #ifdef DISABLE_DYNLOADING
152 (void) jImplName;
153 (void) jSMgr;
154 (void) jRegKey;
155 (void) loader;
157 fprintf(stderr, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__, OUStringToOString(aLibName, osl_getThreadTextEncoding()).getStr());
158 #endif
160 aLibName += SAL_DLLEXTENSION;
162 jobject joSLL_cpp = nullptr;
164 #ifndef DISABLE_DYNLOADING
165 osl::Module lib(aLibName, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL);
166 if (lib.is())
168 // ========================= LATEST VERSION =========================
169 oslGenericFunction pSym = lib.getFunctionSymbol(COMPONENT_GETENV);
170 if (pSym)
172 Environment java_env, loader_env;
174 const char * pEnvTypeName = nullptr;
175 (*reinterpret_cast<component_getImplementationEnvironmentFunc>(pSym))(
176 &pEnvTypeName, reinterpret_cast<uno_Environment **>(&loader_env) );
178 if (! loader_env.is())
180 OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
181 uno_getEnvironment( reinterpret_cast<uno_Environment **>(&loader_env), aEnvTypeName.pData, nullptr );
184 // create vm access
185 ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access(
186 ::javaunohelper::create_vm_access( pJEnv, loader ) );
187 OUString java_env_name = UNO_LB_JAVA;
188 uno_getEnvironment(
189 reinterpret_cast<uno_Environment **>(&java_env), java_env_name.pData, vm_access.get() );
191 pSym = lib.getFunctionSymbol(COMPONENT_GETFACTORY);
192 if (pSym)
194 if (loader_env.is() && java_env.is())
196 Mapping java2dest( java_env.get(), loader_env.get() );
197 Mapping dest2java( loader_env.get(), java_env.get() );
199 if (dest2java.is() && java2dest.is())
201 void * pSMgr =
202 java2dest.mapInterface(
203 jSMgr, cppu::UnoType<lang::XMultiServiceFactory>::get());
204 void * pKey =
205 java2dest.mapInterface(
206 jRegKey, cppu::UnoType<registry::XRegistryKey>::get());
208 const char* pImplName = pJEnv->GetStringUTFChars( jImplName, nullptr );
210 void * pSSF = (*reinterpret_cast<component_getFactoryFunc>(pSym))(
211 pImplName, pSMgr, pKey );
213 pJEnv->ReleaseStringUTFChars( jImplName, pImplName );
215 uno_ExtEnvironment * env = loader_env.get()->pExtEnv;
217 if (pKey && env)
218 (*env->releaseInterface)( env, pKey );
219 if (pSMgr && env)
220 (*env->releaseInterface)( env, pSMgr );
222 if (pSSF)
224 jobject jglobal = static_cast<jobject>(dest2java.mapInterface(
225 pSSF, cppu::UnoType<XInterface>::get()));
226 joSLL_cpp = pJEnv->NewLocalRef( jglobal );
227 pJEnv->DeleteGlobalRef( jglobal );
228 if (env)
229 (*env->releaseInterface)( env, pSSF );
235 lib.release();
237 #endif
238 return joSLL_cpp;
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */