LCOV - code coverage report
Current view: top level - javaunohelper/source - preload.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 37 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 5 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 "jni.h"
      23             : 
      24             : #include "rtl/ustring.hxx"
      25             : #include "osl/module.hxx"
      26             : 
      27             : #include "juhx-export-types.hxx"
      28             : 
      29             : // In retrospect, the reason to create a juh wrapper around the juhx library was
      30             : // probably because java.lang.System.loadLibrary uses RTLD_LOCAL, so uniqueness
      31             : // of GCC RTTI symbols needed for exception handling would not be guaranteed.
      32             : 
      33             : #if ! defined SAL_DLLPREFIX
      34             : #define SAL_DLLPREFIX ""
      35             : #endif
      36             : 
      37             : 
      38             : extern "C"
      39             : {
      40             : 
      41             : static javaunohelper::detail::Func_writeInfo * s_writeInfo;
      42             : static javaunohelper::detail::Func_getFactory * s_getFactory;
      43             : static javaunohelper::detail::Func_bootstrap * s_bootstrap;
      44             : static bool s_inited = false;
      45             : 
      46           0 : extern "C" { static void SAL_CALL thisModule() {} }
      47             : 
      48             : 
      49           0 : static bool inited_juhx( JNIEnv * jni_env )
      50             : {
      51           0 :     if (s_inited)
      52           0 :         return true;
      53           0 :     OUString lib_name = SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION;
      54           0 :     osl::Module aModule;
      55           0 :     if (!aModule.loadRelative(&thisModule, lib_name, SAL_LOADMODULE_LAZY | SAL_LOADMODULE_GLOBAL))
      56             :     {
      57           0 :         jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
      58             :         jni_env->ThrowNew(
      59           0 :             c, "error loading " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
      60           0 :         return false;
      61             :     }
      62             :     else
      63             :     {
      64             :         OUString symbol =
      65           0 :               "Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo";
      66           0 :         s_writeInfo = reinterpret_cast<javaunohelper::detail::Func_writeInfo *>(aModule.getFunctionSymbol(symbol));
      67             :         symbol =
      68           0 :             "Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory";
      69           0 :         s_getFactory = reinterpret_cast<javaunohelper::detail::Func_getFactory *>(aModule.getFunctionSymbol(symbol));
      70             :         symbol =
      71           0 :             "Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap";
      72             :         s_bootstrap =
      73           0 :             reinterpret_cast<javaunohelper::detail::Func_bootstrap *>(aModule.getFunctionSymbol(symbol));
      74             : 
      75           0 :         if (0 == s_writeInfo ||
      76           0 :             0 == s_getFactory ||
      77           0 :             0 == s_bootstrap)
      78             :         {
      79           0 :             jclass c = jni_env->FindClass( "java/lang/RuntimeException" );
      80             :             jni_env->ThrowNew(
      81           0 :                 c, "error resolving symbols of " SAL_DLLPREFIX "juhx" SAL_DLLEXTENSION "!" );
      82           0 :             return false;
      83             :         }
      84           0 :         aModule.release();
      85             :     }
      86           0 :     s_inited = true;
      87           0 :     return true;
      88             : }
      89             : 
      90             : 
      91             : SAL_DLLPUBLIC_EXPORT jboolean JNICALL
      92           0 : Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1writeInfo(
      93             :     JNIEnv * pJEnv, jclass jClass, jstring jLibName, jobject jSMgr,
      94             :     jobject jRegKey, jobject loader )
      95             : {
      96           0 :     if (inited_juhx( pJEnv ))
      97             :         return (*s_writeInfo)(
      98           0 :             pJEnv, jClass, jLibName, jSMgr, jRegKey, loader );
      99           0 :     return JNI_FALSE;
     100             : }
     101             : 
     102             : SAL_DLLPUBLIC_EXPORT jobject JNICALL
     103           0 : Java_com_sun_star_comp_helper_SharedLibraryLoader_component_1getFactory(
     104             :     JNIEnv * pJEnv, jclass jClass, jstring jLibName, jstring jImplName,
     105             :     jobject jSMgr, jobject jRegKey, jobject loader )
     106             : {
     107           0 :     if (inited_juhx( pJEnv ))
     108             :         return (*s_getFactory)(
     109           0 :             pJEnv, jClass, jLibName, jImplName, jSMgr, jRegKey, loader );
     110           0 :     return 0;
     111             : }
     112             : 
     113             : SAL_DLLPUBLIC_EXPORT jobject JNICALL
     114           0 : Java_com_sun_star_comp_helper_Bootstrap_cppuhelper_1bootstrap(
     115             :     JNIEnv * jni_env, jclass jClass, jstring juno_rc, jobjectArray jpairs,
     116             :     jobject loader )
     117             : {
     118           0 :     if (inited_juhx( jni_env ))
     119           0 :         return (*s_bootstrap)( jni_env, jClass, juno_rc, jpairs, loader );
     120           0 :     return 0;
     121             : }
     122             : }
     123             : 
     124             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11