update dev300-m58
[ooovba.git] / extensions / source / ole / servprov.hxx
blobb193fe754d2687a1388a35e6477e838cc5c68719
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: servprov.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _SERVPROV_HXX
32 #define _SERVPROV_HXX
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #ifndef _CPPUHELPER_IMPLBASE3_HXX_
36 #include <cppuhelper/implbase2.hxx>
37 #endif
39 #include "ole2uno.hxx"
40 #include "unoconversionutilities.hxx"
43 using namespace com::sun::star::bridge;
44 using namespace cppu;
45 using namespace std;
47 namespace ole_adapter
49 Reference< XInterface> SAL_CALL ConverterProvider_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr)
50 throw( Exception);
51 Reference< XInterface> SAL_CALL ConverterProvider_CreateInstance2( const Reference<XMultiServiceFactory> & xSMgr)
52 throw( Exception);
53 Reference< XInterface> SAL_CALL ConverterProvider_CreateInstanceVar1( const Reference<XMultiServiceFactory> & xSMgr)
54 throw( Exception);
55 Reference<XInterface> SAL_CALL OleClient_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr)
56 throw( Exception);
57 Reference<XInterface> SAL_CALL OleServer_CreateInstance( const Reference<XMultiServiceFactory> & xSMgr)
58 throw( Exception);
59 /*****************************************************************************
61 class declaration IClassFactoryWrapper
63 Specify abstract helper methods on class factories, which provide
64 UNO objects. These methods are used by objects of class OleServer_Impl,
65 to handle the OLE registration of different class factories.
67 *****************************************************************************/
69 class IClassFactoryWrapper : public IClassFactory
71 public:
73 virtual sal_Bool registerClass() = 0;
74 virtual sal_Bool deregisterClass() = 0;
77 /*****************************************************************************
79 class declaration ProviderOleWrapper_Impl
81 Provides an UNO service provider as OLE class factory. Handle the
82 OLE registration by overloading the abstract methods from
83 IClassFactoryWrapper.
85 Acts as a COM class factory. When IClassFactory::CreateInstance is being called
86 then it creates an service by help of the XSingleServiceFactory member and maps
87 maps it to a COM object.
89 *****************************************************************************/
91 class ProviderOleWrapper_Impl : public IClassFactoryWrapper
93 public:
95 ProviderOleWrapper_Impl( const Reference<XMultiServiceFactory>& smgr,
96 const Reference<XSingleServiceFactory>& xSFactory, GUID* pGuid);
97 virtual ~ProviderOleWrapper_Impl();
99 sal_Bool registerClass();
100 sal_Bool deregisterClass();
102 /* IUnknown methods */
103 STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj);
104 STDMETHOD_(ULONG, AddRef)();
105 STDMETHOD_(ULONG, Release)();
107 /* IClassFactory methods */
108 STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv);
109 STDMETHOD(LockServer)(int fLock);
111 protected:
113 oslInterlockedCount m_refCount;
114 Reference<XSingleServiceFactory> m_xSingleServiceFactory;
115 GUID m_guid;
116 DWORD m_factoryHandle;
117 Reference<XBridgeSupplier2> m_bridgeSupplier;
118 Reference<XMultiServiceFactory> m_smgr;
121 /*****************************************************************************
123 class declaration OneInstanceOleWrapper_Impl
125 Provides an single UNO object as OLE object. Handle the
126 OLE registration by overloading the abstract methods from
127 IClassFactoryWrapper.
129 Acts as a COM class factory. When IClassFactory::CreateInstance is being called
130 then it maps the XInstance member it to a COM object.
132 *****************************************************************************/
134 class OneInstanceOleWrapper_Impl : public IClassFactoryWrapper
136 public:
138 OneInstanceOleWrapper_Impl( const Reference<XMultiServiceFactory>& smgr, const Reference<XInterface>& xInst, GUID* pGuid, sal_Bool bAsApplication );
139 virtual ~OneInstanceOleWrapper_Impl();
141 sal_Bool registerClass();
142 sal_Bool deregisterClass();
144 /* IUnknown methods */
145 STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj);
146 STDMETHOD_(ULONG, AddRef)();
147 STDMETHOD_(ULONG, Release)();
149 /* IClassFactory methods */
150 STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv);
151 STDMETHOD(LockServer)(int fLock);
153 protected:
155 //ORefCount m_refCount;
156 oslInterlockedCount m_refCount;
157 Reference<XInterface> m_xInst;
158 GUID m_guid;
159 DWORD m_factoryHandle;
160 Reference<XBridgeSupplier2> m_bridgeSupplier;
161 Reference<XMultiServiceFactory> m_smgr;
162 unsigned long m_nApplRegHandle;
163 sal_Bool m_bAsApplication;
166 /*****************************************************************************
168 class declaration OleConverter_Impl2
170 Implementation of the UNO service com.sun.star.bridge.OleBridgeSupplier2.
172 *****************************************************************************/
174 // This class realizes the service com.sun.star.bridge.OleBridgeSupplier2 and
175 // com.sun.star.bridge.OleBridgeSupplierVar1. The class implements XBridgeSupplier2
176 // instead of XBridgeSuppplier as done by class OleConverter_Impl. The XBridgeSupplier2
177 // interface does not need a Maschine Id in its createBridge function anymore,
178 // If an UNO interface is to be converted then the member m_nUnoWrapperClass determines
179 // what wrapper class is to be used. There are currently InterfaceOleWrapper_Impl and
180 // UnoObjectWrapperRemoteOpt. The first is used for the OleBridgeSupplier2 and the
181 // latter for OleBridgeSupplierVar1.
182 // The m_nComWrapperClass specifies the class which is used as wrapper for COM interfaces.
183 // Currently there is only one class available ( IUnknownWrapper_Impl).
184 class OleConverter_Impl2 : public WeakImplHelper2<XBridgeSupplier2, XInitialization>,
185 public UnoConversionUtilities<OleConverter_Impl2>
187 public:
188 OleConverter_Impl2( const Reference<XMultiServiceFactory>& smgr);
189 OleConverter_Impl2( const Reference<XMultiServiceFactory>& smgr, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass );
190 virtual ~OleConverter_Impl2();
192 // XBridgeSupplier2 ---------------------------------------------------
194 virtual Any SAL_CALL createBridge(const Any& modelDepObject,
195 const Sequence<sal_Int8>& ProcessId,
196 sal_Int16 sourceModelType,
197 sal_Int16 destModelType)
198 throw (IllegalArgumentException, RuntimeException);
200 // XInitialization
201 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException);
203 // Abstract struct UnoConversionUtilities
204 virtual Reference< XInterface > createUnoWrapperInstance();
205 virtual Reference< XInterface > createComWrapperInstance();
206 protected:
211 /*****************************************************************************
213 class declaration OleClient_Impl
215 Implementation of the UNO service com.sun.star.bridge.OleObjectFactory.
217 *****************************************************************************/
220 class OleClient_Impl : public WeakImplHelper1<XMultiServiceFactory>,
221 public UnoConversionUtilities<OleClient_Impl>
223 public:
224 OleClient_Impl( const Reference<XMultiServiceFactory>& smgr);
225 ~OleClient_Impl();
227 // XMultiServiceFactory
228 virtual Reference<XInterface> SAL_CALL createInstance(const OUString& ServiceSpecifier) throw( Exception, RuntimeException);
229 virtual Reference<XInterface> SAL_CALL createInstanceWithArguments(const OUString& ServiceSpecifier, const Sequence< Any >& Arguments) throw (Exception, RuntimeException);
230 Sequence< OUString > SAL_CALL getAvailableServiceNames() throw (RuntimeException);
232 // Abstract struct UnoConversionUtilities
233 virtual Reference< XInterface > createUnoWrapperInstance();
234 virtual Reference< XInterface > createComWrapperInstance();
237 OUString getImplementationName();
238 protected:
239 Reference<XBridgeSupplier2> m_bridgeSupplier;
242 /*****************************************************************************
244 class declaration OleServer_Impl
246 Implementation of the UNO service com.sun.star.bridge.OleApplicationRegistration.
247 Register the calling application as OLE automation server for
248 standard OLE object. The objects will be registered while instanciating
249 this implementation and deregistrated, if this implementation is destroyed.
251 *****************************************************************************/
253 class OleServer_Impl : public OWeakObject, XTypeProvider
255 public:
256 OleServer_Impl( const Reference<XMultiServiceFactory> &smgr);
257 ~OleServer_Impl();
259 // XInterface
260 virtual Any SAL_CALL queryInterface( const Type& aType ) throw(RuntimeException);
261 virtual void SAL_CALL acquire( ) throw ();
262 virtual void SAL_CALL release( ) throw ();
264 // XTypeProvider
265 virtual Sequence< Type > SAL_CALL getTypes( ) throw(RuntimeException);
266 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException);
268 protected:
270 sal_Bool provideService(const Reference<XSingleServiceFactory>& xMulFact, GUID* guid);
271 sal_Bool provideInstance(const Reference<XInterface>& xInst, GUID* guid, sal_Bool bAsApplication );
273 list< IClassFactoryWrapper* > m_wrapperList;
274 Reference< XBridgeSupplier2 > m_bridgeSupplier;
276 Reference<XMultiServiceFactory> m_smgr;
279 } // end namespace
280 #endif