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