From 9e3c7725909ebce86e30f1e774d5f9e1d761c16a Mon Sep 17 00:00:00 2001 From: Matúš Kukan Date: Sat, 26 Dec 2015 22:18:38 +0100 Subject: tdf#74608: Constructor function for OfficeRestartManager singleton Change-Id: I6c1383c292418b6744dacee95d4f289a6ca1c781 --- comphelper/source/inc/comphelper_services.hxx | 1 - comphelper/source/misc/comphelper_services.cxx | 1 - comphelper/source/misc/officerestartmanager.cxx | 59 +++++++++++-------------- comphelper/source/misc/officerestartmanager.hxx | 10 ----- comphelper/util/comphelp.component | 3 +- 5 files changed, 29 insertions(+), 45 deletions(-) (limited to 'comphelper') diff --git a/comphelper/source/inc/comphelper_services.hxx b/comphelper/source/inc/comphelper_services.hxx index 77d4dd905492..08ed94d31d2c 100644 --- a/comphelper/source/inc/comphelper_services.hxx +++ b/comphelper/source/inc/comphelper_services.hxx @@ -27,7 +27,6 @@ void createRegistryInfo_IndexedPropertyValuesContainer(); void createRegistryInfo_Map(); void createRegistryInfo_NamedPropertyValuesContainer(); void createRegistryInfo_OInstanceLocker(); -void createRegistryInfo_OOfficeRestartManager(); void createRegistryInfo_OPropertyBag(); void createRegistryInfo_OSimpleLogRing(); void createRegistryInfo_OfficeInstallationDirectories(); diff --git a/comphelper/source/misc/comphelper_services.cxx b/comphelper/source/misc/comphelper_services.cxx index e86055cc836a..122f192cdd94 100644 --- a/comphelper/source/misc/comphelper_services.cxx +++ b/comphelper/source/misc/comphelper_services.cxx @@ -45,7 +45,6 @@ namespace comphelper { namespace module createRegistryInfo_OInstanceLocker(); createRegistryInfo_Map(); createRegistryInfo_OSimpleLogRing(); - createRegistryInfo_OOfficeRestartManager(); } }; diff --git a/comphelper/source/misc/officerestartmanager.cxx b/comphelper/source/misc/officerestartmanager.cxx index 54bdac95ff1c..a8895285a0fb 100644 --- a/comphelper/source/misc/officerestartmanager.cxx +++ b/comphelper/source/misc/officerestartmanager.cxx @@ -23,9 +23,8 @@ #include #include -#include -#include #include +#include #include "officerestartmanager.hxx" using namespace ::com::sun::star; @@ -33,31 +32,6 @@ using namespace ::com::sun::star; namespace comphelper { - -uno::Sequence< OUString > SAL_CALL OOfficeRestartManager::getSupportedServiceNames_static() -{ - uno::Sequence aResult { getServiceName_static() }; - return aResult; -} - - -OUString SAL_CALL OOfficeRestartManager::getImplementationName_static() -{ - return OUString( "com.sun.star.comp.task.OfficeRestartManager" ); -} - - -OUString SAL_CALL OOfficeRestartManager::getServiceName_static() -{ - return OUString( "com.sun.star.comp.task.OfficeRestartManager" ); -} - - -uno::Reference< uno::XInterface > SAL_CALL OOfficeRestartManager::Create( const uno::Reference< uno::XComponentContext >& rxContext ) -{ - return static_cast< cppu::OWeakObject* >( new OOfficeRestartManager( rxContext ) ); -} - // XRestartManager void SAL_CALL OOfficeRestartManager::requestRestart( const uno::Reference< task::XInteractionHandler >& /* xInteractionHandler */ ) @@ -160,7 +134,7 @@ void SAL_CALL OOfficeRestartManager::notify( const uno::Any& /* aData */ ) OUString SAL_CALL OOfficeRestartManager::getImplementationName() throw (uno::RuntimeException, std::exception) { - return getImplementationName_static(); + return OUString("com.sun.star.comp.task.OfficeRestartManager"); } sal_Bool SAL_CALL OOfficeRestartManager::supportsService( const OUString& aServiceName ) throw (uno::RuntimeException, std::exception) @@ -170,15 +144,36 @@ sal_Bool SAL_CALL OOfficeRestartManager::supportsService( const OUString& aServi uno::Sequence< OUString > SAL_CALL OOfficeRestartManager::getSupportedServiceNames() throw (uno::RuntimeException, std::exception) { - return getSupportedServiceNames_static(); + return { "com.sun.star.comp.task.OfficeRestartManager" }; } } // namespace comphelper -void createRegistryInfo_OOfficeRestartManager() +namespace { + +struct Instance { + explicit Instance( + css::uno::Reference const & context): + instance(static_cast(new comphelper::OOfficeRestartManager(context))) + {} + + rtl::Reference instance; +}; + +struct Singleton: + public rtl::StaticWithArg< + Instance, css::uno::Reference, Singleton> +{}; + +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL +com_sun_star_comp_task_OfficeRestartManager( + css::uno::XComponentContext *context, + css::uno::Sequence const &) { - static ::comphelper::module::OAutoRegistration< ::comphelper::OOfficeRestartManager > aAutoRegistration; - static ::comphelper::module::OSingletonRegistration< ::comphelper::OOfficeRestartManager > aSingletonRegistration; + return cppu::acquire(static_cast( + Singleton::get(context).instance.get())); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/comphelper/source/misc/officerestartmanager.hxx b/comphelper/source/misc/officerestartmanager.hxx index 15a050f3855c..43d707c36363 100644 --- a/comphelper/source/misc/officerestartmanager.hxx +++ b/comphelper/source/misc/officerestartmanager.hxx @@ -51,16 +51,6 @@ public: virtual ~OOfficeRestartManager() {} - 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 ); - // XRestartManager virtual void SAL_CALL requestRestart( const css::uno::Reference< css::task::XInteractionHandler >& xInteractionHandler ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) override; virtual sal_Bool SAL_CALL isRestartRequested( sal_Bool bInitialized ) throw (css::uno::Exception, css::uno::RuntimeException, std::exception) override; diff --git a/comphelper/util/comphelp.component b/comphelper/util/comphelp.component index 4def104c426c..95432c655704 100644 --- a/comphelper/util/comphelp.component +++ b/comphelper/util/comphelp.component @@ -47,7 +47,8 @@ - + -- cgit