LCOV - code coverage report
Current view: top level - javaunohelper/source - vm.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 26 0.0 %
Date: 2012-08-25 Functions: 0 10 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     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                 :            : 
      21                 :            : #include "sal/config.h"
      22                 :            : 
      23                 :            : #include "vm.hxx"
      24                 :            : 
      25                 :            : #include "com/sun/star/beans/NamedValue.hpp"
      26                 :            : #include "com/sun/star/lang/XSingleComponentFactory.hpp"
      27                 :            : #include "cppuhelper/compbase1.hxx"
      28                 :            : #include "cppuhelper/component_context.hxx"
      29                 :            : #include "jvmaccess/virtualmachine.hxx"
      30                 :            : #include "jvmaccess/unovirtualmachine.hxx"
      31                 :            : #include "osl/mutex.hxx"
      32                 :            : 
      33                 :            : namespace {
      34                 :            : 
      35                 :            : namespace css = ::com::sun::star;
      36                 :            : 
      37                 :          0 : struct MutexHolder
      38                 :            : {
      39                 :            :     ::osl::Mutex m_mutex;
      40                 :            : };
      41                 :            : typedef ::cppu::WeakComponentImplHelper1<
      42                 :            :     css::lang::XSingleComponentFactory > t_impl;
      43                 :            : 
      44                 :          0 : class SingletonFactory : public MutexHolder, public t_impl
      45                 :            : {
      46                 :            :     ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > m_vm_access;
      47                 :            : 
      48                 :            : protected:
      49                 :            :     virtual void SAL_CALL disposing();
      50                 :            : 
      51                 :            : public:
      52                 :          0 :     inline SingletonFactory( ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > const & vm_access )
      53                 :            :         : t_impl( m_mutex ),
      54                 :          0 :           m_vm_access( vm_access )
      55                 :          0 :         {}
      56                 :            : 
      57                 :            :     // XSingleComponentFactory impl
      58                 :            :     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithContext(
      59                 :            :         css::uno::Reference< css::uno::XComponentContext > const & xContext )
      60                 :            :         throw (css::uno::Exception);
      61                 :            :     virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
      62                 :            :         css::uno::Sequence< css::uno::Any > const & args, css::uno::Reference< css::uno::XComponentContext > const & xContext )
      63                 :            :         throw (css::uno::Exception);
      64                 :            : };
      65                 :            : 
      66                 :          0 : void SingletonFactory::disposing()
      67                 :            : {
      68                 :          0 :     m_vm_access.clear();
      69                 :          0 : }
      70                 :            : 
      71                 :          0 : css::uno::Reference< css::uno::XInterface > SingletonFactory::createInstanceWithContext(
      72                 :            :     css::uno::Reference< css::uno::XComponentContext > const & xContext )
      73                 :            :     throw (css::uno::Exception)
      74                 :            : {
      75                 :          0 :     sal_Int64 handle = reinterpret_cast< sal_Int64 >( m_vm_access.get() );
      76                 :            :     css::uno::Any arg(
      77                 :            :         css::uno::makeAny(
      78                 :            :             css::beans::NamedValue(
      79                 :            :                 rtl::OUString(
      80                 :            :                     RTL_CONSTASCII_USTRINGPARAM( "UnoVirtualMachine" ) ),
      81                 :          0 :                 css::uno::makeAny( handle ) ) ) );
      82                 :          0 :     return xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
      83                 :            :         ::rtl::OUString(
      84                 :            :             RTL_CONSTASCII_USTRINGPARAM(
      85                 :            :                 "com.sun.star.java.JavaVirtualMachine")),
      86                 :          0 :         css::uno::Sequence< css::uno::Any >( &arg, 1 ), xContext );
      87                 :            : }
      88                 :            : 
      89                 :          0 : css::uno::Reference< css::uno::XInterface > SingletonFactory::createInstanceWithArgumentsAndContext(
      90                 :            :     css::uno::Sequence< css::uno::Any > const & args, css::uno::Reference< css::uno::XComponentContext > const & xContext )
      91                 :            :     throw (css::uno::Exception)
      92                 :            : {
      93                 :          0 :     return xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
      94                 :            :         ::rtl::OUString(
      95                 :            :             RTL_CONSTASCII_USTRINGPARAM(
      96                 :            :                 "com.sun.star.java.JavaVirtualMachine")),
      97                 :          0 :         args, xContext );
      98                 :            : }
      99                 :            : 
     100                 :            : }
     101                 :            : 
     102                 :            : namespace javaunohelper {
     103                 :            : 
     104                 :          0 : ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > create_vm_access(
     105                 :            :     JNIEnv * jni_env, jobject loader )
     106                 :            : {
     107                 :            :     JavaVM * vm;
     108                 :          0 :     jni_env->GetJavaVM( &vm );
     109                 :            :     try {
     110                 :            :         return new ::jvmaccess::UnoVirtualMachine(
     111                 :            :             new ::jvmaccess::VirtualMachine(
     112                 :          0 :                 vm, JNI_VERSION_1_2, false, jni_env ),
     113                 :          0 :             loader );
     114                 :          0 :     } catch ( ::jvmaccess::UnoVirtualMachine::CreationException & ) {
     115                 :            :         throw css::uno::RuntimeException(
     116                 :            :             ::rtl::OUString(
     117                 :            :                 RTL_CONSTASCII_USTRINGPARAM(
     118                 :            :                     "jmvaccess::UnoVirtualMachine::CreationException"
     119                 :            :                     " occurred" ) ),
     120                 :          0 :             css::uno::Reference< css::uno::XInterface >() );
     121                 :            :     }
     122                 :            : }
     123                 :            : 
     124                 :          0 : css::uno::Reference< css::uno::XComponentContext > install_vm_singleton(
     125                 :            :     css::uno::Reference< ::css::uno::XComponentContext > const & xContext,
     126                 :            :     ::rtl::Reference< ::jvmaccess::UnoVirtualMachine > const & vm_access )
     127                 :            : {
     128                 :          0 :     css::uno::Reference< css::lang::XSingleComponentFactory > xFac( new SingletonFactory( vm_access ) );
     129                 :            :     ::cppu::ContextEntry_Init entry(
     130                 :            :         ::rtl::OUString(
     131                 :            :             RTL_CONSTASCII_USTRINGPARAM(
     132                 :            :                 "/singletons/com.sun.star.java.theJavaVirtualMachine")),
     133                 :          0 :         css::uno::makeAny( xFac ), true );
     134                 :          0 :     return ::cppu::createComponentContext( &entry, 1, xContext );
     135                 :            : }
     136                 :            : 
     137                 :            : }
     138                 :            : 
     139                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10