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 10*46dbaceeSAndrew Rist * 11*46dbaceeSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*46dbaceeSAndrew Rist * 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. 19*46dbaceeSAndrew Rist * 20*46dbaceeSAndrew Rist *************************************************************/ 21*46dbaceeSAndrew Rist 22*46dbaceeSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _SERVPROV_HXX 25cdf0e10cSrcweir #define _SERVPROV_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 28cdf0e10cSrcweir #ifndef _CPPUHELPER_IMPLBASE3_HXX_ 29cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx> 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include "ole2uno.hxx" 33cdf0e10cSrcweir #include "unoconversionutilities.hxx" 34cdf0e10cSrcweir 35cdf0e10cSrcweir 36cdf0e10cSrcweir using namespace com::sun::star::bridge; 37cdf0e10cSrcweir using namespace cppu; 38cdf0e10cSrcweir using namespace std; 39cdf0e10cSrcweir 40cdf0e10cSrcweir namespace ole_adapter 41cdf0e10cSrcweir { 42cdf0e10cSrcweir Reference< XInterface> SAL_CALL ConverterProvider_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr) 43cdf0e10cSrcweir throw( Exception); 44cdf0e10cSrcweir Reference< XInterface> SAL_CALL ConverterProvider_CreateInstance2( const Reference<XMultiServiceFactory> & xSMgr) 45cdf0e10cSrcweir throw( Exception); 46cdf0e10cSrcweir Reference< XInterface> SAL_CALL ConverterProvider_CreateInstanceVar1( const Reference<XMultiServiceFactory> & xSMgr) 47cdf0e10cSrcweir throw( Exception); 48cdf0e10cSrcweir Reference<XInterface> SAL_CALL OleClient_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr) 49cdf0e10cSrcweir throw( Exception); 50cdf0e10cSrcweir Reference<XInterface> SAL_CALL OleServer_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr) 51cdf0e10cSrcweir throw( Exception); 52cdf0e10cSrcweir /***************************************************************************** 53cdf0e10cSrcweir 54cdf0e10cSrcweir class declaration IClassFactoryWrapper 55cdf0e10cSrcweir 56cdf0e10cSrcweir Specify abstract helper methods on class factories, which provide 57cdf0e10cSrcweir UNO objects. These methods are used by objects of class OleServer_Impl, 58cdf0e10cSrcweir to handle the OLE registration of different class factories. 59cdf0e10cSrcweir 60cdf0e10cSrcweir *****************************************************************************/ 61cdf0e10cSrcweir 62cdf0e10cSrcweir class IClassFactoryWrapper : public IClassFactory 63cdf0e10cSrcweir { 64cdf0e10cSrcweir public: 65cdf0e10cSrcweir 66cdf0e10cSrcweir virtual sal_Bool registerClass() = 0; 67cdf0e10cSrcweir virtual sal_Bool deregisterClass() = 0; 68cdf0e10cSrcweir }; 69cdf0e10cSrcweir 70cdf0e10cSrcweir /***************************************************************************** 71cdf0e10cSrcweir 72cdf0e10cSrcweir class declaration ProviderOleWrapper_Impl 73cdf0e10cSrcweir 74cdf0e10cSrcweir Provides an UNO service provider as OLE class factory. Handle the 75cdf0e10cSrcweir OLE registration by overloading the abstract methods from 76cdf0e10cSrcweir IClassFactoryWrapper. 77cdf0e10cSrcweir 78cdf0e10cSrcweir Acts as a COM class factory. When IClassFactory::CreateInstance is being called 79cdf0e10cSrcweir then it creates an service by help of the XSingleServiceFactory member and maps 80cdf0e10cSrcweir maps it to a COM object. 81cdf0e10cSrcweir 82cdf0e10cSrcweir *****************************************************************************/ 83cdf0e10cSrcweir 84cdf0e10cSrcweir class ProviderOleWrapper_Impl : public IClassFactoryWrapper 85cdf0e10cSrcweir { 86cdf0e10cSrcweir public: 87cdf0e10cSrcweir 88cdf0e10cSrcweir ProviderOleWrapper_Impl( const Reference<XMultiServiceFactory>& smgr, 89cdf0e10cSrcweir const Reference<XSingleServiceFactory>& xSFactory, GUID* pGuid); 90cdf0e10cSrcweir virtual ~ProviderOleWrapper_Impl(); 91cdf0e10cSrcweir 92cdf0e10cSrcweir sal_Bool registerClass(); 93cdf0e10cSrcweir sal_Bool deregisterClass(); 94cdf0e10cSrcweir 95cdf0e10cSrcweir /* IUnknown methods */ 96cdf0e10cSrcweir STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj); 97cdf0e10cSrcweir STDMETHOD_(ULONG, AddRef)(); 98cdf0e10cSrcweir STDMETHOD_(ULONG, Release)(); 99cdf0e10cSrcweir 100cdf0e10cSrcweir /* IClassFactory methods */ 101cdf0e10cSrcweir STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv); 102cdf0e10cSrcweir STDMETHOD(LockServer)(int fLock); 103cdf0e10cSrcweir 104cdf0e10cSrcweir protected: 105cdf0e10cSrcweir 106cdf0e10cSrcweir oslInterlockedCount m_refCount; 107cdf0e10cSrcweir Reference<XSingleServiceFactory> m_xSingleServiceFactory; 108cdf0e10cSrcweir GUID m_guid; 109cdf0e10cSrcweir DWORD m_factoryHandle; 110cdf0e10cSrcweir Reference<XBridgeSupplier2> m_bridgeSupplier; 111cdf0e10cSrcweir Reference<XMultiServiceFactory> m_smgr; 112cdf0e10cSrcweir }; 113cdf0e10cSrcweir 114cdf0e10cSrcweir /***************************************************************************** 115cdf0e10cSrcweir 116cdf0e10cSrcweir class declaration OneInstanceOleWrapper_Impl 117cdf0e10cSrcweir 118cdf0e10cSrcweir Provides an single UNO object as OLE object. Handle the 119cdf0e10cSrcweir OLE registration by overloading the abstract methods from 120cdf0e10cSrcweir IClassFactoryWrapper. 121cdf0e10cSrcweir 122cdf0e10cSrcweir Acts as a COM class factory. When IClassFactory::CreateInstance is being called 123cdf0e10cSrcweir then it maps the XInstance member it to a COM object. 124cdf0e10cSrcweir 125cdf0e10cSrcweir *****************************************************************************/ 126cdf0e10cSrcweir 127cdf0e10cSrcweir class OneInstanceOleWrapper_Impl : public IClassFactoryWrapper 128cdf0e10cSrcweir { 129cdf0e10cSrcweir public: 130cdf0e10cSrcweir 131cdf0e10cSrcweir OneInstanceOleWrapper_Impl( const Reference<XMultiServiceFactory>& smgr, const Reference<XInterface>& xInst, GUID* pGuid, sal_Bool bAsApplication ); 132cdf0e10cSrcweir virtual ~OneInstanceOleWrapper_Impl(); 133cdf0e10cSrcweir 134cdf0e10cSrcweir sal_Bool registerClass(); 135cdf0e10cSrcweir sal_Bool deregisterClass(); 136cdf0e10cSrcweir 137cdf0e10cSrcweir /* IUnknown methods */ 138cdf0e10cSrcweir STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj); 139cdf0e10cSrcweir STDMETHOD_(ULONG, AddRef)(); 140cdf0e10cSrcweir STDMETHOD_(ULONG, Release)(); 141cdf0e10cSrcweir 142cdf0e10cSrcweir /* IClassFactory methods */ 143cdf0e10cSrcweir STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv); 144cdf0e10cSrcweir STDMETHOD(LockServer)(int fLock); 145cdf0e10cSrcweir 146cdf0e10cSrcweir protected: 147cdf0e10cSrcweir 148cdf0e10cSrcweir //ORefCount m_refCount; 149cdf0e10cSrcweir oslInterlockedCount m_refCount; 150cdf0e10cSrcweir Reference<XInterface> m_xInst; 151cdf0e10cSrcweir GUID m_guid; 152cdf0e10cSrcweir DWORD m_factoryHandle; 153cdf0e10cSrcweir Reference<XBridgeSupplier2> m_bridgeSupplier; 154cdf0e10cSrcweir Reference<XMultiServiceFactory> m_smgr; 155cdf0e10cSrcweir unsigned long m_nApplRegHandle; 156cdf0e10cSrcweir sal_Bool m_bAsApplication; 157cdf0e10cSrcweir }; 158cdf0e10cSrcweir 159cdf0e10cSrcweir /***************************************************************************** 160cdf0e10cSrcweir 161cdf0e10cSrcweir class declaration OleConverter_Impl2 162cdf0e10cSrcweir 163cdf0e10cSrcweir Implementation of the UNO service com.sun.star.bridge.OleBridgeSupplier2. 164cdf0e10cSrcweir 165cdf0e10cSrcweir *****************************************************************************/ 166cdf0e10cSrcweir 167cdf0e10cSrcweir // This class realizes the service com.sun.star.bridge.OleBridgeSupplier2 and 168cdf0e10cSrcweir // com.sun.star.bridge.OleBridgeSupplierVar1. The class implements XBridgeSupplier2 169cdf0e10cSrcweir // instead of XBridgeSuppplier as done by class OleConverter_Impl. The XBridgeSupplier2 170cdf0e10cSrcweir // interface does not need a Maschine Id in its createBridge function anymore, 171cdf0e10cSrcweir // If an UNO interface is to be converted then the member m_nUnoWrapperClass determines 172cdf0e10cSrcweir // what wrapper class is to be used. There are currently InterfaceOleWrapper_Impl and 173cdf0e10cSrcweir // UnoObjectWrapperRemoteOpt. The first is used for the OleBridgeSupplier2 and the 174cdf0e10cSrcweir // latter for OleBridgeSupplierVar1. 175cdf0e10cSrcweir // The m_nComWrapperClass specifies the class which is used as wrapper for COM interfaces. 176cdf0e10cSrcweir // Currently there is only one class available ( IUnknownWrapper_Impl). 177cdf0e10cSrcweir class OleConverter_Impl2 : public WeakImplHelper2<XBridgeSupplier2, XInitialization>, 178cdf0e10cSrcweir public UnoConversionUtilities<OleConverter_Impl2> 179cdf0e10cSrcweir { 180cdf0e10cSrcweir public: 181cdf0e10cSrcweir OleConverter_Impl2( const Reference<XMultiServiceFactory>& smgr); 182cdf0e10cSrcweir OleConverter_Impl2( const Reference<XMultiServiceFactory>& smgr, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass ); 183cdf0e10cSrcweir virtual ~OleConverter_Impl2(); 184cdf0e10cSrcweir 185cdf0e10cSrcweir // XBridgeSupplier2 --------------------------------------------------- 186cdf0e10cSrcweir 187cdf0e10cSrcweir virtual Any SAL_CALL createBridge(const Any& modelDepObject, 188cdf0e10cSrcweir const Sequence<sal_Int8>& ProcessId, 189cdf0e10cSrcweir sal_Int16 sourceModelType, 190cdf0e10cSrcweir sal_Int16 destModelType) 191cdf0e10cSrcweir throw (IllegalArgumentException, RuntimeException); 192cdf0e10cSrcweir 193cdf0e10cSrcweir // XInitialization 194cdf0e10cSrcweir virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException); 195cdf0e10cSrcweir 196cdf0e10cSrcweir // Abstract struct UnoConversionUtilities 197cdf0e10cSrcweir virtual Reference< XInterface > createUnoWrapperInstance(); 198cdf0e10cSrcweir virtual Reference< XInterface > createComWrapperInstance(); 199cdf0e10cSrcweir protected: 200cdf0e10cSrcweir 201cdf0e10cSrcweir }; 202cdf0e10cSrcweir 203cdf0e10cSrcweir 204cdf0e10cSrcweir /***************************************************************************** 205cdf0e10cSrcweir 206cdf0e10cSrcweir class declaration OleClient_Impl 207cdf0e10cSrcweir 208cdf0e10cSrcweir Implementation of the UNO service com.sun.star.bridge.OleObjectFactory. 209cdf0e10cSrcweir 210cdf0e10cSrcweir *****************************************************************************/ 211cdf0e10cSrcweir 212cdf0e10cSrcweir 213cdf0e10cSrcweir class OleClient_Impl : public WeakImplHelper1<XMultiServiceFactory>, 214cdf0e10cSrcweir public UnoConversionUtilities<OleClient_Impl> 215cdf0e10cSrcweir { 216cdf0e10cSrcweir public: 217cdf0e10cSrcweir OleClient_Impl( const Reference<XMultiServiceFactory>& smgr); 218cdf0e10cSrcweir ~OleClient_Impl(); 219cdf0e10cSrcweir 220cdf0e10cSrcweir // XMultiServiceFactory 221cdf0e10cSrcweir virtual Reference<XInterface> SAL_CALL createInstance(const OUString& ServiceSpecifier) throw( Exception, RuntimeException); 222cdf0e10cSrcweir virtual Reference<XInterface> SAL_CALL createInstanceWithArguments(const OUString& ServiceSpecifier, const Sequence< Any >& Arguments) throw (Exception, RuntimeException); 223cdf0e10cSrcweir Sequence< OUString > SAL_CALL getAvailableServiceNames() throw (RuntimeException); 224cdf0e10cSrcweir 225cdf0e10cSrcweir // Abstract struct UnoConversionUtilities 226cdf0e10cSrcweir virtual Reference< XInterface > createUnoWrapperInstance(); 227cdf0e10cSrcweir virtual Reference< XInterface > createComWrapperInstance(); 228cdf0e10cSrcweir 229cdf0e10cSrcweir 230cdf0e10cSrcweir OUString getImplementationName(); 231cdf0e10cSrcweir protected: 232cdf0e10cSrcweir Reference<XBridgeSupplier2> m_bridgeSupplier; 233cdf0e10cSrcweir }; 234cdf0e10cSrcweir 235cdf0e10cSrcweir /***************************************************************************** 236cdf0e10cSrcweir 237cdf0e10cSrcweir class declaration OleServer_Impl 238cdf0e10cSrcweir 239cdf0e10cSrcweir Implementation of the UNO service com.sun.star.bridge.OleApplicationRegistration. 240cdf0e10cSrcweir Register the calling application as OLE automation server for 241cdf0e10cSrcweir standard OLE object. The objects will be registered while instanciating 242cdf0e10cSrcweir this implementation and deregistrated, if this implementation is destroyed. 243cdf0e10cSrcweir 244cdf0e10cSrcweir *****************************************************************************/ 245cdf0e10cSrcweir 246cdf0e10cSrcweir class OleServer_Impl : public OWeakObject, XTypeProvider 247cdf0e10cSrcweir { 248cdf0e10cSrcweir public: 249cdf0e10cSrcweir OleServer_Impl( const Reference<XMultiServiceFactory> &smgr); 250cdf0e10cSrcweir ~OleServer_Impl(); 251cdf0e10cSrcweir 252cdf0e10cSrcweir // XInterface 253cdf0e10cSrcweir virtual Any SAL_CALL queryInterface( const Type& aType ) throw(RuntimeException); 254cdf0e10cSrcweir virtual void SAL_CALL acquire( ) throw (); 255cdf0e10cSrcweir virtual void SAL_CALL release( ) throw (); 256cdf0e10cSrcweir 257cdf0e10cSrcweir // XTypeProvider 258cdf0e10cSrcweir virtual Sequence< Type > SAL_CALL getTypes( ) throw(RuntimeException); 259cdf0e10cSrcweir virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException); 260cdf0e10cSrcweir 261cdf0e10cSrcweir protected: 262cdf0e10cSrcweir 263cdf0e10cSrcweir sal_Bool provideService(const Reference<XSingleServiceFactory>& xMulFact, GUID* guid); 264cdf0e10cSrcweir sal_Bool provideInstance(const Reference<XInterface>& xInst, GUID* guid, sal_Bool bAsApplication ); 265cdf0e10cSrcweir 266cdf0e10cSrcweir list< IClassFactoryWrapper* > m_wrapperList; 267cdf0e10cSrcweir Reference< XBridgeSupplier2 > m_bridgeSupplier; 268cdf0e10cSrcweir 269cdf0e10cSrcweir Reference<XMultiServiceFactory> m_smgr; 270cdf0e10cSrcweir }; 271cdf0e10cSrcweir 272cdf0e10cSrcweir } // end namespace 273cdf0e10cSrcweir #endif 274cdf0e10cSrcweir 275cdf0e10cSrcweir 276cdf0e10cSrcweir 277