1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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_EXTENSIONS_SOURCE_OLE_UNOOBJW_HXX
21 #define INCLUDED_EXTENSIONS_SOURCE_OLE_UNOOBJW_HXX
23 #include <com/sun/star/bridge/XBridgeSupplier2.hpp>
24 #include <com/sun/star/beans/XExactName.hpp>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/script/InvocationInfo.hpp>
27 #include <salhelper/simplereferenceobject.hxx>
29 #include "comifaces.hxx"
30 #include "ole2uno.hxx"
31 #include "unoconversionutilities.hxx"
33 #define JSCRIPT_VALUE_FUNC L"_GetValueObject"
34 #define GET_STRUCT_FUNC L"_GetStruct"
35 #define BRIDGE_VALUE_FUNC L"Bridge_GetValueObject"
36 #define BRIDGE_GET_STRUCT_FUNC L"Bridge_GetStruct"
37 #define BRIDGE_CREATE_TYPE_FUNC L"Bridge_CreateType"
39 #define DISPID_JSCRIPT_VALUE_FUNC -10l
40 #define DISPID_GET_STRUCT_FUNC -102
41 #define DISPID_CREATE_TYPE_FUNC -103
45 using namespace com::sun::star::bridge
;
46 using namespace com::sun::star::script
;
52 struct hash_IUnknown_Impl
54 size_t operator()(const IUnknown
* p
) const
60 struct equal_to_IUnknown_Impl
62 bool operator()(const IUnknown
* s1
, const IUnknown
* s2
) const
72 MemberInfo() : flags(0), name() {}
73 MemberInfo(WORD f
, const OUString
& n
) : flags(f
), name(n
) {}
79 typedef std::unordered_map
86 typedef std::unordered_map
93 typedef std::unordered_map
99 /*****************************************************************************
101 class declaration: InterfaceOleWrapper_Impl
103 *****************************************************************************/
105 class InterfaceOleWrapper_Impl
: public WeakImplHelper2
<XBridgeSupplier2
, XInitialization
>,
107 public UnoConversionUtilities
<InterfaceOleWrapper_Impl
>,
108 public IUnoObjectWrapper
113 InterfaceOleWrapper_Impl(Reference
<XMultiServiceFactory
>& xFactory
, sal_uInt8 unoWrapperClass
, sal_uInt8 comWrapperClass
);
114 ~InterfaceOleWrapper_Impl();
116 /* IUnknown methods */
117 STDMETHOD(QueryInterface
)(REFIID riid
, LPVOID FAR
* ppvObj
);
118 STDMETHOD_(ULONG
, AddRef
)();
119 STDMETHOD_(ULONG
, Release
)();
121 /* IDispatch methods */
122 STDMETHOD( GetTypeInfoCount
)( unsigned int * pctinfo
);
123 STDMETHOD( GetTypeInfo
)( unsigned int itinfo
, LCID lcid
, ITypeInfo
** pptinfo
);
124 STDMETHOD( GetIDsOfNames
)( REFIID riid
, OLECHAR
** rgszNames
, unsigned int cNames
,
125 LCID lcid
, DISPID
* rgdispid
);
126 STDMETHOD( Invoke
)( DISPID dispidMember
, REFIID riid
, LCID lcid
, unsigned short wFlags
,
127 DISPPARAMS
* pdispparams
, VARIANT
* pvarResult
, EXCEPINFO
* pexcepinfo
,
128 unsigned int * puArgErr
);
130 /* IDispatchEx methods */
132 virtual HRESULT STDMETHODCALLTYPE
GetDispID(
133 /* [in] */ BSTR bstrName
,
134 /* [in] */ DWORD grfdex
,
135 /* [out] */ DISPID __RPC_FAR
*pid
);
137 virtual /* [local] */ HRESULT STDMETHODCALLTYPE
InvokeEx(
138 /* [in] */ DISPID id
,
139 /* [in] */ LCID lcid
,
140 /* [in] */ WORD wFlags
,
141 /* [in] */ DISPPARAMS __RPC_FAR
*pdp
,
142 /* [out] */ VARIANT __RPC_FAR
*pvarRes
,
143 /* [out] */ EXCEPINFO __RPC_FAR
*pei
,
144 /* [unique][in] */ IServiceProvider __RPC_FAR
*pspCaller
);
146 virtual HRESULT STDMETHODCALLTYPE
DeleteMemberByName(
147 /* [in] */ BSTR bstr
,
148 /* [in] */ DWORD grfdex
);
150 virtual HRESULT STDMETHODCALLTYPE
DeleteMemberByDispID(
151 /* [in] */ DISPID id
);
153 virtual HRESULT STDMETHODCALLTYPE
GetMemberProperties(
154 /* [in] */ DISPID id
,
155 /* [in] */ DWORD grfdexFetch
,
156 /* [out] */ DWORD __RPC_FAR
*pgrfdex
);
158 virtual HRESULT STDMETHODCALLTYPE
GetMemberName(
159 /* [in] */ DISPID id
,
160 /* [out] */ BSTR __RPC_FAR
*pbstrName
);
162 virtual HRESULT STDMETHODCALLTYPE
GetNextDispID(
163 /* [in] */ DWORD grfdex
,
164 /* [in] */ DISPID id
,
165 /* [out] */ DISPID __RPC_FAR
*pid
);
167 virtual HRESULT STDMETHODCALLTYPE
GetNameSpaceParent(
168 /* [out] */ IUnknown __RPC_FAR
*__RPC_FAR
*ppunk
);
170 // XBridgeSupplier2 ---------------------------------------------------
171 virtual Any SAL_CALL
createBridge(const Any
& modelDepObject
,
172 const Sequence
<sal_Int8
>& ProcessId
,
173 sal_Int16 sourceModelType
,
174 sal_Int16 destModelType
)
175 throw (IllegalArgumentException
, RuntimeException
);
177 //XInitialization -----------------------------------------------------
178 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
) throw(Exception
, RuntimeException
);
181 STDMETHOD( getWrapperXInterface
)( Reference
<XInterface
>* pXInt
);
182 STDMETHOD( getOriginalUnoObject
)( Reference
<XInterface
>* pXInt
);
183 STDMETHOD( getOriginalUnoStruct
)( Any
* pStruct
);
185 // UnoConversionUtility
186 virtual Reference
< XInterface
> createUnoWrapperInstance();
187 virtual Reference
< XInterface
> createComWrapperInstance();
191 virtual HRESULT
doInvoke( DISPPARAMS
* pdispparams
, VARIANT
* pvarResult
,
192 EXCEPINFO
* pexcepinfo
, unsigned int * puArgErr
, OUString
& name
, Sequence
<Any
>& params
);
194 virtual HRESULT
doGetProperty( DISPPARAMS
* pdispparams
, VARIANT
* pvarResult
,
195 EXCEPINFO
* pexcepinfo
, OUString
& name
);
197 virtual HRESULT
doSetProperty( DISPPARAMS
* pdispparams
, VARIANT
* pvarResult
,
198 EXCEPINFO
* pexcepinfo
, unsigned int * puArgErr
, OUString
& name
, Sequence
<Any
> params
);
200 virtual HRESULT
InvokeGeneral( DISPID dispidMember
, unsigned short wFlags
,
201 DISPPARAMS
* pdispparams
, VARIANT
* pvarResult
, EXCEPINFO
* pexcepinfo
,
202 unsigned int * puArgErr
, sal_Bool
& bHandled
);
204 void convertDispparamsArgs( DISPID id
, unsigned short wFlags
, DISPPARAMS
* pdispparams
,
205 Sequence
<Any
>& rSeq
);
207 sal_Bool
getInvocationInfoForCall(DISPID id
, InvocationInfo
& info
);
209 Reference
<XInvocation
> m_xInvocation
;
210 Reference
<XExactName
> m_xExactName
;
211 Reference
<XInterface
> m_xOrigin
;
212 NameToIdMap m_nameToDispIdMap
;
213 vector
<MemberInfo
> m_MemberInfos
;
214 // This member is used to determine the default value
215 // denoted by DISPID_VALUE (0). For proper results in JavaScript
216 // we have to return the default value when we write an object
217 // as out parameter. That is, we get an JScript Array as parameter
218 // and put a wrapped object on index null. The array object tries
219 // to detect the default value. The wrapped object must then return
220 // its own IDispatch* otherwise we cannot access it within the script.
221 // see InterfaceOleWrapper_Impl::Invoke
222 VARTYPE m_defaultValueType
;
226 /*****************************************************************************
228 class declaration: UnoObjectWrapperRemoteOpt
229 ( Uno Object Wrapper Remote Optimized)
230 This is the UNO wrapper used in the service com.sun.star.bridge.OleBridgeSupplierVar1.
232 DISPIDs are passed out blindly. That is in GetIDsOfNames is no name checking carried out.
233 Only if Invoke fails the name is being checked. Moreover Invoke tries to figure out
234 if a call is made to a property or method if the flags are DISPATCH_METHOD | DISPATCH_PROPERTYPUT.
235 If something has been found out about a property or member than it is saved
236 in a MemberInfo structure hold by a IdToMemberInfoMap stl map.
238 *****************************************************************************/
239 class UnoObjectWrapperRemoteOpt
: public InterfaceOleWrapper_Impl
242 UnoObjectWrapperRemoteOpt( Reference
<XMultiServiceFactory
>& aFactory
, sal_uInt8 unoWrapperClass
, sal_uInt8 comWrapperClass
);
243 ~UnoObjectWrapperRemoteOpt();
245 STDMETHOD( GetIDsOfNames
)( REFIID riid
, OLECHAR
** rgszNames
, unsigned int cNames
,
246 LCID lcid
, DISPID
* rgdispid
);
247 STDMETHOD( Invoke
)( DISPID dispidMember
, REFIID riid
, LCID lcid
, unsigned short wFlags
,
248 DISPPARAMS
* pdispparams
, VARIANT
* pvarResult
, EXCEPINFO
* pexcepinfo
,
249 unsigned int * puArgErr
);
251 // UnoConversionUtility
252 // If UNO interfaces are converted in methods of this class then
253 // they are always wrapped with instances of this class
254 virtual Reference
< XInterface
> createUnoWrapperInstance();
258 HRESULT
methodInvoke( DISPID dispidMember
, DISPPARAMS
* pdispparams
, VARIANT
* pvarResult
,
259 EXCEPINFO
* pexcepinfo
, unsigned int * puArgErr
, Sequence
<Any
> params
);
260 // In GetIDsOfNames are blindly passed out, that is without verifying
261 // the name. If two names are passed in during different calls to
262 // GetIDsOfNames and the names differ only in their cases then different
263 // id's are passed out ( e.g. "doSomethingMethod" or "dosomethingmethod").
264 // In Invoke the DISPID is remapped to the name passed to GetIDsOfNames
265 // and the name is used as parameter for XInvocation::invoke. If invoke
266 // fails because of a wrong name, then m_xExactName ( XExactName) is used
267 // to verify the name. The correct name is then inserted to m_MemberInfos
268 // ( vector<MemberInfo> ). During the next call to Invoke the right name
272 BadNameMap m_badNameMap
;
274 IdToMemberInfoMap m_idToMemberInfoMap
;
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */