masterfix DEV300: #i10000# build fix
[LibreOffice.git] / extensions / source / ole / servprov.hxx
blobbbce935aa98ea09ea82da67420627b803dad696c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef _SERVPROV_HXX
29 #define _SERVPROV_HXX
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #ifndef _CPPUHELPER_IMPLBASE3_HXX_
33 #include <cppuhelper/implbase2.hxx>
34 #endif
36 #include "ole2uno.hxx"
37 #include "unoconversionutilities.hxx"
40 using namespace com::sun::star::bridge;
41 using namespace cppu;
42 using namespace std;
44 namespace ole_adapter
46 Reference< XInterface> SAL_CALL ConverterProvider_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr)
47 throw( Exception);
48 Reference< XInterface> SAL_CALL ConverterProvider_CreateInstance2( const Reference<XMultiServiceFactory> & xSMgr)
49 throw( Exception);
50 Reference< XInterface> SAL_CALL ConverterProvider_CreateInstanceVar1( const Reference<XMultiServiceFactory> & xSMgr)
51 throw( Exception);
52 Reference<XInterface> SAL_CALL OleClient_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr)
53 throw( Exception);
54 Reference<XInterface> SAL_CALL OleServer_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr)
55 throw( Exception);
56 /*****************************************************************************
58 class declaration IClassFactoryWrapper
60 Specify abstract helper methods on class factories, which provide
61 UNO objects. These methods are used by objects of class OleServer_Impl,
62 to handle the OLE registration of different class factories.
64 *****************************************************************************/
66 class IClassFactoryWrapper : public IClassFactory
68 public:
70 virtual sal_Bool registerClass() = 0;
71 virtual sal_Bool deregisterClass() = 0;
74 /*****************************************************************************
76 class declaration ProviderOleWrapper_Impl
78 Provides an UNO service provider as OLE class factory. Handle the
79 OLE registration by overloading the abstract methods from
80 IClassFactoryWrapper.
82 Acts as a COM class factory. When IClassFactory::CreateInstance is being called
83 then it creates an service by help of the XSingleServiceFactory member and maps
84 maps it to a COM object.
86 *****************************************************************************/
88 class ProviderOleWrapper_Impl : public IClassFactoryWrapper
90 public:
92 ProviderOleWrapper_Impl( const Reference<XMultiServiceFactory>& smgr,
93 const Reference<XSingleServiceFactory>& xSFactory, GUID* pGuid);
94 virtual ~ProviderOleWrapper_Impl();
96 sal_Bool registerClass();
97 sal_Bool deregisterClass();
99 /* IUnknown methods */
100 STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj);
101 STDMETHOD_(ULONG, AddRef)();
102 STDMETHOD_(ULONG, Release)();
104 /* IClassFactory methods */
105 STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv);
106 STDMETHOD(LockServer)(int fLock);
108 protected:
110 oslInterlockedCount m_refCount;
111 Reference<XSingleServiceFactory> m_xSingleServiceFactory;
112 GUID m_guid;
113 DWORD m_factoryHandle;
114 Reference<XBridgeSupplier2> m_bridgeSupplier;
115 Reference<XMultiServiceFactory> m_smgr;
118 /*****************************************************************************
120 class declaration OneInstanceOleWrapper_Impl
122 Provides an single UNO object as OLE object. Handle the
123 OLE registration by overloading the abstract methods from
124 IClassFactoryWrapper.
126 Acts as a COM class factory. When IClassFactory::CreateInstance is being called
127 then it maps the XInstance member it to a COM object.
129 *****************************************************************************/
131 class OneInstanceOleWrapper_Impl : public IClassFactoryWrapper
133 public:
135 OneInstanceOleWrapper_Impl( const Reference<XMultiServiceFactory>& smgr, const Reference<XInterface>& xInst, GUID* pGuid, sal_Bool bAsApplication );
136 virtual ~OneInstanceOleWrapper_Impl();
138 sal_Bool registerClass();
139 sal_Bool deregisterClass();
141 /* IUnknown methods */
142 STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj);
143 STDMETHOD_(ULONG, AddRef)();
144 STDMETHOD_(ULONG, Release)();
146 /* IClassFactory methods */
147 STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv);
148 STDMETHOD(LockServer)(int fLock);
150 protected:
152 //ORefCount m_refCount;
153 oslInterlockedCount m_refCount;
154 Reference<XInterface> m_xInst;
155 GUID m_guid;
156 DWORD m_factoryHandle;
157 Reference<XBridgeSupplier2> m_bridgeSupplier;
158 Reference<XMultiServiceFactory> m_smgr;
159 unsigned long m_nApplRegHandle;
160 sal_Bool m_bAsApplication;
163 /*****************************************************************************
165 class declaration OleConverter_Impl2
167 Implementation of the UNO service com.sun.star.bridge.OleBridgeSupplier2.
169 *****************************************************************************/
171 // This class realizes the service com.sun.star.bridge.OleBridgeSupplier2 and
172 // com.sun.star.bridge.OleBridgeSupplierVar1. The class implements XBridgeSupplier2
173 // instead of XBridgeSuppplier as done by class OleConverter_Impl. The XBridgeSupplier2
174 // interface does not need a Maschine Id in its createBridge function anymore,
175 // If an UNO interface is to be converted then the member m_nUnoWrapperClass determines
176 // what wrapper class is to be used. There are currently InterfaceOleWrapper_Impl and
177 // UnoObjectWrapperRemoteOpt. The first is used for the OleBridgeSupplier2 and the
178 // latter for OleBridgeSupplierVar1.
179 // The m_nComWrapperClass specifies the class which is used as wrapper for COM interfaces.
180 // Currently there is only one class available ( IUnknownWrapper_Impl).
181 class OleConverter_Impl2 : public WeakImplHelper2<XBridgeSupplier2, XInitialization>,
182 public UnoConversionUtilities<OleConverter_Impl2>
184 public:
185 OleConverter_Impl2( const Reference<XMultiServiceFactory>& smgr);
186 OleConverter_Impl2( const Reference<XMultiServiceFactory>& smgr, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass );
187 virtual ~OleConverter_Impl2();
189 // XBridgeSupplier2 ---------------------------------------------------
191 virtual Any SAL_CALL createBridge(const Any& modelDepObject,
192 const Sequence<sal_Int8>& ProcessId,
193 sal_Int16 sourceModelType,
194 sal_Int16 destModelType)
195 throw (IllegalArgumentException, RuntimeException);
197 // XInitialization
198 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException);
200 // Abstract struct UnoConversionUtilities
201 virtual Reference< XInterface > createUnoWrapperInstance();
202 virtual Reference< XInterface > createComWrapperInstance();
203 protected:
208 /*****************************************************************************
210 class declaration OleClient_Impl
212 Implementation of the UNO service com.sun.star.bridge.OleObjectFactory.
214 *****************************************************************************/
217 class OleClient_Impl : public WeakImplHelper1<XMultiServiceFactory>,
218 public UnoConversionUtilities<OleClient_Impl>
220 public:
221 OleClient_Impl( const Reference<XMultiServiceFactory>& smgr);
222 ~OleClient_Impl();
224 // XMultiServiceFactory
225 virtual Reference<XInterface> SAL_CALL createInstance(const OUString& ServiceSpecifier) throw( Exception, RuntimeException);
226 virtual Reference<XInterface> SAL_CALL createInstanceWithArguments(const OUString& ServiceSpecifier, const Sequence< Any >& Arguments) throw (Exception, RuntimeException);
227 Sequence< OUString > SAL_CALL getAvailableServiceNames() throw (RuntimeException);
229 // Abstract struct UnoConversionUtilities
230 virtual Reference< XInterface > createUnoWrapperInstance();
231 virtual Reference< XInterface > createComWrapperInstance();
234 OUString getImplementationName();
235 protected:
236 Reference<XBridgeSupplier2> m_bridgeSupplier;
239 /*****************************************************************************
241 class declaration OleServer_Impl
243 Implementation of the UNO service com.sun.star.bridge.OleApplicationRegistration.
244 Register the calling application as OLE automation server for
245 standard OLE object. The objects will be registered while instanciating
246 this implementation and deregistrated, if this implementation is destroyed.
248 *****************************************************************************/
250 class OleServer_Impl : public OWeakObject, XTypeProvider
252 public:
253 OleServer_Impl( const Reference<XMultiServiceFactory> &smgr);
254 ~OleServer_Impl();
256 // XInterface
257 virtual Any SAL_CALL queryInterface( const Type& aType ) throw(RuntimeException);
258 virtual void SAL_CALL acquire( ) throw ();
259 virtual void SAL_CALL release( ) throw ();
261 // XTypeProvider
262 virtual Sequence< Type > SAL_CALL getTypes( ) throw(RuntimeException);
263 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException);
265 protected:
267 sal_Bool provideService(const Reference<XSingleServiceFactory>& xMulFact, GUID* guid);
268 sal_Bool provideInstance(const Reference<XInterface>& xInst, GUID* guid, sal_Bool bAsApplication );
270 list< IClassFactoryWrapper* > m_wrapperList;
271 Reference< XBridgeSupplier2 > m_bridgeSupplier;
273 Reference<XMultiServiceFactory> m_smgr;
276 } // end namespace
277 #endif