xref: /trunk/main/extensions/source/ole/servprov.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 
28 #ifndef _SERVPROV_HXX
29 #define _SERVPROV_HXX
30 
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #ifndef _CPPUHELPER_IMPLBASE3_HXX_
33 #include <cppuhelper/implbase2.hxx>
34 #endif
35 
36 #include "ole2uno.hxx"
37 #include "unoconversionutilities.hxx"
38 
39 
40 using namespace com::sun::star::bridge;
41 using namespace cppu;
42 using namespace std;
43 
44 namespace ole_adapter
45 {
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 /*****************************************************************************
57 
58     class declaration IClassFactoryWrapper
59 
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.
63 
64 *****************************************************************************/
65 
66 class IClassFactoryWrapper : public IClassFactory
67 {
68 public:
69 
70     virtual sal_Bool registerClass() = 0;
71     virtual sal_Bool deregisterClass() = 0;
72 };
73 
74 /*****************************************************************************
75 
76     class declaration ProviderOleWrapper_Impl
77 
78     Provides an UNO service provider as OLE class factory. Handle the
79     OLE registration by overloading the abstract methods from
80     IClassFactoryWrapper.
81 
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.
85 
86 *****************************************************************************/
87 
88 class ProviderOleWrapper_Impl : public IClassFactoryWrapper
89 {
90 public:
91 
92     ProviderOleWrapper_Impl( const Reference<XMultiServiceFactory>& smgr,
93                              const Reference<XSingleServiceFactory>& xSFactory, GUID* pGuid);
94     virtual ~ProviderOleWrapper_Impl();
95 
96     sal_Bool registerClass();
97     sal_Bool deregisterClass();
98 
99     /* IUnknown methods */
100     STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj);
101     STDMETHOD_(ULONG, AddRef)();
102     STDMETHOD_(ULONG, Release)();
103 
104     /* IClassFactory methods */
105     STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv);
106     STDMETHOD(LockServer)(int fLock);
107 
108 protected:
109 
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;
116 };
117 
118 /*****************************************************************************
119 
120     class declaration OneInstanceOleWrapper_Impl
121 
122     Provides an single UNO object as OLE object. Handle the
123     OLE registration by overloading the abstract methods from
124     IClassFactoryWrapper.
125 
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.
128 
129 *****************************************************************************/
130 
131 class OneInstanceOleWrapper_Impl : public IClassFactoryWrapper
132 {
133 public:
134 
135     OneInstanceOleWrapper_Impl( const Reference<XMultiServiceFactory>& smgr, const Reference<XInterface>& xInst, GUID* pGuid, sal_Bool bAsApplication );
136     virtual ~OneInstanceOleWrapper_Impl();
137 
138     sal_Bool registerClass();
139     sal_Bool deregisterClass();
140 
141     /* IUnknown methods */
142     STDMETHOD(QueryInterface)(REFIID riid, LPVOID FAR * ppvObj);
143     STDMETHOD_(ULONG, AddRef)();
144     STDMETHOD_(ULONG, Release)();
145 
146     /* IClassFactory methods */
147     STDMETHOD(CreateInstance)(IUnknown FAR* punkOuter, REFIID riid, void FAR* FAR* ppv);
148     STDMETHOD(LockServer)(int fLock);
149 
150 protected:
151 
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;
161 };
162 
163 /*****************************************************************************
164 
165     class declaration OleConverter_Impl2
166 
167     Implementation of the UNO service com.sun.star.bridge.OleBridgeSupplier2.
168 
169 *****************************************************************************/
170 
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>
183 {
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();
188 
189     // XBridgeSupplier2 ---------------------------------------------------
190 
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);
196 
197     // XInitialization
198     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) throw(Exception, RuntimeException);
199 
200     // Abstract struct UnoConversionUtilities
201     virtual Reference< XInterface > createUnoWrapperInstance();
202     virtual Reference< XInterface > createComWrapperInstance();
203 protected:
204 
205 };
206 
207 
208 /*****************************************************************************
209 
210     class declaration OleClient_Impl
211 
212     Implementation of the UNO service com.sun.star.bridge.OleObjectFactory.
213 
214 *****************************************************************************/
215 
216 
217 class OleClient_Impl : public WeakImplHelper1<XMultiServiceFactory>,
218                        public UnoConversionUtilities<OleClient_Impl>
219 {
220 public:
221     OleClient_Impl( const Reference<XMultiServiceFactory>& smgr);
222     ~OleClient_Impl();
223 
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);
228 
229     // Abstract struct UnoConversionUtilities
230     virtual Reference< XInterface > createUnoWrapperInstance();
231     virtual Reference< XInterface > createComWrapperInstance();
232 
233 
234     OUString getImplementationName();
235 protected:
236     Reference<XBridgeSupplier2> m_bridgeSupplier;
237 };
238 
239 /*****************************************************************************
240 
241     class declaration OleServer_Impl
242 
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.
247 
248 *****************************************************************************/
249 
250 class OleServer_Impl : public OWeakObject, XTypeProvider
251 {
252 public:
253     OleServer_Impl( const Reference<XMultiServiceFactory> &smgr);
254     ~OleServer_Impl();
255 
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 ();
260 
261     // XTypeProvider
262     virtual Sequence< Type > SAL_CALL getTypes( ) throw(RuntimeException);
263     virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException);
264 
265 protected:
266 
267     sal_Bool provideService(const Reference<XSingleServiceFactory>& xMulFact, GUID* guid);
268     sal_Bool provideInstance(const Reference<XInterface>& xInst, GUID* guid, sal_Bool bAsApplication );
269 
270     list< IClassFactoryWrapper* > m_wrapperList;
271     Reference< XBridgeSupplier2 >   m_bridgeSupplier;
272 
273     Reference<XMultiServiceFactory> m_smgr;
274 };
275 
276 } // end namespace
277 #endif
278 
279 
280 
281