xref: /AOO41X/main/extensions/source/ole/servprov.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 
31 #ifdef __MINGW32__
32 #define INITGUID
33 #include <initguid.h>
34 #else
35 #include "ole2uno.hxx"
36 #include "unoconversionutilities.hxx"
37 #endif
38 #include "servprov.hxx"
39 #include "unoobjw.hxx"
40 #include "oleobjw.hxx"
41 #include <rtl/unload.h>
42 
43 #include <tools/presys.h>
44 #define _WIN32_WINNT 0x0400
45 
46 #if defined(_MSC_VER) && (_MSC_VER >= 1300)
47 #undef _DEBUG
48 #endif
49 #include <atlbase.h>
50 extern CComModule _Module;
51 #include <atlcom.h>
52 #include <tools/postsys.h>
53 
54 
55 using namespace std;
56 using namespace cppu;
57 using namespace rtl;
58 using namespace osl;
59 using namespace com::sun::star::lang;
60 using namespace com::sun::star::uno;
61 using namespace com::sun::star::bridge;
62 using namespace com::sun::star::bridge::ModelDependent;
63 
64 
65 
66 namespace ole_adapter
67 {
68 
69 #include <initguid.h>
70 // prior 5.2 ( src569 ver m)
71 // {3ECF78F0-B149-11D2-8EBE-00105AD848AF}
72 //DEFINE_GUID(OID_ServiceManager, 0x3ECF78F0, 0xB149, 0x11d2, 0x8E, 0xBE, 0x00, 0x10, 0x5A, 0xD8, 0x48, 0xAF);
73 
74 #ifndef OWNGUID
75 // GUID used since 5.2 ( src569 m)
76 // {82154420-0FBF-11d4-8313-005004526AB4}
77 DEFINE_GUID(OID_ServiceManager, 0x82154420, 0xfbf, 0x11d4, 0x83, 0x13, 0x0, 0x50, 0x4, 0x52, 0x6a, 0xb4);
78 #else
79 // Alternative GUID
80 // {D9BB9D1D-BFA9-4357-9F11-9A2E9061F06E}
81 DEFINE_GUID(OID_ServiceManager, 0xd9bb9d1d, 0xbfa9, 0x4357, 0x9f, 0x11, 0x9a, 0x2e, 0x90, 0x61, 0xf0, 0x6e);
82 #endif
83 
84 extern	rtl_StandardModuleCount globalModuleCount;
85 
86 /*****************************************************************************
87 
88 	class implementation ProviderOleWrapper_Impl
89 
90 *****************************************************************************/
91 
92 ProviderOleWrapper_Impl::ProviderOleWrapper_Impl(const Reference<XMultiServiceFactory>& smgr,
93 												 const Reference<XSingleServiceFactory>& xSFact, GUID* pGuid)
94 	: m_xSingleServiceFactory(xSFact),
95 	  m_smgr( smgr)
96 {
97 	m_guid = *pGuid;
98 
99 	Reference<XInterface> xInt = smgr->createInstance(reinterpret_cast<const sal_Unicode*>(L"com.sun.star.bridge.oleautomation.BridgeSupplier"));
100 
101 	if (xInt.is())
102 	{
103 		Any a= xInt->queryInterface( ::getCppuType( reinterpret_cast<
104 												  Reference< XBridgeSupplier2>* >(0)));
105 		a >>= m_bridgeSupplier;
106 
107 	}
108 }
109 
110 ProviderOleWrapper_Impl::~ProviderOleWrapper_Impl()
111 {
112 }
113 
114 sal_Bool ProviderOleWrapper_Impl::registerClass()
115 {
116 	HRESULT hresult;
117 
118 	o2u_attachCurrentThread();
119 
120 	hresult = CoRegisterClassObject(
121 			m_guid,
122 			this,
123 			CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
124 			REGCLS_MULTIPLEUSE,
125 			&m_factoryHandle);
126 
127 	return (hresult == NOERROR);
128 }
129 
130 sal_Bool ProviderOleWrapper_Impl::deregisterClass()
131 {
132 	HRESULT hresult = CoRevokeClassObject(m_factoryHandle);
133 
134 	return (hresult == NOERROR);
135 }
136 
137 STDMETHODIMP ProviderOleWrapper_Impl::QueryInterface(REFIID riid, void FAR* FAR* ppv)
138 {
139     if(IsEqualIID(riid, IID_IUnknown))
140 	{
141 		AddRef();
142 		*ppv = (IUnknown*) (IClassFactory*) this;
143 		return NOERROR;
144     }
145     else if (IsEqualIID(riid, IID_IClassFactory))
146 	{
147 		AddRef();
148 		*ppv = (IClassFactory*) this;
149 		return NOERROR;
150 	}
151 
152     *ppv = NULL;
153     return ResultFromScode(E_NOINTERFACE);
154 }
155 
156 STDMETHODIMP_(ULONG) ProviderOleWrapper_Impl::AddRef()
157 {
158 	return osl_incrementInterlockedCount( &m_refCount);
159 }
160 
161 STDMETHODIMP_(ULONG) ProviderOleWrapper_Impl::Release()
162 {
163     MutexGuard aGuard( Mutex::getGlobalMutex());
164     ULONG refCount = --m_refCount;
165 	if (m_refCount == 0)
166 	{
167 		delete this;
168 	}
169 
170     return refCount;
171 }
172 
173 STDMETHODIMP ProviderOleWrapper_Impl::CreateInstance(IUnknown FAR* punkOuter,
174 													 REFIID riid,
175     												 void FAR* FAR* ppv)
176 {
177 	HRESULT ret = ResultFromScode(E_UNEXPECTED);
178 	punkOuter = NULL;
179 
180 	Reference<XInterface> xInstance;
181 
182 	if (m_xSingleServiceFactory.is())
183 	{
184 		xInstance = m_xSingleServiceFactory->createInstance();
185 
186 		if (xInstance.is())
187 		{
188 			Any usrAny(&xInstance, getCppuType( & xInstance));
189 
190 			sal_uInt8 arId[16];
191 			rtl_getGlobalProcessId( arId );
192 			Any oleAny = m_bridgeSupplier->createBridge(usrAny,
193 										Sequence<sal_Int8>((sal_Int8*)arId, 16),
194 										UNO,
195 										OLE);
196 
197 
198 			if (oleAny.getValueTypeClass() == getCppuType( (sal_uInt32 *)0).getTypeClass())
199 			{
200 				VARIANT* pVariant = *(VARIANT**)oleAny.getValue();
201 
202 				if (pVariant->vt == VT_DISPATCH)
203 				{
204 		    		ret = pVariant->pdispVal->QueryInterface(riid, ppv);
205 				}
206 
207 				VariantClear(pVariant);
208 				CoTaskMemFree(pVariant);
209 			}
210 		}
211 	}
212 
213 	return ret;
214 }
215 
216 STDMETHODIMP ProviderOleWrapper_Impl::LockServer(int /*fLock*/)
217 {
218     return NOERROR;
219 }
220 
221 /*****************************************************************************
222 
223 	class implementation OneInstanceOleWrapper_Impl
224 
225 *****************************************************************************/
226 
227 OneInstanceOleWrapper_Impl::OneInstanceOleWrapper_Impl(  const Reference<XMultiServiceFactory>& smgr,
228 														 const Reference<XInterface>& xInst,
229                                                          GUID* pGuid,
230                                                          sal_Bool bAsApplication )
231 	: m_xInst(xInst), m_refCount(0),
232 	  m_smgr( smgr),
233       m_factoryHandle( 0 ),
234       m_bAsApplication( bAsApplication ),
235       m_nApplRegHandle( 0 )
236 {
237 	m_guid = *pGuid;
238 
239 	Reference<XInterface> xInt = m_smgr->createInstance(reinterpret_cast<const sal_Unicode*>(L"com.sun.star.bridge.oleautomation.BridgeSupplier"));
240 
241 	if (xInt.is())
242 	{
243 		Any a= xInt->queryInterface( getCppuType(
244 			reinterpret_cast< Reference<XBridgeSupplier2>*>(0)));
245 		a >>= m_bridgeSupplier;
246 	}
247 }
248 
249 OneInstanceOleWrapper_Impl::~OneInstanceOleWrapper_Impl()
250 {
251 }
252 
253 sal_Bool OneInstanceOleWrapper_Impl::registerClass()
254 {
255 	HRESULT hresult;
256 
257 	o2u_attachCurrentThread();
258 
259 	hresult = CoRegisterClassObject(
260 			m_guid,
261 			this,
262 			CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
263 			REGCLS_MULTIPLEUSE,
264 			&m_factoryHandle);
265 
266     if ( hresult == NOERROR && m_bAsApplication )
267         hresult = RegisterActiveObject( this, m_guid, ACTIVEOBJECT_WEAK, &m_nApplRegHandle );
268 
269 	return (hresult == NOERROR);
270 }
271 
272 sal_Bool OneInstanceOleWrapper_Impl::deregisterClass()
273 {
274     HRESULT hresult1 = NOERROR;
275     if ( m_bAsApplication )
276         hresult1 = RevokeActiveObject( m_nApplRegHandle, NULL );
277 
278 	HRESULT hresult2 = CoRevokeClassObject(m_factoryHandle);
279 
280 	return (hresult1 == NOERROR && hresult2 == NOERROR);
281 }
282 
283 STDMETHODIMP OneInstanceOleWrapper_Impl::QueryInterface(REFIID riid, void FAR* FAR* ppv)
284 {
285     if(IsEqualIID(riid, IID_IUnknown))
286 	{
287 		AddRef();
288 		*ppv = (IUnknown*) (IClassFactory*) this;
289 		return NOERROR;
290     }
291     else if (IsEqualIID(riid, IID_IClassFactory))
292 	{
293 		AddRef();
294 		*ppv = (IClassFactory*) this;
295 		return NOERROR;
296 	}
297 
298     *ppv = NULL;
299     return ResultFromScode(E_NOINTERFACE);
300 }
301 
302 STDMETHODIMP_(ULONG) OneInstanceOleWrapper_Impl::AddRef()
303 {
304 	return osl_incrementInterlockedCount( &m_refCount);
305 }
306 
307 STDMETHODIMP_(ULONG) OneInstanceOleWrapper_Impl::Release()
308 {
309     MutexGuard oGuard( Mutex::getGlobalMutex());
310 	ULONG refCount = --m_refCount;
311 	if ( m_refCount == 0)
312 	{
313 		delete this;
314 	}
315 
316     return refCount;
317 }
318 
319 STDMETHODIMP OneInstanceOleWrapper_Impl::CreateInstance(IUnknown FAR* punkOuter,
320 													 	REFIID riid,
321     												 	void FAR* FAR* ppv)
322 {
323 	HRESULT ret = ResultFromScode(E_UNEXPECTED);
324 	punkOuter = NULL;
325 
326 	if (m_xInst.is())
327 	{
328 		Any usrAny(&m_xInst, getCppuType( &m_xInst));
329 		sal_uInt8 arId[16];
330 		rtl_getGlobalProcessId( arId);
331 		Any oleAny = m_bridgeSupplier->createBridge(usrAny,
332 										Sequence<sal_Int8>( (sal_Int8*)arId, 16),
333 										UNO,
334 										OLE);
335 
336 
337 		if (oleAny.getValueTypeClass() == TypeClass_UNSIGNED_LONG)
338 		{
339 			VARIANT* pVariant = *(VARIANT**)oleAny.getValue();
340 
341 			if ((pVariant->vt == VT_UNKNOWN) || (pVariant->vt == VT_DISPATCH))
342 			{
343 	    		ret = pVariant->punkVal->QueryInterface(riid, ppv);
344 			}
345 
346 			VariantClear(pVariant);
347 			CoTaskMemFree(pVariant);
348 		}
349 	}
350 
351 	return ret;
352 }
353 
354 STDMETHODIMP OneInstanceOleWrapper_Impl::LockServer(int /*fLock*/)
355 {
356     return NOERROR;
357 }
358 
359 
360 /*****************************************************************************
361 
362 	class implementation OleConverter_Impl2
363 
364 *****************************************************************************/
365 
366 OleConverter_Impl2::OleConverter_Impl2( const Reference<XMultiServiceFactory> &smgr):
367 	UnoConversionUtilities<OleConverter_Impl2>( smgr)
368 
369 {
370 	// library unloading support
371 	globalModuleCount.modCnt.acquire( &globalModuleCount.modCnt);
372 }
373 
374 // The XMultiServiceFactory is later set by XInitialization
375 OleConverter_Impl2::OleConverter_Impl2( const  Reference<XMultiServiceFactory>& smgr, sal_uInt8 unoWrapperClass, sal_uInt8 comWrapperClass ):
376 	UnoConversionUtilities<OleConverter_Impl2>( smgr, unoWrapperClass, comWrapperClass  )
377 
378 {
379 	//library unloading support
380 	globalModuleCount.modCnt.acquire( &globalModuleCount.modCnt);
381 }
382 
383 OleConverter_Impl2::~OleConverter_Impl2()
384 {
385 	globalModuleCount.modCnt.release( &globalModuleCount.modCnt);
386 }
387 
388 // XBridgeSupplier --------------------------------------------------------------
389 Any SAL_CALL OleConverter_Impl2::createBridge(const Any& modelDepObject,
390 									   const Sequence< sal_Int8 >& ProcessId,
391 									   sal_Int16 sourceModelType,
392 									   sal_Int16 destModelType)
393 									   throw (IllegalArgumentException,
394 									   			RuntimeException )
395 {
396 	Any ret;
397 	sal_uInt8 arId[16];
398 	rtl_getGlobalProcessId( arId );
399 
400 	Sequence< sal_Int8 > seqProcessId( (sal_Int8*)arId, 16);
401 
402 	if ( seqProcessId == ProcessId)
403 	{
404 		if (sourceModelType == UNO)
405 		{
406 			if (destModelType == UNO)
407 			{
408 				// same model -> copy value only
409 				ret = modelDepObject;
410 			}
411 			else if (destModelType == OLE)
412 			{
413 				// convert UNO any into variant
414 				VARIANT* pVariant = (VARIANT*) CoTaskMemAlloc(sizeof(VARIANT));
415 				VariantInit( pVariant);
416                 try
417                 {
418                     anyToVariant( pVariant, modelDepObject);
419                 }
420                 catch(...)
421 				{
422 					CoTaskMemFree(pVariant);
423 					throw IllegalArgumentException();
424 				}
425                 ret.setValue((void*) &pVariant, getCppuType((sal_uInt32*)0));
426 			}
427 			else
428 				throw IllegalArgumentException();
429 		}
430 		else if (sourceModelType == OLE)
431 		{
432 			if (modelDepObject.getValueType() != getCppuType((sal_uInt32*)0))
433 			{
434 				throw IllegalArgumentException();
435 			}
436 			else if (destModelType == OLE)
437 			{
438 				// same model -> copy value only
439 				VARIANT* pVariant = (VARIANT*) CoTaskMemAlloc(sizeof(VARIANT));
440 
441 				if (NOERROR != VariantCopy(pVariant, *(VARIANT**)modelDepObject.getValue()))
442 				{
443 					CoTaskMemFree(pVariant);
444 					throw(IllegalArgumentException());
445 				}
446 				else
447 				{
448 					ret.setValue((void*) &pVariant, getCppuType((sal_uInt32*)0));
449 				}
450 			}
451 			else if (destModelType == UNO)
452 			{
453 				// convert variant into UNO any
454 				VARIANT* pVariant = *(VARIANT**)modelDepObject.getValue();
455 				try
456 				{
457 					variantToAny(pVariant, ret);
458 				}
459 				catch (CannotConvertException & e)
460 				{
461 					throw IllegalArgumentException(
462 						e.Message, 0, -1);
463 				}
464 			}
465 			else
466 				throw IllegalArgumentException();
467 
468 		}
469 		else
470 			throw IllegalArgumentException();
471 	}
472 
473 	return ret;
474 }
475 
476 
477 // XInitialize ------------------------------------------------------------------------------
478 // the first argument is an XMultiServiceFactory if at all
479 void SAL_CALL OleConverter_Impl2::initialize( const Sequence< Any >& aArguments )
480 				throw(Exception, RuntimeException)
481 {
482 	if( aArguments.getLength() == 1 && aArguments[0].getValueTypeClass() == TypeClass_INTERFACE)
483 	{
484 		Reference < XInterface > xInt;
485 		aArguments[0] >>= xInt;
486 		Reference <XMultiServiceFactory> xMulti( xInt, UNO_QUERY);
487 		m_smgrRemote= xMulti;
488 	}
489 }
490 
491 // UnoConversionUtilities -------------------------------------------------------------------
492 Reference< XInterface > OleConverter_Impl2::createUnoWrapperInstance()
493 {
494 	if( m_nUnoWrapperClass == INTERFACE_OLE_WRAPPER_IMPL)
495 	{
496 		Reference<XWeak> xWeak= static_cast<XWeak*>( new InterfaceOleWrapper_Impl(
497 								m_smgr, m_nUnoWrapperClass, m_nComWrapperClass));
498 		return Reference<XInterface>( xWeak, UNO_QUERY);
499 	}
500 	else if( m_nUnoWrapperClass == UNO_OBJECT_WRAPPER_REMOTE_OPT)
501 	{
502 		Reference<XWeak> xWeak= static_cast<XWeak*>( new UnoObjectWrapperRemoteOpt(
503 								m_smgr, m_nUnoWrapperClass, m_nComWrapperClass));
504 		return Reference<XInterface>( xWeak, UNO_QUERY);
505 	}
506 	else
507 		return Reference<XInterface>();
508 }
509 
510 Reference< XInterface > OleConverter_Impl2::createComWrapperInstance()
511 {
512 	Reference<XWeak> xWeak= static_cast<XWeak*>( new IUnknownWrapper_Impl(
513 							m_smgr, m_nUnoWrapperClass, m_nComWrapperClass));
514 	return Reference<XInterface>( xWeak, UNO_QUERY);
515 }
516 
517 
518 
519 /*****************************************************************************
520 
521 	class implementation OleClient_Impl
522 
523 *****************************************************************************/
524 
525 OleClient_Impl::OleClient_Impl( const Reference<XMultiServiceFactory>& smgr):
526 	UnoConversionUtilities<OleClient_Impl>( smgr)
527 {
528 	// library unloading support
529 	globalModuleCount.modCnt.acquire( &globalModuleCount.modCnt);
530 	Reference<XInterface> xInt;// = m_smgr->createInstance(L"com.sun.star.bridge.OleBridgeSupplier2");
531 
532 	if (xInt.is())
533 	{
534 		Any a= xInt->queryInterface(getCppuType(
535 			reinterpret_cast<Reference<XBridgeSupplier2>*>(0)));
536 		a >>= m_bridgeSupplier;
537 	}
538 }
539 
540 OleClient_Impl::~OleClient_Impl()
541 {
542 	// library unloading support
543 	globalModuleCount.modCnt.release( &globalModuleCount.modCnt);
544 }
545 
546 Sequence< OUString >	SAL_CALL OleClient_Impl::getAvailableServiceNames() throw( RuntimeException )
547 {
548 	Sequence< OUString > ret;
549 
550 	return ret;
551 }
552 
553 
554 OUString OleClient_Impl::getImplementationName()
555 {
556 	return OUString(reinterpret_cast<const sal_Unicode*>(L"com.sun.star.comp.ole.OleClient"));
557 }
558 
559 Reference<XInterface> SAL_CALL OleClient_Impl::createInstance(const OUString& ServiceSpecifier) throw (Exception, RuntimeException )
560 {
561 	Reference<XInterface> 	ret;
562 	HRESULT 		result;
563 	IUnknown* 		pUnknown = NULL;
564 	CLSID			classId;
565 
566 	o2u_attachCurrentThread();
567 
568 	result = CLSIDFromProgID(
569   				reinterpret_cast<LPCWSTR>(ServiceSpecifier.getStr()),  	//Pointer to the ProgID
570   				&classId);         				//Pointer to the CLSID
571 
572 
573 	if (result == NOERROR)
574 	{
575 		result = CoCreateInstance(
576 					  classId,     			//Class identifier (CLSID) of the object
577 					  NULL, 			   	//Pointer to whether object is or isn't part of an aggregate
578 					  CLSCTX_SERVER,  //Context for running executable code
579 					  IID_IUnknown,         //Reference to the identifier of the interface
580 					  (void**)&pUnknown);   //Address of output variable that receives
581 	                       				   	// the interface pointer requested in riid
582 	}
583 
584 	if (pUnknown != NULL)
585 	{
586 		Any	any;
587 		CComVariant variant;
588 
589 		V_VT(&variant) = VT_UNKNOWN;
590 		V_UNKNOWN(&variant)	= pUnknown;
591 		// AddRef for Variant
592 		pUnknown->AddRef();
593 
594 		// When the object is wrapped, then its refcount is increased
595 		variantToAny(&variant, any);
596         if (any.getValueTypeClass() == TypeClass_INTERFACE)
597         {
598             any >>= ret;
599         }
600 		pUnknown->Release(); // CoCreateInstance
601 	}
602 
603 	return ret;
604 }
605 
606 Reference<XInterface> SAL_CALL OleClient_Impl::createInstanceWithArguments(const OUString& ServiceSpecifier, const Sequence< Any >& /*Arguments*/) throw (Exception, RuntimeException)
607 {
608 	return createInstance( ServiceSpecifier);
609 }
610 
611 // UnoConversionUtilities -----------------------------------------------------------------------------
612 Reference< XInterface > OleClient_Impl::createUnoWrapperInstance()
613 {
614 	if( m_nUnoWrapperClass == INTERFACE_OLE_WRAPPER_IMPL)
615 	{
616 		Reference<XWeak> xWeak= static_cast<XWeak*>( new InterfaceOleWrapper_Impl(
617 								m_smgr, m_nUnoWrapperClass, m_nComWrapperClass));
618 		return Reference<XInterface>( xWeak, UNO_QUERY);
619 	}
620 	else if( m_nUnoWrapperClass == UNO_OBJECT_WRAPPER_REMOTE_OPT)
621 	{
622 		Reference<XWeak> xWeak= static_cast<XWeak*>( new UnoObjectWrapperRemoteOpt(
623 								m_smgr, m_nUnoWrapperClass, m_nComWrapperClass));
624 		return Reference<XInterface>( xWeak, UNO_QUERY);
625 	}
626 	else
627 		return Reference< XInterface>();
628 }
629 // UnoConversionUtilities -----------------------------------------------------------------------------
630 Reference< XInterface > OleClient_Impl::createComWrapperInstance( )
631 {
632 	Reference<XWeak> xWeak= static_cast<XWeak*>( new IUnknownWrapper_Impl(
633 							m_smgr, m_nUnoWrapperClass, m_nComWrapperClass));
634 	return Reference<XInterface>( xWeak, UNO_QUERY);
635 }
636 
637 
638 
639 /*****************************************************************************
640 
641 	class implementation OleServer_Impl
642 
643 *****************************************************************************/
644 
645 OleServer_Impl::OleServer_Impl( const Reference<XMultiServiceFactory>& smgr):
646 	m_smgr( smgr)
647 {
648 	//library unloading support
649 	globalModuleCount.modCnt.acquire( &globalModuleCount.modCnt);
650 	Reference<XInterface> xInt = m_smgr->createInstance(reinterpret_cast<const sal_Unicode*>(L"com.sun.star.bridge.oleautomation.BridgeSupplier"));
651 
652 	if (xInt.is())
653 	{
654 		Any a= xInt->queryInterface( getCppuType(
655 			reinterpret_cast< Reference<XBridgeSupplier2>*>(0)));
656 		a >>= m_bridgeSupplier;
657 	}
658 
659 #ifndef OWNGUID
660 	sal_Bool bOLERegister = sal_False;
661 #else
662 	sal_Bool bOLERegister = sal_True;
663 #endif
664 	sal_Bool ret = provideInstance( m_smgr, (GUID*)&OID_ServiceManager, bOLERegister );
665     (void)ret;
666 }
667 
668 OleServer_Impl::~OleServer_Impl()
669 {
670 	while (!m_wrapperList.empty())
671 	{
672 		(*m_wrapperList.begin())->deregisterClass();
673 		(*m_wrapperList.begin())->Release();
674 		m_wrapperList.pop_front();
675 	}
676 	//library unloading support
677 	globalModuleCount.modCnt.release( &globalModuleCount.modCnt);
678 }
679 // XInterface --------------------------------------------------
680 Any SAL_CALL OleServer_Impl::queryInterface( const Type& aType ) throw(RuntimeException)
681 {
682 	Any a= ::cppu::queryInterface( aType, static_cast<XTypeProvider*>(this));
683 	if( a == Any())
684 		return OWeakObject::queryInterface( aType);
685 	else
686 		return a;
687 }
688 void SAL_CALL OleServer_Impl::acquire(  ) throw()
689 {
690 	OWeakObject::acquire();
691 }
692 void SAL_CALL OleServer_Impl::release(  ) throw ()
693 {
694 	OWeakObject::release();
695 }
696 
697 
698 // XTypeProvider --------------------------------------------------
699 Sequence< Type > SAL_CALL OleServer_Impl::getTypes( ) throw(RuntimeException)
700 {
701 	static OTypeCollection *pCollection = 0;
702 	if( ! pCollection )
703 	{
704 		MutexGuard guard( Mutex::getGlobalMutex() );
705 		if( ! pCollection )
706 		{
707 			static OTypeCollection collection(
708 				getCppuType(reinterpret_cast< Reference< XWeak>*>(0)),
709 				getCppuType(reinterpret_cast< Reference< XTypeProvider>*>(0)) );
710 			pCollection = &collection;
711 		}
712 	}
713 	return (*pCollection).getTypes();
714 }
715 Sequence< sal_Int8 > SAL_CALL OleServer_Impl::getImplementationId() throw(RuntimeException)
716 {
717 	static OImplementationId *pId = 0;
718 	if( ! pId )
719 	{
720 		MutexGuard guard( Mutex::getGlobalMutex() );
721 		if( ! pId )
722 		{
723 			static OImplementationId id( sal_False );
724 			pId = &id;
725 		}
726 	}
727 	return (*pId).getImplementationId();
728 }
729 
730 
731 sal_Bool OleServer_Impl::provideService(const Reference<XSingleServiceFactory>& xSFact, GUID* guid)
732 {
733 	IClassFactoryWrapper* pFac = new ProviderOleWrapper_Impl( m_smgr, xSFact, guid);
734 
735 	pFac->AddRef();
736 
737 	m_wrapperList.push_back(pFac);
738 
739 	return pFac->registerClass();
740 }
741 
742 sal_Bool OleServer_Impl::provideInstance(const Reference<XInterface>& xInst, GUID* guid, sal_Bool bAsApplication )
743 {
744 	IClassFactoryWrapper* pFac = new OneInstanceOleWrapper_Impl( m_smgr, xInst, guid, bAsApplication );
745 
746 	pFac->AddRef();
747 	m_wrapperList.push_back(pFac);
748 
749 	return pFac->registerClass();
750 }
751 
752 
753 
754 } // end namespace
755