Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / bridges / source / jni_uno / jni_uno2java.cxx
blob98666dfc1929ef002c1c375108f68a15162422d9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
21 #include <sal/log.hxx>
23 #include <atomic>
24 #include <cassert>
25 #include <cstddef>
26 #include <memory>
28 #include <sal/alloca.h>
30 #include <com/sun/star/uno/RuntimeException.hpp>
32 #include <rtl/ustrbuf.hxx>
33 #include <utility>
35 #include "jni_bridge.h"
36 #include "jniunoenvironmentdata.hxx"
38 namespace
40 extern "C"
44 void UNO_proxy_free( uno_ExtEnvironment * env, void * proxy )
45 SAL_THROW_EXTERN_C();
48 void UNO_proxy_acquire( uno_Interface * pUnoI )
49 SAL_THROW_EXTERN_C();
52 void UNO_proxy_release( uno_Interface * pUnoI )
53 SAL_THROW_EXTERN_C();
56 void UNO_proxy_dispatch(
57 uno_Interface * pUnoI, typelib_TypeDescription const * member_td,
58 void * uno_ret, void * uno_args[], uno_Any ** uno_exc )
59 SAL_THROW_EXTERN_C();
63 namespace jni_uno
67 void Bridge::handle_java_exc(
68 JNI_context const & jni,
69 JLocalAutoRef const & jo_exc, uno_Any * uno_exc ) const
71 assert( jo_exc.is() );
72 if (! jo_exc.is())
74 throw BridgeRuntimeError(
75 "java exception occurred, but no java exception available!?" +
76 jni.get_stack_trace() );
79 JLocalAutoRef jo_class( jni, jni->GetObjectClass( jo_exc.get() ) );
80 JLocalAutoRef jo_class_name(
81 jni, jni->CallObjectMethodA(
82 jo_class.get(), getJniInfo()->m_method_Class_getName, nullptr ) );
83 jni.ensure_no_exception();
84 OUString exc_name(
85 jstring_to_oustring( jni, static_cast<jstring>(jo_class_name.get()) ) );
87 css::uno::TypeDescription td( exc_name.pData );
88 if (!td.is() || (td.get()->eTypeClass != typelib_TypeClass_EXCEPTION))
90 // call toString()
91 JLocalAutoRef jo_descr(
92 jni, jni->CallObjectMethodA(
93 jo_exc.get(), getJniInfo()->m_method_Object_toString, nullptr ) );
94 jni.ensure_no_exception();
95 throw BridgeRuntimeError(
96 "non-UNO exception occurred: "
97 + jstring_to_oustring( jni, static_cast<jstring>(jo_descr.get()) )
98 + jni.get_stack_trace( jo_exc.get() ) );
101 std::unique_ptr< rtl_mem > uno_data( rtl_mem::allocate( td.get()->nSize ) );
102 jvalue val;
103 val.l = jo_exc.get();
104 map_to_uno(
105 jni, uno_data.get(), val, td.get()->pWeakRef, nullptr,
106 false /* no assign */, false /* no out param */ );
108 #if OSL_DEBUG_LEVEL > 0
109 // patch Message, append stack trace
110 reinterpret_cast< css::uno::Exception * >(
111 uno_data.get() )->Message += jni.get_stack_trace( jo_exc.get() );
112 #endif
114 typelib_typedescriptionreference_acquire( td.get()->pWeakRef );
115 uno_exc->pType = td.get()->pWeakRef;
116 uno_exc->pData = uno_data.release();
118 SAL_INFO(
119 "bridges",
120 "exception occurred uno->java: [" << exc_name << "] "
121 << (static_cast<css::uno::Exception const *>(uno_exc->pData)
122 ->Message));
126 void Bridge::call_java(
127 jobject javaI, typelib_InterfaceTypeDescription * iface_td,
128 sal_Int32 local_member_index, sal_Int32 function_pos_offset,
129 typelib_TypeDescriptionReference * return_type,
130 typelib_MethodParameter * params, sal_Int32 nParams,
131 void * uno_ret, void * uno_args [], uno_Any ** uno_exc ) const
133 assert( function_pos_offset == 0 || function_pos_offset == 1 );
135 JNI_guarded_context jni(
136 getJniInfo(),
137 static_cast<JniUnoEnvironmentData *>(m_java_env->pContext)->machine);
139 // assure fully initialized iface_td:
140 css::uno::TypeDescription iface_holder;
141 if (! iface_td->aBase.bComplete) {
142 iface_holder = css::uno::TypeDescription(
143 reinterpret_cast<typelib_TypeDescription *>(iface_td) );
144 iface_holder.makeComplete();
145 if (! iface_holder.get()->bComplete) {
146 throw BridgeRuntimeError(
147 "cannot make type complete: "
148 + OUString::unacquired(&iface_holder.get()->pTypeName)
149 + jni.get_stack_trace() );
151 iface_td = reinterpret_cast<typelib_InterfaceTypeDescription *>(
152 iface_holder.get() );
153 assert( iface_td->aBase.eTypeClass == typelib_TypeClass_INTERFACE );
156 // prepare java args, save param td
157 jvalue * java_args = static_cast<jvalue *>(alloca( sizeof (jvalue) * nParams ));
159 sal_Int32 nPos;
160 for ( nPos = 0; nPos < nParams; ++nPos )
164 typelib_MethodParameter const & param = params[ nPos ];
165 java_args[ nPos ].l = nullptr; // if out: build up array[ 1 ]
166 map_to_java(
167 jni, &java_args[ nPos ],
168 uno_args[ nPos ],
169 param.pTypeRef, nullptr,
170 param.bIn /* convert uno value */,
171 param.bOut /* build up array[ 1 ] */ );
173 catch (...)
175 // cleanup
176 for ( sal_Int32 n = 0; n < nPos; ++n )
178 typelib_MethodParameter const & param = params[ n ];
179 if (param.bOut ||
180 typelib_TypeClass_DOUBLE < param.pTypeRef->eTypeClass)
182 jni->DeleteLocalRef( java_args[ n ].l );
185 throw;
189 sal_Int32 base_members = iface_td->nAllMembers - iface_td->nMembers;
190 assert( base_members < iface_td->nAllMembers );
191 sal_Int32 base_members_function_pos =
192 iface_td->pMapMemberIndexToFunctionIndex[ base_members ];
193 sal_Int32 member_pos = base_members + local_member_index;
194 SAL_WARN_IF(
195 member_pos >= iface_td->nAllMembers, "bridges",
196 "member pos out of range");
197 sal_Int32 function_pos =
198 iface_td->pMapMemberIndexToFunctionIndex[ member_pos ]
199 + function_pos_offset;
200 SAL_WARN_IF(
201 (function_pos < base_members_function_pos
202 || function_pos >= iface_td->nMapFunctionIndexToMemberIndex),
203 "bridges", "illegal function index");
204 function_pos -= base_members_function_pos;
206 JNI_interface_type_info const * info =
207 static_cast< JNI_interface_type_info const * >(
208 getJniInfo()->get_type_info( jni, &iface_td->aBase ) );
209 jmethodID method_id = info->m_methods[ function_pos ];
211 #if OSL_DEBUG_LEVEL > 0
212 JLocalAutoRef jo_method(
213 jni, jni->ToReflectedMethod( info->m_class, method_id, JNI_FALSE ) );
214 jni.ensure_no_exception();
215 JLocalAutoRef jo_descr1(
216 jni, jni->CallObjectMethodA(
217 jo_method.get(), getJniInfo()->m_method_Object_toString, nullptr ) );
218 jni.ensure_no_exception();
219 JLocalAutoRef jo_descr2(
220 jni,
221 jni->CallObjectMethodA(
222 javaI, getJniInfo()->m_method_Object_toString, nullptr ) );
223 jni.ensure_no_exception();
224 JLocalAutoRef jo_class( jni, jni->GetObjectClass( javaI ) );
225 JLocalAutoRef jo_descr3(
226 jni,
227 jni->CallObjectMethodA(
228 jo_class.get(), getJniInfo()->m_method_Object_toString, nullptr ) );
229 jni.ensure_no_exception();
230 SAL_INFO(
231 "bridges",
232 "calling " << jstring_to_oustring( jni, static_cast<jstring>(jo_descr1.get()) ) << " on "
233 << jstring_to_oustring( jni, static_cast<jstring>(jo_descr2.get()) ) << " ("
234 << jstring_to_oustring( jni, static_cast<jstring>(jo_descr3.get()) ) << ")");
235 #endif
237 // complex return value
238 JLocalAutoRef java_ret( jni );
240 switch (return_type->eTypeClass)
242 case typelib_TypeClass_VOID:
243 jni->CallVoidMethodA( javaI, method_id, java_args );
244 break;
245 case typelib_TypeClass_CHAR:
246 *static_cast<sal_Unicode *>(uno_ret) =
247 jni->CallCharMethodA( javaI, method_id, java_args );
248 break;
249 case typelib_TypeClass_BOOLEAN:
250 *static_cast<sal_Bool *>(uno_ret) =
251 jni->CallBooleanMethodA( javaI, method_id, java_args );
252 break;
253 case typelib_TypeClass_BYTE:
254 *static_cast<sal_Int8 *>(uno_ret) =
255 jni->CallByteMethodA( javaI, method_id, java_args );
256 break;
257 case typelib_TypeClass_SHORT:
258 case typelib_TypeClass_UNSIGNED_SHORT:
259 *static_cast<sal_Int16 *>(uno_ret) =
260 jni->CallShortMethodA( javaI, method_id, java_args );
261 break;
262 case typelib_TypeClass_LONG:
263 case typelib_TypeClass_UNSIGNED_LONG:
264 *static_cast<sal_Int32 *>(uno_ret) =
265 jni->CallIntMethodA( javaI, method_id, java_args );
266 break;
267 case typelib_TypeClass_HYPER:
268 case typelib_TypeClass_UNSIGNED_HYPER:
269 *static_cast<sal_Int64 *>(uno_ret) =
270 jni->CallLongMethodA( javaI, method_id, java_args );
271 break;
272 case typelib_TypeClass_FLOAT:
273 *static_cast<float *>(uno_ret) =
274 jni->CallFloatMethodA( javaI, method_id, java_args );
275 break;
276 case typelib_TypeClass_DOUBLE:
277 *static_cast<double *>(uno_ret) =
278 jni->CallDoubleMethodA( javaI, method_id, java_args );
279 break;
280 default:
281 java_ret.reset(
282 jni->CallObjectMethodA( javaI, method_id, java_args ) );
283 break;
286 if (jni->ExceptionCheck())
288 JLocalAutoRef jo_exc( jni, jni->ExceptionOccurred() );
289 jni->ExceptionClear();
291 // release temp java local refs
292 for ( nPos = 0; nPos < nParams; ++nPos )
294 typelib_MethodParameter const & param = params[ nPos ];
295 if (param.bOut ||
296 typelib_TypeClass_DOUBLE < param.pTypeRef->eTypeClass)
298 jni->DeleteLocalRef( java_args[ nPos ].l );
302 handle_java_exc( jni, jo_exc, *uno_exc );
304 else // no exception
306 for ( nPos = 0; nPos < nParams; ++nPos )
308 typelib_MethodParameter const & param = params[ nPos ];
309 if (param.bOut)
313 map_to_uno(
314 jni, uno_args[ nPos ],
315 java_args[ nPos ], param.pTypeRef, nullptr,
316 param.bIn /* assign if inout */,
317 true /* out param */ );
319 catch (...)
321 // cleanup uno pure out
322 for ( sal_Int32 n = 0; n < nPos; ++n )
324 typelib_MethodParameter const & p = params[ n ];
325 if (! p.bIn)
327 uno_type_destructData(
328 uno_args[ n ], p.pTypeRef, nullptr );
331 // cleanup java temp local refs
332 for ( ; nPos < nParams; ++nPos )
334 typelib_MethodParameter const & p = params[ nPos ];
335 if (p.bOut ||
336 typelib_TypeClass_DOUBLE <
337 p.pTypeRef->eTypeClass)
339 jni->DeleteLocalRef( java_args[ nPos ].l );
342 throw;
344 jni->DeleteLocalRef( java_args[ nPos ].l );
346 else // pure temp in param
348 if (typelib_TypeClass_DOUBLE < param.pTypeRef->eTypeClass)
349 jni->DeleteLocalRef( java_args[ nPos ].l );
353 // return value
354 if (typelib_TypeClass_DOUBLE < return_type->eTypeClass)
358 jvalue val;
359 val.l = java_ret.get();
360 map_to_uno(
361 jni, uno_ret, val, return_type, nullptr,
362 false /* no assign */, false /* no out param */ );
364 catch (...)
366 // cleanup uno pure out
367 for ( sal_Int32 i = 0; i < nParams; ++i )
369 typelib_MethodParameter const & param = params[ i ];
370 if (! param.bIn)
372 uno_type_destructData(
373 uno_args[ i ], param.pTypeRef, nullptr );
376 throw;
378 } // else: already set integral uno return value
380 // no exception occurred
381 *uno_exc = nullptr;
385 namespace {
387 // a UNO proxy wrapping a Java interface
388 struct UNO_proxy : public uno_Interface
390 mutable std::atomic<std::size_t> m_ref;
391 Bridge const * m_bridge;
393 // mapping information
394 jobject m_javaI;
395 jstring m_jo_oid;
396 OUString m_oid;
397 JNI_interface_type_info const * m_type_info;
399 inline void acquire() const;
400 inline void release() const;
402 // ctor
403 inline UNO_proxy(
404 JNI_context const & jni, Bridge const * bridge,
405 jobject javaI, jstring jo_oid, OUString oid,
406 JNI_interface_type_info const * info );
411 inline UNO_proxy::UNO_proxy(
412 JNI_context const & jni, Bridge const * bridge,
413 jobject javaI, jstring jo_oid, OUString oid,
414 JNI_interface_type_info const * info )
415 : m_ref( 1 ),
416 m_oid(std::move( oid )),
417 m_type_info( info )
419 JNI_info const * jni_info = bridge->getJniInfo();
420 JLocalAutoRef jo_string_array(
421 jni, jni->NewObjectArray( 1, jni_info->m_class_String, jo_oid ) );
422 jni.ensure_no_exception();
423 jvalue args[ 3 ];
424 args[ 0 ].l = javaI;
425 args[ 1 ].l = jo_string_array.get();
426 args[ 2 ].l = info->m_type;
427 jobject jo_iface = jni->CallObjectMethodA(
428 jni_info->m_object_java_env,
429 jni_info->m_method_IEnvironment_registerInterface, args );
430 jni.ensure_no_exception();
432 m_javaI = jni->NewGlobalRef( jo_iface );
433 m_jo_oid = static_cast<jstring>(jni->NewGlobalRef( jo_oid ));
434 bridge->acquire();
435 m_bridge = bridge;
437 // uno_Interface
438 uno_Interface::acquire = UNO_proxy_acquire;
439 uno_Interface::release = UNO_proxy_release;
440 uno_Interface::pDispatcher = UNO_proxy_dispatch;
444 inline void UNO_proxy::acquire() const
446 if (++m_ref == 1)
448 // rebirth of proxy zombie
449 void * that = const_cast< UNO_proxy * >( this );
450 // register at uno env
451 (*m_bridge->m_uno_env->registerProxyInterface)(
452 m_bridge->m_uno_env, &that,
453 UNO_proxy_free, m_oid.pData,
454 reinterpret_cast<typelib_InterfaceTypeDescription *>(m_type_info->m_td.get()) );
455 assert( this == that );
460 inline void UNO_proxy::release() const
462 if (--m_ref == 0)
464 // revoke from uno env on last release
465 (*m_bridge->m_uno_env->revokeInterface)(
466 m_bridge->m_uno_env, const_cast< UNO_proxy * >( this ) );
471 uno_Interface * Bridge::map_to_uno(
472 JNI_context const & jni,
473 jobject javaI, JNI_interface_type_info const * info ) const
475 JLocalAutoRef jo_oid( jni, compute_oid( jni, javaI ) );
476 OUString oid( jstring_to_oustring( jni, static_cast<jstring>(jo_oid.get()) ) );
478 uno_Interface * pUnoI = nullptr;
479 (*m_uno_env->getRegisteredInterface)(
480 m_uno_env, reinterpret_cast<void **>(&pUnoI),
481 oid.pData, reinterpret_cast<typelib_InterfaceTypeDescription *>(info->m_td.get()) );
483 if (pUnoI == nullptr) // no existing interface, register new proxy
485 // refcount initially 1
486 pUnoI = new UNO_proxy(
487 jni, this,
488 javaI, static_cast<jstring>(jo_oid.get()), oid, info );
490 (*m_uno_env->registerProxyInterface)(
491 m_uno_env, reinterpret_cast<void **>(&pUnoI),
492 UNO_proxy_free,
493 oid.pData, reinterpret_cast<typelib_InterfaceTypeDescription *>(info->m_td.get()) );
495 return pUnoI;
500 using namespace ::jni_uno;
502 namespace
504 extern "C"
508 void UNO_proxy_free( uno_ExtEnvironment * env, void * proxy )
509 SAL_THROW_EXTERN_C()
511 UNO_proxy * that = static_cast< UNO_proxy * >( proxy );
512 Bridge const * bridge = that->m_bridge;
514 assert(env == bridge->m_uno_env); (void) env;
515 SAL_INFO("bridges", "freeing binary uno proxy: " << that->m_oid);
519 JNI_guarded_context jni(
520 bridge->getJniInfo(),
521 (static_cast<JniUnoEnvironmentData *>(bridge->m_java_env->pContext)
522 ->machine));
524 jni->DeleteGlobalRef( that->m_javaI );
525 jni->DeleteGlobalRef( that->m_jo_oid );
527 catch (BridgeRuntimeError & err)
529 SAL_WARN(
530 "bridges",
531 "ignoring BridgeRuntimeError \"" << err.m_message << "\"");
533 catch (::jvmaccess::VirtualMachine::AttachGuard::CreationException &)
535 SAL_WARN("bridges", "attaching current thread to java failed");
538 bridge->release();
539 #if OSL_DEBUG_LEVEL > 0
540 *reinterpret_cast<int *>(that) = 0xdeadcafe;
541 #endif
542 delete that;
546 void UNO_proxy_acquire( uno_Interface * pUnoI )
547 SAL_THROW_EXTERN_C()
549 UNO_proxy const * that = static_cast< UNO_proxy const * >( pUnoI );
550 that->acquire();
554 void UNO_proxy_release( uno_Interface * pUnoI )
555 SAL_THROW_EXTERN_C()
557 UNO_proxy const * that = static_cast< UNO_proxy const * >( pUnoI );
558 that->release();
562 void UNO_proxy_dispatch(
563 uno_Interface * pUnoI, typelib_TypeDescription const * member_td,
564 void * uno_ret, void * uno_args [], uno_Any ** uno_exc )
565 SAL_THROW_EXTERN_C()
567 UNO_proxy const * that = static_cast< UNO_proxy const * >( pUnoI );
568 Bridge const * bridge = that->m_bridge;
570 SAL_INFO(
571 "bridges",
572 "uno->java call: " << OUString::unacquired(&member_td->pTypeName)
573 << " on oid " << that->m_oid);
577 switch (member_td->eTypeClass)
579 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
581 typelib_InterfaceAttributeTypeDescription const * attrib_td =
582 reinterpret_cast<
583 typelib_InterfaceAttributeTypeDescription const * >(
584 member_td );
585 com::sun::star::uno::TypeDescription attrib_holder;
586 while ( attrib_td->pBaseRef != nullptr ) {
587 attrib_holder = com::sun::star::uno::TypeDescription(
588 attrib_td->pBaseRef );
589 assert(
590 attrib_holder.get()->eTypeClass
591 == typelib_TypeClass_INTERFACE_ATTRIBUTE );
592 attrib_td = reinterpret_cast<
593 typelib_InterfaceAttributeTypeDescription * >(
594 attrib_holder.get() );
596 typelib_InterfaceTypeDescription * iface_td = attrib_td->pInterface;
598 if (uno_ret == nullptr) // is setter method
600 typelib_MethodParameter param;
601 param.pTypeRef = attrib_td->pAttributeTypeRef;
602 param.bIn = true;
603 param.bOut = false;
605 bridge->call_java(
606 that->m_javaI, iface_td,
607 attrib_td->nIndex, 1, // get, then set method
608 bridge->getJniInfo()->m_void_type.getTypeLibType(),
609 &param, 1,
610 nullptr, uno_args, uno_exc );
612 else // is getter method
614 bridge->call_java(
615 that->m_javaI, iface_td, attrib_td->nIndex, 0,
616 attrib_td->pAttributeTypeRef,
617 nullptr, 0, // no params
618 uno_ret, nullptr, uno_exc );
620 break;
622 case typelib_TypeClass_INTERFACE_METHOD:
624 typelib_InterfaceMethodTypeDescription const * method_td =
625 reinterpret_cast<
626 typelib_InterfaceMethodTypeDescription const * >(
627 member_td );
628 com::sun::star::uno::TypeDescription method_holder;
629 while ( method_td->pBaseRef != nullptr ) {
630 method_holder = com::sun::star::uno::TypeDescription(
631 method_td->pBaseRef );
632 assert(
633 method_holder.get()->eTypeClass
634 == typelib_TypeClass_INTERFACE_METHOD );
635 method_td = reinterpret_cast<
636 typelib_InterfaceMethodTypeDescription * >(
637 method_holder.get() );
639 typelib_InterfaceTypeDescription * iface_td = method_td->pInterface;
641 switch ( method_td->aBase.nPosition )
643 case 0: // queryInterface()
645 TypeDescr demanded_td(
646 *static_cast< typelib_TypeDescriptionReference ** >(
647 uno_args[ 0 ] ) );
648 if (demanded_td.get()->eTypeClass !=
649 typelib_TypeClass_INTERFACE)
651 throw BridgeRuntimeError(
652 "queryInterface() call demands an INTERFACE type!" );
655 uno_Interface * pInterface = nullptr;
656 (*bridge->m_uno_env->getRegisteredInterface)(
657 bridge->m_uno_env,
658 reinterpret_cast<void **>(&pInterface), that->m_oid.pData,
659 reinterpret_cast<typelib_InterfaceTypeDescription *>(demanded_td.get()) );
661 if (pInterface == nullptr)
663 JNI_info const * jni_info = bridge->getJniInfo();
664 JNI_guarded_context jni(
665 jni_info,
666 (static_cast<JniUnoEnvironmentData *>(
667 bridge->m_java_env->pContext)
668 ->machine));
670 JNI_interface_type_info const * info =
671 static_cast< JNI_interface_type_info const * >(
672 jni_info->get_type_info( jni, demanded_td.get() ) );
674 jvalue args[ 2 ];
675 args[ 0 ].l = info->m_type;
676 args[ 1 ].l = that->m_javaI;
678 JLocalAutoRef jo_ret(
679 jni, jni->CallStaticObjectMethodA(
680 jni_info->m_class_UnoRuntime,
681 jni_info->m_method_UnoRuntime_queryInterface,
682 args ) );
684 if (jni->ExceptionCheck())
686 JLocalAutoRef jo_exc( jni, jni->ExceptionOccurred() );
687 jni->ExceptionClear();
688 bridge->handle_java_exc( jni, jo_exc, *uno_exc );
690 else
692 if (jo_ret.is())
694 SAL_WARN_IF(
695 (jstring_to_oustring(
696 jni,
697 static_cast<jstring>(
698 JLocalAutoRef(
699 jni, compute_oid(jni, jo_ret.get()))
700 .get()))
701 != that->m_oid),
702 "bridges", "different oids");
703 // refcount initially 1
704 uno_Interface * pUnoI2 = new UNO_proxy(
705 jni, bridge, jo_ret.get(),
706 that->m_jo_oid, that->m_oid, info );
708 (*bridge->m_uno_env->registerProxyInterface)(
709 bridge->m_uno_env,
710 reinterpret_cast<void **>(&pUnoI2),
711 UNO_proxy_free, that->m_oid.pData,
712 reinterpret_cast<
713 typelib_InterfaceTypeDescription * >(
714 info->m_td.get() ) );
716 uno_any_construct(
717 static_cast<uno_Any *>(uno_ret), &pUnoI2,
718 demanded_td.get(), nullptr );
719 (*pUnoI2->release)( pUnoI2 );
721 else // object does not support demanded interface
723 uno_any_construct(
724 static_cast< uno_Any * >( uno_ret ),
725 nullptr, nullptr, nullptr );
727 // no exception occurred
728 *uno_exc = nullptr;
731 else
733 uno_any_construct(
734 static_cast< uno_Any * >( uno_ret ),
735 &pInterface, demanded_td.get(), nullptr );
736 (*pInterface->release)( pInterface );
737 *uno_exc = nullptr;
739 break;
741 case 1: // acquire this proxy
742 that->acquire();
743 *uno_exc = nullptr;
744 break;
745 case 2: // release this proxy
746 that->release();
747 *uno_exc = nullptr;
748 break;
749 default: // arbitrary method call
750 bridge->call_java(
751 that->m_javaI, iface_td, method_td->nIndex, 0,
752 method_td->pReturnTypeRef,
753 method_td->pParams, method_td->nParams,
754 uno_ret, uno_args, uno_exc );
755 break;
757 break;
759 default:
761 throw BridgeRuntimeError(
762 "illegal member type description!" );
766 catch (BridgeRuntimeError & err)
768 OUStringBuffer buf( 128 );
769 buf.append( "[jni_uno bridge error] UNO calling Java method " );
770 if (member_td->eTypeClass == typelib_TypeClass_INTERFACE_METHOD ||
771 member_td->eTypeClass == typelib_TypeClass_INTERFACE_ATTRIBUTE)
773 buf.append( OUString::unacquired(
774 &reinterpret_cast<
775 typelib_InterfaceMemberTypeDescription const * >(
776 member_td )->pMemberName ) );
778 buf.append( ": " + err.m_message );
779 // binary identical struct
780 css::uno::RuntimeException exc(
781 buf.makeStringAndClear(),
782 css::uno::Reference<
783 css::uno::XInterface >() );
784 css::uno::Type const & exc_type = cppu::UnoType<decltype(exc)>::get();
785 uno_type_any_construct( *uno_exc, &exc, exc_type.getTypeLibType(), nullptr );
786 SAL_INFO("bridges", exc.Message);
788 catch (::jvmaccess::VirtualMachine::AttachGuard::CreationException &)
790 // binary identical struct
791 css::uno::RuntimeException exc(
792 "[jni_uno bridge error] attaching current thread to java failed!",
793 css::uno::Reference<
794 css::uno::XInterface >() );
795 css::uno::Type const & exc_type = cppu::UnoType<decltype(exc)>::get();
796 uno_type_any_construct( *uno_exc, &exc, exc_type.getTypeLibType(), nullptr );
797 SAL_WARN("bridges", exc.Message);
804 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */