diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2014-01-09 20:08:25 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2014-01-30 10:48:25 +0100 |
commit | 92c8a8fc823e8a96fb3997386364652b759a31fa (patch) | |
tree | 7d3775906e300674aec1b128013137d12da800ea /framework | |
parent | 19e16083c61c46a9d014b2db79e70194c14dec64 (diff) |
fwk: Ctor feature for single-instance ModuleUIConfigurationManagerSupplier.
Change-Id: I4674ed6852807e08ff8319515b0ab4e9535b668a
Diffstat (limited to 'framework')
-rw-r--r-- | framework/inc/uiconfiguration/moduleuicfgsupplier.hxx | 101 | ||||
-rw-r--r-- | framework/source/register/registerservices.cxx | 2 | ||||
-rw-r--r-- | framework/source/uiconfiguration/moduleuicfgsupplier.cxx | 168 | ||||
-rw-r--r-- | framework/util/fwk.component | 3 |
4 files changed, 90 insertions, 184 deletions
diff --git a/framework/inc/uiconfiguration/moduleuicfgsupplier.hxx b/framework/inc/uiconfiguration/moduleuicfgsupplier.hxx deleted file mode 100644 index 6a34a12b26b1..000000000000 --- a/framework/inc/uiconfiguration/moduleuicfgsupplier.hxx +++ /dev/null @@ -1,101 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#ifndef INCLUDED_FRAMEWORK_INC_UICONFIGURATION_MODULEUICFGSUPPLIER_HXX -#define INCLUDED_FRAMEWORK_INC_UICONFIGURATION_MODULEUICFGSUPPLIER_HXX - - -/** Attention: stl headers must(!) be included at first. Otherwise it can make trouble - with solaris headers ... -*/ -#include <vector> -#include <list> -#include <boost/unordered_map.hpp> - -#include <threadhelp/threadhelpbase.hxx> -#include <macros/generic.hxx> -#include <macros/xinterface.hxx> -#include <macros/xtypeprovider.hxx> -#include <macros/xserviceinfo.hxx> -#include <stdtypes.h> - -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/lang/XTypeProvider.hpp> -#include <com/sun/star/lang/XComponent.hpp> -#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> -#include <com/sun/star/ui/XUIConfigurationManager.hpp> -#include <com/sun/star/ui/XModuleUIConfigurationManager2.hpp> -#include <com/sun/star/frame/XModuleManager2.hpp> -#include <com/sun/star/embed/XStorage.hpp> -#include <com/sun/star/embed/XTransactedObject.hpp> - -#include <cppuhelper/implbase3.hxx> -#include <rtl/ustring.hxx> - - -namespace framework -{ - class ModuleUIConfigurationManagerSupplier : private ThreadHelpBase , // Struct for right initalization of mutex member! Must be first of baseclasses. - public cppu::WeakImplHelper3< - com::sun::star::lang::XServiceInfo , - com::sun::star::lang::XComponent , - com::sun::star::ui::XModuleUIConfigurationManagerSupplier > - { - public: - // XInterface, XTypeProvider, XServiceInfo - DECLARE_XSERVICEINFO - - ModuleUIConfigurationManagerSupplier( const com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >& rxContext ); - virtual ~ModuleUIConfigurationManagerSupplier(); - - // XComponent - virtual void SAL_CALL dispose() - throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) - throw (::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) - throw (::com::sun::star::uno::RuntimeException); - - // XModuleUIConfigurationManagerSupplier - virtual ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager > SAL_CALL getUIConfigurationManager( const OUString& ModuleIdentifier ) - throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::uno::RuntimeException); - - private: - typedef ::boost::unordered_map< OUString, com::sun::star::uno::Reference< ::com::sun::star::ui::XModuleUIConfigurationManager2 >, OUStringHash, ::std::equal_to< OUString > > ModuleToModuleCfgMgr; - -//TODO_AS void impl_initStorages(); - - // private methods - ModuleToModuleCfgMgr m_aModuleToModuleUICfgMgrMap; - bool m_bDisposed; -// TODO_AS bool m_bInit; - OUString m_aDefaultConfigURL; - OUString m_aUserConfigURL; - com::sun::star::uno::Reference< com::sun::star::embed::XStorage > m_xDefaultCfgRootStorage; - com::sun::star::uno::Reference< com::sun::star::embed::XStorage > m_xUserCfgRootStorage; - com::sun::star::uno::Reference< com::sun::star::embed::XTransactedObject > m_xUserRootCommit; - com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager2 > m_xModuleMgr; - com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > m_xContext; - ::cppu::OMultiTypeInterfaceContainerHelper m_aListenerContainer; /// container for ALL Listener - }; -} - -#endif // INCLUDED_FRAMEWORK_INC_UICONFIGURATION_MODULEUICFGSUPPLIER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/source/register/registerservices.cxx b/framework/source/register/registerservices.cxx index 5e5040d119e1..b66c1b9c37ba 100644 --- a/framework/source/register/registerservices.cxx +++ b/framework/source/register/registerservices.cxx @@ -34,7 +34,6 @@ ) =================================================================================================================*/ #include <services/desktop.hxx> -#include <uiconfiguration/moduleuicfgsupplier.hxx> #include <uifactory/menubarfactory.hxx> #include <uifactory/toolboxfactory.hxx> #include "uiconfiguration/windowstateconfiguration.hxx" @@ -45,7 +44,6 @@ COMPONENTGETFACTORY ( fwk, IFFACTORY( ::framework::Desktop ) else - IFFACTORY( ::framework::ModuleUIConfigurationManagerSupplier ) else IFFACTORY( ::framework::MenuBarFactory ) else IFFACTORY( ::framework::ToolBoxFactory ) else IFFACTORY( ::framework::WindowStateConfiguration ) else diff --git a/framework/source/uiconfiguration/moduleuicfgsupplier.cxx b/framework/source/uiconfiguration/moduleuicfgsupplier.cxx index 48f116a9f74e..66c3c82a2b92 100644 --- a/framework/source/uiconfiguration/moduleuicfgsupplier.cxx +++ b/framework/source/uiconfiguration/moduleuicfgsupplier.cxx @@ -17,11 +17,8 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include <uiconfiguration/moduleuicfgsupplier.hxx> -#include <threadhelp/resetableguard.hxx> -#include <services.h> +#include <stdtypes.h> -#include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/container/XNameAccess.hpp> #include <com/sun/star/embed/ElementModes.hpp> @@ -31,10 +28,18 @@ #include <com/sun/star/io/XSeekable.hpp> #include <com/sun/star/embed/XPackageStructureCreator.hpp> #include <com/sun/star/ui/ModuleUIConfigurationManager.hpp> - -#include <cppuhelper/implbase1.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp> +#include <com/sun/star/ui/XUIConfigurationManager.hpp> +#include <com/sun/star/ui/XModuleUIConfigurationManager2.hpp> +#include <com/sun/star/frame/XModuleManager2.hpp> + +#include <cppuhelper/compbase2.hxx> +#include <cppuhelper/supportsservice.hxx> #include <vcl/svapp.hxx> +#include <boost/unordered_map.hpp> + using namespace com::sun::star::uno; using namespace com::sun::star::io; using namespace com::sun::star::lang; @@ -43,53 +48,63 @@ using namespace com::sun::star::beans; using namespace com::sun::star::embed; using namespace ::com::sun::star::ui; using namespace ::com::sun::star::frame; +using namespace framework; -namespace framework -{ +namespace { -class RootStorageWrapper : public ::cppu::WeakImplHelper1< com::sun::star::embed::XTransactedObject > +typedef cppu::WeakComponentImplHelper2< + css::lang::XServiceInfo, + css::ui::XModuleUIConfigurationManagerSupplier > + ModuleUIConfigurationManagerSupplier_BASE; + +class ModuleUIConfigurationManagerSupplier : private osl::Mutex, + public ModuleUIConfigurationManagerSupplier_BASE { - public: - // XInterface, XTypeProvider - RootStorageWrapper( const Reference< XTransactedObject >& xRootCommit ) : m_xRootCommit( xRootCommit ) {} - virtual ~RootStorageWrapper() {} +public: + ModuleUIConfigurationManagerSupplier( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + virtual ~ModuleUIConfigurationManagerSupplier(); - // XTransactedObject - virtual void SAL_CALL commit() throw ( com::sun::star::io::IOException, com::sun::star::lang::WrappedTargetException ) - { - m_xRootCommit->commit(); - } + virtual OUString SAL_CALL getImplementationName() + throw (css::uno::RuntimeException) + { + return OUString("com.sun.star.comp.framework.ModuleUIConfigurationManagerSupplier"); + } - virtual void SAL_CALL revert() throw ( com::sun::star::io::IOException, com::sun::star::lang::WrappedTargetException ) - { - m_xRootCommit->revert(); - } + virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) + throw (css::uno::RuntimeException) + { + return cppu::supportsService(this, ServiceName); + } - private: - Reference< XTransactedObject > m_xRootCommit; -}; + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() + throw (css::uno::RuntimeException) + { + css::uno::Sequence< OUString > aSeq(1); + aSeq[0] = OUString("com.sun.star.ui.ModuleUIConfigurationManagerSupplier"); + return aSeq; + } -//***************************************************************************************************************** -// XInterface, XTypeProvider, XServiceInfo -//***************************************************************************************************************** + // XModuleUIConfigurationManagerSupplier + virtual css::uno::Reference< css::ui::XUIConfigurationManager > SAL_CALL getUIConfigurationManager( const OUString& ModuleIdentifier ) + throw (css::container::NoSuchElementException, css::uno::RuntimeException); -DEFINE_XSERVICEINFO_ONEINSTANCESERVICE_2( ModuleUIConfigurationManagerSupplier , - ::cppu::OWeakObject , - "com.sun.star.ui.ModuleUIConfigurationManagerSupplier" , - IMPLEMENTATIONNAME_MODULEUICONFIGURATIONMANAGERSUPPLIER - ) +private: + virtual void SAL_CALL disposing() SAL_OVERRIDE; -DEFINE_INIT_SERVICE ( ModuleUIConfigurationManagerSupplier, {} ) + typedef ::boost::unordered_map< OUString, css::uno::Reference< css::ui::XModuleUIConfigurationManager2 >, OUStringHash, ::std::equal_to< OUString > > ModuleToModuleCfgMgr; +//TODO_AS void impl_initStorages(); + // private methods + ModuleToModuleCfgMgr m_aModuleToModuleUICfgMgrMap; + css::uno::Reference< css::frame::XModuleManager2 > m_xModuleMgr; + css::uno::Reference< css::uno::XComponentContext > m_xContext; +}; ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( const Reference< XComponentContext >& xContext ) : - ThreadHelpBase( &Application::GetSolarMutex() ) - , m_bDisposed( false ) -//TODO_AS , m_bInit( false ) + ModuleUIConfigurationManagerSupplier_BASE(*static_cast<osl::Mutex *>(this)) , m_xModuleMgr( ModuleManager::create( xContext ) ) , m_xContext( xContext ) - , m_aListenerContainer( m_aLock.getShareableOslMutex() ) { try { @@ -107,7 +122,12 @@ ModuleUIConfigurationManagerSupplier::ModuleUIConfigurationManagerSupplier( cons ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier() { - m_xUserRootCommit.clear(); + disposing(); +} + +void SAL_CALL ModuleUIConfigurationManagerSupplier::disposing() +{ + osl::MutexGuard g(rBHelper.rMutex); // dispose all our module user interface configuration managers ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.begin(); @@ -118,53 +138,16 @@ ModuleUIConfigurationManagerSupplier::~ModuleUIConfigurationManagerSupplier() xComponent->dispose(); ++pIter; } -} - -// XComponent -void SAL_CALL ModuleUIConfigurationManagerSupplier::dispose() -throw ( RuntimeException ) -{ - Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY ); - - css::lang::EventObject aEvent( xThis ); - m_aListenerContainer.disposeAndClear( aEvent ); - - { - ResetableGuard aGuard( m_aLock ); - m_bDisposed = true; - } -} - -void SAL_CALL ModuleUIConfigurationManagerSupplier::addEventListener( const Reference< XEventListener >& xListener ) -throw ( RuntimeException ) -{ - { - ResetableGuard aGuard( m_aLock ); - - /* SAFE AREA ----------------------------------------------------------------------------------------------- */ - if ( m_bDisposed ) - throw DisposedException(); - } - - m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener ); -} - -void SAL_CALL ModuleUIConfigurationManagerSupplier::removeEventListener( const Reference< XEventListener >& xListener ) -throw ( RuntimeException ) -{ - /* SAFE AREA ----------------------------------------------------------------------------------------------- */ - m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener ); + m_aModuleToModuleUICfgMgrMap.clear(); + m_xModuleMgr.clear(); } // XModuleUIConfigurationManagerSupplier Reference< XUIConfigurationManager > SAL_CALL ModuleUIConfigurationManagerSupplier::getUIConfigurationManager( const OUString& sModuleIdentifier ) throw ( NoSuchElementException, RuntimeException) { - ResetableGuard aGuard( m_aLock ); - + osl::MutexGuard g(rBHelper.rMutex); /* SAFE AREA ----------------------------------------------------------------------------------------------- */ - if ( m_bDisposed ) - throw DisposedException(); ModuleToModuleCfgMgr::iterator pIter = m_aModuleToModuleUICfgMgrMap.find( sModuleIdentifier ); if ( pIter == m_aModuleToModuleUICfgMgrMap.end() ) @@ -203,6 +186,31 @@ throw ( NoSuchElementException, RuntimeException) return pIter->second; } -} // namespace framework +struct Instance { + explicit Instance( + css::uno::Reference<css::uno::XComponentContext> const & context): + instance(static_cast<cppu::OWeakObject *>( + new ModuleUIConfigurationManagerSupplier(context))) + { + } + + css::uno::Reference<css::uno::XInterface> instance; +}; + +struct Singleton: + public rtl::StaticWithArg< + Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton> +{}; + +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL +com_sun_star_comp_framework_ModuleUIConfigurationManagerSupplier_get_implementation( + css::uno::XComponentContext *context, + css::uno::Sequence<css::uno::Any> const &) +{ + return cppu::acquire(static_cast<cppu::OWeakObject *>( + Singleton::get(context).instance.get())); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/util/fwk.component b/framework/util/fwk.component index d8792ecfe8ee..fc94a5eaaafd 100644 --- a/framework/util/fwk.component +++ b/framework/util/fwk.component @@ -85,7 +85,8 @@ constructor="com_sun_star_comp_framework_ModuleUIConfigurationManager_get_implementation"> <service name="com.sun.star.ui.ModuleUIConfigurationManager"/> </implementation> - <implementation name="com.sun.star.comp.framework.ModuleUIConfigurationManagerSupplier"> + <implementation name="com.sun.star.comp.framework.ModuleUIConfigurationManagerSupplier" + constructor="com_sun_star_comp_framework_ModuleUIConfigurationManagerSupplier_get_implementation"> <service name="com.sun.star.ui.ModuleUIConfigurationManagerSupplier"/> <singleton name="com.sun.star.ui.theModuleUIConfigurationManagerSupplier"/> </implementation> |