Bump version to 24.04.3.4
[LibreOffice.git] / cli_ure / source / uno_bridge / cli_proxy.h
blob25f7d2801314554cb58dc1121e7da27aaac40a65
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_CLI_URE_SOURCE_UNO_BRIDGE_CLI_PROXY_H
21 #define INCLUDED_CLI_URE_SOURCE_UNO_BRIDGE_CLI_PROXY_H
23 #include "uno/environment.hxx"
24 #include "uno/mapping.hxx"
25 #include "uno/dispatcher.h"
26 #include "cli_bridge.h"
27 #include "cli_environment.h"
29 #using <cli_ure.dll>
31 namespace srrp = System::Runtime::Remoting::Proxies;
32 namespace srrm = System::Runtime::Remoting::Messaging;
33 namespace srr = System::Runtime::Remoting;
34 namespace sr = System::Reflection;
35 namespace sc = System::Collections;
36 using namespace uno;
38 namespace cli_uno
41 public ref class UnoInterfaceInfo
43 public:
44 UnoInterfaceInfo(Bridge const * bridge, uno_Interface* unoI,
45 typelib_InterfaceTypeDescription* td);
46 ~UnoInterfaceInfo();
47 !UnoInterfaceInfo();
49 uno_Interface * m_unoI; // wrapped interface
50 System::Type ^ m_type;
51 typelib_InterfaceTypeDescription* m_typeDesc;
53 Bridge const* m_bridge;
56 public ref class UnoInterfaceProxy: public srrp::RealProxy,
57 public srr::IRemotingTypeInfo
59 /** used for IRemotingTypeInfo.TypeName
61 System::String^ m_sTypeName;
62 /** The list is filled with UnoInterfaceInfo objects. The list can only
63 grow and elements are never changed. If an element was added it
64 must not be changed!
66 sc::ArrayList^ m_listIfaces;
67 /** The number of UNO interfaces this proxy represents. It corresponds
68 to the number of elements in m_listIfaces.
70 int m_numUnoIfaces;
71 /** The list is filled with additional UnoInterfaceProxy object due
72 to aggregation via bridges. Though the latter is strongly
73 discouraged, this has to be supported.
75 sc::ArrayList^ m_listAdditionalProxies;
76 int m_nlistAdditionalProxies;
78 UnoInterfaceInfo ^ findInfo( ::System::Type ^ type );
80 Bridge const* m_bridge;
81 System::String^ m_oid;
83 #if OSL_DEBUG_LEVEL >= 2
84 /** The string contains all names of UNO interfaces which are
85 represented by this proxy. It is used to print out the interfaces
86 when this proxy dies. In the destructor it is not allowed to
87 access m_listIfaces or any other managed object.
89 rtl_uString * _sInterfaces;
90 // /** Count of interfaces. Used in conjunction with _sInterfaces.
91 // */
92 int _numInterfaces;
93 #endif
95 public:
97 /** Creates a proxy and registers it on the dot NET side.
99 static System::Object^ create(Bridge * bridge,
100 uno_Interface * pUnoI,
101 typelib_InterfaceTypeDescription* pTd,
102 const OUString& oid);
104 /** RealProxy::Invoke */
105 virtual srrm::IMessage^ Invoke(srrm::IMessage^ msg) override;
107 /** Must be called from within a synchronized section.
108 Add only the interface if it is not already contained.
109 This method is called from the constructor and as a result
110 of IRemotingTypeInfo::CanCastTo
112 void addUnoInterface(uno_Interface* pUnoI,
113 typelib_InterfaceTypeDescription* pTd);
114 ~UnoInterfaceProxy();
115 !UnoInterfaceProxy();
117 inline System::String ^ getOid()
118 { return m_oid; }
120 //IRemotingTypeInfo ----------------------------------------------
121 virtual bool CanCastTo(System::Type^ fromType, System::Object^ o);
123 virtual property System::String^ TypeName
125 System::String^ get()
127 return m_sTypeName;
129 void set(System::String^ name)
131 m_sTypeName = name;
136 private:
137 UnoInterfaceProxy(
138 Bridge * bridge,
139 uno_Interface * pUnoI,
140 typelib_InterfaceTypeDescription* pTD,
141 const OUString& oid );
143 static srrm::IMessage^ constructReturnMessage(System::Object^ retVal,
144 array<System::Object^>^ outArgs,
145 typelib_InterfaceMethodTypeDescription* mtd,
146 srrm::IMessage^ msg, System::Object^ exc);
148 static System::String^ m_methodNameString =
149 gcnew System::String("__MethodName");
150 static System::String^ m_typeNameString = gcnew System::String("__TypeName");
151 static System::String^ m_ArgsString = gcnew System::String("__Args");
152 static System::String^ m_CallContextString =
153 gcnew System::String("__CallContext");
154 static System::String^ m_system_Object_String =
155 gcnew System::String("System.Object");
156 static System::String^ m_methodSignatureString =
157 gcnew System::String("__MethodSignature");
158 static System::String^ m_Equals_String = gcnew System::String("Equals");
159 static System::String^ m_GetHashCode_String =
160 gcnew System::String("GetHashCode");
161 static System::String^ m_GetType_String = gcnew System::String("GetType");
162 static System::String^ m_ToString_String = gcnew System::String("ToString");
164 protected:
165 srrm::IMessage^ invokeObject(sc::IDictionary^ properties,
166 srrm::LogicalCallContext^ context,
167 srrm::IMethodCallMessage^ mcm);
171 //Cannot make this __gc because a managed type cannot derive from unmanaged type
172 struct CliProxy: public uno_Interface
174 mutable oslInterlockedCount m_ref;
175 const Bridge* m_bridge;
176 const gcroot<System::Object^> m_cliI;
177 gcroot<System::Type^> m_type;
178 const css::uno::TypeDescription m_unoType;
179 const gcroot<System::String^> m_oid;
180 const OUString m_usOid;
182 enum MethodKind {MK_METHOD = 0, MK_SET, MK_GET};
183 /** The array contains MethodInfos of the cli object. Each one reflects an
184 implemented interface method of the interface for which this proxy was
185 created. The MethodInfos are from the object's method and not from the
186 interface type. That is, they can be used to invoke the methods. The
187 order of the MethodInfo objects corresponds to the order of the
188 interface methods (see member m_type). Position 0 contains the
189 MethodInfo of the first method of the interface which represents the
190 root of the inheritance chain. The last MethodInfo represents the last
191 method of the furthest derived interface.
193 The array is completely initialized in the constructor of this object.
195 When the uno_DispatchMethod is called for this proxy then it receives
196 a typelib_TypeDescription of the member which is either an attribute
197 (setter or getter) or method. After determining the position of the
198 method within the UNO interface one can use the position to obtain the
199 MethodInfo of the corresponding cli method. To obtain the index for the
200 m_arMethodInfos array the function position has to be decreased by 3.
201 This is because, the cli interface does not contain the XInterface
202 methods.
204 gcroot<array<sr::MethodInfo^>^> m_arMethodInfos;
206 /** This array is similar to m_arMethodInfos but it contains the MethodInfo
207 objects of the interface (not the object). When a call is made from uno
208 to cli then the uno method name is compared to the cli method name. The
209 cli method name can be obtained from the MethodInfo object in this
210 array. The name of the actual implemented method may not be the same as
211 the interface method.
213 gcroot<array<sr::MethodInfo^>^> m_arInterfaceMethodInfos;
215 /** Maps the position of the method in the UNO interface to the position of
216 the corresponding MethodInfo in m_arMethodInfos. The Uno position must
217 not include the XInterface methods. For example,
218 pos 0 = XInterface::queryInterface
219 pos 1 = XInterface::acquire
220 pos 2 = XInterface::release
222 That is the real Uno position has to be deducted by 3. Then
223 arUnoPosToCliPos[pos] contains the index for m_arMethodInfos.
226 gcroot<array<System::Int32>^> m_arUnoPosToCliPos;
228 /** Count of inherited interfaces of the cli interface.
230 int m_nInheritedInterfaces;
231 /** Contains the number of methods of each interface.
233 gcroot<array<System::Int32^>^> m_arInterfaceMethodCount;
235 CliProxy( Bridge const* bridge, System::Object^ cliI,
236 typelib_TypeDescription const* pTD,
237 const OUString& usOid);
238 ~CliProxy();
240 static uno_Interface* create(Bridge const * bridge,
241 System::Object^ cliI,
242 typelib_TypeDescription const * TD,
243 OUString const & usOid );
245 /** Prepares an array (m_arMethoInfos) containing MethodInfo object of the
246 interface and all inherited interfaces. At index null is the first
247 method of the base interface and at the last position is the last method
248 of the furthest derived interface.
249 If a UNO call is received then one can determine the position of the
250 method (or getter or setter for an attribute) from the passed type
251 information. The position minus 3 (there is no XInterface in the cli
252 mapping) corresponds to the index of the cli interface method in the
253 array.
255 void makeMethodInfos();
257 /**Obtains a MethodInfo which can be used to invoke the cli object.
258 Internally it maps nUnoFunctionPos to an index that is used to get the
259 corresponding MethodInfo object from m_arMethoInfos. The mapping table
260 is dynamically initialized. If the cli interface has no base interface
261 or exactly one then the mapping table is initialized in one go at the
262 first call. In all ensuing calls the MethodInfo object is immediately
263 retrieved through the mapping table.
265 If the interface has more than one interface in its inheritance chain,
266 that is Type.GetInterfaces return more than one Type, then the mapping
267 table is partially initialized. On the first call the mappings for the
268 methods of the belonging interface are created.
270 The implementation assumes that the order of interface methods as
271 provided by InterfaceMapping.InterfaceMethods corresponds to the order
272 of methods in the interface declaration.
274 @param nUnoFunctionPos
275 Position of the method in the uno interface.
277 sr::MethodInfo^ getMethodInfo(int nUnoFunctionPos,
278 const OUString & usMethodName,
279 MethodKind mk);
281 void SAL_CALL uno_DispatchMethod(
282 struct _uno_Interface * pUnoI,
283 const struct _typelib_TypeDescription * pMemberType,
284 void * pReturn,
285 void * pArgs[],
286 uno_Any ** ppException );
288 inline void acquire() const;
289 inline void release() const;
292 #endif
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */