1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_bridges.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <sal/alloca.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp" 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx" 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include "jni_bridge.h" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir using namespace ::std; 41*cdf0e10cSrcweir using namespace ::rtl; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir namespace 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir extern "C" 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir //------------------------------------------------------------------------------ 49*cdf0e10cSrcweir void SAL_CALL UNO_proxy_free( uno_ExtEnvironment * env, void * proxy ) 50*cdf0e10cSrcweir SAL_THROW_EXTERN_C(); 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir //------------------------------------------------------------------------------ 53*cdf0e10cSrcweir void SAL_CALL UNO_proxy_acquire( uno_Interface * pUnoI ) 54*cdf0e10cSrcweir SAL_THROW_EXTERN_C(); 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir //------------------------------------------------------------------------------ 57*cdf0e10cSrcweir void SAL_CALL UNO_proxy_release( uno_Interface * pUnoI ) 58*cdf0e10cSrcweir SAL_THROW_EXTERN_C(); 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir //------------------------------------------------------------------------------ 61*cdf0e10cSrcweir void SAL_CALL UNO_proxy_dispatch( 62*cdf0e10cSrcweir uno_Interface * pUnoI, typelib_TypeDescription const * member_td, 63*cdf0e10cSrcweir void * uno_ret, void * uno_args[], uno_Any ** uno_exc ) 64*cdf0e10cSrcweir SAL_THROW_EXTERN_C(); 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir } 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir namespace jni_uno 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir //______________________________________________________________________________ 72*cdf0e10cSrcweir void Bridge::handle_java_exc( 73*cdf0e10cSrcweir JNI_context const & jni, 74*cdf0e10cSrcweir JLocalAutoRef const & jo_exc, uno_Any * uno_exc ) const 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir OSL_ASSERT( jo_exc.is() ); 77*cdf0e10cSrcweir if (! jo_exc.is()) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir throw BridgeRuntimeError( 80*cdf0e10cSrcweir OUSTR("java exception occured, but no java exception available!?") + 81*cdf0e10cSrcweir jni.get_stack_trace() ); 82*cdf0e10cSrcweir } 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir JLocalAutoRef jo_class( jni, jni->GetObjectClass( jo_exc.get() ) ); 85*cdf0e10cSrcweir JLocalAutoRef jo_class_name( 86*cdf0e10cSrcweir jni, jni->CallObjectMethodA( 87*cdf0e10cSrcweir jo_class.get(), m_jni_info->m_method_Class_getName, 0 ) ); 88*cdf0e10cSrcweir jni.ensure_no_exception(); 89*cdf0e10cSrcweir OUString exc_name( 90*cdf0e10cSrcweir jstring_to_oustring( jni, (jstring) jo_class_name.get() ) ); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir ::com::sun::star::uno::TypeDescription td( exc_name.pData ); 93*cdf0e10cSrcweir if (!td.is() || (typelib_TypeClass_EXCEPTION != td.get()->eTypeClass)) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir // call toString() 96*cdf0e10cSrcweir JLocalAutoRef jo_descr( 97*cdf0e10cSrcweir jni, jni->CallObjectMethodA( 98*cdf0e10cSrcweir jo_exc.get(), m_jni_info->m_method_Object_toString, 0 ) ); 99*cdf0e10cSrcweir jni.ensure_no_exception(); 100*cdf0e10cSrcweir OUStringBuffer buf( 128 ); 101*cdf0e10cSrcweir buf.appendAscii( 102*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("non-UNO exception occurred: ") ); 103*cdf0e10cSrcweir buf.append( jstring_to_oustring( jni, (jstring) jo_descr.get() ) ); 104*cdf0e10cSrcweir buf.append( jni.get_stack_trace( jo_exc.get() ) ); 105*cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir auto_ptr< rtl_mem > uno_data( rtl_mem::allocate( td.get()->nSize ) ); 109*cdf0e10cSrcweir jvalue val; 110*cdf0e10cSrcweir val.l = jo_exc.get(); 111*cdf0e10cSrcweir map_to_uno( 112*cdf0e10cSrcweir jni, uno_data.get(), val, td.get()->pWeakRef, 0, 113*cdf0e10cSrcweir false /* no assign */, false /* no out param */ ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 116*cdf0e10cSrcweir // patch Message, append stack trace 117*cdf0e10cSrcweir reinterpret_cast< ::com::sun::star::uno::Exception * >( 118*cdf0e10cSrcweir uno_data.get() )->Message += jni.get_stack_trace( jo_exc.get() ); 119*cdf0e10cSrcweir #endif 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir typelib_typedescriptionreference_acquire( td.get()->pWeakRef ); 122*cdf0e10cSrcweir uno_exc->pType = td.get()->pWeakRef; 123*cdf0e10cSrcweir uno_exc->pData = uno_data.release(); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 126*cdf0e10cSrcweir OUStringBuffer trace_buf( 128 ); 127*cdf0e10cSrcweir trace_buf.appendAscii( 128*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("exception occured uno->java: [") ); 129*cdf0e10cSrcweir trace_buf.append( exc_name ); 130*cdf0e10cSrcweir trace_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("] ") ); 131*cdf0e10cSrcweir trace_buf.append( 132*cdf0e10cSrcweir reinterpret_cast< ::com::sun::star::uno::Exception const * >( 133*cdf0e10cSrcweir uno_exc->pData )->Message ); 134*cdf0e10cSrcweir OString cstr_trace( 135*cdf0e10cSrcweir OUStringToOString( 136*cdf0e10cSrcweir trace_buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US ) ); 137*cdf0e10cSrcweir OSL_TRACE( cstr_trace.getStr() ); 138*cdf0e10cSrcweir #endif 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir //______________________________________________________________________________ 142*cdf0e10cSrcweir void Bridge::call_java( 143*cdf0e10cSrcweir jobject javaI, typelib_InterfaceTypeDescription * iface_td, 144*cdf0e10cSrcweir sal_Int32 local_member_index, sal_Int32 function_pos_offset, 145*cdf0e10cSrcweir typelib_TypeDescriptionReference * return_type, 146*cdf0e10cSrcweir typelib_MethodParameter * params, sal_Int32 nParams, 147*cdf0e10cSrcweir void * uno_ret, void * uno_args [], uno_Any ** uno_exc ) const 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir OSL_ASSERT( function_pos_offset == 0 || function_pos_offset == 1 ); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir JNI_guarded_context jni( 152*cdf0e10cSrcweir m_jni_info, reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >( 153*cdf0e10cSrcweir m_java_env->pContext ) ); 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // assure fully initialized iface_td: 156*cdf0e10cSrcweir ::com::sun::star::uno::TypeDescription iface_holder; 157*cdf0e10cSrcweir if (! iface_td->aBase.bComplete) { 158*cdf0e10cSrcweir iface_holder = ::com::sun::star::uno::TypeDescription( 159*cdf0e10cSrcweir reinterpret_cast<typelib_TypeDescription *>(iface_td) ); 160*cdf0e10cSrcweir iface_holder.makeComplete(); 161*cdf0e10cSrcweir if (! iface_holder.get()->bComplete) { 162*cdf0e10cSrcweir OUStringBuffer buf; 163*cdf0e10cSrcweir buf.appendAscii( 164*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM("cannot make type complete: ") ); 165*cdf0e10cSrcweir buf.append( OUString::unacquired(&iface_holder.get()->pTypeName) ); 166*cdf0e10cSrcweir buf.append( jni.get_stack_trace() ); 167*cdf0e10cSrcweir throw BridgeRuntimeError( buf.makeStringAndClear() ); 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir iface_td = reinterpret_cast<typelib_InterfaceTypeDescription *>( 170*cdf0e10cSrcweir iface_holder.get() ); 171*cdf0e10cSrcweir OSL_ASSERT( iface_td->aBase.eTypeClass == typelib_TypeClass_INTERFACE ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir // prepare java args, save param td 175*cdf0e10cSrcweir #ifdef BROKEN_ALLOCA 176*cdf0e10cSrcweir jvalue * java_args = (jvalue *) malloc( sizeof (jvalue) * nParams ); 177*cdf0e10cSrcweir #else 178*cdf0e10cSrcweir jvalue * java_args = (jvalue *) alloca( sizeof (jvalue) * nParams ); 179*cdf0e10cSrcweir #endif 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir sal_Int32 nPos; 182*cdf0e10cSrcweir for ( nPos = 0; nPos < nParams; ++nPos ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir try 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir typelib_MethodParameter const & param = params[ nPos ]; 187*cdf0e10cSrcweir java_args[ nPos ].l = 0; // if out: build up array[ 1 ] 188*cdf0e10cSrcweir map_to_java( 189*cdf0e10cSrcweir jni, &java_args[ nPos ], 190*cdf0e10cSrcweir uno_args[ nPos ], 191*cdf0e10cSrcweir param.pTypeRef, 0, 192*cdf0e10cSrcweir sal_False != param.bIn /* convert uno value */, 193*cdf0e10cSrcweir sal_False != param.bOut /* build up array[ 1 ] */ ); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir catch (...) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir // cleanup 198*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nPos; ++n ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir typelib_MethodParameter const & param = params[ n ]; 201*cdf0e10cSrcweir if (param.bOut || 202*cdf0e10cSrcweir typelib_TypeClass_DOUBLE < param.pTypeRef->eTypeClass) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir jni->DeleteLocalRef( java_args[ n ].l ); 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir #ifdef BROKEN_ALLOCA 208*cdf0e10cSrcweir free( java_args ); 209*cdf0e10cSrcweir #endif 210*cdf0e10cSrcweir throw; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir sal_Int32 base_members = iface_td->nAllMembers - iface_td->nMembers; 215*cdf0e10cSrcweir OSL_ASSERT( base_members < iface_td->nAllMembers ); 216*cdf0e10cSrcweir sal_Int32 base_members_function_pos = 217*cdf0e10cSrcweir iface_td->pMapMemberIndexToFunctionIndex[ base_members ]; 218*cdf0e10cSrcweir sal_Int32 member_pos = base_members + local_member_index; 219*cdf0e10cSrcweir OSL_ENSURE( 220*cdf0e10cSrcweir member_pos < iface_td->nAllMembers, "### member pos out of range!" ); 221*cdf0e10cSrcweir sal_Int32 function_pos = 222*cdf0e10cSrcweir iface_td->pMapMemberIndexToFunctionIndex[ member_pos ] 223*cdf0e10cSrcweir + function_pos_offset; 224*cdf0e10cSrcweir OSL_ENSURE( 225*cdf0e10cSrcweir function_pos >= base_members_function_pos 226*cdf0e10cSrcweir && function_pos < iface_td->nMapFunctionIndexToMemberIndex, 227*cdf0e10cSrcweir "### illegal function index!" ); 228*cdf0e10cSrcweir function_pos -= base_members_function_pos; 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir JNI_interface_type_info const * info = 231*cdf0e10cSrcweir static_cast< JNI_interface_type_info const * >( 232*cdf0e10cSrcweir m_jni_info->get_type_info( jni, &iface_td->aBase ) ); 233*cdf0e10cSrcweir jmethodID method_id = info->m_methods[ function_pos ]; 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 236*cdf0e10cSrcweir OUStringBuffer trace_buf( 128 ); 237*cdf0e10cSrcweir trace_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("calling ") ); 238*cdf0e10cSrcweir JLocalAutoRef jo_method( 239*cdf0e10cSrcweir jni, jni->ToReflectedMethod( info->m_class, method_id, JNI_FALSE ) ); 240*cdf0e10cSrcweir jni.ensure_no_exception(); 241*cdf0e10cSrcweir JLocalAutoRef jo_descr( 242*cdf0e10cSrcweir jni, jni->CallObjectMethodA( 243*cdf0e10cSrcweir jo_method.get(), m_jni_info->m_method_Object_toString, 0 ) ); 244*cdf0e10cSrcweir jni.ensure_no_exception(); 245*cdf0e10cSrcweir trace_buf.append( jstring_to_oustring( jni, (jstring) jo_descr.get() ) ); 246*cdf0e10cSrcweir trace_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" on ") ); 247*cdf0e10cSrcweir jo_descr.reset( 248*cdf0e10cSrcweir jni->CallObjectMethodA( 249*cdf0e10cSrcweir javaI, m_jni_info->m_method_Object_toString, 0 ) ); 250*cdf0e10cSrcweir jni.ensure_no_exception(); 251*cdf0e10cSrcweir trace_buf.append( jstring_to_oustring( jni, (jstring) jo_descr.get() ) ); 252*cdf0e10cSrcweir trace_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" (") ); 253*cdf0e10cSrcweir JLocalAutoRef jo_class( jni, jni->GetObjectClass( javaI ) ); 254*cdf0e10cSrcweir jo_descr.reset( 255*cdf0e10cSrcweir jni->CallObjectMethodA( 256*cdf0e10cSrcweir jo_class.get(), m_jni_info->m_method_Object_toString, 0 ) ); 257*cdf0e10cSrcweir jni.ensure_no_exception(); 258*cdf0e10cSrcweir trace_buf.append( jstring_to_oustring( jni, (jstring) jo_descr.get() ) ); 259*cdf0e10cSrcweir trace_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(")") ); 260*cdf0e10cSrcweir OString cstr_trace( 261*cdf0e10cSrcweir OUStringToOString( 262*cdf0e10cSrcweir trace_buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US ) ); 263*cdf0e10cSrcweir OSL_TRACE( cstr_trace.getStr() ); 264*cdf0e10cSrcweir #endif 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir // complex return value 267*cdf0e10cSrcweir JLocalAutoRef java_ret( jni ); 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir switch (return_type->eTypeClass) 270*cdf0e10cSrcweir { 271*cdf0e10cSrcweir case typelib_TypeClass_VOID: 272*cdf0e10cSrcweir jni->CallVoidMethodA( javaI, method_id, java_args ); 273*cdf0e10cSrcweir break; 274*cdf0e10cSrcweir case typelib_TypeClass_CHAR: 275*cdf0e10cSrcweir *(sal_Unicode *)uno_ret = 276*cdf0e10cSrcweir jni->CallCharMethodA( javaI, method_id, java_args ); 277*cdf0e10cSrcweir break; 278*cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN: 279*cdf0e10cSrcweir *(sal_Bool *)uno_ret = 280*cdf0e10cSrcweir jni->CallBooleanMethodA( javaI, method_id, java_args ); 281*cdf0e10cSrcweir break; 282*cdf0e10cSrcweir case typelib_TypeClass_BYTE: 283*cdf0e10cSrcweir *(sal_Int8 *)uno_ret = 284*cdf0e10cSrcweir jni->CallByteMethodA( javaI, method_id, java_args ); 285*cdf0e10cSrcweir break; 286*cdf0e10cSrcweir case typelib_TypeClass_SHORT: 287*cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT: 288*cdf0e10cSrcweir *(sal_Int16 *)uno_ret = 289*cdf0e10cSrcweir jni->CallShortMethodA( javaI, method_id, java_args ); 290*cdf0e10cSrcweir break; 291*cdf0e10cSrcweir case typelib_TypeClass_LONG: 292*cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG: 293*cdf0e10cSrcweir *(sal_Int32 *)uno_ret = 294*cdf0e10cSrcweir jni->CallIntMethodA( javaI, method_id, java_args ); 295*cdf0e10cSrcweir break; 296*cdf0e10cSrcweir case typelib_TypeClass_HYPER: 297*cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER: 298*cdf0e10cSrcweir *(sal_Int64 *)uno_ret = 299*cdf0e10cSrcweir jni->CallLongMethodA( javaI, method_id, java_args ); 300*cdf0e10cSrcweir break; 301*cdf0e10cSrcweir case typelib_TypeClass_FLOAT: 302*cdf0e10cSrcweir *(float *)uno_ret = 303*cdf0e10cSrcweir jni->CallFloatMethodA( javaI, method_id, java_args ); 304*cdf0e10cSrcweir break; 305*cdf0e10cSrcweir case typelib_TypeClass_DOUBLE: 306*cdf0e10cSrcweir *(double *)uno_ret = 307*cdf0e10cSrcweir jni->CallDoubleMethodA( javaI, method_id, java_args ); 308*cdf0e10cSrcweir break; 309*cdf0e10cSrcweir default: 310*cdf0e10cSrcweir java_ret.reset( 311*cdf0e10cSrcweir jni->CallObjectMethodA( javaI, method_id, java_args ) ); 312*cdf0e10cSrcweir break; 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir if (jni->ExceptionCheck()) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir JLocalAutoRef jo_exc( jni, jni->ExceptionOccurred() ); 318*cdf0e10cSrcweir jni->ExceptionClear(); 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir // release temp java local refs 321*cdf0e10cSrcweir for ( nPos = 0; nPos < nParams; ++nPos ) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir typelib_MethodParameter const & param = params[ nPos ]; 324*cdf0e10cSrcweir if (param.bOut || 325*cdf0e10cSrcweir typelib_TypeClass_DOUBLE < param.pTypeRef->eTypeClass) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir jni->DeleteLocalRef( java_args[ nPos ].l ); 328*cdf0e10cSrcweir } 329*cdf0e10cSrcweir } 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir handle_java_exc( jni, jo_exc, *uno_exc ); 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir else // no exception 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir for ( nPos = 0; nPos < nParams; ++nPos ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir typelib_MethodParameter const & param = params[ nPos ]; 338*cdf0e10cSrcweir if (param.bOut) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir try 341*cdf0e10cSrcweir { 342*cdf0e10cSrcweir map_to_uno( 343*cdf0e10cSrcweir jni, uno_args[ nPos ], 344*cdf0e10cSrcweir java_args[ nPos ], param.pTypeRef, 0, 345*cdf0e10cSrcweir sal_False != param.bIn /* assign if inout */, 346*cdf0e10cSrcweir true /* out param */ ); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir catch (...) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir // cleanup uno pure out 351*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < nPos; ++n ) 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir typelib_MethodParameter const & p = params[ n ]; 354*cdf0e10cSrcweir if (! p.bIn) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir uno_type_destructData( 357*cdf0e10cSrcweir uno_args[ n ], p.pTypeRef, 0 ); 358*cdf0e10cSrcweir } 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir // cleanup java temp local refs 361*cdf0e10cSrcweir for ( ; nPos < nParams; ++nPos ) 362*cdf0e10cSrcweir { 363*cdf0e10cSrcweir typelib_MethodParameter const & p = params[ nPos ]; 364*cdf0e10cSrcweir if (p.bOut || 365*cdf0e10cSrcweir typelib_TypeClass_DOUBLE < 366*cdf0e10cSrcweir p.pTypeRef->eTypeClass) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir jni->DeleteLocalRef( java_args[ nPos ].l ); 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir } 371*cdf0e10cSrcweir #ifdef BROKEN_ALLOCA 372*cdf0e10cSrcweir free( java_args ); 373*cdf0e10cSrcweir #endif 374*cdf0e10cSrcweir throw; 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir jni->DeleteLocalRef( java_args[ nPos ].l ); 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir else // pure temp in param 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir if (typelib_TypeClass_DOUBLE < param.pTypeRef->eTypeClass) 381*cdf0e10cSrcweir jni->DeleteLocalRef( java_args[ nPos ].l ); 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir // return value 386*cdf0e10cSrcweir if (typelib_TypeClass_DOUBLE < return_type->eTypeClass) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir try 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir jvalue val; 391*cdf0e10cSrcweir val.l = java_ret.get(); 392*cdf0e10cSrcweir map_to_uno( 393*cdf0e10cSrcweir jni, uno_ret, val, return_type, 0, 394*cdf0e10cSrcweir false /* no assign */, false /* no out param */ ); 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir catch (...) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir // cleanup uno pure out 399*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nParams; ++i ) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir typelib_MethodParameter const & param = params[ i ]; 402*cdf0e10cSrcweir if (! param.bIn) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir uno_type_destructData( 405*cdf0e10cSrcweir uno_args[ i ], param.pTypeRef, 0 ); 406*cdf0e10cSrcweir } 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir #ifdef BROKEN_ALLOCA 409*cdf0e10cSrcweir free( java_args ); 410*cdf0e10cSrcweir #endif 411*cdf0e10cSrcweir throw; 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir } // else: already set integral uno return value 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir // no exception occured 416*cdf0e10cSrcweir *uno_exc = 0; 417*cdf0e10cSrcweir } 418*cdf0e10cSrcweir #ifdef BROKEN_ALLOCA 419*cdf0e10cSrcweir free( java_args ); 420*cdf0e10cSrcweir #endif 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir //==== a uno proxy wrapping a java interface =================================== 424*cdf0e10cSrcweir struct UNO_proxy : public uno_Interface 425*cdf0e10cSrcweir { 426*cdf0e10cSrcweir mutable oslInterlockedCount m_ref; 427*cdf0e10cSrcweir Bridge const * m_bridge; 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir // mapping information 430*cdf0e10cSrcweir jobject m_javaI; 431*cdf0e10cSrcweir jstring m_jo_oid; 432*cdf0e10cSrcweir OUString m_oid; 433*cdf0e10cSrcweir JNI_interface_type_info const * m_type_info; 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir inline void acquire() const; 436*cdf0e10cSrcweir inline void release() const; 437*cdf0e10cSrcweir 438*cdf0e10cSrcweir // ctor 439*cdf0e10cSrcweir inline UNO_proxy( 440*cdf0e10cSrcweir JNI_context const & jni, Bridge const * bridge, 441*cdf0e10cSrcweir jobject javaI, jstring jo_oid, OUString const & oid, 442*cdf0e10cSrcweir JNI_interface_type_info const * info ); 443*cdf0e10cSrcweir }; 444*cdf0e10cSrcweir 445*cdf0e10cSrcweir //______________________________________________________________________________ 446*cdf0e10cSrcweir inline UNO_proxy::UNO_proxy( 447*cdf0e10cSrcweir JNI_context const & jni, Bridge const * bridge, 448*cdf0e10cSrcweir jobject javaI, jstring jo_oid, OUString const & oid, 449*cdf0e10cSrcweir JNI_interface_type_info const * info ) 450*cdf0e10cSrcweir : m_ref( 1 ), 451*cdf0e10cSrcweir m_oid( oid ), 452*cdf0e10cSrcweir m_type_info( info ) 453*cdf0e10cSrcweir { 454*cdf0e10cSrcweir JNI_info const * jni_info = bridge->m_jni_info; 455*cdf0e10cSrcweir JLocalAutoRef jo_string_array( 456*cdf0e10cSrcweir jni, jni->NewObjectArray( 1, jni_info->m_class_String, jo_oid ) ); 457*cdf0e10cSrcweir jni.ensure_no_exception(); 458*cdf0e10cSrcweir jvalue args[ 3 ]; 459*cdf0e10cSrcweir args[ 0 ].l = javaI; 460*cdf0e10cSrcweir args[ 1 ].l = jo_string_array.get(); 461*cdf0e10cSrcweir args[ 2 ].l = info->m_type; 462*cdf0e10cSrcweir jobject jo_iface = jni->CallObjectMethodA( 463*cdf0e10cSrcweir jni_info->m_object_java_env, 464*cdf0e10cSrcweir jni_info->m_method_IEnvironment_registerInterface, args ); 465*cdf0e10cSrcweir jni.ensure_no_exception(); 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir m_javaI = jni->NewGlobalRef( jo_iface ); 468*cdf0e10cSrcweir m_jo_oid = (jstring) jni->NewGlobalRef( jo_oid ); 469*cdf0e10cSrcweir bridge->acquire(); 470*cdf0e10cSrcweir m_bridge = bridge; 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir // uno_Interface 473*cdf0e10cSrcweir uno_Interface::acquire = UNO_proxy_acquire; 474*cdf0e10cSrcweir uno_Interface::release = UNO_proxy_release; 475*cdf0e10cSrcweir uno_Interface::pDispatcher = UNO_proxy_dispatch; 476*cdf0e10cSrcweir } 477*cdf0e10cSrcweir 478*cdf0e10cSrcweir //______________________________________________________________________________ 479*cdf0e10cSrcweir inline void UNO_proxy::acquire() const 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir if (1 == osl_incrementInterlockedCount( &m_ref )) 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir // rebirth of proxy zombie 484*cdf0e10cSrcweir void * that = const_cast< UNO_proxy * >( this ); 485*cdf0e10cSrcweir // register at uno env 486*cdf0e10cSrcweir (*m_bridge->m_uno_env->registerProxyInterface)( 487*cdf0e10cSrcweir m_bridge->m_uno_env, &that, 488*cdf0e10cSrcweir UNO_proxy_free, m_oid.pData, 489*cdf0e10cSrcweir (typelib_InterfaceTypeDescription *)m_type_info->m_td.get() ); 490*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 491*cdf0e10cSrcweir OSL_ASSERT( this == (void const * const)that ); 492*cdf0e10cSrcweir #endif 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir //______________________________________________________________________________ 497*cdf0e10cSrcweir inline void UNO_proxy::release() const 498*cdf0e10cSrcweir { 499*cdf0e10cSrcweir if (0 == osl_decrementInterlockedCount( &m_ref )) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir // revoke from uno env on last release 502*cdf0e10cSrcweir (*m_bridge->m_uno_env->revokeInterface)( 503*cdf0e10cSrcweir m_bridge->m_uno_env, const_cast< UNO_proxy * >( this ) ); 504*cdf0e10cSrcweir } 505*cdf0e10cSrcweir } 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir 508*cdf0e10cSrcweir //______________________________________________________________________________ 509*cdf0e10cSrcweir uno_Interface * Bridge::map_to_uno( 510*cdf0e10cSrcweir JNI_context const & jni, 511*cdf0e10cSrcweir jobject javaI, JNI_interface_type_info const * info ) const 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir JLocalAutoRef jo_oid( jni, compute_oid( jni, javaI ) ); 514*cdf0e10cSrcweir OUString oid( jstring_to_oustring( jni, (jstring) jo_oid.get() ) ); 515*cdf0e10cSrcweir 516*cdf0e10cSrcweir uno_Interface * pUnoI = 0; 517*cdf0e10cSrcweir (*m_uno_env->getRegisteredInterface)( 518*cdf0e10cSrcweir m_uno_env, (void **)&pUnoI, 519*cdf0e10cSrcweir oid.pData, (typelib_InterfaceTypeDescription *)info->m_td.get() ); 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir if (0 == pUnoI) // no existing interface, register new proxy 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir // refcount initially 1 524*cdf0e10cSrcweir pUnoI = new UNO_proxy( 525*cdf0e10cSrcweir jni, const_cast< Bridge * >( this ), 526*cdf0e10cSrcweir javaI, (jstring) jo_oid.get(), oid, info ); 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir (*m_uno_env->registerProxyInterface)( 529*cdf0e10cSrcweir m_uno_env, (void **)&pUnoI, 530*cdf0e10cSrcweir UNO_proxy_free, 531*cdf0e10cSrcweir oid.pData, (typelib_InterfaceTypeDescription *)info->m_td.get() ); 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir return pUnoI; 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir using namespace ::jni_uno; 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir namespace 541*cdf0e10cSrcweir { 542*cdf0e10cSrcweir extern "C" 543*cdf0e10cSrcweir { 544*cdf0e10cSrcweir 545*cdf0e10cSrcweir //------------------------------------------------------------------------------ 546*cdf0e10cSrcweir void SAL_CALL UNO_proxy_free( uno_ExtEnvironment * env, void * proxy ) 547*cdf0e10cSrcweir SAL_THROW_EXTERN_C() 548*cdf0e10cSrcweir { 549*cdf0e10cSrcweir UNO_proxy const * that = reinterpret_cast< UNO_proxy const * >( proxy ); 550*cdf0e10cSrcweir Bridge const * bridge = that->m_bridge; 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir if ( env != bridge->m_uno_env ) { 553*cdf0e10cSrcweir OSL_ASSERT(false); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 556*cdf0e10cSrcweir OString cstr_msg( 557*cdf0e10cSrcweir OUStringToOString( 558*cdf0e10cSrcweir OUSTR("freeing binary uno proxy: ") + that->m_oid, 559*cdf0e10cSrcweir RTL_TEXTENCODING_ASCII_US ) ); 560*cdf0e10cSrcweir OSL_TRACE( cstr_msg.getStr() ); 561*cdf0e10cSrcweir #endif 562*cdf0e10cSrcweir 563*cdf0e10cSrcweir try 564*cdf0e10cSrcweir { 565*cdf0e10cSrcweir JNI_guarded_context jni( 566*cdf0e10cSrcweir bridge->m_jni_info, 567*cdf0e10cSrcweir reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >( 568*cdf0e10cSrcweir bridge->m_java_env->pContext ) ); 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir jni->DeleteGlobalRef( that->m_javaI ); 571*cdf0e10cSrcweir jni->DeleteGlobalRef( that->m_jo_oid ); 572*cdf0e10cSrcweir } 573*cdf0e10cSrcweir catch (BridgeRuntimeError & err) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 576*cdf0e10cSrcweir OString cstr_msg2( 577*cdf0e10cSrcweir OUStringToOString( err.m_message, RTL_TEXTENCODING_ASCII_US ) ); 578*cdf0e10cSrcweir OSL_ENSURE( 0, cstr_msg2.getStr() ); 579*cdf0e10cSrcweir #else 580*cdf0e10cSrcweir (void) err; // unused 581*cdf0e10cSrcweir #endif 582*cdf0e10cSrcweir } 583*cdf0e10cSrcweir catch (::jvmaccess::VirtualMachine::AttachGuard::CreationException &) 584*cdf0e10cSrcweir { 585*cdf0e10cSrcweir OSL_ENSURE( 586*cdf0e10cSrcweir 0, 587*cdf0e10cSrcweir "[jni_uno bridge error] attaching current thread to java failed!" ); 588*cdf0e10cSrcweir } 589*cdf0e10cSrcweir 590*cdf0e10cSrcweir bridge->release(); 591*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 592*cdf0e10cSrcweir *(int *)that = 0xdeadcafe; 593*cdf0e10cSrcweir #endif 594*cdf0e10cSrcweir delete that; 595*cdf0e10cSrcweir } 596*cdf0e10cSrcweir 597*cdf0e10cSrcweir //------------------------------------------------------------------------------ 598*cdf0e10cSrcweir void SAL_CALL UNO_proxy_acquire( uno_Interface * pUnoI ) 599*cdf0e10cSrcweir SAL_THROW_EXTERN_C() 600*cdf0e10cSrcweir { 601*cdf0e10cSrcweir UNO_proxy const * that = static_cast< UNO_proxy const * >( pUnoI ); 602*cdf0e10cSrcweir that->acquire(); 603*cdf0e10cSrcweir } 604*cdf0e10cSrcweir 605*cdf0e10cSrcweir //------------------------------------------------------------------------------ 606*cdf0e10cSrcweir void SAL_CALL UNO_proxy_release( uno_Interface * pUnoI ) 607*cdf0e10cSrcweir SAL_THROW_EXTERN_C() 608*cdf0e10cSrcweir { 609*cdf0e10cSrcweir UNO_proxy const * that = static_cast< UNO_proxy const * >( pUnoI ); 610*cdf0e10cSrcweir that->release(); 611*cdf0e10cSrcweir } 612*cdf0e10cSrcweir 613*cdf0e10cSrcweir //------------------------------------------------------------------------------ 614*cdf0e10cSrcweir void SAL_CALL UNO_proxy_dispatch( 615*cdf0e10cSrcweir uno_Interface * pUnoI, typelib_TypeDescription const * member_td, 616*cdf0e10cSrcweir void * uno_ret, void * uno_args [], uno_Any ** uno_exc ) 617*cdf0e10cSrcweir SAL_THROW_EXTERN_C() 618*cdf0e10cSrcweir { 619*cdf0e10cSrcweir UNO_proxy const * that = static_cast< UNO_proxy const * >( pUnoI ); 620*cdf0e10cSrcweir Bridge const * bridge = that->m_bridge; 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 623*cdf0e10cSrcweir OUStringBuffer trace_buf( 64 ); 624*cdf0e10cSrcweir trace_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("uno->java call: ") ); 625*cdf0e10cSrcweir trace_buf.append( OUString::unacquired( &member_td->pTypeName ) ); 626*cdf0e10cSrcweir trace_buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(" on oid ") ); 627*cdf0e10cSrcweir trace_buf.append( that->m_oid ); 628*cdf0e10cSrcweir OString cstr_msg( 629*cdf0e10cSrcweir OUStringToOString( 630*cdf0e10cSrcweir trace_buf.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US ) ); 631*cdf0e10cSrcweir OSL_TRACE( cstr_msg.getStr() ); 632*cdf0e10cSrcweir #endif 633*cdf0e10cSrcweir 634*cdf0e10cSrcweir try 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir switch (member_td->eTypeClass) 637*cdf0e10cSrcweir { 638*cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE: 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription const * attrib_td = 641*cdf0e10cSrcweir reinterpret_cast< 642*cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription const * >( 643*cdf0e10cSrcweir member_td ); 644*cdf0e10cSrcweir com::sun::star::uno::TypeDescription attrib_holder; 645*cdf0e10cSrcweir while ( attrib_td->pBaseRef != 0 ) { 646*cdf0e10cSrcweir attrib_holder = com::sun::star::uno::TypeDescription( 647*cdf0e10cSrcweir attrib_td->pBaseRef ); 648*cdf0e10cSrcweir OSL_ASSERT( 649*cdf0e10cSrcweir attrib_holder.get()->eTypeClass 650*cdf0e10cSrcweir == typelib_TypeClass_INTERFACE_ATTRIBUTE ); 651*cdf0e10cSrcweir attrib_td = reinterpret_cast< 652*cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription * >( 653*cdf0e10cSrcweir attrib_holder.get() ); 654*cdf0e10cSrcweir } 655*cdf0e10cSrcweir typelib_InterfaceTypeDescription * iface_td = attrib_td->pInterface; 656*cdf0e10cSrcweir 657*cdf0e10cSrcweir if (0 == uno_ret) // is setter method 658*cdf0e10cSrcweir { 659*cdf0e10cSrcweir typelib_MethodParameter param; 660*cdf0e10cSrcweir param.pTypeRef = attrib_td->pAttributeTypeRef; 661*cdf0e10cSrcweir param.bIn = sal_True; 662*cdf0e10cSrcweir param.bOut = sal_False; 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir bridge->call_java( 665*cdf0e10cSrcweir that->m_javaI, iface_td, 666*cdf0e10cSrcweir attrib_td->nIndex, 1, // get, then set method 667*cdf0e10cSrcweir bridge->m_jni_info->m_void_type.getTypeLibType(), 668*cdf0e10cSrcweir ¶m, 1, 669*cdf0e10cSrcweir 0, uno_args, uno_exc ); 670*cdf0e10cSrcweir } 671*cdf0e10cSrcweir else // is getter method 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir bridge->call_java( 674*cdf0e10cSrcweir that->m_javaI, iface_td, attrib_td->nIndex, 0, 675*cdf0e10cSrcweir attrib_td->pAttributeTypeRef, 676*cdf0e10cSrcweir 0, 0, // no params 677*cdf0e10cSrcweir uno_ret, 0, uno_exc ); 678*cdf0e10cSrcweir } 679*cdf0e10cSrcweir break; 680*cdf0e10cSrcweir } 681*cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD: 682*cdf0e10cSrcweir { 683*cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription const * method_td = 684*cdf0e10cSrcweir reinterpret_cast< 685*cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription const * >( 686*cdf0e10cSrcweir member_td ); 687*cdf0e10cSrcweir com::sun::star::uno::TypeDescription method_holder; 688*cdf0e10cSrcweir while ( method_td->pBaseRef != 0 ) { 689*cdf0e10cSrcweir method_holder = com::sun::star::uno::TypeDescription( 690*cdf0e10cSrcweir method_td->pBaseRef ); 691*cdf0e10cSrcweir OSL_ASSERT( 692*cdf0e10cSrcweir method_holder.get()->eTypeClass 693*cdf0e10cSrcweir == typelib_TypeClass_INTERFACE_METHOD ); 694*cdf0e10cSrcweir method_td = reinterpret_cast< 695*cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription * >( 696*cdf0e10cSrcweir method_holder.get() ); 697*cdf0e10cSrcweir } 698*cdf0e10cSrcweir typelib_InterfaceTypeDescription * iface_td = method_td->pInterface; 699*cdf0e10cSrcweir 700*cdf0e10cSrcweir switch ( method_td->aBase.nPosition ) 701*cdf0e10cSrcweir { 702*cdf0e10cSrcweir case 0: // queryInterface() 703*cdf0e10cSrcweir { 704*cdf0e10cSrcweir TypeDescr demanded_td( 705*cdf0e10cSrcweir *reinterpret_cast< typelib_TypeDescriptionReference ** >( 706*cdf0e10cSrcweir uno_args[ 0 ] ) ); 707*cdf0e10cSrcweir if (typelib_TypeClass_INTERFACE != 708*cdf0e10cSrcweir demanded_td.get()->eTypeClass) 709*cdf0e10cSrcweir { 710*cdf0e10cSrcweir throw BridgeRuntimeError( 711*cdf0e10cSrcweir OUSTR("queryInterface() call demands " 712*cdf0e10cSrcweir "an INTERFACE type!") ); 713*cdf0e10cSrcweir } 714*cdf0e10cSrcweir 715*cdf0e10cSrcweir uno_Interface * pInterface = 0; 716*cdf0e10cSrcweir (*bridge->m_uno_env->getRegisteredInterface)( 717*cdf0e10cSrcweir bridge->m_uno_env, 718*cdf0e10cSrcweir (void **) &pInterface, that->m_oid.pData, 719*cdf0e10cSrcweir (typelib_InterfaceTypeDescription *)demanded_td.get() ); 720*cdf0e10cSrcweir 721*cdf0e10cSrcweir if (0 == pInterface) 722*cdf0e10cSrcweir { 723*cdf0e10cSrcweir JNI_info const * jni_info = bridge->m_jni_info; 724*cdf0e10cSrcweir JNI_guarded_context jni( 725*cdf0e10cSrcweir jni_info, 726*cdf0e10cSrcweir reinterpret_cast< ::jvmaccess::UnoVirtualMachine * >( 727*cdf0e10cSrcweir bridge->m_java_env->pContext ) ); 728*cdf0e10cSrcweir 729*cdf0e10cSrcweir JNI_interface_type_info const * info = 730*cdf0e10cSrcweir static_cast< JNI_interface_type_info const * >( 731*cdf0e10cSrcweir jni_info->get_type_info( jni, demanded_td.get() ) ); 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir jvalue args[ 2 ]; 734*cdf0e10cSrcweir args[ 0 ].l = info->m_type; 735*cdf0e10cSrcweir args[ 1 ].l = that->m_javaI; 736*cdf0e10cSrcweir 737*cdf0e10cSrcweir JLocalAutoRef jo_ret( 738*cdf0e10cSrcweir jni, jni->CallStaticObjectMethodA( 739*cdf0e10cSrcweir jni_info->m_class_UnoRuntime, 740*cdf0e10cSrcweir jni_info->m_method_UnoRuntime_queryInterface, 741*cdf0e10cSrcweir args ) ); 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir if (jni->ExceptionCheck()) 744*cdf0e10cSrcweir { 745*cdf0e10cSrcweir JLocalAutoRef jo_exc( jni, jni->ExceptionOccurred() ); 746*cdf0e10cSrcweir jni->ExceptionClear(); 747*cdf0e10cSrcweir bridge->handle_java_exc( jni, jo_exc, *uno_exc ); 748*cdf0e10cSrcweir } 749*cdf0e10cSrcweir else 750*cdf0e10cSrcweir { 751*cdf0e10cSrcweir if (jo_ret.is()) 752*cdf0e10cSrcweir { 753*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 754*cdf0e10cSrcweir JLocalAutoRef jo_oid( 755*cdf0e10cSrcweir jni, compute_oid( jni, jo_ret.get() ) ); 756*cdf0e10cSrcweir OUString oid( jstring_to_oustring( 757*cdf0e10cSrcweir jni, (jstring) jo_oid.get() ) ); 758*cdf0e10cSrcweir OSL_ENSURE( 759*cdf0e10cSrcweir oid.equals( that->m_oid ), 760*cdf0e10cSrcweir "### different oids!" ); 761*cdf0e10cSrcweir #endif 762*cdf0e10cSrcweir // refcount initially 1 763*cdf0e10cSrcweir uno_Interface * pUnoI2 = new UNO_proxy( 764*cdf0e10cSrcweir jni, bridge, jo_ret.get(), 765*cdf0e10cSrcweir that->m_jo_oid, that->m_oid, info ); 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir (*bridge->m_uno_env->registerProxyInterface)( 768*cdf0e10cSrcweir bridge->m_uno_env, 769*cdf0e10cSrcweir (void **) &pUnoI2, 770*cdf0e10cSrcweir UNO_proxy_free, that->m_oid.pData, 771*cdf0e10cSrcweir reinterpret_cast< 772*cdf0e10cSrcweir typelib_InterfaceTypeDescription * >( 773*cdf0e10cSrcweir info->m_td.get() ) ); 774*cdf0e10cSrcweir 775*cdf0e10cSrcweir uno_any_construct( 776*cdf0e10cSrcweir (uno_Any *)uno_ret, &pUnoI2, 777*cdf0e10cSrcweir demanded_td.get(), 0 ); 778*cdf0e10cSrcweir (*pUnoI2->release)( pUnoI2 ); 779*cdf0e10cSrcweir } 780*cdf0e10cSrcweir else // object does not support demanded interface 781*cdf0e10cSrcweir { 782*cdf0e10cSrcweir uno_any_construct( 783*cdf0e10cSrcweir reinterpret_cast< uno_Any * >( uno_ret ), 784*cdf0e10cSrcweir 0, 0, 0 ); 785*cdf0e10cSrcweir } 786*cdf0e10cSrcweir // no exception occured 787*cdf0e10cSrcweir *uno_exc = 0; 788*cdf0e10cSrcweir } 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir else 791*cdf0e10cSrcweir { 792*cdf0e10cSrcweir uno_any_construct( 793*cdf0e10cSrcweir reinterpret_cast< uno_Any * >( uno_ret ), 794*cdf0e10cSrcweir &pInterface, demanded_td.get(), 0 ); 795*cdf0e10cSrcweir (*pInterface->release)( pInterface ); 796*cdf0e10cSrcweir *uno_exc = 0; 797*cdf0e10cSrcweir } 798*cdf0e10cSrcweir break; 799*cdf0e10cSrcweir } 800*cdf0e10cSrcweir case 1: // acquire this proxy 801*cdf0e10cSrcweir that->acquire(); 802*cdf0e10cSrcweir *uno_exc = 0; 803*cdf0e10cSrcweir break; 804*cdf0e10cSrcweir case 2: // release this proxy 805*cdf0e10cSrcweir that->release(); 806*cdf0e10cSrcweir *uno_exc = 0; 807*cdf0e10cSrcweir break; 808*cdf0e10cSrcweir default: // arbitrary method call 809*cdf0e10cSrcweir bridge->call_java( 810*cdf0e10cSrcweir that->m_javaI, iface_td, method_td->nIndex, 0, 811*cdf0e10cSrcweir method_td->pReturnTypeRef, 812*cdf0e10cSrcweir method_td->pParams, method_td->nParams, 813*cdf0e10cSrcweir uno_ret, uno_args, uno_exc ); 814*cdf0e10cSrcweir break; 815*cdf0e10cSrcweir } 816*cdf0e10cSrcweir break; 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir default: 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir throw BridgeRuntimeError( 821*cdf0e10cSrcweir OUSTR("illegal member type description!") ); 822*cdf0e10cSrcweir } 823*cdf0e10cSrcweir } 824*cdf0e10cSrcweir } 825*cdf0e10cSrcweir catch (BridgeRuntimeError & err) 826*cdf0e10cSrcweir { 827*cdf0e10cSrcweir OUStringBuffer buf( 128 ); 828*cdf0e10cSrcweir buf.appendAscii( 829*cdf0e10cSrcweir RTL_CONSTASCII_STRINGPARAM( 830*cdf0e10cSrcweir "[jni_uno bridge error] UNO calling Java method ") ); 831*cdf0e10cSrcweir if (typelib_TypeClass_INTERFACE_METHOD == member_td->eTypeClass || 832*cdf0e10cSrcweir typelib_TypeClass_INTERFACE_ATTRIBUTE == member_td->eTypeClass) 833*cdf0e10cSrcweir { 834*cdf0e10cSrcweir buf.append( OUString::unacquired( 835*cdf0e10cSrcweir &reinterpret_cast< 836*cdf0e10cSrcweir typelib_InterfaceMemberTypeDescription const * >( 837*cdf0e10cSrcweir member_td )->pMemberName ) ); 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir buf.appendAscii( RTL_CONSTASCII_STRINGPARAM(": ") ); 840*cdf0e10cSrcweir buf.append( err.m_message ); 841*cdf0e10cSrcweir // binary identical struct 842*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException exc( 843*cdf0e10cSrcweir buf.makeStringAndClear(), 844*cdf0e10cSrcweir ::com::sun::star::uno::Reference< 845*cdf0e10cSrcweir ::com::sun::star::uno::XInterface >() ); 846*cdf0e10cSrcweir ::com::sun::star::uno::Type const & exc_type = ::getCppuType( &exc ); 847*cdf0e10cSrcweir uno_type_any_construct( *uno_exc, &exc, exc_type.getTypeLibType(), 0 ); 848*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 849*cdf0e10cSrcweir OString cstr_msg2( 850*cdf0e10cSrcweir OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); 851*cdf0e10cSrcweir OSL_TRACE( "%s", cstr_msg2.getStr() ); 852*cdf0e10cSrcweir #endif 853*cdf0e10cSrcweir } 854*cdf0e10cSrcweir catch (::jvmaccess::VirtualMachine::AttachGuard::CreationException &) 855*cdf0e10cSrcweir { 856*cdf0e10cSrcweir // binary identical struct 857*cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException exc( 858*cdf0e10cSrcweir OUSTR("[jni_uno bridge error] attaching current thread " 859*cdf0e10cSrcweir "to java failed!"), 860*cdf0e10cSrcweir ::com::sun::star::uno::Reference< 861*cdf0e10cSrcweir ::com::sun::star::uno::XInterface >() ); 862*cdf0e10cSrcweir ::com::sun::star::uno::Type const & exc_type = ::getCppuType( &exc ); 863*cdf0e10cSrcweir uno_type_any_construct( *uno_exc, &exc, exc_type.getTypeLibType(), 0 ); 864*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 865*cdf0e10cSrcweir OString cstr_msg2( 866*cdf0e10cSrcweir OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); 867*cdf0e10cSrcweir OSL_ENSURE( 0, cstr_msg2.getStr() ); 868*cdf0e10cSrcweir #endif 869*cdf0e10cSrcweir } 870*cdf0e10cSrcweir } 871*cdf0e10cSrcweir 872*cdf0e10cSrcweir } 873*cdf0e10cSrcweir } 874