diff --git a/compilerplugins/clang/mergeclasses.results b/compilerplugins/clang/mergeclasses.results index 1682b3ea21bf..7b002c436974 100644 --- a/compilerplugins/clang/mergeclasses.results +++ b/compilerplugins/clang/mergeclasses.results @@ -289,7 +289,6 @@ merge cppcanvas::PolyPolygon with cppcanvas::internal::ImplPolyPolygon merge cppcanvas::Renderer with cppcanvas::internal::ImplRenderer merge cppcanvas::SpriteCanvas with cppcanvas::internal::ImplSpriteCanvas merge cppcanvas::internal::ImplSprite with cppcanvas::internal::ImplCustomSprite -merge cppu::(anonymous namespace)::OSingleFactoryHelper with cppu::(anonymous namespace)::OFactoryComponentHelper merge cppu::PropertySetMixinImpl with cppu::PropertySetMixin merge dbaccess::IPropertyContainer with dbaccess::OColumn merge dbaccess::IRefreshListener with dbaccess::OConnection diff --git a/cppuhelper/source/factory.cxx b/cppuhelper/source/factory.cxx index 37ac44ffa1a5..6d5cdc7b23bc 100644 --- a/cppuhelper/source/factory.cxx +++ b/cppuhelper/source/factory.cxx @@ -58,20 +58,30 @@ namespace cppu namespace { -class OSingleFactoryHelper - : public XServiceInfo +struct OFactoryComponentHelper_Mutex +{ + Mutex aMutex; +}; + +class OFactoryComponentHelper + : public OFactoryComponentHelper_Mutex + , public OComponentHelper + , public XServiceInfo , public XSingleServiceFactory , public lang::XSingleComponentFactory , public XUnloadingPreference { public: - OSingleFactoryHelper( + OFactoryComponentHelper( const Reference & rServiceManager, OUString aImplementationName_, ComponentInstantiation pCreateFunction_, ComponentFactoryFunc fptr, - const Sequence< OUString > * pServiceNames_ ) - : xSMgr( rServiceManager ) + const Sequence< OUString > * pServiceNames_, + bool bOneInstance_ ) + : OComponentHelper( aMutex ) + , bOneInstance( bOneInstance_ ) + , xSMgr( rServiceManager ) , pCreateFunction( pCreateFunction_ ) , m_fptr( fptr ) , aImplementationName(std::move( aImplementationName_ )) @@ -80,14 +90,16 @@ public: aServiceNames = *pServiceNames_; } - virtual ~OSingleFactoryHelper(); - // XInterface Any SAL_CALL queryInterface( const Type & rType ) override; + void SAL_CALL acquire() noexcept override + { OComponentHelper::acquire(); } + void SAL_CALL release() noexcept override + { OComponentHelper::release(); } // XSingleServiceFactory Reference SAL_CALL createInstance() override; - virtual Reference SAL_CALL createInstanceWithArguments(const Sequence& Arguments) override; + Reference SAL_CALL createInstanceWithArguments( const Sequence& Arguments ) override; // XSingleComponentFactory virtual Reference< XInterface > SAL_CALL createInstanceWithContext( Reference< XComponentContext > const & xContext ) override; @@ -100,7 +112,31 @@ public: sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + // XTypeProvider + virtual Sequence< Type > SAL_CALL getTypes() override; + virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() override; + + // XAggregation + Any SAL_CALL queryAggregation( const Type & rType ) override; + + // XUnloadingPreference + virtual sal_Bool SAL_CALL releaseOnNotification() override; + + // OComponentHelper + void SAL_CALL dispose() override; + +private: + css::uno::Reference createInstanceWithArgumentsEveryTime( + css::uno::Sequence const & rArguments, + css::uno::Reference const & xContext); + + Reference xTheInstance; + bool bOneInstance; protected: + // needed for implementing XUnloadingPreference in inheriting classes + bool isOneInstance() const {return bOneInstance;} + bool isInstance() const {return xTheInstance.is();} + /** * Create an instance specified by the factory. The one instance logic is implemented * in the createInstance and createInstanceWithArguments methods. @@ -116,32 +152,50 @@ protected: ComponentFactoryFunc m_fptr; Sequence< OUString > aServiceNames; OUString aImplementationName; - -private: - css::uno::Reference createInstanceWithArgumentsEveryTime( - css::uno::Sequence const & rArguments, - css::uno::Reference const & xContext); }; } -OSingleFactoryHelper::~OSingleFactoryHelper() +Any SAL_CALL OFactoryComponentHelper::queryInterface( const Type & rType ) { + return OComponentHelper::queryInterface( rType ); } - -Any OSingleFactoryHelper::queryInterface( const Type & rType ) +// XAggregation +Any OFactoryComponentHelper::queryAggregation( const Type & rType ) { - return ::cppu::queryInterface( - rType, - static_cast< XSingleComponentFactory * >( this ), - static_cast< XSingleServiceFactory * >( this ), - static_cast< XServiceInfo * >( this ) , - static_cast< XUnloadingPreference * >( this )); + Any aRet( OComponentHelper::queryAggregation( rType ) ); + return (aRet.hasValue() + ? aRet + : ::cppu::queryInterface( + rType, + static_cast< XSingleComponentFactory * >( this ), + static_cast< XSingleServiceFactory * >( this ), + static_cast< XServiceInfo * >( this ) , + static_cast< XUnloadingPreference * >( this ))); } -// OSingleFactoryHelper -Reference OSingleFactoryHelper::createInstanceEveryTime( +// XTypeProvider +Sequence< Type > OFactoryComponentHelper::getTypes() +{ + Type ar[ 4 ]; + ar[ 0 ] = cppu::UnoType::get(); + ar[ 1 ] = cppu::UnoType::get(); + ar[ 2 ] = cppu::UnoType::get(); + + if (m_fptr) + ar[ 3 ] = cppu::UnoType::get(); + + return Sequence< Type >( ar, m_fptr ? 4 : 3 ); +} + +Sequence< sal_Int8 > OFactoryComponentHelper::getImplementationId() +{ + return css::uno::Sequence(); +} + +// OFactoryComponentHelper +Reference OFactoryComponentHelper::createInstanceEveryTime( Reference< XComponentContext > const & xContext ) { if (m_fptr) @@ -163,36 +217,78 @@ Reference OSingleFactoryHelper::createInstanceEveryTime( } // XSingleServiceFactory -Reference OSingleFactoryHelper::createInstance() +Reference OFactoryComponentHelper::createInstance() { + if( bOneInstance ) + { + if( !xTheInstance.is() ) + { + MutexGuard aGuard( aMutex ); + if( !xTheInstance.is() ) + xTheInstance = createInstanceEveryTime( Reference< XComponentContext >() ); + } + return xTheInstance; + } return createInstanceEveryTime( Reference< XComponentContext >() ); } -// XSingleServiceFactory -Reference OSingleFactoryHelper::createInstanceWithArguments( +Reference OFactoryComponentHelper::createInstanceWithArguments( const Sequence& Arguments ) { - return createInstanceWithArgumentsEveryTime( - Arguments, Reference< XComponentContext >() ); + if( bOneInstance ) + { + if( !xTheInstance.is() ) + { + MutexGuard aGuard( aMutex ); +// OSL_ENSURE( !xTheInstance.is(), "### arguments will be ignored!" ); + if( !xTheInstance.is() ) + xTheInstance = createInstanceWithArgumentsEveryTime( + Arguments, Reference< XComponentContext >() ); + } + return xTheInstance; + } + return createInstanceWithArgumentsEveryTime( Arguments, Reference< XComponentContext >() ); } // XSingleComponentFactory -Reference< XInterface > OSingleFactoryHelper::createInstanceWithContext( +Reference< XInterface > OFactoryComponentHelper::createInstanceWithContext( Reference< XComponentContext > const & xContext ) { + if( bOneInstance ) + { + if( !xTheInstance.is() ) + { + MutexGuard aGuard( aMutex ); +// OSL_ENSURE( !xTheInstance.is(), "### context will be ignored!" ); + if( !xTheInstance.is() ) + xTheInstance = createInstanceEveryTime( xContext ); + } + return xTheInstance; + } return createInstanceEveryTime( xContext ); } -Reference< XInterface > OSingleFactoryHelper::createInstanceWithArgumentsAndContext( +Reference< XInterface > OFactoryComponentHelper::createInstanceWithArgumentsAndContext( Sequence< Any > const & rArguments, Reference< XComponentContext > const & xContext ) { - return createInstanceWithArgumentsEveryTime(rArguments, xContext); + if( bOneInstance ) + { + if( !xTheInstance.is() ) + { + MutexGuard aGuard( aMutex ); +// OSL_ENSURE( !xTheInstance.is(), "### context and arguments will be ignored!" ); + if( !xTheInstance.is() ) + xTheInstance = createInstanceWithArgumentsEveryTime( rArguments, xContext ); + } + return xTheInstance; + } + return createInstanceWithArgumentsEveryTime( rArguments, xContext ); } css::uno::Reference -OSingleFactoryHelper::createInstanceWithArgumentsEveryTime( +OFactoryComponentHelper::createInstanceWithArgumentsEveryTime( css::uno::Sequence const & rArguments, css::uno::Reference const & xContext) { @@ -223,193 +319,6 @@ OSingleFactoryHelper::createInstanceWithArgumentsEveryTime( return xRet; } -// XServiceInfo -OUString OSingleFactoryHelper::getImplementationName() -{ - return aImplementationName; -} - -// XServiceInfo -sal_Bool OSingleFactoryHelper::supportsService( - const OUString& ServiceName ) -{ - return cppu::supportsService(this, ServiceName); -} - -// XServiceInfo -Sequence< OUString > OSingleFactoryHelper::getSupportedServiceNames() -{ - return aServiceNames; -} - -namespace { - -struct OFactoryComponentHelper_Mutex -{ - Mutex aMutex; -}; - -class OFactoryComponentHelper - : public OFactoryComponentHelper_Mutex - , public OComponentHelper - , public OSingleFactoryHelper -{ -public: - OFactoryComponentHelper( - const Reference & rServiceManager, - const OUString & rImplementationName_, - ComponentInstantiation pCreateFunction_, - ComponentFactoryFunc fptr, - const Sequence< OUString > * pServiceNames_, - bool bOneInstance_ ) - : OComponentHelper( aMutex ) - , OSingleFactoryHelper( rServiceManager, rImplementationName_, pCreateFunction_, fptr, pServiceNames_ ) - , bOneInstance( bOneInstance_ ) - { - } - - // XInterface - Any SAL_CALL queryInterface( const Type & rType ) override; - void SAL_CALL acquire() noexcept override - { OComponentHelper::acquire(); } - void SAL_CALL release() noexcept override - { OComponentHelper::release(); } - - // XSingleServiceFactory - Reference SAL_CALL createInstance() override; - Reference SAL_CALL createInstanceWithArguments( const Sequence& Arguments ) override; - // XSingleComponentFactory - virtual Reference< XInterface > SAL_CALL createInstanceWithContext( - Reference< XComponentContext > const & xContext ) override; - virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext( - Sequence< Any > const & rArguments, - Reference< XComponentContext > const & xContext ) override; - - // XTypeProvider - virtual Sequence< Type > SAL_CALL getTypes() override; - virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() override; - - // XAggregation - Any SAL_CALL queryAggregation( const Type & rType ) override; - - // XUnloadingPreference - virtual sal_Bool SAL_CALL releaseOnNotification() override; - - // OComponentHelper - void SAL_CALL dispose() override; - -private: - Reference xTheInstance; - bool bOneInstance; -protected: - // needed for implementing XUnloadingPreference in inheriting classes - bool isOneInstance() const {return bOneInstance;} - bool isInstance() const {return xTheInstance.is();} -}; - -} - -Any SAL_CALL OFactoryComponentHelper::queryInterface( const Type & rType ) -{ - return OComponentHelper::queryInterface( rType ); -} - -// XAggregation -Any OFactoryComponentHelper::queryAggregation( const Type & rType ) -{ - Any aRet( OComponentHelper::queryAggregation( rType ) ); - return (aRet.hasValue() ? aRet : OSingleFactoryHelper::queryInterface( rType )); -} - -// XTypeProvider -Sequence< Type > OFactoryComponentHelper::getTypes() -{ - Type ar[ 4 ]; - ar[ 0 ] = cppu::UnoType::get(); - ar[ 1 ] = cppu::UnoType::get(); - ar[ 2 ] = cppu::UnoType::get(); - - if (m_fptr) - ar[ 3 ] = cppu::UnoType::get(); - - return Sequence< Type >( ar, m_fptr ? 4 : 3 ); -} - -Sequence< sal_Int8 > OFactoryComponentHelper::getImplementationId() -{ - return css::uno::Sequence(); -} - -// XSingleServiceFactory -Reference OFactoryComponentHelper::createInstance() -{ - if( bOneInstance ) - { - if( !xTheInstance.is() ) - { - MutexGuard aGuard( aMutex ); - if( !xTheInstance.is() ) - xTheInstance = OSingleFactoryHelper::createInstance(); - } - return xTheInstance; - } - return OSingleFactoryHelper::createInstance(); -} - -Reference OFactoryComponentHelper::createInstanceWithArguments( - const Sequence& Arguments ) -{ - if( bOneInstance ) - { - if( !xTheInstance.is() ) - { - MutexGuard aGuard( aMutex ); -// OSL_ENSURE( !xTheInstance.is(), "### arguments will be ignored!" ); - if( !xTheInstance.is() ) - xTheInstance = OSingleFactoryHelper::createInstanceWithArguments( Arguments ); - } - return xTheInstance; - } - return OSingleFactoryHelper::createInstanceWithArguments( Arguments ); -} - -// XSingleComponentFactory - -Reference< XInterface > OFactoryComponentHelper::createInstanceWithContext( - Reference< XComponentContext > const & xContext ) -{ - if( bOneInstance ) - { - if( !xTheInstance.is() ) - { - MutexGuard aGuard( aMutex ); -// OSL_ENSURE( !xTheInstance.is(), "### context will be ignored!" ); - if( !xTheInstance.is() ) - xTheInstance = OSingleFactoryHelper::createInstanceWithContext( xContext ); - } - return xTheInstance; - } - return OSingleFactoryHelper::createInstanceWithContext( xContext ); -} - -Reference< XInterface > OFactoryComponentHelper::createInstanceWithArgumentsAndContext( - Sequence< Any > const & rArguments, - Reference< XComponentContext > const & xContext ) -{ - if( bOneInstance ) - { - if( !xTheInstance.is() ) - { - MutexGuard aGuard( aMutex ); -// OSL_ENSURE( !xTheInstance.is(), "### context and arguments will be ignored!" ); - if( !xTheInstance.is() ) - xTheInstance = OSingleFactoryHelper::createInstanceWithArgumentsAndContext( rArguments, xContext ); - } - return xTheInstance; - } - return OSingleFactoryHelper::createInstanceWithArgumentsAndContext( rArguments, xContext ); -} - // OComponentHelper void OFactoryComponentHelper::dispose() @@ -429,6 +338,25 @@ void OFactoryComponentHelper::dispose() xComp->dispose(); } +// XServiceInfo +OUString OFactoryComponentHelper::getImplementationName() +{ + return aImplementationName; +} + +// XServiceInfo +sal_Bool OFactoryComponentHelper::supportsService( + const OUString& ServiceName ) +{ + return cppu::supportsService(this, ServiceName); +} + +// XServiceInfo +Sequence< OUString > OFactoryComponentHelper::getSupportedServiceNames() +{ + return aServiceNames; +} + // XUnloadingPreference // This class is used for single factories, component factories and // one-instance factories. Depending on the usage this function has @@ -481,7 +409,7 @@ public: virtual void SAL_CALL getFastPropertyValue( Any & rValue, sal_Int32 nHandle ) const override; - // OSingleFactoryHelper + // OFactoryComponentHelper Reference createInstanceEveryTime( Reference< XComponentContext > const & xContext ) override; @@ -705,7 +633,6 @@ Reference< XInterface > ORegistryFactoryHelper::createInstanceWithArgumentsAndCo } -// OSingleFactoryHelper Reference< XInterface > ORegistryFactoryHelper::createModuleFactory() { OUString aActivatorUrl;