xref: /trunk/main/bridges/source/jni_uno/jni_bridge.h (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #if ! defined INCLUDED_JNI_BRIDGE_H
29 #define INCLUDED_JNI_BRIDGE_H
30 
31 #include "jni_base.h"
32 #include "jni_info.h"
33 #include "jni_helper.h"
34 
35 #include "osl/diagnose.h"
36 #include "osl/interlck.h"
37 
38 #include "uno/mapping.h"
39 #include "uno/dispatcher.h"
40 
41 #include "com/sun/star/uno/XInterface.hpp"
42 
43 
44 namespace jni_uno
45 {
46 
47 //==== holds environments and mappings =========================================
48 struct Bridge;
49 struct Mapping : public uno_Mapping
50 {
51     Bridge * m_bridge;
52 };
53 
54 //==============================================================================
55 struct Bridge
56 {
57     mutable oslInterlockedCount m_ref;
58 
59     uno_ExtEnvironment *        m_uno_env;
60     uno_Environment *           m_java_env;
61 
62     Mapping                     m_java2uno;
63     Mapping                     m_uno2java;
64     bool                        m_registered_java2uno;
65 
66     JNI_info const *            m_jni_info;
67 
68     //
69     ~Bridge() SAL_THROW( () );
70     explicit Bridge(
71         uno_Environment * java_env, uno_ExtEnvironment * uno_env,
72         bool registered_java2uno );
73 
74     void acquire() const;
75     void release() const;
76 
77     // jni_data.cxx
78     void map_to_uno(
79         JNI_context const & jni,
80         void * uno_data, jvalue java_data,
81         typelib_TypeDescriptionReference * type,
82         JNI_type_info const * info /* maybe 0 */,
83         bool assign, bool out_param,
84         bool special_wrapped_integral_types = false ) const;
85     void map_to_java(
86         JNI_context const & jni,
87         jvalue * java_data, void const * uno_data,
88         typelib_TypeDescriptionReference * type,
89         JNI_type_info const * info /* maybe 0 */,
90         bool in_param, bool out_param,
91         bool special_wrapped_integral_types = false ) const;
92 
93     // jni_uno2java.cxx
94     void handle_uno_exc(
95         JNI_context const & jni, uno_Any * uno_exc ) const;
96     void call_java(
97         jobject javaI,
98         typelib_InterfaceTypeDescription * iface_td,
99         sal_Int32 local_member_index, sal_Int32 function_pos_offset,
100         typelib_TypeDescriptionReference * return_type,
101         typelib_MethodParameter * params, sal_Int32 nParams,
102         void * uno_ret, void * uno_args [], uno_Any ** uno_exc ) const;
103     jobject map_to_java(
104         JNI_context const & jni,
105         uno_Interface * pUnoI, JNI_interface_type_info const * info ) const;
106 
107     // jni_java2uno.cxx
108     void handle_java_exc(
109         JNI_context const & jni,
110         JLocalAutoRef const & jo_exc, uno_Any * uno_exc ) const;
111     jobject call_uno(
112         JNI_context const & jni,
113         uno_Interface * pUnoI, typelib_TypeDescription * member_td,
114         typelib_TypeDescriptionReference * return_tdref,
115         sal_Int32 nParams, typelib_MethodParameter const * pParams,
116         jobjectArray jo_args ) const;
117     uno_Interface * map_to_uno(
118         JNI_context const & jni,
119         jobject javaI, JNI_interface_type_info const * info ) const;
120 };
121 
122 }
123 
124 #endif
125