1*46dbaceeSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*46dbaceeSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*46dbaceeSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*46dbaceeSAndrew Rist * distributed with this work for additional information 6*46dbaceeSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*46dbaceeSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*46dbaceeSAndrew Rist * "License"); you may not use this file except in compliance 9*46dbaceeSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*46dbaceeSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*46dbaceeSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*46dbaceeSAndrew Rist * software distributed under the License is distributed on an 15*46dbaceeSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*46dbaceeSAndrew Rist * KIND, either express or implied. See the License for the 17*46dbaceeSAndrew Rist * specific language governing permissions and limitations 18*46dbaceeSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*46dbaceeSAndrew Rist *************************************************************/ 21*46dbaceeSAndrew Rist 22*46dbaceeSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _UNOOBJW_HXX 25cdf0e10cSrcweir #define _UNOOBJW_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/bridge/XBridgeSupplier2.hpp> 28cdf0e10cSrcweir #include <com/sun/star/beans/XExactName.hpp> 29cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 30cdf0e10cSrcweir #include <com/sun/star/script/InvocationInfo.hpp> 31cdf0e10cSrcweir #include <vos/refernce.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <tools/presys.h> 34cdf0e10cSrcweir #include "comifaces.hxx" 35cdf0e10cSrcweir #include <tools/postsys.h> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include "ole2uno.hxx" 38cdf0e10cSrcweir #include "unoconversionutilities.hxx" 39cdf0e10cSrcweir 40cdf0e10cSrcweir //#define INVOCATION_SERVICE L"com.sun.star.script.Invocation" 41cdf0e10cSrcweir #define JSCRIPT_VALUE_FUNC L"_GetValueObject" 42cdf0e10cSrcweir #define GET_STRUCT_FUNC L"_GetStruct" 43cdf0e10cSrcweir #define BRIDGE_VALUE_FUNC L"Bridge_GetValueObject" 44cdf0e10cSrcweir #define BRIDGE_GET_STRUCT_FUNC L"Bridge_GetStruct" 45cdf0e10cSrcweir #define BRIDGE_CREATE_TYPE_FUNC L"Bridge_CreateType" 46cdf0e10cSrcweir 47cdf0e10cSrcweir #define DISPID_JSCRIPT_VALUE_FUNC -10l 48cdf0e10cSrcweir #define DISPID_GET_STRUCT_FUNC -102 49cdf0e10cSrcweir #define DISPID_CREATE_TYPE_FUNC -103 50cdf0e10cSrcweir 51cdf0e10cSrcweir using namespace std; 52cdf0e10cSrcweir using namespace cppu; 53cdf0e10cSrcweir using namespace com::sun::star::bridge; 54cdf0e10cSrcweir using namespace com::sun::star::script; 55cdf0e10cSrcweir namespace ole_adapter 56cdf0e10cSrcweir { 57cdf0e10cSrcweir 58cdf0e10cSrcweir 59cdf0e10cSrcweir 60cdf0e10cSrcweir struct hash_IUnknown_Impl 61cdf0e10cSrcweir { operator ()ole_adapter::hash_IUnknown_Impl62cdf0e10cSrcweir size_t operator()(const IUnknown* p) const 63cdf0e10cSrcweir { 64cdf0e10cSrcweir return (size_t)p; 65cdf0e10cSrcweir } 66cdf0e10cSrcweir }; 67cdf0e10cSrcweir 68cdf0e10cSrcweir struct equal_to_IUnknown_Impl 69cdf0e10cSrcweir { operator ()ole_adapter::equal_to_IUnknown_Impl70cdf0e10cSrcweir bool operator()(const IUnknown* s1, const IUnknown* s2) const 71cdf0e10cSrcweir { 72cdf0e10cSrcweir return s1 == s2; 73cdf0e10cSrcweir } 74cdf0e10cSrcweir }; 75cdf0e10cSrcweir 76cdf0e10cSrcweir 77cdf0e10cSrcweir 78cdf0e10cSrcweir struct MemberInfo 79cdf0e10cSrcweir { MemberInfoole_adapter::MemberInfo80cdf0e10cSrcweir MemberInfo() : flags(0), name() {} MemberInfoole_adapter::MemberInfo81cdf0e10cSrcweir MemberInfo(WORD f, const OUString& n) : flags(f), name(n) {} 82cdf0e10cSrcweir 83cdf0e10cSrcweir WORD flags; 84cdf0e10cSrcweir OUString name; 85cdf0e10cSrcweir }; 86cdf0e10cSrcweir 87cdf0e10cSrcweir typedef hash_map 88cdf0e10cSrcweir < 89cdf0e10cSrcweir OUString, 90cdf0e10cSrcweir DISPID, 91cdf0e10cSrcweir hashOUString_Impl, 92cdf0e10cSrcweir equalOUString_Impl 93cdf0e10cSrcweir > NameToIdMap; 94cdf0e10cSrcweir 95cdf0e10cSrcweir typedef hash_map 96cdf0e10cSrcweir < 97cdf0e10cSrcweir OUString, 98cdf0e10cSrcweir sal_Bool, 99cdf0e10cSrcweir hashOUString_Impl, 100cdf0e10cSrcweir equalOUString_Impl 101cdf0e10cSrcweir > BadNameMap; 102cdf0e10cSrcweir 103cdf0e10cSrcweir typedef hash_map 104cdf0e10cSrcweir < 105cdf0e10cSrcweir DISPID, 106cdf0e10cSrcweir MemberInfo 107cdf0e10cSrcweir > IdToMemberInfoMap; 108cdf0e10cSrcweir 109cdf0e10cSrcweir /***************************************************************************** 110cdf0e10cSrcweir 111cdf0e10cSrcweir class declaration: InterfaceOleWrapper_Impl 112cdf0e10cSrcweir 113cdf0e10cSrcweir *****************************************************************************/ 114cdf0e10cSrcweir 115cdf0e10cSrcweir class InterfaceOleWrapper_Impl : public WeakImplHelper2<XBridgeSupplier2, XInitialization>, 116cdf0e10cSrcweir public IDispatchEx, 117cdf0e10cSrcweir public UnoConversionUtilities<InterfaceOleWrapper_Impl>, 118cdf0e10cSrcweir public IUnoObjectWrapper 119cdf0e10cSrcweir { 120cdf0e10cSrcweir public: 121cdf0e10cSrcweir 122cdf0e10cSrcweir 123cdf0e10cSrcweir InterfaceOleWrapper_Impl(Reference<XMultiServiceFactory>& xFactory, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass); 124cdf0e10cSrcweir ~InterfaceOleWrapper_Impl(); 125cdf0e10cSrcweir 126cdf0e10cSrcweir /* IUnknown methods */ 127cdf0e10cSrcweir STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj); 128cdf0e10cSrcweir STDMETHOD_(ULONG, AddRef)(); 129cdf0e10cSrcweir STDMETHOD_(ULONG, Release)(); 130cdf0e10cSrcweir 131cdf0e10cSrcweir /* IDispatch methods */ 132cdf0e10cSrcweir STDMETHOD( GetTypeInfoCount )( unsigned int * pctinfo ); 133cdf0e10cSrcweir STDMETHOD( GetTypeInfo )( unsigned int itinfo, LCID lcid, ITypeInfo ** pptinfo ); 134cdf0e10cSrcweir STDMETHOD( GetIDsOfNames )( REFIID riid, OLECHAR ** rgszNames, unsigned int cNames, 135cdf0e10cSrcweir LCID lcid, DISPID * rgdispid ); 136cdf0e10cSrcweir STDMETHOD( Invoke )( DISPID dispidMember, REFIID riid, LCID lcid, unsigned short wFlags, 137cdf0e10cSrcweir DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, 138cdf0e10cSrcweir unsigned int * puArgErr ); 139cdf0e10cSrcweir 140cdf0e10cSrcweir /* IDispatchEx methods */ 141cdf0e10cSrcweir 142cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE GetDispID( 143cdf0e10cSrcweir /* [in] */ BSTR bstrName, 144cdf0e10cSrcweir /* [in] */ DWORD grfdex, 145cdf0e10cSrcweir /* [out] */ DISPID __RPC_FAR *pid); 146cdf0e10cSrcweir 147cdf0e10cSrcweir virtual /* [local] */ HRESULT STDMETHODCALLTYPE InvokeEx( 148cdf0e10cSrcweir /* [in] */ DISPID id, 149cdf0e10cSrcweir /* [in] */ LCID lcid, 150cdf0e10cSrcweir /* [in] */ WORD wFlags, 151cdf0e10cSrcweir /* [in] */ DISPPARAMS __RPC_FAR *pdp, 152cdf0e10cSrcweir /* [out] */ VARIANT __RPC_FAR *pvarRes, 153cdf0e10cSrcweir /* [out] */ EXCEPINFO __RPC_FAR *pei, 154cdf0e10cSrcweir /* [unique][in] */ IServiceProvider __RPC_FAR *pspCaller); 155cdf0e10cSrcweir 156cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE DeleteMemberByName( 157cdf0e10cSrcweir /* [in] */ BSTR bstr, 158cdf0e10cSrcweir /* [in] */ DWORD grfdex); 159cdf0e10cSrcweir 160cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE DeleteMemberByDispID( 161cdf0e10cSrcweir /* [in] */ DISPID id); 162cdf0e10cSrcweir 163cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE GetMemberProperties( 164cdf0e10cSrcweir /* [in] */ DISPID id, 165cdf0e10cSrcweir /* [in] */ DWORD grfdexFetch, 166cdf0e10cSrcweir /* [out] */ DWORD __RPC_FAR *pgrfdex); 167cdf0e10cSrcweir 168cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE GetMemberName( 169cdf0e10cSrcweir /* [in] */ DISPID id, 170cdf0e10cSrcweir /* [out] */ BSTR __RPC_FAR *pbstrName); 171cdf0e10cSrcweir 172cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE GetNextDispID( 173cdf0e10cSrcweir /* [in] */ DWORD grfdex, 174cdf0e10cSrcweir /* [in] */ DISPID id, 175cdf0e10cSrcweir /* [out] */ DISPID __RPC_FAR *pid); 176cdf0e10cSrcweir 177cdf0e10cSrcweir virtual HRESULT STDMETHODCALLTYPE GetNameSpaceParent( 178cdf0e10cSrcweir /* [out] */ IUnknown __RPC_FAR *__RPC_FAR *ppunk); 179cdf0e10cSrcweir 180cdf0e10cSrcweir // XBridgeSupplier2 --------------------------------------------------- 181cdf0e10cSrcweir virtual Any SAL_CALL createBridge(const Any& modelDepObject, 182cdf0e10cSrcweir const Sequence<sal_Int8>& ProcessId, 183cdf0e10cSrcweir sal_Int16 sourceModelType, 184cdf0e10cSrcweir sal_Int16 destModelType) 185cdf0e10cSrcweir throw (IllegalArgumentException, RuntimeException); 186cdf0e10cSrcweir 187cdf0e10cSrcweir //XInitialization ----------------------------------------------------- 188cdf0e10cSrcweir virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException); 189cdf0e10cSrcweir 190cdf0e10cSrcweir // IUnoObjectWrapper 191cdf0e10cSrcweir STDMETHOD( getWrapperXInterface)( Reference<XInterface>* pXInt); 192cdf0e10cSrcweir STDMETHOD( getOriginalUnoObject)( Reference<XInterface>* pXInt); 193cdf0e10cSrcweir STDMETHOD( getOriginalUnoStruct)( Any * pStruct); 194cdf0e10cSrcweir 195cdf0e10cSrcweir // UnoConversionUtility 196cdf0e10cSrcweir virtual Reference< XInterface > createUnoWrapperInstance(); 197cdf0e10cSrcweir virtual Reference< XInterface > createComWrapperInstance(); 198cdf0e10cSrcweir 199cdf0e10cSrcweir 200cdf0e10cSrcweir protected: 201cdf0e10cSrcweir virtual HRESULT doInvoke( DISPPARAMS * pdispparams, VARIANT * pvarResult, 202cdf0e10cSrcweir EXCEPINFO * pexcepinfo, unsigned int * puArgErr, OUString & name, Sequence<Any>& params); 203cdf0e10cSrcweir 204cdf0e10cSrcweir virtual HRESULT doGetProperty( DISPPARAMS * pdispparams, VARIANT * pvarResult, 205cdf0e10cSrcweir EXCEPINFO * pexcepinfo, OUString & name ); 206cdf0e10cSrcweir 207cdf0e10cSrcweir virtual HRESULT doSetProperty( DISPPARAMS * pdispparams, VARIANT * pvarResult, 208cdf0e10cSrcweir EXCEPINFO * pexcepinfo, unsigned int * puArgErr, OUString & name, Sequence<Any> params); 209cdf0e10cSrcweir 210cdf0e10cSrcweir virtual HRESULT InvokeGeneral( DISPID dispidMember, unsigned short wFlags, 211cdf0e10cSrcweir DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, 212cdf0e10cSrcweir unsigned int * puArgErr, sal_Bool& bHandled); 213cdf0e10cSrcweir 214cdf0e10cSrcweir void convertDispparamsArgs( DISPID id, unsigned short wFlags, DISPPARAMS* pdispparams, 215cdf0e10cSrcweir Sequence<Any>& rSeq); 216cdf0e10cSrcweir 217cdf0e10cSrcweir sal_Bool getInvocationInfoForCall(DISPID id, InvocationInfo& info); 218cdf0e10cSrcweir 219cdf0e10cSrcweir // vos::ORefCount m_refCount; 220cdf0e10cSrcweir Reference<XInvocation> m_xInvocation; 221cdf0e10cSrcweir Reference<XExactName> m_xExactName; 222cdf0e10cSrcweir Reference<XInterface> m_xOrigin; 223cdf0e10cSrcweir NameToIdMap m_nameToDispIdMap; 224cdf0e10cSrcweir vector<MemberInfo> m_MemberInfos; 225cdf0e10cSrcweir // This member is used to determine the default value 226cdf0e10cSrcweir // denoted by DISPID_VALUE (0). For proper results in JavaScript 227cdf0e10cSrcweir // we have to return the default value when we write an object 228cdf0e10cSrcweir // as out parameter. That is, we get an JScript Array as parameter 229cdf0e10cSrcweir // and put a wrapped object on index null. The array object tries 230cdf0e10cSrcweir // to detect the default value. The wrapped object must then return 231cdf0e10cSrcweir // its own IDispatch* otherwise we cannot access it within the script. 232cdf0e10cSrcweir // see InterfaceOleWrapper_Impl::Invoke 233cdf0e10cSrcweir VARTYPE m_defaultValueType; 234cdf0e10cSrcweir 235cdf0e10cSrcweir }; 236cdf0e10cSrcweir 237cdf0e10cSrcweir /***************************************************************************** 238cdf0e10cSrcweir 239cdf0e10cSrcweir class declaration: UnoObjectWrapperRemoteOpt 240cdf0e10cSrcweir ( Uno Object Wrapper Remote Optimized) 241cdf0e10cSrcweir This is the UNO wrapper used in the service com.sun.star.bridge.OleBridgeSupplierVar1. 242cdf0e10cSrcweir Key features: 243cdf0e10cSrcweir DISPIDs are passed out blindly. That is in GetIDsOfNames is no name checking carried out. 244cdf0e10cSrcweir Only if Invoke fails the name is being checked. Moreover Invoke tries to figure out 245cdf0e10cSrcweir if a call is made to a property or method if the flags are DISPATCH_METHOD | DISPATCH_PROPERTYPUT. 246cdf0e10cSrcweir If something has been found out about a property or member than it is saved 247cdf0e10cSrcweir in a MemberInfo structure hold by a IdToMemberInfoMap stl map. 248cdf0e10cSrcweir 249cdf0e10cSrcweir *****************************************************************************/ 250cdf0e10cSrcweir class UnoObjectWrapperRemoteOpt: public InterfaceOleWrapper_Impl 251cdf0e10cSrcweir { 252cdf0e10cSrcweir public: 253cdf0e10cSrcweir UnoObjectWrapperRemoteOpt( Reference<XMultiServiceFactory>& aFactory, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass); 254cdf0e10cSrcweir ~UnoObjectWrapperRemoteOpt(); 255cdf0e10cSrcweir 256cdf0e10cSrcweir STDMETHOD( GetIDsOfNames )( REFIID riid, OLECHAR ** rgszNames, unsigned int cNames, 257cdf0e10cSrcweir LCID lcid, DISPID * rgdispid ); 258cdf0e10cSrcweir STDMETHOD( Invoke )( DISPID dispidMember, REFIID riid, LCID lcid, unsigned short wFlags, 259cdf0e10cSrcweir DISPPARAMS * pdispparams, VARIANT * pvarResult, EXCEPINFO * pexcepinfo, 260cdf0e10cSrcweir unsigned int * puArgErr ); 261cdf0e10cSrcweir 262cdf0e10cSrcweir // UnoConversionUtility 263cdf0e10cSrcweir // If UNO interfaces are converted in methods of this class then 264cdf0e10cSrcweir // they are always wrapped with instances of this class 265cdf0e10cSrcweir virtual Reference< XInterface > createUnoWrapperInstance(); 266cdf0e10cSrcweir 267cdf0e10cSrcweir protected: 268cdf0e10cSrcweir 269cdf0e10cSrcweir HRESULT methodInvoke( DISPID dispidMember, DISPPARAMS * pdispparams, VARIANT * pvarResult, 270cdf0e10cSrcweir EXCEPINFO * pexcepinfo, unsigned int * puArgErr, Sequence<Any> params); 271cdf0e10cSrcweir // In GetIDsOfNames are blindly passed out, that is without verifying 272cdf0e10cSrcweir // the name. If two names are passed in during different calls to 273cdf0e10cSrcweir // GetIDsOfNames and the names differ only in their cases then different 274cdf0e10cSrcweir // id's are passed out ( e.g. "doSomethingMethod" or "dosomethingmethod"). 275cdf0e10cSrcweir // In Invoke the DISPID is remapped to the name passed to GetIDsOfNames 276cdf0e10cSrcweir // and the name is used as parameter for XInvocation::invoke. If invoke 277cdf0e10cSrcweir // fails because of a wrong name, then m_xExactName ( XExactName) is used 278cdf0e10cSrcweir // to verify the name. The correct name is then inserted to m_MemberInfos 279cdf0e10cSrcweir // ( vector<MemberInfo> ). During the next call to Invoke the right name 280cdf0e10cSrcweir // is used. . 281cdf0e10cSrcweir 282cdf0e10cSrcweir 283cdf0e10cSrcweir BadNameMap m_badNameMap; 284cdf0e10cSrcweir 285cdf0e10cSrcweir IdToMemberInfoMap m_idToMemberInfoMap; 286cdf0e10cSrcweir 287cdf0e10cSrcweir DISPID m_currentId; 288cdf0e10cSrcweir 289cdf0e10cSrcweir 290cdf0e10cSrcweir }; 291cdf0e10cSrcweir 292cdf0e10cSrcweir 293cdf0e10cSrcweir 294cdf0e10cSrcweir } // end namespace 295cdf0e10cSrcweir 296cdf0e10cSrcweir #endif 297