LibreOffice Module extensions (master) 1
unoobjw.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
22#include <com/sun/star/bridge/XBridgeSupplier2.hpp>
23#include <com/sun/star/beans/XExactName.hpp>
24#include <com/sun/star/lang/XInitialization.hpp>
25#include <com/sun/star/script/InvocationInfo.hpp>
28
29#include "comifaces.hxx"
30#include "ole2uno.hxx"
32
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"
38
39#define DISPID_JSCRIPT_VALUE_FUNC -10l
40#define DISPID_GET_STRUCT_FUNC -102
41#define DISPID_CREATE_TYPE_FUNC -103
42
43using namespace cppu;
44using namespace com::sun::star::bridge;
45using namespace com::sun::star::script;
46
48{
49 MemberInfo() : flags(0), name() {}
50 MemberInfo(WORD f, const OUString& n) : flags(f), name(n) {}
51
53 OUString name;
54};
55
56typedef std::unordered_map
57<
58 OUString,
59 DISPID
61
62typedef std::unordered_map
63<
64 OUString,
65 bool
67
68typedef std::unordered_map
69<
70 DISPID,
73
74// An InterfaceOleWrapper object can wrap either a UNO struct or a UNO
75// interface as a COM IDispatchEx and IUnoObjectWrapper.
76
77class InterfaceOleWrapper : public WeakImplHelper<XBridgeSupplier2, XInitialization>,
78 public IDispatchEx,
79 public IProvideClassInfo,
80 public IConnectionPointContainer,
81 public UnoConversionUtilities<InterfaceOleWrapper>,
82 public IUnoObjectWrapper
83{
84public:
85 InterfaceOleWrapper(Reference<XMultiServiceFactory> const & xFactory, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass);
86 ~InterfaceOleWrapper() override;
87
88 // IUnknown
89 STDMETHOD(QueryInterface)(REFIID riid, void ** ppvObj) override;
90 STDMETHOD_(ULONG, AddRef)() override;
91 STDMETHOD_(ULONG, Release)() override;
92
93 // IDispatch
94 STDMETHOD( GetTypeInfoCount )( UINT * pctinfo ) override;
95 STDMETHOD( GetTypeInfo )( UINT itinfo, LCID lcid, ITypeInfo ** pptinfo ) override;
96 STDMETHOD( GetIDsOfNames )( REFIID riid, LPOLESTR * rgszNames, UINT cNames,
97 LCID lcid, DISPID * rgdispid ) override;
98 STDMETHOD( Invoke )( DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
99 DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo,
100 UINT * puArgErr ) override;
101
102 // IDispatchEx
103 virtual HRESULT STDMETHODCALLTYPE GetDispID(
104 /* [in] */ BSTR bstrName,
105 /* [in] */ DWORD grfdex,
106 /* [out] */ DISPID __RPC_FAR *pid) override;
107
108 virtual /* [local] */ HRESULT STDMETHODCALLTYPE InvokeEx(
109 /* [in] */ DISPID id,
110 /* [in] */ LCID lcid,
111 /* [in] */ WORD wFlags,
112 /* [in] */ DISPPARAMS __RPC_FAR *pdp,
113 /* [out] */ VARIANT __RPC_FAR *pvarRes,
114 /* [out] */ EXCEPINFO __RPC_FAR *pei,
115 /* [unique][in] */ IServiceProvider __RPC_FAR *pspCaller) override;
116
117 virtual HRESULT STDMETHODCALLTYPE DeleteMemberByName(
118 /* [in] */ BSTR bstr,
119 /* [in] */ DWORD grfdex) override;
120
121 virtual HRESULT STDMETHODCALLTYPE DeleteMemberByDispID(
122 /* [in] */ DISPID id) override;
123
124 virtual HRESULT STDMETHODCALLTYPE GetMemberProperties(
125 /* [in] */ DISPID id,
126 /* [in] */ DWORD grfdexFetch,
127 /* [out] */ DWORD __RPC_FAR *pgrfdex) override;
128
129 virtual HRESULT STDMETHODCALLTYPE GetMemberName(
130 /* [in] */ DISPID id,
131 /* [out] */ BSTR __RPC_FAR *pbstrName) override;
132
133 virtual HRESULT STDMETHODCALLTYPE GetNextDispID(
134 /* [in] */ DWORD grfdex,
135 /* [in] */ DISPID id,
136 /* [out] */ DISPID __RPC_FAR *pid) override;
137
138 virtual HRESULT STDMETHODCALLTYPE GetNameSpaceParent(
139 /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppunk) override;
140
141 // IProvideClassInfo
142 virtual HRESULT STDMETHODCALLTYPE GetClassInfo(
143 /* [out] */ ITypeInfo **ppTI) override;
144
145 // IConnectionPointContainer
146 virtual HRESULT STDMETHODCALLTYPE EnumConnectionPoints(
147 /* [out] */ IEnumConnectionPoints **ppEnum) override;
148 virtual HRESULT STDMETHODCALLTYPE FindConnectionPoint(
149 /* [in] */ REFIID riid,
150 /* [out] */ IConnectionPoint **ppCP) override;
151
152 // XBridgeSupplier2
153 virtual Any SAL_CALL createBridge(const Any& modelDepObject,
154 const Sequence<sal_Int8>& ProcessId,
155 sal_Int16 sourceModelType,
156 sal_Int16 destModelType) override;
157
158 // XInitialization
159 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
160
161 // IUnoObjectWrapper
162 STDMETHOD( getWrapperXInterface)( Reference<XInterface>* pXInt) override;
163 STDMETHOD( getOriginalUnoObject)( Reference<XInterface>* pXInt) override;
164 STDMETHOD( getOriginalUnoStruct)( Any * pStruct) override;
165
166 // UnoConversionUtility
169
170 const OUString& getImplementationName() const
171 {
173 }
174
175protected:
176 virtual HRESULT doInvoke( DISPPARAMS * pdispparams, VARIANT * pvarResult,
177 EXCEPINFO * pexcepinfo, unsigned int * puArgErr, OUString & name, Sequence<Any>& params);
178
179 virtual HRESULT doGetProperty( DISPPARAMS * pdispparams, VARIANT * pvarResult,
180 EXCEPINFO * pexcepinfo, OUString & name );
181
182 virtual HRESULT doSetProperty( DISPPARAMS * pdispparams, VARIANT * pvarResult,
183 EXCEPINFO * pexcepinfo, unsigned int * puArgErr, OUString & name, Sequence<Any> const & params);
184
185 virtual HRESULT InvokeGeneral( DISPID dispidMember, unsigned short wFlags,
186 DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo,
187 unsigned int * puArgErr, bool& bHandled);
188
189 void convertDispparamsArgs( DISPID id, unsigned short wFlags, DISPPARAMS* pdispparams,
190 Sequence<Any>& rSeq);
191
192 bool getInvocationInfoForCall(DISPID id, InvocationInfo& info);
193
198 std::vector<MemberInfo> m_MemberInfos;
199 // This member is used to determine the default value
200 // denoted by DISPID_VALUE (0). For proper results in JavaScript
201 // we have to return the default value when we write an object
202 // as out parameter. That is, we get a JScript Array as parameter
203 // and put a wrapped object on index null. The array object tries
204 // to detect the default value. The wrapped object must then return
205 // its own IDispatch* otherwise we cannot access it within the script.
206 // see InterfaceOleWrapper::Invoke
208
209 // The name of the implementation. Can be empty if unknown.
211};
212
213/*****************************************************************************
214
215 UnoObjectWrapperRemoteOpt = Uno Object Wrapper Remote Optimized
216
217 This is the UNO wrapper used in the service com.sun.star.bridge.OleBridgeSupplierVar1.
218 Key features:
219 DISPIDs are passed out blindly. That is in GetIDsOfNames is no name checking carried out.
220 Only if Invoke fails the name is being checked. Moreover Invoke tries to figure out
221 if a call is made to a property or method if the flags are DISPATCH_METHOD | DISPATCH_PROPERTYPUT.
222 If something has been found out about a property or member than it is saved
223 in a MemberInfo structure hold by an IdToMemberInfoMap stl map.
224
225*****************************************************************************/
227{
228public:
229 UnoObjectWrapperRemoteOpt( Reference<XMultiServiceFactory> const & aFactory, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass);
231
232 STDMETHOD( GetIDsOfNames )( REFIID riid, LPOLESTR * rgszNames, UINT cNames,
233 LCID lcid, DISPID * rgdispid ) override;
234 STDMETHOD( Invoke )( DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
235 DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo,
236 UINT * puArgErr ) override;
237
238 // UnoConversionUtility
239 // If UNO interfaces are converted in methods of this class then
240 // they are always wrapped with instances of this class
242
243protected:
244
245 static HRESULT methodInvoke( DISPID dispidMember, DISPPARAMS * pdispparams, VARIANT * pvarResult,
246 EXCEPINFO * pexcepinfo, unsigned int * puArgErr, Sequence<Any> const & params);
247 // In GetIDsOfNames are blindly passed out, that is without verifying
248 // the name. If two names are passed in during different calls to
249 // GetIDsOfNames and the names differ only in their cases then different
250 // id's are passed out ( e.g. "doSomethingMethod" or "dosomethingmethod").
251 // In Invoke the DISPID is remapped to the name passed to GetIDsOfNames
252 // and the name is used as parameter for XInvocation::invoke. If invoke
253 // fails because of a wrong name, then m_xExactName ( XExactName) is used
254 // to verify the name. The correct name is then inserted to m_MemberInfos
255 // ( vector<MemberInfo> ). During the next call to Invoke the right name
256 // is used. .
257
258
260
262
264
265
266};
267
268/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
STDMETHOD_(ULONG, AddRef)() override
NameToIdMap m_nameToDispIdMap
Definition: unoobjw.hxx:197
virtual HRESULT doSetProperty(DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, unsigned int *puArgErr, OUString &name, Sequence< Any > const &params)
Definition: unoobjw.cxx:2102
virtual HRESULT STDMETHODCALLTYPE FindConnectionPoint(REFIID riid, IConnectionPoint **ppCP) override
Definition: unoobjw.cxx:2995
STDMETHOD_(ULONG, Release)() override
virtual Reference< XInterface > createComWrapperInstance() override
Definition: unoobjw.cxx:1548
InterfaceOleWrapper(Reference< XMultiServiceFactory > const &xFactory, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass)
Definition: unoobjw.cxx:126
STDMETHOD() QueryInterface(REFIID riid, void **ppvObj) override
Definition: unoobjw.cxx:142
virtual Any SAL_CALL createBridge(const Any &modelDepObject, const Sequence< sal_Int8 > &ProcessId, sal_Int16 sourceModelType, sal_Int16 destModelType) override
Definition: unoobjw.cxx:1484
virtual Reference< XInterface > createUnoWrapperInstance() override
Definition: unoobjw.cxx:1541
STDMETHOD() GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgdispid) override
Definition: unoobjw.cxx:1077
virtual HRESULT InvokeGeneral(DISPID dispidMember, unsigned short wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, unsigned int *puArgErr, bool &bHandled)
Definition: unoobjw.cxx:2735
virtual HRESULT STDMETHODCALLTYPE DeleteMemberByDispID(DISPID id) override
Definition: unoobjw.cxx:2916
virtual HRESULT doGetProperty(DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, OUString &name)
Definition: unoobjw.cxx:2066
const OUString & getImplementationName() const
Definition: unoobjw.hxx:170
STDMETHOD() getWrapperXInterface(Reference< XInterface > *pXInt) override
Definition: unoobjw.cxx:210
void convertDispparamsArgs(DISPID id, unsigned short wFlags, DISPPARAMS *pdispparams, Sequence< Any > &rSeq)
Definition: unoobjw.cxx:1278
STDMETHOD() getOriginalUnoStruct(Any *pStruct) override
Definition: unoobjw.cxx:220
virtual HRESULT STDMETHODCALLTYPE GetMemberProperties(DISPID id, DWORD grfdexFetch, DWORD __RPC_FAR *pgrfdex) override
Definition: unoobjw.cxx:2921
STDMETHOD() GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo **pptinfo) override
Definition: unoobjw.cxx:1035
OUString m_sImplementationName
Definition: unoobjw.hxx:210
virtual HRESULT STDMETHODCALLTYPE GetNextDispID(DWORD grfdex, DISPID id, DISPID __RPC_FAR *pid) override
Definition: unoobjw.cxx:2936
virtual HRESULT STDMETHODCALLTYPE GetMemberName(DISPID id, BSTR __RPC_FAR *pbstrName) override
Definition: unoobjw.cxx:2929
virtual HRESULT doInvoke(DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, unsigned int *puArgErr, OUString &name, Sequence< Any > &params)
Definition: unoobjw.cxx:1976
virtual HRESULT STDMETHODCALLTYPE GetDispID(BSTR bstrName, DWORD grfdex, DISPID __RPC_FAR *pid) override
Definition: unoobjw.cxx:2892
STDMETHOD() getOriginalUnoObject(Reference< XInterface > *pXInt) override
Definition: unoobjw.cxx:215
STDMETHOD() Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr) override
Definition: unoobjw.cxx:1800
Reference< XInterface > m_xOrigin
Definition: unoobjw.hxx:196
STDMETHOD() GetTypeInfoCount(UINT *pctinfo) override
Definition: unoobjw.cxx:241
~InterfaceOleWrapper() override
Definition: unoobjw.cxx:133
virtual HRESULT STDMETHODCALLTYPE EnumConnectionPoints(IEnumConnectionPoints **ppEnum) override
Definition: unoobjw.cxx:2988
Reference< XInvocation > m_xInvocation
Definition: unoobjw.hxx:194
virtual HRESULT STDMETHODCALLTYPE GetNameSpaceParent(IUnknown __RPC_FAR *__RPC_FAR *ppunk) override
Definition: unoobjw.cxx:2944
bool getInvocationInfoForCall(DISPID id, InvocationInfo &info)
Definition: unoobjw.cxx:1428
std::vector< MemberInfo > m_MemberInfos
Definition: unoobjw.hxx:198
VARTYPE m_defaultValueType
Definition: unoobjw.hxx:207
virtual HRESULT STDMETHODCALLTYPE InvokeEx(DISPID id, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pdp, VARIANT __RPC_FAR *pvarRes, EXCEPINFO __RPC_FAR *pei, IServiceProvider __RPC_FAR *pspCaller) override
Definition: unoobjw.cxx:2897
virtual HRESULT STDMETHODCALLTYPE GetClassInfo(ITypeInfo **ppTI) override
Definition: unoobjw.cxx:2951
virtual void SAL_CALL initialize(const Sequence< Any > &aArguments) override
Definition: unoobjw.cxx:1516
virtual HRESULT STDMETHODCALLTYPE DeleteMemberByName(BSTR bstr, DWORD grfdex) override
Definition: unoobjw.cxx:2909
Reference< XExactName > m_xExactName
Definition: unoobjw.hxx:195
All methods are allowed to throw at least a BridgeRuntimeError.
UnoObjectWrapperRemoteOpt(Reference< XMultiServiceFactory > const &aFactory, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass)
Definition: unoobjw.cxx:3045
IdToMemberInfoMap m_idToMemberInfoMap
Definition: unoobjw.hxx:261
STDMETHOD() Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr) override
Definition: unoobjw.cxx:3111
static HRESULT methodInvoke(DISPID dispidMember, DISPPARAMS *pdispparams, VARIANT *pvarResult, EXCEPINFO *pexcepinfo, unsigned int *puArgErr, Sequence< Any > const &params)
Definition: unoobjw.cxx:3360
~UnoObjectWrapperRemoteOpt() override
Definition: unoobjw.cxx:3052
virtual Reference< XInterface > createUnoWrapperInstance() override
Definition: unoobjw.cxx:3057
STDMETHOD() GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgdispid) override
Definition: unoobjw.cxx:3064
Reference< XSingleServiceFactory > xFactory
sal_Int64 n
unsigned short WORD
MemberInfo(WORD f, const OUString &n)
Definition: unoobjw.hxx:50
MemberInfo()
Definition: unoobjw.hxx:49
OUString name
Definition: unoobjw.hxx:53
WORD flags
Definition: unoobjw.hxx:52
unsigned char sal_uInt8
std::unordered_map< DISPID, MemberInfo > IdToMemberInfoMap
Definition: unoobjw.hxx:72
std::unordered_map< OUString, DISPID > NameToIdMap
Definition: unoobjw.hxx:60
std::unordered_map< OUString, bool > BadNameMap
Definition: unoobjw.hxx:66