From 1b6a84a5a24e7e02c6066ca0fcb5a0011d2decd6 Mon Sep 17 00:00:00 2001 From: yeliztaneroglu Date: Tue, 2 Feb 2016 11:04:49 +0200 Subject: [PATCH] tdf#74608: Constructor function for SimpleLogRing singleton Change-Id: Ia8c2f214b635114ecac4a2ceb06628a2f18b6411 Reviewed-on: https://gerrit.libreoffice.org/22020 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- comphelper/source/inc/comphelper_services.hxx | 1 - .../source/misc/comphelper_services.cxx | 1 - comphelper/source/misc/documentiologring.cxx | 58 ++++++++----------- comphelper/source/misc/documentiologring.hxx | 10 ---- comphelper/util/comphelp.component | 3 +- 5 files changed, 27 insertions(+), 46 deletions(-) diff --git a/comphelper/source/inc/comphelper_services.hxx b/comphelper/source/inc/comphelper_services.hxx index 0f499f33dbd6..318eaa65f996 100644 --- a/comphelper/source/inc/comphelper_services.hxx +++ b/comphelper/source/inc/comphelper_services.hxx @@ -25,7 +25,6 @@ void createRegistryInfo_Map(); void createRegistryInfo_OInstanceLocker(); void createRegistryInfo_OPropertyBag(); -void createRegistryInfo_OSimpleLogRing(); void createRegistryInfo_SequenceInputStream(); void createRegistryInfo_SequenceOutputStream(); void createRegistryInfo_UNOMemoryStream(); diff --git a/comphelper/source/misc/comphelper_services.cxx b/comphelper/source/misc/comphelper_services.cxx index 47fdf2047225..ef136eede5f9 100644 --- a/comphelper/source/misc/comphelper_services.cxx +++ b/comphelper/source/misc/comphelper_services.cxx @@ -40,7 +40,6 @@ namespace comphelper { namespace module createRegistryInfo_UNOMemoryStream(); createRegistryInfo_OInstanceLocker(); createRegistryInfo_Map(); - createRegistryInfo_OSimpleLogRing(); } }; diff --git a/comphelper/source/misc/documentiologring.cxx b/comphelper/source/misc/documentiologring.cxx index aaea0caea8fe..3940d1da4fa9 100644 --- a/comphelper/source/misc/documentiologring.cxx +++ b/comphelper/source/misc/documentiologring.cxx @@ -20,12 +20,11 @@ #include #include - -#include -#include +#include #include #include "documentiologring.hxx" +#include using namespace ::com::sun::star; @@ -46,31 +45,6 @@ OSimpleLogRing::~OSimpleLogRing() { } - -uno::Sequence< OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames_static() -{ - uno::Sequence aResult { getServiceName_static() }; - return aResult; -} - - -OUString SAL_CALL OSimpleLogRing::getImplementationName_static() -{ - return OUString( "com.sun.star.comp.logging.SimpleLogRing" ); -} - - -OUString SAL_CALL OSimpleLogRing::getServiceName_static() -{ - return OUString( "com.sun.star.logging.SimpleLogRing" ); -} - - -uno::Reference< uno::XInterface > SAL_CALL OSimpleLogRing::Create( SAL_UNUSED_PARAMETER const uno::Reference< uno::XComponentContext >& ) -{ - return static_cast< cppu::OWeakObject* >( new OSimpleLogRing ); -} - // XSimpleLogRing void SAL_CALL OSimpleLogRing::logString( const OUString& aMessage ) throw (uno::RuntimeException, std::exception) @@ -135,7 +109,7 @@ void SAL_CALL OSimpleLogRing::initialize( const uno::Sequence< uno::Any >& aArgu // XServiceInfo OUString SAL_CALL OSimpleLogRing::getImplementationName() throw (uno::RuntimeException, std::exception) { - return getImplementationName_static(); + return OUString("com.sun.star.comp.logging.SimpleLogRing"); } sal_Bool SAL_CALL OSimpleLogRing::supportsService( const OUString& aServiceName ) throw (uno::RuntimeException, std::exception) @@ -145,15 +119,33 @@ sal_Bool SAL_CALL OSimpleLogRing::supportsService( const OUString& aServiceName uno::Sequence< OUString > SAL_CALL OSimpleLogRing::getSupportedServiceNames() throw (uno::RuntimeException, std::exception) { - return getSupportedServiceNames_static(); + return { "com.sun.star.logging.SimpleLogRing" }; } } // namespace comphelper -void createRegistryInfo_OSimpleLogRing() +namespace { + +struct Instance { + explicit Instance(): + instance(new comphelper::OSimpleLogRing()) + {} + + css::uno::Reference instance; +}; + +struct Singleton: + public rtl::Static +{}; + +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL +com_sun_star_comp_logging_SimpleLogRing( + css::uno::XComponentContext *, + css::uno::Sequence const &) { - static ::comphelper::module::OAutoRegistration< ::comphelper::OSimpleLogRing > aAutoRegistration; - static ::comphelper::module::OSingletonRegistration< ::comphelper::OSimpleLogRing > aSingletonRegistration; + return cppu::acquire(Singleton::get().instance.get()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/source/misc/documentiologring.hxx b/comphelper/source/misc/documentiologring.hxx index e6974d988caa..5eabc8e56598 100644 --- a/comphelper/source/misc/documentiologring.hxx +++ b/comphelper/source/misc/documentiologring.hxx @@ -48,16 +48,6 @@ public: OSimpleLogRing(); virtual ~OSimpleLogRing(); - static css::uno::Sequence< OUString > SAL_CALL - getSupportedServiceNames_static(); - - static OUString SAL_CALL getImplementationName_static(); - - static OUString SAL_CALL getServiceName_static(); - - static css::uno::Reference< css::uno::XInterface > SAL_CALL - Create( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); - // XSimpleLogRing virtual void SAL_CALL logString( const OUString& aMessage ) throw (css::uno::RuntimeException, std::exception) override; virtual css::uno::Sequence< OUString > SAL_CALL getCollectedLog() throw (css::uno::RuntimeException, std::exception) override; diff --git a/comphelper/util/comphelp.component b/comphelper/util/comphelp.component index 4de65e1c2c75..71ddeea1d261 100644 --- a/comphelper/util/comphelp.component +++ b/comphelper/util/comphelp.component @@ -46,7 +46,8 @@ - +