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 #if ! defined INCLUDED_JNI_BRIDGE_H
29*cdf0e10cSrcweir #define INCLUDED_JNI_BRIDGE_H
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "jni_base.h"
32*cdf0e10cSrcweir #include "jni_info.h"
33*cdf0e10cSrcweir #include "jni_helper.h"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "osl/diagnose.h"
36*cdf0e10cSrcweir #include "osl/interlck.h"
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir #include "uno/mapping.h"
39*cdf0e10cSrcweir #include "uno/dispatcher.h"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir namespace jni_uno
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //==== holds environments and mappings =========================================
48*cdf0e10cSrcweir struct Bridge;
49*cdf0e10cSrcweir struct Mapping : public uno_Mapping
50*cdf0e10cSrcweir {
51*cdf0e10cSrcweir     Bridge * m_bridge;
52*cdf0e10cSrcweir };
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir //==============================================================================
55*cdf0e10cSrcweir struct Bridge
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir     mutable oslInterlockedCount m_ref;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     uno_ExtEnvironment *        m_uno_env;
60*cdf0e10cSrcweir     uno_Environment *           m_java_env;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir     Mapping                     m_java2uno;
63*cdf0e10cSrcweir     Mapping                     m_uno2java;
64*cdf0e10cSrcweir     bool                        m_registered_java2uno;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir     JNI_info const *            m_jni_info;
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     //
69*cdf0e10cSrcweir     ~Bridge() SAL_THROW( () );
70*cdf0e10cSrcweir     explicit Bridge(
71*cdf0e10cSrcweir         uno_Environment * java_env, uno_ExtEnvironment * uno_env,
72*cdf0e10cSrcweir         bool registered_java2uno );
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir     void acquire() const;
75*cdf0e10cSrcweir     void release() const;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir     // jni_data.cxx
78*cdf0e10cSrcweir     void map_to_uno(
79*cdf0e10cSrcweir         JNI_context const & jni,
80*cdf0e10cSrcweir         void * uno_data, jvalue java_data,
81*cdf0e10cSrcweir         typelib_TypeDescriptionReference * type,
82*cdf0e10cSrcweir         JNI_type_info const * info /* maybe 0 */,
83*cdf0e10cSrcweir         bool assign, bool out_param,
84*cdf0e10cSrcweir         bool special_wrapped_integral_types = false ) const;
85*cdf0e10cSrcweir     void map_to_java(
86*cdf0e10cSrcweir         JNI_context const & jni,
87*cdf0e10cSrcweir         jvalue * java_data, void const * uno_data,
88*cdf0e10cSrcweir         typelib_TypeDescriptionReference * type,
89*cdf0e10cSrcweir         JNI_type_info const * info /* maybe 0 */,
90*cdf0e10cSrcweir         bool in_param, bool out_param,
91*cdf0e10cSrcweir         bool special_wrapped_integral_types = false ) const;
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     // jni_uno2java.cxx
94*cdf0e10cSrcweir     void handle_uno_exc(
95*cdf0e10cSrcweir         JNI_context const & jni, uno_Any * uno_exc ) const;
96*cdf0e10cSrcweir     void call_java(
97*cdf0e10cSrcweir         jobject javaI,
98*cdf0e10cSrcweir         typelib_InterfaceTypeDescription * iface_td,
99*cdf0e10cSrcweir         sal_Int32 local_member_index, sal_Int32 function_pos_offset,
100*cdf0e10cSrcweir         typelib_TypeDescriptionReference * return_type,
101*cdf0e10cSrcweir         typelib_MethodParameter * params, sal_Int32 nParams,
102*cdf0e10cSrcweir         void * uno_ret, void * uno_args [], uno_Any ** uno_exc ) const;
103*cdf0e10cSrcweir     jobject map_to_java(
104*cdf0e10cSrcweir         JNI_context const & jni,
105*cdf0e10cSrcweir         uno_Interface * pUnoI, JNI_interface_type_info const * info ) const;
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     // jni_java2uno.cxx
108*cdf0e10cSrcweir     void handle_java_exc(
109*cdf0e10cSrcweir         JNI_context const & jni,
110*cdf0e10cSrcweir         JLocalAutoRef const & jo_exc, uno_Any * uno_exc ) const;
111*cdf0e10cSrcweir     jobject call_uno(
112*cdf0e10cSrcweir         JNI_context const & jni,
113*cdf0e10cSrcweir         uno_Interface * pUnoI, typelib_TypeDescription * member_td,
114*cdf0e10cSrcweir         typelib_TypeDescriptionReference * return_tdref,
115*cdf0e10cSrcweir         sal_Int32 nParams, typelib_MethodParameter const * pParams,
116*cdf0e10cSrcweir         jobjectArray jo_args ) const;
117*cdf0e10cSrcweir     uno_Interface * map_to_uno(
118*cdf0e10cSrcweir         JNI_context const & jni,
119*cdf0e10cSrcweir         jobject javaI, JNI_interface_type_info const * info ) const;
120*cdf0e10cSrcweir };
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir #endif
125