Kaydet (Commit) 55aa40bc authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Quick and dirty adaption of ModuleManager to WeakImplHelper

...to better be able to change its set of implemented interfaces later on.

Some potential for further clean up:
* a generic helper for supportsService;
* remove need for impl_createFactory;
* base impl_createInstance on XComponentContext instead of XMultiServiceFactory;
* replace ThreadHelpBase with a plain osl::Mutex.

Change-Id: Ia2cbd14872a609c2ed57d9ce58b546f087c2fdfb
üst 24f69186
...@@ -20,23 +20,23 @@ ...@@ -20,23 +20,23 @@
#ifndef __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_ #ifndef __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_
#define __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_ #define __FRAMEWORK_SERVICES_MODULEMANAGER_HXX_
#include "sal/config.h"
#include <threadhelp/threadhelpbase.hxx> #include <threadhelp/threadhelpbase.hxx>
#include <macros/xinterface.hxx>
#include <macros/xtypeprovider.hxx> #include <boost/noncopyable.hpp>
#include <macros/xserviceinfo.hxx>
#include <general.h>
#include <general.h>
#include <stdtypes.h>
#include <com/sun/star/uno/XInterface.hpp>
#include <com/sun/star/lang/XTypeProvider.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/frame/XModuleManager.hpp> #include <com/sun/star/frame/XModuleManager.hpp>
#include <com/sun/star/container/XNameReplace.hpp> #include <com/sun/star/container/XNameReplace.hpp>
#include <com/sun/star/container/XContainerQuery.hpp> #include <com/sun/star/container/XContainerQuery.hpp>
#include <cppuhelper/implbase4.hxx>
namespace com { namespace sun { namespace star { namespace lang {
class XSingleServiceFactory;
} } } }
#include <cppuhelper/weak.hxx> namespace css = com::sun::star;
//_______________________________________________ //_______________________________________________
// definition // definition
...@@ -48,14 +48,11 @@ namespace framework ...@@ -48,14 +48,11 @@ namespace framework
/** /**
implements the service com.sun.star.frame.ModuleManager implements the service com.sun.star.frame.ModuleManager
*/ */
class ModuleManager : public css::lang::XTypeProvider class ModuleManager:
, public css::lang::XServiceInfo public cppu::WeakImplHelper4<
, public css::frame::XModuleManager css::lang::XServiceInfo, css::frame::XModuleManager,
, public css::container::XNameReplace // => XNameAccess, XElementAccess css::container::XNameReplace, css::container::XContainerQuery >,
, public css::container::XContainerQuery private ThreadHelpBase, private boost::noncopyable
// attention! Must be the first base class to guarentee right initialize lock ...
, private ThreadHelpBase
, public ::cppu::OWeakObject
{ {
//___________________________________________ //___________________________________________
// member // member
...@@ -80,13 +77,37 @@ class ModuleManager : public css::lang::XTypeProvider ...@@ -80,13 +77,37 @@ class ModuleManager : public css::lang::XTypeProvider
public: public:
static rtl::OUString SAL_CALL impl_getStaticImplementationName();
static css::uno::Reference< css::lang::XSingleServiceFactory > SAL_CALL
impl_createFactory(
css::uno::Reference< css::lang::XMultiServiceFactory > const &
manager);
private:
static css::uno::Sequence< rtl::OUString >
impl_getSupportedServiceNames();
static css::uno::Reference< css::uno::XInterface > SAL_CALL
impl_createInstance(
css::uno::Reference< css::lang::XMultiServiceFactory > const &
manager);
ModuleManager(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR); ModuleManager(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
virtual ~ModuleManager( ); virtual ~ModuleManager( );
// XInterface, XTypeProvider, XServiceInfo // XServiceInfo
FWK_DECLARE_XINTERFACE virtual rtl::OUString SAL_CALL getImplementationName()
FWK_DECLARE_XTYPEPROVIDER throw (css::uno::RuntimeException);
DECLARE_XSERVICEINFO
virtual sal_Bool SAL_CALL supportsService(
rtl::OUString const & ServiceName)
throw (css::uno::RuntimeException);
virtual css::uno::Sequence< rtl::OUString > SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException);
// XModuleManager // XModuleManager
virtual ::rtl::OUString SAL_CALL identify(const css::uno::Reference< css::uno::XInterface >& xModule) virtual ::rtl::OUString SAL_CALL identify(const css::uno::Reference< css::uno::XInterface >& xModule)
......
...@@ -51,40 +51,31 @@ namespace framework ...@@ -51,40 +51,31 @@ namespace framework
static const char CFGPATH_FACTORIES[] = "/org.openoffice.Setup/Office/Factories"; static const char CFGPATH_FACTORIES[] = "/org.openoffice.Setup/Office/Factories";
static const char MODULEPROP_IDENTIFIER[] = "ooSetupFactoryModuleIdentifier"; static const char MODULEPROP_IDENTIFIER[] = "ooSetupFactoryModuleIdentifier";
DEFINE_XINTERFACE_7(ModuleManager , rtl::OUString ModuleManager::impl_getStaticImplementationName() {
OWeakObject , return IMPLEMENTATIONNAME_MODULEMANAGER;
DIRECT_INTERFACE(css::lang::XTypeProvider ), }
DIRECT_INTERFACE(css::lang::XServiceInfo ),
DIRECT_INTERFACE(css::container::XNameReplace ), css::uno::Reference< css::lang::XSingleServiceFactory >
DIRECT_INTERFACE(css::container::XNameAccess ), ModuleManager::impl_createFactory(
DIRECT_INTERFACE(css::container::XElementAccess ), css::uno::Reference< css::lang::XMultiServiceFactory > const & manager)
DIRECT_INTERFACE(css::container::XContainerQuery), {
DIRECT_INTERFACE(css::frame::XModuleManager )) return cppu::createSingleFactory(
manager, impl_getStaticImplementationName(), &impl_createInstance,
DEFINE_XTYPEPROVIDER_7(ModuleManager , impl_getSupportedServiceNames());
css::lang::XTypeProvider , }
css::lang::XServiceInfo ,
css::container::XNameReplace , css::uno::Sequence< rtl::OUString >
css::container::XNameAccess , ModuleManager::impl_getSupportedServiceNames() {
css::container::XElementAccess , css::uno::Sequence< rtl::OUString > s(1);
css::container::XContainerQuery, s[0] = SERVICENAME_MODULEMANAGER;
css::frame::XModuleManager ) return s;
}
DEFINE_XSERVICEINFO_ONEINSTANCESERVICE(ModuleManager ,
::cppu::OWeakObject , css::uno::Reference< css::uno::XInterface > ModuleManager::impl_createInstance(
SERVICENAME_MODULEMANAGER , css::uno::Reference< css::lang::XMultiServiceFactory > const & manager)
IMPLEMENTATIONNAME_MODULEMANAGER) {
return static_cast< cppu::OWeakObject * >(new ModuleManager(manager));
DEFINE_INIT_SERVICE( }
ModuleManager,
{
/*Attention
I think we don't need any mutex or lock here ... because we are called by our own static method impl_createInstance()
to create a new instance of this class by our own supported service factory.
see macro DEFINE_XSERVICEINFO_MULTISERVICE and "impl_initService()" for further informations!
*/
}
)
ModuleManager::ModuleManager(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR) ModuleManager::ModuleManager(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
: ThreadHelpBase( ) : ThreadHelpBase( )
...@@ -98,6 +89,30 @@ ModuleManager::~ModuleManager() ...@@ -98,6 +89,30 @@ ModuleManager::~ModuleManager()
m_xCFG.clear(); m_xCFG.clear();
} }
rtl::OUString ModuleManager::getImplementationName()
throw (css::uno::RuntimeException)
{
return impl_getStaticImplementationName();
}
sal_Bool ModuleManager::supportsService(rtl::OUString const & ServiceName)
throw (css::uno::RuntimeException)
{
css::uno::Sequence< rtl::OUString > s(getSupportedServiceNames());
for (sal_Int32 i = 0; i != s.getLength(); ++i) {
if (s[i] == ServiceName) {
return true;
}
}
return false;
}
css::uno::Sequence< rtl::OUString > ModuleManager::getSupportedServiceNames()
throw (css::uno::RuntimeException)
{
return impl_getSupportedServiceNames();
}
::rtl::OUString SAL_CALL ModuleManager::identify(const css::uno::Reference< css::uno::XInterface >& xModule) ::rtl::OUString SAL_CALL ModuleManager::identify(const css::uno::Reference< css::uno::XInterface >& xModule)
throw(css::lang::IllegalArgumentException, throw(css::lang::IllegalArgumentException,
css::frame::UnknownModuleException, css::frame::UnknownModuleException,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment