LCOV - code coverage report
Current view: top level - javaunohelper/source - javaunohelper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 87 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 2 0.0 %
Legend: Lines: hit not hit

          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             : #include "sal/config.h"
      21             : 
      22             : #include <osl/diagnose.h>
      23             : #include <osl/module.hxx>
      24             : #include <osl/thread.h>
      25             : 
      26             : #include <uno/environment.hxx>
      27             : #include <uno/lbnames.h>
      28             : #include <uno/mapping.hxx>
      29             : 
      30             : #include <cppuhelper/factory.hxx>
      31             : 
      32             : #include <com/sun/star/beans/XPropertySet.hpp>
      33             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      34             : #include <com/sun/star/lang/XServiceInfo.hpp>
      35             : #include <com/sun/star/registry/XRegistryKey.hpp>
      36             : 
      37             : #include "jni.h"
      38             : #include "jvmaccess/virtualmachine.hxx"
      39             : #include "jvmaccess/unovirtualmachine.hxx"
      40             : 
      41             : #include "juhx-export-functions.hxx"
      42             : #include "vm.hxx"
      43             : 
      44             : using namespace ::com::sun::star;
      45             : using namespace ::com::sun::star::uno;
      46             : 
      47             : /*
      48             :  * Class:     com_sun_star_comp_helper_SharedLibraryLoader
      49             :  * Method:    component_writeInfo
      50             :  * Signature: (Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Z
      51             :  */
      52           0 : jboolean Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
      53             :     JNIEnv * pJEnv, SAL_UNUSED_PARAMETER jclass, jstring jLibName, jobject jSMgr,
      54             :     jobject jRegKey, jobject loader )
      55             : {
      56           0 :     bool bRet = false;
      57             : 
      58           0 :     const jchar* pJLibName = pJEnv->GetStringChars(jLibName, NULL);
      59           0 :     OUString aLibName(pJLibName);
      60           0 :     pJEnv->ReleaseStringChars(jLibName, pJLibName);
      61             : 
      62             : #ifdef DISABLE_DYNLOADING
      63             :     (void) jSMgr;
      64             :     (void) jRegKey;
      65             :     (void) loader;
      66             : 
      67             :     fprintf(stderr, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__, OUStringToOString(aLibName, osl_getThreadTextEncoding()).getStr());
      68             : #else
      69           0 :     osl::Module lib(aLibName, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL);
      70           0 :     if (lib.is())
      71             :     {
      72           0 :         lib.release();
      73             : 
      74             :         // ========================= LATEST VERSION =========================
      75           0 :         OUString aGetEnvName( COMPONENT_GETENV );
      76           0 :         oslGenericFunction pSym = lib.getFunctionSymbol(aGetEnvName);
      77           0 :         if (pSym)
      78             :         {
      79           0 :             Environment java_env, loader_env;
      80             : 
      81           0 :             const sal_Char * pEnvTypeName = 0;
      82             :             (*reinterpret_cast<component_getImplementationEnvironmentFunc>(pSym))(
      83           0 :                 &pEnvTypeName, reinterpret_cast<uno_Environment **>(&loader_env) );
      84           0 :             if (! loader_env.is())
      85             :             {
      86           0 :                 OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
      87           0 :                 uno_getEnvironment( reinterpret_cast<uno_Environment **>(&loader_env), aEnvTypeName.pData, 0 );
      88             :             }
      89             : 
      90             :             // create vm access
      91             :             ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access(
      92           0 :                 ::javaunohelper::create_vm_access( pJEnv, loader ) );
      93           0 :             OUString java_env_name = UNO_LB_JAVA;
      94             :             uno_getEnvironment(
      95           0 :                 reinterpret_cast<uno_Environment **>(&java_env), java_env_name.pData, vm_access.get() );
      96             : 
      97           0 :             OUString aWriteInfoName( COMPONENT_WRITEINFO );
      98           0 :             pSym = lib.getFunctionSymbol(aWriteInfoName);
      99           0 :             if (pSym)
     100             :             {
     101           0 :                 if (loader_env.is() && java_env.is())
     102             :                 {
     103           0 :                     Mapping java2dest(java_env.get(), loader_env.get());
     104             : 
     105           0 :                     if ( java2dest.is() )
     106             :                     {
     107             :                         void * pSMgr =
     108             :                             java2dest.mapInterface(
     109           0 :                                 jSMgr, cppu::UnoType<lang::XMultiServiceFactory>::get());
     110             :                         void * pKey =
     111             :                             java2dest.mapInterface(
     112           0 :                                 jRegKey, cppu::UnoType<registry::XRegistryKey>::get());
     113             : 
     114           0 :                         uno_ExtEnvironment * env = loader_env.get()->pExtEnv;
     115           0 :                         if (pKey)
     116             :                         {
     117           0 :                             bRet = (*reinterpret_cast<component_writeInfoFunc>(pSym))( pSMgr, pKey );
     118             : 
     119           0 :                             if (env)
     120           0 :                                 (*env->releaseInterface)( env, pKey );
     121             :                         }
     122             : 
     123           0 :                         if (pSMgr && env)
     124           0 :                             (*env->releaseInterface)( env, pSMgr );
     125           0 :                     }
     126             :                 }
     127           0 :             }
     128           0 :         }
     129             :     }
     130             : #endif
     131           0 :     return bRet ? JNI_TRUE : JNI_FALSE;
     132             : }
     133             : 
     134             : /*
     135             :  * Class:     com_sun_star_comp_helper_SharedLibraryLoader
     136             :  * Method:    component_getFactory
     137             :  * Signature: (Ljava/lang/String;Ljava/lang/String;Lcom/sun/star/lang/XMultiServiceFactory;Lcom/sun/star/registry/XRegistryKey;)Ljava/lang/Object;
     138             :  */
     139           0 : jobject Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
     140             :     JNIEnv * pJEnv, SAL_UNUSED_PARAMETER jclass, jstring jLibName, jstring jImplName,
     141             :     jobject jSMgr, jobject jRegKey, jobject loader )
     142             : {
     143           0 :     const jchar* pJLibName = pJEnv->GetStringChars(jLibName, NULL);
     144           0 :     OUString aLibName(pJLibName);
     145           0 :     pJEnv->ReleaseStringChars(jLibName, pJLibName);
     146             : 
     147             : #ifdef DISABLE_DYNLOADING
     148             :     (void) jImplName;
     149             :     (void) jSMgr;
     150             :     (void) jRegKey;
     151             :     (void) loader;
     152             : 
     153             :     fprintf(stderr, "Hmm, %s called for %s\n", __PRETTY_FUNCTION__, OUStringToOString(aLibName, osl_getThreadTextEncoding()).getStr());
     154             : #endif
     155             : 
     156           0 :     aLibName += OUString( SAL_DLLEXTENSION );
     157             : 
     158           0 :     jobject joSLL_cpp = 0;
     159             : 
     160             : #ifndef DISABLE_DYNLOADING
     161           0 :     osl::Module lib(aLibName, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL);
     162           0 :     if (lib.is())
     163             :     {
     164           0 :         lib.release();
     165             : 
     166             :         // ========================= LATEST VERSION =========================
     167           0 :         OUString aGetEnvName( COMPONENT_GETENV );
     168           0 :         oslGenericFunction pSym = lib.getFunctionSymbol(aGetEnvName);
     169           0 :         if (pSym)
     170             :         {
     171           0 :             Environment java_env, loader_env;
     172             : 
     173           0 :             const sal_Char * pEnvTypeName = 0;
     174             :             (*reinterpret_cast<component_getImplementationEnvironmentFunc>(pSym))(
     175           0 :                 &pEnvTypeName, reinterpret_cast<uno_Environment **>(&loader_env) );
     176             : 
     177           0 :             if (! loader_env.is())
     178             :             {
     179           0 :                 OUString aEnvTypeName( OUString::createFromAscii( pEnvTypeName ) );
     180           0 :                 uno_getEnvironment( reinterpret_cast<uno_Environment **>(&loader_env), aEnvTypeName.pData, 0 );
     181             :             }
     182             : 
     183             :             // create vm access
     184             :             ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > vm_access(
     185           0 :                 ::javaunohelper::create_vm_access( pJEnv, loader ) );
     186           0 :             OUString java_env_name = UNO_LB_JAVA;
     187             :             uno_getEnvironment(
     188           0 :                 reinterpret_cast<uno_Environment **>(&java_env), java_env_name.pData, vm_access.get() );
     189             : 
     190           0 :             OUString aGetFactoryName( COMPONENT_GETFACTORY );
     191           0 :             pSym = lib.getFunctionSymbol(aGetFactoryName);
     192           0 :             if (pSym)
     193             :             {
     194           0 :                 if (loader_env.is() && java_env.is())
     195             :                 {
     196           0 :                     Mapping java2dest( java_env.get(), loader_env.get() );
     197           0 :                     Mapping dest2java( loader_env.get(), java_env.get() );
     198             : 
     199           0 :                     if (dest2java.is() && java2dest.is())
     200             :                     {
     201             :                         void * pSMgr =
     202             :                             java2dest.mapInterface(
     203           0 :                                 jSMgr, cppu::UnoType<lang::XMultiServiceFactory>::get());
     204             :                         void * pKey =
     205             :                             java2dest.mapInterface(
     206           0 :                                 jRegKey, cppu::UnoType<registry::XRegistryKey>::get());
     207             : 
     208           0 :                         const char* pImplName = pJEnv->GetStringUTFChars( jImplName, NULL );
     209             : 
     210             :                         void * pSSF = (*reinterpret_cast<component_getFactoryFunc>(pSym))(
     211           0 :                             pImplName, pSMgr, pKey );
     212             : 
     213           0 :                         pJEnv->ReleaseStringUTFChars( jImplName, pImplName );
     214             : 
     215           0 :                         uno_ExtEnvironment * env = loader_env.get()->pExtEnv;
     216             : 
     217           0 :                         if (pKey && env)
     218           0 :                             (*env->releaseInterface)( env, pKey );
     219           0 :                         if (pSMgr && env)
     220           0 :                             (*env->releaseInterface)( env, pSMgr );
     221             : 
     222           0 :                         if (pSSF)
     223             :                         {
     224             :                             jobject jglobal = static_cast<jobject>(dest2java.mapInterface(
     225           0 :                                 pSSF, cppu::UnoType<XInterface>::get()));
     226           0 :                             joSLL_cpp = pJEnv->NewLocalRef( jglobal );
     227           0 :                             pJEnv->DeleteGlobalRef( jglobal );
     228           0 :                             if (env)
     229           0 :                                 (*env->releaseInterface)( env, pSSF );
     230             :                         }
     231           0 :                     }
     232             :                 }
     233           0 :             }
     234           0 :         }
     235             :     }
     236             : #endif
     237           0 :     return joSLL_cpp;
     238             : }
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11