update dev300-m58
[ooovba.git] / cli_ure / source / uno_bridge / cli_proxy.h
blobaa1e4422ef9a4df604ecf6adf4ad4027f535e48d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cli_proxy.h,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_CLI_PROXY_H
32 #define INCLUDED_CLI_PROXY_H
34 #pragma warning(push, 1)
35 #include "uno/environment.hxx"
36 #pragma warning(pop)
37 #include "uno/mapping.hxx"
38 #include "uno/dispatcher.h"
39 #include "cli_bridge.h"
40 #include "cli_environment.h"
42 #using <mscorlib.dll>
43 #using <cli_ure.dll>
45 namespace srrp = System::Runtime::Remoting::Proxies;
46 namespace srrm = System::Runtime::Remoting::Messaging;
47 namespace srr = System::Runtime::Remoting;
48 namespace sr = System::Reflection;
49 namespace sc = System::Collections;
50 using namespace uno;
52 namespace cli_uno
55 public __gc class UnoInterfaceInfo
57 public:
58 UnoInterfaceInfo(Bridge const * bridge, uno_Interface* unoI,
59 typelib_InterfaceTypeDescription* td);
60 ~UnoInterfaceInfo();
61 uno_Interface * m_unoI; // wrapped interface
62 System::Type * m_type;
63 typelib_InterfaceTypeDescription* m_typeDesc;
65 Bridge const* m_bridge;
68 public __gc class UnoInterfaceProxy: public srrp::RealProxy,
69 public srr::IRemotingTypeInfo
71 /** used for IRemotingTypeInfo.TypeName
73 System::String* m_sTypeName;
74 /** The list is filled with UnoInterfaceInfo objects. The list can only
75 grow and elements are never changed. If an element was added it
76 must not be changed!
78 sc::ArrayList* m_listIfaces;
79 /** The number of UNO interfaces this proxy represents. It corresponds
80 to the the number of elements in m_listIfaces.
81 */
82 int m_numUnoIfaces;
83 /** The list is filled with additional UnoInterfaceProxy object due
84 to aggregation via bridges. Though the latter is strongly
85 discouraged, this has to be supported.
87 sc::ArrayList* m_listAdditionalProxies;
88 int m_nlistAdditionalProxies;
90 UnoInterfaceInfo * findInfo( ::System::Type * type );
92 Bridge const* m_bridge;
93 System::String* m_oid;
95 #if OSL_DEBUG_LEVEL >= 2
96 /** The string contains all names of UNO interfaces which are
97 represented by this proxy. It is used to print out the interfaces
98 when this proxy dies. In the destructor it is not allowed to
99 access m_listIfaces or any other managed object.
101 rtl_uString * _sInterfaces;
102 // /** Count of interfaces. Used in conjunction with _sInterfaces.
103 // */
104 int _numInterfaces;
105 #endif
107 public:
109 /** Creates a proxy and registers it on the dot NET side.
111 static System::Object* create(Bridge * bridge,
112 uno_Interface * pUnoI,
113 typelib_InterfaceTypeDescription* pTd,
114 const rtl::OUString& oid);
116 /** RealProxy::Invoke */
117 srrm::IMessage* Invoke(srrm::IMessage* msg);
119 /** Must be called from within a synchronized section.
120 Add only the interface if it is not already contained.
121 This method is called from the constructor and as a result
122 of IRemotingTypeInfo::CanCastTo
124 void addUnoInterface(uno_Interface* pUnoI,
125 typelib_InterfaceTypeDescription* pTd);
126 ~UnoInterfaceProxy();
130 inline System::String * getOid()
131 { return m_oid; }
133 //IRemotingTypeInfo ----------------------------------------------
134 bool CanCastTo(System::Type* fromType, System::Object* o);
136 __property System::String* get_TypeName()
138 return m_sTypeName;
140 __property void set_TypeName(System::String* name)
142 m_sTypeName = name;
146 private:
147 UnoInterfaceProxy(
148 Bridge * bridge,
149 uno_Interface * pUnoI,
150 typelib_InterfaceTypeDescription* pTD,
151 const rtl::OUString& oid );
153 static srrm::IMessage* constructReturnMessage(System::Object* retVal,
154 System::Object* outArgs[],
155 typelib_InterfaceMethodTypeDescription* mtd,
156 srrm::IMessage* msg, System::Object* exc);
158 static System::String* m_methodNameString =
159 new System::String("__MethodName");
160 static System::String* m_typeNameString = new System::String("__TypeName");
161 static System::String* m_ArgsString = new System::String("__Args");
162 static System::String* m_CallContextString =
163 new System::String("__CallContext");
164 static System::String* m_system_Object_String =
165 new System::String("System.Object");
166 static System::String* m_methodSignatureString =
167 new System::String("__MethodSignature");
168 static System::String* m_Equals_String = new System::String("Equals");
169 static System::String* m_GetHashCode_String =
170 new System::String("GetHashCode");
171 static System::String* m_GetType_String = new System::String("GetType");
172 static System::String* m_ToString_String = new System::String("ToString");
174 protected:
175 srrm::IMessage* invokeObject(sc::IDictionary* properties,
176 srrm::LogicalCallContext* context,
177 srrm::IMethodCallMessage* mcm);
181 //Cannot make this __gc because a managed type cannot derive from unmanaged type
182 struct CliProxy: public uno_Interface
184 mutable oslInterlockedCount m_ref;
185 const Bridge* m_bridge;
186 const gcroot<System::Object*> m_cliI;
187 gcroot<System::Type*> m_type;
188 const com::sun::star::uno::TypeDescription m_unoType;
189 const gcroot<System::String*> m_oid;
190 const rtl::OUString m_usOid;
192 enum MethodKind {MK_METHOD = 0, MK_SET, MK_GET};
193 /** The array contains MethodInfos of the cli object. Each one reflects an
194 implemented interface method of the interface for which this proxy was
195 created. The MethodInfos are from the object's method and not from the
196 interface type. That is, they can be used to invoke the methods. The
197 order of the MethodInfo objects corresponds to the order of the
198 interface methods (see member m_type). Position 0 contains the
199 MethodInfo of the first method of the interface which represents the
200 root of the inheritance chain. The last MethodInfo represents the last
201 method of the furthest derived interface.
203 The array is completely initialized in the constructor of this object.
205 When the uno_DispatchMethod is called for this proxy then it receives
206 a typelib_TypeDescription of the member which is either an attribute
207 (setter or getter) or method. After determining the position of the
208 method within the UNO interface one can use the position to obtain the
209 MethodInfo of the corresponding cli method. To obtain the index for the
210 m_arMethodInfos array the function position has to be decreased by 3.
211 This is becaus, the cli interface does not contain the XInterface
212 methods.
214 gcroot<sr::MethodInfo*[]> m_arMethodInfos;
216 /** This array is similar to m_arMethodInfos but it contains the MethodInfo
217 objects of the interface (not the object). When a call is made from uno
218 to cli then the uno method name is compared to the cli method name. The
219 cli method name can be obtained from the MethodInfo object in this
220 array. The name of the actual implemented method may not be the same as
221 the interface method.
223 gcroot<sr::MethodInfo*[]> m_arInterfaceMethodInfos;
225 /** Maps the position of the method in the UNO interface to the position of
226 the corresponding MethodInfo in m_arMethodInfos. The Uno position must
227 not include the XInterface methods. For example,
228 pos 0 = XInterface::queryInterface
229 pos 1 = XInterface::acquire
230 pos 2 = XInterface::release
232 That is the real Uno position has to be deducted by 3. Then
233 arUnoPosToCliPos[pos] contains the index for m_arMethodInfos.
236 gcroot<System::Int32[]> m_arUnoPosToCliPos;
238 /** Count of inherited interfaces of the cli interface.
240 int m_nInheritedInterfaces;
241 /** Contains the number of methods of each interface.
243 gcroot<System::Int32[]> m_arInterfaceMethodCount;
245 CliProxy( Bridge const* bridge, System::Object* cliI,
246 typelib_TypeDescription const* pTD,
247 const rtl::OUString& usOid);
248 ~CliProxy();
250 static uno_Interface* create(Bridge const * bridge,
251 System::Object* cliI,
252 typelib_TypeDescription const * TD,
253 rtl::OUString const & usOid );
255 /** Prepares an array (m_arMethoInfos) containing MethodInfo object of the
256 interface and all inherited interfaces. At index null is the first
257 method of the base interface and at the last position is the last method
258 of the furthest derived interface.
259 If a UNO call is received then one can determine the position of the
260 method (or getter or setter for an attribute) from the passed type
261 information. The position minus 3 (there is no XInterface in the cli
262 mapping) corresponds to the index of the cli interface method in the
263 array.
265 void makeMethodInfos();
267 /**Obtains a MethodInfo which can be used to invoke the cli object.
268 Internally it maps nUnoFunctionPos to an index that is used to get the
269 corresponding MethodInfo object from m_arMethoInfos. The mapping table
270 is dynamically initialized. If the cli interface has no base interface
271 or exactly one then the mapping table is initialized in one go at the
272 first call. In all ensuing calls the MethodInfo object is immediately
273 retrieved through the mapping table.
275 If the interface has more then one interface in its inheritance chain,
276 that is Type.GetInterfaces return more then one Type, then the mapping
277 table is partially initiallized. On the first call the mappings for the
278 methods of the belonging interface are created.
280 The implementation assumes that the order of interface methods as
281 provided by InterfaceMapping.InterfaceMethods corresponds to the order
282 of methods in the interface declaration.
284 @param nUnoFunctionPos
285 Position of the method in the uno interface.
287 sr::MethodInfo* getMethodInfo(int nUnoFunctionPos,
288 const rtl::OUString & usMethodName,
289 MethodKind mk);
291 void SAL_CALL uno_DispatchMethod(
292 struct _uno_Interface * pUnoI,
293 const struct _typelib_TypeDescription * pMemberType,
294 void * pReturn,
295 void * pArgs[],
296 uno_Any ** ppException );
298 inline void acquire() const;
299 inline void release() const;
302 #endif