config leaks: drop dodgy LegacySingleton foo

This commit is contained in:
Caolán McNamara 2011-05-06 11:31:54 +01:00
parent 4d4159463b
commit c639da5a41
5 changed files with 1 additions and 314 deletions

View file

@ -90,7 +90,6 @@ $(eval $(call gb_Library_add_exception_objects,comphelper,\
comphelper/source/misc/ihwrapnofilter \
comphelper/source/misc/instancelocker \
comphelper/source/misc/interaction \
comphelper/source/misc/legacysingletonfactory \
comphelper/source/misc/listenernotification \
comphelper/source/misc/locale \
comphelper/source/misc/logging \

View file

@ -89,7 +89,6 @@ $(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/ChainablePropert
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/stl_types.hxx,comphelper/stl_types.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/eventattachermgr.hxx,comphelper/eventattachermgr.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/componentcontext.hxx,comphelper/componentcontext.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/legacysingletonfactory.hxx,comphelper/legacysingletonfactory.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/accessibleeventnotifier.hxx,comphelper/accessibleeventnotifier.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/ihwrapnofilter.hxx,comphelper/ihwrapnofilter.hxx))
$(eval $(call gb_Package_add_file,comphelper_inc,inc/comphelper/sequenceasvector.hxx,comphelper/sequenceasvector.hxx))

View file

@ -29,7 +29,6 @@
#define COMPHELPER_INC_COMPHELPER_COMPONENTMODULE_HXX
#include <comphelper/comphelperdllapi.h>
#include <comphelper/legacysingletonfactory.hxx>
/** === begin UNO includes === **/
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
@ -271,29 +270,6 @@ namespace comphelper
) );
}
//==========================================================================
//= OLegacySingletonRegistration
//==========================================================================
template <class TYPE>
class OLegacySingletonRegistration
{
public:
OLegacySingletonRegistration( OModule& _rModule );
};
//--------------------------------------------------------------------------
template <class TYPE>
OLegacySingletonRegistration<TYPE>::OLegacySingletonRegistration( OModule& _rModule )
{
_rModule.registerImplementation( ComponentDescription(
TYPE::getImplementationName_static(),
TYPE::getSupportedServiceNames_static(),
::rtl::OUString(),
&TYPE::Create,
&::comphelper::createLegacySingletonFactory
) );
}
//==========================================================================
//= helpers
//==========================================================================
@ -350,19 +326,7 @@ namespace comphelper
OSingletonRegistration() : BaseClass( ModuleClass::getInstance() ) \
{ \
} \
}; \
/* -------------------------------------------------------------------- */ \
template < class TYPE > \
class OLegacySingletonRegistration : public ::comphelper::OLegacySingletonRegistration< TYPE > \
{ \
private: \
typedef ::comphelper::OLegacySingletonRegistration< TYPE > BaseClass; \
\
public: \
OLegacySingletonRegistration() : BaseClass( ModuleClass::getInstance() ) \
{ \
} \
}; \
};
//==========================================================================
//= implementing a OModule for a component library

View file

@ -1,75 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#ifndef COMPHELPER_LEGACYSINGLETONFACTORY_HXX
#define COMPHELPER_LEGACYSINGLETONFACTORY_HXX
#include "comphelper/comphelperdllapi.h"
/** === begin UNO includes === **/
/** === end UNO includes === **/
#include <cppuhelper/factory.hxx>
//........................................................................
namespace comphelper
{
//........................................................................
/** creates a factory which can be used when implementing old-style singletons
Before UNO having the component context concept, singletons were implemented by providing
a factory which return the very same component instance for every creation request.
Nowadays, singletons are implemented by making them available at the component context,
as dedicated property.
To bridge between both worlds - sometimes necessary to support legacy code, which instantiates
singletons at the global service manager, instead of obtaining the property at the
component context -, you can use the function below. I creates a single-component
factory, which behaves like the old factories did: Upon multiple creation requests,
it will always return the same instance. Additionally, the signature of the function
is the same as the signature of <code>::cppu::createSingleComponentFactory</code>
(which creates a "normal" component factory), so you can use both factory functions
in the same context.
*/
::com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory >
COMPHELPER_DLLPUBLIC createLegacySingletonFactory(
::cppu::ComponentFactoryFunc _componentFactoryFunc,
const ::rtl::OUString& _rImplementationName,
const ::com::sun::star::uno::Sequence< ::rtl::OUString >& _rServiceNames,
rtl_ModuleCount* _pModCount = NULL
);
//........................................................................
} // namespace comphelper
//........................................................................
#endif // COMPHELPER_LEGACYSINGLETONFACTORY_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View file

@ -1,200 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_comphelper.hxx"
#include "comphelper/legacysingletonfactory.hxx"
/** === begin UNO includes === **/
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/lang/XInitialization.hpp>
/** === end UNO includes === **/
#include <cppuhelper/implbase2.hxx>
#include <algorithm>
//........................................................................
namespace comphelper
{
//........................................................................
/** === begin UNO using === **/
using ::com::sun::star::uno::Reference;
using ::com::sun::star::uno::XInterface;
using ::com::sun::star::uno::UNO_QUERY;
using ::com::sun::star::uno::UNO_QUERY_THROW;
using ::com::sun::star::uno::UNO_SET_THROW;
using ::com::sun::star::uno::Exception;
using ::com::sun::star::uno::RuntimeException;
using ::com::sun::star::uno::Any;
using ::com::sun::star::uno::makeAny;
using ::com::sun::star::lang::XSingleComponentFactory;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::XComponentContext;
using ::com::sun::star::lang::XServiceInfo;
using ::com::sun::star::lang::XInitialization;
/** === end UNO using === **/
//====================================================================
//= LegacySingletonFactory
//====================================================================
typedef ::cppu::WeakImplHelper2 < XServiceInfo
, XSingleComponentFactory
> LegacySingletonFactory_Base;
class COMPHELPER_DLLPRIVATE LegacySingletonFactory : public LegacySingletonFactory_Base
{
public:
LegacySingletonFactory(
::cppu::ComponentFactoryFunc _componentFactoryFunc, const ::rtl::OUString& _rImplementationName,
const Sequence< ::rtl::OUString >& _rServiceNames, rtl_ModuleCount* _pModCount
);
// XServiceInfo
virtual ::rtl::OUString SAL_CALL getImplementationName( ) throw (RuntimeException);
virtual ::sal_Bool SAL_CALL supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException);
virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames( ) throw (RuntimeException);
// XSingleComponentFactory
virtual Reference< XInterface > SAL_CALL createInstanceWithContext( const Reference< XComponentContext >& Context ) throw (Exception, RuntimeException);
virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext( const Sequence< Any >& Arguments, const Reference< XComponentContext >& Context ) throw (Exception, RuntimeException);
protected:
~LegacySingletonFactory();
private:
/** creates m_xInstance, returns whether it actually was created (<TRUE/>) or existed before (<FALSE/>
*/
bool impl_nts_ensureInstance( const Reference< XComponentContext >& _rxContext );
private:
::osl::Mutex m_aMutex;
::cppu::ComponentFactoryFunc m_componentFactoryFunc;
::rtl::OUString m_sImplementationName;
Sequence< ::rtl::OUString > m_aServiceNames;
rtl_ModuleCount* m_pModuleCount;
Reference< XInterface > m_xTheInstance;
};
//--------------------------------------------------------------------
LegacySingletonFactory::LegacySingletonFactory( ::cppu::ComponentFactoryFunc _componentFactoryFunc, const ::rtl::OUString& _rImplementationName,
const Sequence< ::rtl::OUString >& _rServiceNames, rtl_ModuleCount* _pModCount )
:m_componentFactoryFunc ( _componentFactoryFunc )
,m_sImplementationName ( _rImplementationName )
,m_aServiceNames ( _rServiceNames )
,m_pModuleCount ( _pModCount )
,m_xTheInstance ( )
{
if ( m_pModuleCount )
m_pModuleCount->acquire( m_pModuleCount );
}
//--------------------------------------------------------------------
LegacySingletonFactory::~LegacySingletonFactory()
{
if ( m_pModuleCount )
m_pModuleCount->release( m_pModuleCount );
}
//--------------------------------------------------------------------
::rtl::OUString SAL_CALL LegacySingletonFactory::getImplementationName( ) throw (RuntimeException)
{
return m_sImplementationName;
}
//--------------------------------------------------------------------
::sal_Bool SAL_CALL LegacySingletonFactory::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
{
Sequence< ::rtl::OUString > aServices( getSupportedServiceNames() );
const ::rtl::OUString* pStart = aServices.getConstArray();
const ::rtl::OUString* pEnd = aServices.getConstArray() + aServices.getLength();
return ::std::find( pStart, pEnd, _rServiceName ) != pEnd;
}
//--------------------------------------------------------------------
Sequence< ::rtl::OUString > SAL_CALL LegacySingletonFactory::getSupportedServiceNames( ) throw (RuntimeException)
{
return m_aServiceNames;
}
//--------------------------------------------------------------------
bool LegacySingletonFactory::impl_nts_ensureInstance( const Reference< XComponentContext >& _rxContext )
{
if ( m_xTheInstance.is() )
return false;
m_xTheInstance = (*m_componentFactoryFunc)( _rxContext );
if ( !m_xTheInstance.is() )
throw RuntimeException();
return true; // true -> "was newly created"
}
//--------------------------------------------------------------------
Reference< XInterface > SAL_CALL LegacySingletonFactory::createInstanceWithContext( const Reference< XComponentContext >& _rxContext ) throw (Exception, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
impl_nts_ensureInstance( _rxContext );
return m_xTheInstance;
}
//--------------------------------------------------------------------
Reference< XInterface > SAL_CALL LegacySingletonFactory::createInstanceWithArgumentsAndContext( const Sequence< Any >& _rArguments, const Reference< XComponentContext >& _rxContext ) throw (Exception, RuntimeException)
{
::osl::MutexGuard aGuard( m_aMutex );
if ( !impl_nts_ensureInstance( _rxContext ) )
throw RuntimeException(
::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Instance already created before, unable to initialize it." ) ),
*this
);
Reference< XInitialization > xInit( m_xTheInstance, UNO_QUERY_THROW );
xInit->initialize( _rArguments );
return m_xTheInstance;
}
//====================================================================
//= createLegacySingletonFactory
//====================================================================
Reference< XSingleComponentFactory > createLegacySingletonFactory(
::cppu::ComponentFactoryFunc _componentFactoryFunc, const ::rtl::OUString& _rImplementationName,
const Sequence< ::rtl::OUString >& _rServiceNames, rtl_ModuleCount* _pModCount )
{
return new LegacySingletonFactory( _componentFactoryFunc, _rImplementationName, _rServiceNames, _pModCount );
}
//........................................................................
} // namespace comphelper
//........................................................................
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */