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