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_CLI_BRIDGE_H
25 #define INCLUDED_CLI_BRIDGE_H
26 #include <vcclr.h>
27 #include "osl/interlck.h"
28 #include "uno/mapping.h"
29 #include "uno/environment.h"
30 #include "uno/dispatcher.h"
31 #include "cli_base.h"
32 #include "cli_environment.h"
33 #using <mscorlib.dll>
34 //#using <cli_uretypes.dll>
35 #using <cli_basetypes.dll>
36 #using <system.dll>
37 
38 namespace sr = System::Reflection;
39 
40 namespace cli_uno
41 {
42 
43 
44 //==== holds environments and mappings =============================================================
45 struct Bridge;
46 struct Mapping : public uno_Mapping
47 {
48     Bridge* m_bridge;
49 };
50 
51 // The environment will be created in uno_initEnvironment. See also the remarks there
52 //Managed cli environment for cli objects an UNO proxies (which are cli
53 //objects. The uno_Environment is not used for cli objects.
54 __gc struct CliEnvHolder {
55 static Cli_environment * g_cli_env = NULL;
56 };
57 
58 //==================================================================================================
59 /** An instance of Bridge represents exactly one mapping therefore either
60     m_cli2uno or m_uno2cli is valid.
61 */
62 struct Bridge
63 {
64     mutable oslInterlockedCount m_ref;
65     uno_ExtEnvironment *        m_uno_env;
66     uno_Environment *           m_uno_cli_env;
67 
68     Mapping                     m_cli2uno;
69     Mapping                     m_uno2cli;
70     bool                        m_registered_cli2uno;
71 
72     ~Bridge() SAL_THROW( () );
73     Bridge( uno_Environment * java_env, uno_ExtEnvironment * uno_env, bool registered_java2uno );
74 
75     void acquire() const;
76     void release() const;
77 
78     void  map_to_uno(
79         void * uno_data, System::Object* cli_data,
80         typelib_TypeDescriptionReference * type,
81         bool assign) const;
82 
83     /**
84        @param info
85        the type of the converted data. It may be a byref type.
86      */
87     void map_to_cli(
88         System::Object* *cli_data, void const * uno_data,
89         typelib_TypeDescriptionReference * type, System::Type* info /* maybe 0 */,
90         bool bDontCreateObj) const;
91 
92     System::Object* map_uno2cli(uno_Interface * pUnoI, typelib_InterfaceTypeDescription* pTD) const;
93 
94     System::Object* Bridge::call_uno(uno_Interface * pUnoI,
95                       typelib_TypeDescription* member_td,
96                       typelib_TypeDescriptionReference * return_type,
97                       sal_Int32 nParams, typelib_MethodParameter const * pParams,
98                       System::Object * args[], System::Type* argTypes[],
99                       System::Object** pException) const;
100 
101 
102     void call_cli(
103         System::Object* cliI, sr::MethodInfo* method,
104         typelib_TypeDescriptionReference * return_type,
105         typelib_MethodParameter * params, int nParams,
106         void * uno_ret, void * uno_args [], uno_Any ** uno_exc ) const;
107 
108     uno_Interface * map_cli2uno(
109         System::Object* cliI, typelib_TypeDescription* pTD) const;
110 
111 };
112 
113 } //namespace cli_uno
114 
115 
116 #endif
117