1*9eab2a37SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9eab2a37SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9eab2a37SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9eab2a37SAndrew Rist  * distributed with this work for additional information
6*9eab2a37SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9eab2a37SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9eab2a37SAndrew Rist  * "License"); you may not use this file except in compliance
9*9eab2a37SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9eab2a37SAndrew Rist  *
11*9eab2a37SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9eab2a37SAndrew Rist  *
13*9eab2a37SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9eab2a37SAndrew Rist  * software distributed under the License is distributed on an
15*9eab2a37SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9eab2a37SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9eab2a37SAndrew Rist  * specific language governing permissions and limitations
18*9eab2a37SAndrew Rist  * under the License.
19*9eab2a37SAndrew Rist  *
20*9eab2a37SAndrew Rist  *************************************************************/
21*9eab2a37SAndrew Rist 
22*9eab2a37SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #if ! defined INCLUDED_JNI_BRIDGE_H
25cdf0e10cSrcweir #define INCLUDED_JNI_BRIDGE_H
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "jni_base.h"
28cdf0e10cSrcweir #include "jni_info.h"
29cdf0e10cSrcweir #include "jni_helper.h"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "osl/diagnose.h"
32cdf0e10cSrcweir #include "osl/interlck.h"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "uno/mapping.h"
35cdf0e10cSrcweir #include "uno/dispatcher.h"
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace jni_uno
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //==== holds environments and mappings =========================================
44cdf0e10cSrcweir struct Bridge;
45cdf0e10cSrcweir struct Mapping : public uno_Mapping
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     Bridge * m_bridge;
48cdf0e10cSrcweir };
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //==============================================================================
51cdf0e10cSrcweir struct Bridge
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     mutable oslInterlockedCount m_ref;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     uno_ExtEnvironment *        m_uno_env;
56cdf0e10cSrcweir     uno_Environment *           m_java_env;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     Mapping                     m_java2uno;
59cdf0e10cSrcweir     Mapping                     m_uno2java;
60cdf0e10cSrcweir     bool                        m_registered_java2uno;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     JNI_info const *            m_jni_info;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     //
65cdf0e10cSrcweir     ~Bridge() SAL_THROW( () );
66cdf0e10cSrcweir     explicit Bridge(
67cdf0e10cSrcweir         uno_Environment * java_env, uno_ExtEnvironment * uno_env,
68cdf0e10cSrcweir         bool registered_java2uno );
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     void acquire() const;
71cdf0e10cSrcweir     void release() const;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     // jni_data.cxx
74cdf0e10cSrcweir     void map_to_uno(
75cdf0e10cSrcweir         JNI_context const & jni,
76cdf0e10cSrcweir         void * uno_data, jvalue java_data,
77cdf0e10cSrcweir         typelib_TypeDescriptionReference * type,
78cdf0e10cSrcweir         JNI_type_info const * info /* maybe 0 */,
79cdf0e10cSrcweir         bool assign, bool out_param,
80cdf0e10cSrcweir         bool special_wrapped_integral_types = false ) const;
81cdf0e10cSrcweir     void map_to_java(
82cdf0e10cSrcweir         JNI_context const & jni,
83cdf0e10cSrcweir         jvalue * java_data, void const * uno_data,
84cdf0e10cSrcweir         typelib_TypeDescriptionReference * type,
85cdf0e10cSrcweir         JNI_type_info const * info /* maybe 0 */,
86cdf0e10cSrcweir         bool in_param, bool out_param,
87cdf0e10cSrcweir         bool special_wrapped_integral_types = false ) const;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     // jni_uno2java.cxx
90cdf0e10cSrcweir     void handle_uno_exc(
91cdf0e10cSrcweir         JNI_context const & jni, uno_Any * uno_exc ) const;
92cdf0e10cSrcweir     void call_java(
93cdf0e10cSrcweir         jobject javaI,
94cdf0e10cSrcweir         typelib_InterfaceTypeDescription * iface_td,
95cdf0e10cSrcweir         sal_Int32 local_member_index, sal_Int32 function_pos_offset,
96cdf0e10cSrcweir         typelib_TypeDescriptionReference * return_type,
97cdf0e10cSrcweir         typelib_MethodParameter * params, sal_Int32 nParams,
98cdf0e10cSrcweir         void * uno_ret, void * uno_args [], uno_Any ** uno_exc ) const;
99cdf0e10cSrcweir     jobject map_to_java(
100cdf0e10cSrcweir         JNI_context const & jni,
101cdf0e10cSrcweir         uno_Interface * pUnoI, JNI_interface_type_info const * info ) const;
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     // jni_java2uno.cxx
104cdf0e10cSrcweir     void handle_java_exc(
105cdf0e10cSrcweir         JNI_context const & jni,
106cdf0e10cSrcweir         JLocalAutoRef const & jo_exc, uno_Any * uno_exc ) const;
107cdf0e10cSrcweir     jobject call_uno(
108cdf0e10cSrcweir         JNI_context const & jni,
109cdf0e10cSrcweir         uno_Interface * pUnoI, typelib_TypeDescription * member_td,
110cdf0e10cSrcweir         typelib_TypeDescriptionReference * return_tdref,
111cdf0e10cSrcweir         sal_Int32 nParams, typelib_MethodParameter const * pParams,
112cdf0e10cSrcweir         jobjectArray jo_args ) const;
113cdf0e10cSrcweir     uno_Interface * map_to_uno(
114cdf0e10cSrcweir         JNI_context const & jni,
115cdf0e10cSrcweir         jobject javaI, JNI_interface_type_info const * info ) const;
116cdf0e10cSrcweir };
117cdf0e10cSrcweir 
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir #endif
121