summaryrefslogtreecommitdiffstats
path: root/javaunohelper/source/javaunohelper.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /javaunohelper/source/javaunohelper.cxx
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'javaunohelper/source/javaunohelper.cxx')
-rw-r--r--javaunohelper/source/javaunohelper.cxx241
1 files changed, 241 insertions, 0 deletions
diff --git a/javaunohelper/source/javaunohelper.cxx b/javaunohelper/source/javaunohelper.cxx
new file mode 100644
index 000000000..8db57c5b7
--- /dev/null
+++ b/javaunohelper/source/javaunohelper.cxx
@@ -0,0 +1,241 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <sal/config.h>
+
+#include <osl/module.hxx>
+
+#include <uno/environment.hxx>
+#include <uno/lbnames.h>
+#include <uno/mapping.hxx>
+
+#include <cppuhelper/factory.hxx>
+
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
+#include <com/sun/star/registry/XRegistryKey.hpp>
+
+#if defined __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunknown-attributes"
+#endif
+#include <jni.h>
+#if defined __clang__
+#pragma clang diagnostic pop
+#endif
+
+#include <jvmaccess/unovirtualmachine.hxx>
+
+#include "juhx-export-functions.hxx"
+#include "vm.hxx"
+
+#ifdef DISABLE_DYNLOADING
+#include <osl/thread.h>
+#endif
+
+using namespace ::com::sun::star;
+using namespace ::com::sun::star::uno;
+
+/*
+ * Class: com_sun_star_comp_helper_SharedLibraryLoader
+ * Method: component_writeInfo
+ * Signature: (Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Z
+ */
+jboolean Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
+ JNIEnv * pJEnv, SAL_UNUSED_PARAMETER jclass, jstring jLibName, jobject jSMgr,
+ jobject jRegKey, jobject loader )
+{
+ bool bRet = false;
+
+ const jchar* pJLibName = pJEnv->GetStringChars(jLibName, nullptr);
+ OUString aLibName(reinterpret_cast<sal_Unicode const *>(pJLibName));
+ pJEnv->ReleaseStringChars(jLibName, pJLibName);
+
+#ifdef DISABLE_DYNLOADING
+ (void) jSMgr;
+ (void) jRegKey;
+ (void) loader;
+
+ fprintf(stderr, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__, OUStringToOString(aLibName, osl_getThreadTextEncoding()).getStr());
+#else
+ osl::Module lib(aLibName, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL);
+ if (lib.is())
+ {
+ // ========================= LATEST VERSION =========================
+ oslGenericFunction pSym = lib.getFunctionSymbol(COMPONENT_GETENV);
+ if (pSym)
+ {
+ Environment java_env, loader_env;
+
+ const char * pEnvTypeName = nullptr;
+ (*reinterpret_cast<component_getImplementationEnvironmentFunc>(pSym))(
+ &pEnvTypeName, reinterpret_cast<uno_Environment **>(&loader_env) );
+ if (! loader_env.is())
+ {
+ OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
+ uno_getEnvironment( reinterpret_cast<uno_Environment **>(&loader_env), aEnvTypeName.pData, nullptr );
+ }
+
+ // create vm access
+ ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access(
+ ::javaunohelper::create_vm_access( pJEnv, loader ) );
+ OUString java_env_name = UNO_LB_JAVA;
+ uno_getEnvironment(
+ reinterpret_cast<uno_Environment **>(&java_env), java_env_name.pData, vm_access.get() );
+
+ pSym = lib.getFunctionSymbol(COMPONENT_WRITEINFO);
+ if (pSym)
+ {
+ if (loader_env.is() && java_env.is())
+ {
+ Mapping java2dest(java_env.get(), loader_env.get());
+
+ if ( java2dest.is() )
+ {
+ void * pSMgr =
+ java2dest.mapInterface(
+ jSMgr, cppu::UnoType<lang::XMultiServiceFactory>::get());
+ void * pKey =
+ java2dest.mapInterface(
+ jRegKey, cppu::UnoType<registry::XRegistryKey>::get());
+
+ uno_ExtEnvironment * env = loader_env.get()->pExtEnv;
+ if (pKey)
+ {
+ bRet = (*reinterpret_cast<component_writeInfoFunc>(pSym))( pSMgr, pKey );
+
+ if (env)
+ (*env->releaseInterface)( env, pKey );
+ }
+
+ if (pSMgr && env)
+ (*env->releaseInterface)( env, pSMgr );
+ }
+ }
+ }
+ }
+ lib.release();
+ }
+#endif
+ return bRet;
+}
+
+/*
+ * Class: com_sun_star_comp_helper_SharedLibraryLoader
+ * Method: component_getFactory
+ * Signature: (Ljava/lang/String;Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Ljava/lang/Object;
+ */
+jobject Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
+ JNIEnv * pJEnv, SAL_UNUSED_PARAMETER jclass, jstring jLibName, jstring jImplName,
+ jobject jSMgr, jobject jRegKey, jobject loader )
+{
+ const jchar* pJLibName = pJEnv->GetStringChars(jLibName, nullptr);
+ OUString aLibName(reinterpret_cast<sal_Unicode const *>(pJLibName));
+ pJEnv->ReleaseStringChars(jLibName, pJLibName);
+
+#ifdef DISABLE_DYNLOADING
+ (void) jImplName;
+ (void) jSMgr;
+ (void) jRegKey;
+ (void) loader;
+
+ fprintf(stderr, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__, OUStringToOString(aLibName, osl_getThreadTextEncoding()).getStr());
+#endif
+
+ aLibName += SAL_DLLEXTENSION;
+
+ jobject joSLL_cpp = nullptr;
+
+#ifndef DISABLE_DYNLOADING
+ osl::Module lib(aLibName, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL);
+ if (lib.is())
+ {
+ // ========================= LATEST VERSION =========================
+ oslGenericFunction pSym = lib.getFunctionSymbol(COMPONENT_GETENV);
+ if (pSym)
+ {
+ Environment java_env, loader_env;
+
+ const char * pEnvTypeName = nullptr;
+ (*reinterpret_cast<component_getImplementationEnvironmentFunc>(pSym))(
+ &pEnvTypeName, reinterpret_cast<uno_Environment **>(&loader_env) );
+
+ if (! loader_env.is())
+ {
+ OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
+ uno_getEnvironment( reinterpret_cast<uno_Environment **>(&loader_env), aEnvTypeName.pData, nullptr );
+ }
+
+ // create vm access
+ ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access(
+ ::javaunohelper::create_vm_access( pJEnv, loader ) );
+ OUString java_env_name = UNO_LB_JAVA;
+ uno_getEnvironment(
+ reinterpret_cast<uno_Environment **>(&java_env), java_env_name.pData, vm_access.get() );
+
+ pSym = lib.getFunctionSymbol(COMPONENT_GETFACTORY);
+ if (pSym)
+ {
+ if (loader_env.is() && java_env.is())
+ {
+ Mapping java2dest( java_env.get(), loader_env.get() );
+ Mapping dest2java( loader_env.get(), java_env.get() );
+
+ if (dest2java.is() && java2dest.is())
+ {
+ void * pSMgr =
+ java2dest.mapInterface(
+ jSMgr, cppu::UnoType<lang::XMultiServiceFactory>::get());
+ void * pKey =
+ java2dest.mapInterface(
+ jRegKey, cppu::UnoType<registry::XRegistryKey>::get());
+
+ const char* pImplName = pJEnv->GetStringUTFChars( jImplName, nullptr );
+
+ void * pSSF = (*reinterpret_cast<component_getFactoryFunc>(pSym))(
+ pImplName, pSMgr, pKey );
+
+ pJEnv->ReleaseStringUTFChars( jImplName, pImplName );
+
+ uno_ExtEnvironment * env = loader_env.get()->pExtEnv;
+
+ if (pKey && env)
+ (*env->releaseInterface)( env, pKey );
+ if (pSMgr && env)
+ (*env->releaseInterface)( env, pSMgr );
+
+ if (pSSF)
+ {
+ jobject jglobal = static_cast<jobject>(dest2java.mapInterface(
+ pSSF, cppu::UnoType<XInterface>::get()));
+ joSLL_cpp = pJEnv->NewLocalRef( jglobal );
+ pJEnv->DeleteGlobalRef( jglobal );
+ if (env)
+ (*env->releaseInterface)( env, pSSF );
+ }
+ }
+ }
+ }
+ }
+ lib.release();
+ }
+#endif
+ return joSLL_cpp;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */