LibreOffice Module cppuhelper (master) 1
factory.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/log.hxx>
21#include <osl/diagnose.h>
22#include <osl/mutex.hxx>
23#include <cppuhelper/weak.hxx>
29#include <rtl/unload.h>
30
32#include <o3tl/string_view.hxx>
33
34#include <com/sun/star/lang/XServiceInfo.hpp>
35#include <com/sun/star/lang/XSingleServiceFactory.hpp>
36#include <com/sun/star/lang/XSingleComponentFactory.hpp>
37#include <com/sun/star/lang/XInitialization.hpp>
38#include <com/sun/star/lang/XMultiServiceFactory.hpp>
39#include <com/sun/star/loader/XImplementationLoader.hpp>
40#include <com/sun/star/lang/XComponent.hpp>
41#include <com/sun/star/lang/IllegalArgumentException.hpp>
42#include <com/sun/star/uno/XUnloadingPreference.hpp>
43#include <com/sun/star/beans/PropertyAttribute.hpp>
44
45#include <memory>
46#include <utility>
47
48
49using namespace osl;
50using namespace com::sun::star;
51using namespace com::sun::star::uno;
52using namespace com::sun::star::lang;
53using namespace com::sun::star::loader;
54using namespace com::sun::star::registry;
55
56namespace cppu
57{
58
59namespace {
60
61class OSingleFactoryHelper
62 : public XServiceInfo
63 , public XSingleServiceFactory
64 , public lang::XSingleComponentFactory
65 , public XUnloadingPreference
66{
67public:
68 OSingleFactoryHelper(
69 const Reference<XMultiServiceFactory > & rServiceManager,
70 OUString aImplementationName_,
71 ComponentInstantiation pCreateFunction_,
72 ComponentFactoryFunc fptr,
73 const Sequence< OUString > * pServiceNames_ )
74 : xSMgr( rServiceManager )
75 , pCreateFunction( pCreateFunction_ )
76 , m_fptr( fptr )
77 , aImplementationName(std::move( aImplementationName_ ))
78 {
79 if( pServiceNames_ )
80 aServiceNames = *pServiceNames_;
81 }
82
83 virtual ~OSingleFactoryHelper();
84
85 // XInterface
86 Any SAL_CALL queryInterface( const Type & rType ) override;
87
88 // XSingleServiceFactory
89 Reference<XInterface > SAL_CALL createInstance() override;
90 virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const Sequence<Any>& Arguments) override;
91 // XSingleComponentFactory
92 virtual Reference< XInterface > SAL_CALL createInstanceWithContext(
93 Reference< XComponentContext > const & xContext ) override;
94 virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
95 Sequence< Any > const & rArguments,
96 Reference< XComponentContext > const & xContext ) override;
97
98 // XServiceInfo
99 OUString SAL_CALL getImplementationName() override;
100 sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
102
103protected:
111 virtual Reference<XInterface > createInstanceEveryTime(
112 Reference< XComponentContext > const & xContext );
113
115 ComponentInstantiation pCreateFunction;
116 ComponentFactoryFunc m_fptr;
119};
120
121}
122
123OSingleFactoryHelper::~OSingleFactoryHelper()
124{
125}
126
127
129{
131 rType,
132 static_cast< XSingleComponentFactory * >( this ),
133 static_cast< XSingleServiceFactory * >( this ),
134 static_cast< XServiceInfo * >( this ) ,
135 static_cast< XUnloadingPreference * >( this ));
136}
137
138// OSingleFactoryHelper
139Reference<XInterface > OSingleFactoryHelper::createInstanceEveryTime(
140 Reference< XComponentContext > const & xContext )
141{
142 if (m_fptr)
143 {
144 return (*m_fptr)( xContext );
145 }
146 if( pCreateFunction )
147 {
148 if (xContext.is())
149 {
151 xContext->getServiceManager(), UNO_QUERY );
152 if (xContextMgr.is())
153 return (*pCreateFunction)( xContextMgr );
154 }
155 return (*pCreateFunction)( xSMgr );
156 }
158}
159
160// XSingleServiceFactory
161Reference<XInterface > OSingleFactoryHelper::createInstance()
162{
163 return createInstanceWithContext( Reference< XComponentContext >() );
164}
165
166// XSingleServiceFactory
167Reference<XInterface > OSingleFactoryHelper::createInstanceWithArguments(
168 const Sequence<Any>& Arguments )
169{
170 return createInstanceWithArgumentsAndContext(
171 Arguments, Reference< XComponentContext >() );
172}
173
174// XSingleComponentFactory
175
176Reference< XInterface > OSingleFactoryHelper::createInstanceWithContext(
177 Reference< XComponentContext > const & xContext )
178{
179 return createInstanceEveryTime( xContext );
180}
181
182Reference< XInterface > OSingleFactoryHelper::createInstanceWithArgumentsAndContext(
183 Sequence< Any > const & rArguments,
184 Reference< XComponentContext > const & xContext )
185{
186 Reference< XInterface > xRet( createInstanceWithContext( xContext ) );
187
188 Reference< lang::XInitialization > xInit( xRet, UNO_QUERY );
189 // always call initialize, even if there are no arguments. #i63511#
190 if (xInit.is())
191 {
192 xInit->initialize( rArguments );
193 }
194 else
195 {
196 if ( rArguments.hasElements() )
197 {
198 // dispose the here created UNO object before throwing out exception
199 // to avoid risk of memory leaks #i113722#
200 Reference<XComponent> xComp( xRet, UNO_QUERY );
201 if (xComp.is())
202 xComp->dispose();
203
204 throw lang::IllegalArgumentException(
205 "cannot pass arguments to component => no XInitialization implemented!",
207 }
208 }
209
210 return xRet;
211}
212
213// XServiceInfo
214OUString OSingleFactoryHelper::getImplementationName()
215{
216 return aImplementationName;
217}
218
219// XServiceInfo
221 const OUString& ServiceName )
222{
223 return cppu::supportsService(this, ServiceName);
224}
225
226// XServiceInfo
227Sequence< OUString > OSingleFactoryHelper::getSupportedServiceNames()
228{
229 return aServiceNames;
230}
231
232namespace {
233
234struct OFactoryComponentHelper_Mutex
235{
236 Mutex aMutex;
237};
238
239class OFactoryComponentHelper
240 : public OFactoryComponentHelper_Mutex
241 , public OComponentHelper
242 , public OSingleFactoryHelper
243{
244public:
245 OFactoryComponentHelper(
246 const Reference<XMultiServiceFactory > & rServiceManager,
247 const OUString & rImplementationName_,
248 ComponentInstantiation pCreateFunction_,
249 ComponentFactoryFunc fptr,
250 const Sequence< OUString > * pServiceNames_,
251 bool bOneInstance_ )
252 : OComponentHelper( aMutex )
253 , OSingleFactoryHelper( rServiceManager, rImplementationName_, pCreateFunction_, fptr, pServiceNames_ )
254 , bOneInstance( bOneInstance_ )
255 {
256 }
257
258 // XInterface
259 Any SAL_CALL queryInterface( const Type & rType ) override;
260 void SAL_CALL acquire() noexcept override
262 void SAL_CALL release() noexcept override
264
265 // XSingleServiceFactory
266 Reference<XInterface > SAL_CALL createInstance() override;
267 Reference<XInterface > SAL_CALL createInstanceWithArguments( const Sequence<Any>& Arguments ) override;
268 // XSingleComponentFactory
269 virtual Reference< XInterface > SAL_CALL createInstanceWithContext(
270 Reference< XComponentContext > const & xContext ) override;
271 virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
272 Sequence< Any > const & rArguments,
273 Reference< XComponentContext > const & xContext ) override;
274
275 // XTypeProvider
276 virtual Sequence< Type > SAL_CALL getTypes() override;
277 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
278
279 // XAggregation
280 Any SAL_CALL queryAggregation( const Type & rType ) override;
281
282 // XUnloadingPreference
283 virtual sal_Bool SAL_CALL releaseOnNotification() override;
284
285 // OComponentHelper
286 void SAL_CALL dispose() override;
287
288private:
291protected:
292 // needed for implementing XUnloadingPreference in inheriting classes
293 bool isOneInstance() const {return bOneInstance;}
294 bool isInstance() const {return xTheInstance.is();}
295};
296
297}
298
299Any SAL_CALL OFactoryComponentHelper::queryInterface( const Type & rType )
300{
302 {
303 return Any(
305 static_cast< XUnloadingPreference * >(this) ) );
306 }
307 return OComponentHelper::queryInterface( rType );
308}
309
310// XAggregation
311Any OFactoryComponentHelper::queryAggregation( const Type & rType )
312{
314 return (aRet.hasValue() ? aRet : OSingleFactoryHelper::queryInterface( rType ));
315}
316
317// XTypeProvider
318Sequence< Type > OFactoryComponentHelper::getTypes()
319{
320 Type ar[ 4 ];
324
325 if (m_fptr)
327
328 return Sequence< Type >( ar, m_fptr ? 4 : 3 );
329}
330
331Sequence< sal_Int8 > OFactoryComponentHelper::getImplementationId()
332{
333 return css::uno::Sequence<sal_Int8>();
334}
335
336// XSingleServiceFactory
337Reference<XInterface > OFactoryComponentHelper::createInstance()
338{
339 if( bOneInstance )
340 {
341 if( !xTheInstance.is() )
342 {
343 MutexGuard aGuard( aMutex );
344 if( !xTheInstance.is() )
345 xTheInstance = OSingleFactoryHelper::createInstance();
346 }
347 return xTheInstance;
348 }
349 return OSingleFactoryHelper::createInstance();
350}
351
352Reference<XInterface > OFactoryComponentHelper::createInstanceWithArguments(
353 const Sequence<Any>& Arguments )
354{
355 if( bOneInstance )
356 {
357 if( !xTheInstance.is() )
358 {
359 MutexGuard aGuard( aMutex );
360// OSL_ENSURE( !xTheInstance.is(), "### arguments will be ignored!" );
361 if( !xTheInstance.is() )
362 xTheInstance = OSingleFactoryHelper::createInstanceWithArguments( Arguments );
363 }
364 return xTheInstance;
365 }
366 return OSingleFactoryHelper::createInstanceWithArguments( Arguments );
367}
368
369// XSingleComponentFactory
370
371Reference< XInterface > OFactoryComponentHelper::createInstanceWithContext(
372 Reference< XComponentContext > const & xContext )
373{
374 if( bOneInstance )
375 {
376 if( !xTheInstance.is() )
377 {
378 MutexGuard aGuard( aMutex );
379// OSL_ENSURE( !xTheInstance.is(), "### context will be ignored!" );
380 if( !xTheInstance.is() )
381 xTheInstance = OSingleFactoryHelper::createInstanceWithContext( xContext );
382 }
383 return xTheInstance;
384 }
385 return OSingleFactoryHelper::createInstanceWithContext( xContext );
386}
387
388Reference< XInterface > OFactoryComponentHelper::createInstanceWithArgumentsAndContext(
389 Sequence< Any > const & rArguments,
390 Reference< XComponentContext > const & xContext )
391{
392 if( bOneInstance )
393 {
394 if( !xTheInstance.is() )
395 {
396 MutexGuard aGuard( aMutex );
397// OSL_ENSURE( !xTheInstance.is(), "### context and arguments will be ignored!" );
398 if( !xTheInstance.is() )
399 xTheInstance = OSingleFactoryHelper::createInstanceWithArgumentsAndContext( rArguments, xContext );
400 }
401 return xTheInstance;
402 }
403 return OSingleFactoryHelper::createInstanceWithArgumentsAndContext( rArguments, xContext );
404}
405
406
407// OComponentHelper
408void OFactoryComponentHelper::dispose()
409{
411
413 {
414 // do not delete in the guard section
415 MutexGuard aGuard( aMutex );
416 x = xTheInstance;
417 xTheInstance.clear();
418 }
419 // if it is a component call dispose at the component
420 Reference<XComponent > xComp( x, UNO_QUERY );
421 if( xComp.is() )
422 xComp->dispose();
423}
424
425// XUnloadingPreference
426// This class is used for single factories, component factories and
427// one-instance factories. Depending on the usage this function has
428// to return different values.
429// one-instance factory: sal_False
430// single factory: sal_True
431// component factory: sal_True
432sal_Bool SAL_CALL OFactoryComponentHelper::releaseOnNotification()
433{
434 if( bOneInstance)
435 return false;
436 return true;
437}
438
439namespace {
440
441class ORegistryFactoryHelper : public OFactoryComponentHelper,
442 public OPropertySetHelper
443
444{
445public:
446 ORegistryFactoryHelper(
447 const Reference<XMultiServiceFactory > & rServiceManager,
448 const OUString & rImplementationName_,
449 const Reference<XRegistryKey > & xImplementationKey_,
450 bool bOneInstance_ )
451 : OFactoryComponentHelper(
452 rServiceManager, rImplementationName_, nullptr, nullptr, nullptr, bOneInstance_ ),
453 OPropertySetHelper( OComponentHelper::rBHelper ),
454 xImplementationKey( xImplementationKey_ )
455 {}
456
457 // XInterface
458 virtual Any SAL_CALL queryInterface( Type const & type ) override;
459 virtual void SAL_CALL acquire() noexcept override;
460 virtual void SAL_CALL release() noexcept override;
461 // XTypeProvider
462 virtual Sequence< Type > SAL_CALL getTypes() override;
463 // XPropertySet
464 virtual Reference< beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override;
465
466 // OPropertySetHelper
467 virtual IPropertyArrayHelper & SAL_CALL getInfoHelper() override;
468 virtual sal_Bool SAL_CALL convertFastPropertyValue(
469 Any & rConvertedValue, Any & rOldValue,
470 sal_Int32 nHandle, Any const & rValue ) override;
471 virtual void SAL_CALL setFastPropertyValue_NoBroadcast(
472 sal_Int32 nHandle, Any const & rValue ) override;
473 using OPropertySetHelper::getFastPropertyValue;
474 virtual void SAL_CALL getFastPropertyValue(
475 Any & rValue, sal_Int32 nHandle ) const override;
476
477 // OSingleFactoryHelper
478 Reference<XInterface > createInstanceEveryTime(
479 Reference< XComponentContext > const & xContext ) override;
480
481 // XSingleServiceFactory
482 Reference<XInterface > SAL_CALL createInstanceWithArguments(const Sequence<Any>& Arguments) override;
483 // XSingleComponentFactory
484 Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext(
485 Sequence< Any > const & rArguments,
486 Reference< XComponentContext > const & xContext ) override;
487
488 // XServiceInfo
489 Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
490 // XUnloadingPreference
491 sal_Bool SAL_CALL releaseOnNotification() override;
492
493
494private:
497 Reference< XInterface > createModuleFactory();
498
502 Reference<XSingleComponentFactory > xModuleFactory;
503 Reference<XSingleServiceFactory > xModuleFactoryDepr;
504 Reference< beans::XPropertySetInfo > m_xInfo;
505 std::unique_ptr< IPropertyArrayHelper > m_property_array_helper;
506protected:
507 using OPropertySetHelper::getTypes;
508};
509
510}
511
512// XInterface
513
514Any SAL_CALL ORegistryFactoryHelper::queryInterface(
515 Type const & type )
516{
518 if (ret.hasValue())
519 return ret;
521}
522
523
524void ORegistryFactoryHelper::acquire() noexcept
525{
526 OFactoryComponentHelper::acquire();
527}
528
529
530void ORegistryFactoryHelper::release() noexcept
531{
532 OFactoryComponentHelper::release();
533}
534
535// XTypeProvider
536
537Sequence< Type > ORegistryFactoryHelper::getTypes()
538{
539 Sequence< Type > types( OFactoryComponentHelper::getTypes() );
540 sal_Int32 pos = types.getLength();
541 types.realloc( pos + 3 );
542 Type * p = types.getArray();
546 return types;
547}
548
549// XPropertySet
550
552ORegistryFactoryHelper::getPropertySetInfo()
553{
554 ::osl::MutexGuard guard( aMutex );
555 if (! m_xInfo.is())
556 m_xInfo = createPropertySetInfo( getInfoHelper() );
557 return m_xInfo;
558}
559
560// OPropertySetHelper
561
562IPropertyArrayHelper & ORegistryFactoryHelper::getInfoHelper()
563{
564 ::osl::MutexGuard guard( aMutex );
565 if (m_property_array_helper == nullptr)
566 {
567 beans::Property prop(
568 "ImplementationKey" /* name */,
569 0 /* handle */,
570 cppu::UnoType<decltype(xImplementationKey)>::get(),
571 beans::PropertyAttribute::READONLY |
572 beans::PropertyAttribute::OPTIONAL );
574 new ::cppu::OPropertyArrayHelper( &prop, 1 ) );
575 }
577}
578
579
580sal_Bool ORegistryFactoryHelper::convertFastPropertyValue(
581 Any &, Any &, sal_Int32, Any const & )
582{
583 OSL_FAIL( "unexpected!" );
584 return false;
585}
586
587
588void ORegistryFactoryHelper::setFastPropertyValue_NoBroadcast(
589 sal_Int32, Any const & )
590{
591 throw beans::PropertyVetoException(
592 "unexpected: only readonly properties!",
593 static_cast< OWeakObject * >(this) );
594}
595
596
597void ORegistryFactoryHelper::getFastPropertyValue(
598 Any & rValue, sal_Int32 nHandle ) const
599{
600 if (nHandle == 0)
601 {
602 rValue <<= xImplementationKey;
603 }
604 else
605 {
606 rValue.clear();
607 throw beans::UnknownPropertyException(
608 "unknown property!", static_cast< OWeakObject * >(
609 const_cast< ORegistryFactoryHelper * >(this) ) );
610 }
611}
612
613Reference<XInterface > ORegistryFactoryHelper::createInstanceEveryTime(
614 Reference< XComponentContext > const & xContext )
615{
616 if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
617 {
618 Reference< XInterface > x( createModuleFactory() );
619 if (x.is())
620 {
621 MutexGuard aGuard( aMutex );
622 if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
623 {
624 xModuleFactory.set( x, UNO_QUERY );
625 xModuleFactoryDepr.set( x, UNO_QUERY );
626 }
627 }
628 }
629 if( xModuleFactory.is() )
630 {
631 return xModuleFactory->createInstanceWithContext( xContext );
632 }
633 if( xModuleFactoryDepr.is() )
634 {
635 return xModuleFactoryDepr->createInstance();
636 }
637
638 return Reference<XInterface >();
639}
640
641Reference<XInterface > SAL_CALL ORegistryFactoryHelper::createInstanceWithArguments(
642 const Sequence<Any>& Arguments )
643{
644 if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
645 {
646 Reference< XInterface > x( createModuleFactory() );
647 if (x.is())
648 {
649 MutexGuard aGuard( aMutex );
650 if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
651 {
652 xModuleFactory.set( x, UNO_QUERY );
653 xModuleFactoryDepr.set( x, UNO_QUERY );
654 }
655 }
656 }
657 if( xModuleFactoryDepr.is() )
658 {
659 return xModuleFactoryDepr->createInstanceWithArguments( Arguments );
660 }
661 if( xModuleFactory.is() )
662 {
663 SAL_INFO("cppuhelper", "no context ORegistryFactoryHelper::createInstanceWithArgumentsAndContext()!");
664 return xModuleFactory->createInstanceWithArgumentsAndContext( Arguments, Reference< XComponentContext >() );
665 }
666
667 return Reference<XInterface >();
668}
669
670Reference< XInterface > ORegistryFactoryHelper::createInstanceWithArgumentsAndContext(
671 Sequence< Any > const & rArguments,
672 Reference< XComponentContext > const & xContext )
673{
674 if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
675 {
676 Reference< XInterface > x( createModuleFactory() );
677 if (x.is())
678 {
679 MutexGuard aGuard( aMutex );
680 if( !xModuleFactory.is() && !xModuleFactoryDepr.is() )
681 {
682 xModuleFactory.set( x, UNO_QUERY );
683 xModuleFactoryDepr.set( x, UNO_QUERY );
684 }
685 }
686 }
687 if( xModuleFactory.is() )
688 {
689 return xModuleFactory->createInstanceWithArgumentsAndContext( rArguments, xContext );
690 }
691 if( xModuleFactoryDepr.is() )
692 {
693 SAL_INFO_IF(xContext.is(), "cppuhelper", "ignoring context calling ORegistryFactoryHelper::createInstanceWithArgumentsAndContext()!");
694 return xModuleFactoryDepr->createInstanceWithArguments( rArguments );
695 }
696
697 return Reference<XInterface >();
698}
699
700
701// OSingleFactoryHelper
702Reference< XInterface > ORegistryFactoryHelper::createModuleFactory()
703{
704 OUString aActivatorUrl;
705 OUString aActivatorName;
706 OUString aLocation;
707
708 Reference<XRegistryKey > xActivatorKey = xImplementationKey->openKey(
709 "/UNO/ACTIVATOR" );
710 if( xActivatorKey.is() && xActivatorKey->getValueType() == RegistryValueType_ASCII )
711 {
712 aActivatorUrl = xActivatorKey->getAsciiValue();
713
714 aActivatorName = o3tl::getToken(aActivatorUrl, 0, ':');
715
716 Reference<XRegistryKey > xLocationKey = xImplementationKey->openKey(
717 "/UNO/LOCATION" );
718 if( xLocationKey.is() && xLocationKey->getValueType() == RegistryValueType_ASCII )
719 aLocation = xLocationKey->getAsciiValue();
720 }
721 else
722 {
723 // old style"url"
724 // the location of the program code of the implementation
725 Reference<XRegistryKey > xLocationKey = xImplementationKey->openKey(
726 "/UNO/URL" );
727 // is the key of the right type ?
728 if( xLocationKey.is() && xLocationKey->getValueType() == RegistryValueType_ASCII )
729 {
730 // one implementation found -> try to activate
731 aLocation = xLocationKey->getAsciiValue();
732
733 // search protocol delimiter
734 sal_Int32 nPos = aLocation.indexOf("://");
735 if( nPos != -1 )
736 {
737 aActivatorName = aLocation.subView( 0, nPos );
738 if( aActivatorName == u"java" )
739 aActivatorName = u"com.sun.star.loader.Java";
740 else if( aActivatorName == u"module" )
741 aActivatorName = u"com.sun.star.loader.SharedLibrary";
742 aLocation = aLocation.copy( nPos + 3 );
743 }
744 }
745 }
746
748 if( !aActivatorName.isEmpty() )
749 {
750 Reference<XInterface > x = xSMgr->createInstance( aActivatorName );
751 Reference<XImplementationLoader > xLoader( x, UNO_QUERY );
752 if (xLoader.is())
753 {
754 xFactory = xLoader->activate( aImplementationName, aActivatorUrl, aLocation, xImplementationKey );
755 }
756 }
757 return xFactory;
758}
759
760// XServiceInfo
761Sequence< OUString > ORegistryFactoryHelper::getSupportedServiceNames()
762{
763 MutexGuard aGuard( aMutex );
764 if( !aServiceNames.hasElements() )
765 {
766 // not yet loaded
767 try
768 {
769 Reference<XRegistryKey > xKey = xImplementationKey->openKey( "UNO/SERVICES" );
770
771 if (xKey.is())
772 {
773 // length of prefix. +1 for the '/' at the end
774 sal_Int32 nPrefixLen = xKey->getKeyName().getLength() + 1;
775
776 // Full qualified names like "IMPLEMENTATIONS/TEST/UNO/SERVICES/com.sun.star..."
777 Sequence<OUString> seqKeys = xKey->getKeyNames();
778 for( OUString & key : asNonConstRange(seqKeys) )
779 key = key.copy(nPrefixLen);
780
781 aServiceNames = seqKeys;
782 }
783 }
784 catch (InvalidRegistryException &)
785 {
786 }
787 }
788 return aServiceNames;
789}
790
791sal_Bool SAL_CALL ORegistryFactoryHelper::releaseOnNotification()
792{
793 bool retVal= true;
794 if( isOneInstance() && isInstance())
795 {
796 retVal= false;
797 }
798 else if( ! isOneInstance())
799 {
800 // try to delegate
801 if( xModuleFactory.is())
802 {
803 Reference<XUnloadingPreference> xunloading( xModuleFactory, UNO_QUERY);
804 if( xunloading.is())
805 retVal= xunloading->releaseOnNotification();
806 }
807 else if( xModuleFactoryDepr.is())
808 {
810 if( xunloading.is())
811 retVal= xunloading->releaseOnNotification();
812 }
813 }
814 return retVal;
815}
816
817namespace {
818
819class OFactoryProxyHelper : public WeakImplHelper< XServiceInfo, XSingleServiceFactory,
820 XUnloadingPreference >
821{
823
824public:
825
826 explicit OFactoryProxyHelper( const Reference<XSingleServiceFactory > & rFactory )
827 : xFactory( rFactory )
828 {}
829
830 // XSingleServiceFactory
831 Reference<XInterface > SAL_CALL createInstance() override;
832 Reference<XInterface > SAL_CALL createInstanceWithArguments(const Sequence<Any>& Arguments) override;
833
834 // XServiceInfo
835 OUString SAL_CALL getImplementationName() override;
836 sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
838 //XUnloadingPreference
839 sal_Bool SAL_CALL releaseOnNotification() override;
840
841};
842
843}
844
845// XSingleServiceFactory
846Reference<XInterface > OFactoryProxyHelper::createInstance()
847{
848 return xFactory->createInstance();
849}
850
851// XSingleServiceFactory
852Reference<XInterface > OFactoryProxyHelper::createInstanceWithArguments
853(
854 const Sequence<Any>& Arguments
855)
856{
857 return xFactory->createInstanceWithArguments( Arguments );
858}
859
860// XServiceInfo
861OUString OFactoryProxyHelper::getImplementationName()
862{
863 Reference<XServiceInfo > xInfo( xFactory, UNO_QUERY );
864 if( xInfo.is() )
865 return xInfo->getImplementationName();
866 return OUString();
867}
868
869// XServiceInfo
870sal_Bool OFactoryProxyHelper::supportsService(const OUString& ServiceName)
871{
872 return cppu::supportsService(this, ServiceName);
873}
874
875// XServiceInfo
876Sequence< OUString > OFactoryProxyHelper::getSupportedServiceNames()
877{
878 Reference<XServiceInfo > xInfo( xFactory, UNO_QUERY );
879 if( xInfo.is() )
880 return xInfo->getSupportedServiceNames();
881 return Sequence< OUString >();
882}
883
884sal_Bool SAL_CALL OFactoryProxyHelper::releaseOnNotification()
885{
886
888 if( pref.is())
889 return pref->releaseOnNotification();
890 return true;
891}
892
893// global function
895 const Reference<XMultiServiceFactory > & rServiceManager,
896 const OUString & rImplementationName,
897 ComponentInstantiation pCreateFunction,
898 const Sequence< OUString > & rServiceNames,
899 rtl_ModuleCount * )
900{
901 return new OFactoryComponentHelper(
902 rServiceManager, rImplementationName, pCreateFunction, nullptr, &rServiceNames, false );
903}
904
905// global function
907 SAL_UNUSED_PARAMETER const Reference<XMultiServiceFactory > &,
908 const Reference<XSingleServiceFactory > & rFactory )
909{
910 return new OFactoryProxyHelper( rFactory );
911}
912
913// global function
915 const Reference<XMultiServiceFactory > & rServiceManager,
916 const OUString & rImplementationName,
917 ComponentInstantiation pCreateFunction,
918 const Sequence< OUString > & rServiceNames,
919 rtl_ModuleCount * )
920{
921 return new OFactoryComponentHelper(
922 rServiceManager, rImplementationName, pCreateFunction, nullptr, &rServiceNames, true );
923}
924
925// global function
927 const Reference<XMultiServiceFactory > & rServiceManager,
928 const OUString & rImplementationName,
929 const Reference<XRegistryKey > & rImplementationKey )
930{
931 return new ORegistryFactoryHelper(
932 rServiceManager, rImplementationName, rImplementationKey, false );
933}
934
935// global function
937 const Reference<XMultiServiceFactory > & rServiceManager,
938 const OUString & rImplementationName,
939 const Reference<XRegistryKey > & rImplementationKey )
940{
941 return new ORegistryFactoryHelper(
942 rServiceManager, rImplementationName, rImplementationKey, true );
943}
944
945
947 ComponentFactoryFunc fptr,
948 OUString const & rImplementationName,
949 Sequence< OUString > const & rServiceNames,
950 rtl_ModuleCount *)
951{
952 return new OFactoryComponentHelper(
953 Reference< XMultiServiceFactory >(), rImplementationName, nullptr, fptr, &rServiceNames, false );
954}
955
957 ComponentFactoryFunc fptr,
958 OUString const & rImplementationName,
959 Sequence< OUString > const & rServiceNames,
960 rtl_ModuleCount *)
961{
962 return new OFactoryComponentHelper(
963 Reference< XMultiServiceFactory >(), rImplementationName, nullptr, fptr, &rServiceNames, true );
964}
965
966}
967
968
969/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
If a delegator is set, then the delegators gets acquired.
Definition: component.cxx:66
virtual void SAL_CALL dispose() SAL_OVERRIDE
Definition: component.cxx:125
virtual css::uno::Any SAL_CALL queryAggregation(css::uno::Type const &rType) SAL_OVERRIDE
Called by the delegator or queryInterface.
Definition: component.cxx:52
virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE
If a delegator is set, then the delegators gets released.
Definition: component.cxx:71
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &rType) SAL_OVERRIDE
If a delegator is set, then the delegator is queried for the demanded interface.
Definition: component.cxx:48
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) SAL_OVERRIDE
Only returns a reference to XMultiPropertySet, XFastPropertySet, XPropertySet and XEventListener.
Definition: propshlp.cxx:207
css::uno::Type const & get()
float u
float x
Reference< XInterface > xTheInstance
Definition: factory.cxx:289
Reference< XMultiServiceFactory > xSMgr
Definition: factory.cxx:114
std::unique_ptr< IPropertyArrayHelper > m_property_array_helper
Definition: factory.cxx:505
Reference< XSingleServiceFactory > xFactory
Definition: factory.cxx:822
Reference< XRegistryKey > xImplementationKey
The registry key of the implementation section.
Definition: factory.cxx:500
Sequence< OUString > aServiceNames
Definition: factory.cxx:117
ComponentInstantiation pCreateFunction
Definition: factory.cxx:115
Reference< beans::XPropertySetInfo > m_xInfo
Definition: factory.cxx:504
Reference< XSingleComponentFactory > xModuleFactory
The factory created with the loader.
Definition: factory.cxx:502
OUString aImplementationName
Definition: factory.cxx:118
ComponentFactoryFunc m_fptr
Definition: factory.cxx:116
bool bOneInstance
Definition: factory.cxx:290
Reference< XSingleServiceFactory > xModuleFactoryDepr
Definition: factory.cxx:503
Mutex aMutex
Definition: factory.cxx:236
void * p
sal_uInt16 nPos
#define SAL_INFO_IF(condition, area, stream)
#define SAL_INFO(area, stream)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
Type
Reference< XSingleServiceFactory > SAL_CALL createOneInstanceRegistryFactory(const Reference< XMultiServiceFactory > &rServiceManager, const OUString &rImplementationName, const Reference< XRegistryKey > &rImplementationKey)
Definition: factory.cxx:936
css::uno::Reference< css::uno::XInterface >(SAL_CALL *ComponentFactoryFunc)(css CPPUHELPER_DLLPUBLIC css::uno::Reference< css::lang::XSingleComponentFactory > SAL_CALL createSingleComponentFactory(ComponentFactoryFunc fptr, ::rtl::OUString const &rImplementationName, css::uno::Sequence< ::rtl::OUString > const &rServiceNames, rtl_ModuleCount *pModCount=NULL)
Function pointer declaration.
Definition: factory.hxx:146
Reference< XSingleServiceFactory > SAL_CALL createSingleRegistryFactory(const Reference< XMultiServiceFactory > &rServiceManager, const OUString &rImplementationName, const Reference< XRegistryKey > &rImplementationKey)
Definition: factory.cxx:926
Reference< XSingleServiceFactory > SAL_CALL createOneInstanceFactory(const Reference< XMultiServiceFactory > &rServiceManager, const OUString &rImplementationName, ComponentInstantiation pCreateFunction, const Sequence< OUString > &rServiceNames, rtl_ModuleCount *)
Definition: factory.cxx:914
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
Compares demanded type to given template argument types.
Reference< lang::XSingleComponentFactory > SAL_CALL createOneInstanceComponentFactory(ComponentFactoryFunc fptr, OUString const &rImplementationName, Sequence< OUString > const &rServiceNames, rtl_ModuleCount *)
Definition: factory.cxx:956
css::uno::Reference< css::uno::XInterface >(SAL_CALL *ComponentInstantiation)(const css CPPUHELPER_DLLPUBLIC css::uno::Reference< css::lang::XSingleServiceFactory > SAL_CALL createSingleFactory(const css::uno::Reference< css::lang::XMultiServiceFactory > &rServiceManager, const ::rtl::OUString &rImplementationName, ComponentInstantiation pCreateFunction, const css::uno::Sequence< ::rtl::OUString > &rServiceNames, rtl_ModuleCount *pModCount=NULL)
Deprecated.
Definition: factory.hxx:193
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
A helper for implementations of com.sun.star.lang.XServiceInfo.
Reference< XSingleServiceFactory > SAL_CALL createFactoryProxy(SAL_UNUSED_PARAMETER const Reference< XMultiServiceFactory > &, const Reference< XSingleServiceFactory > &rFactory)
Definition: factory.cxx:906
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
void dispose()
unsigned char sal_Bool
ResultType type
size_t pos