2013-01-15 16:28:30 +01:00
|
|
|
/* -*- 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/.
|
|
|
|
*/
|
|
|
|
|
2020-09-13 11:57:19 +00:00
|
|
|
#pragma once
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2014-06-04 16:23:19 +02:00
|
|
|
#include <sal/config.h>
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
#include <cassert>
|
2021-03-10 19:19:26 +01:00
|
|
|
#include <unordered_map>
|
2015-09-14 09:21:33 +01:00
|
|
|
#include <memory>
|
2020-12-28 17:56:40 +01:00
|
|
|
#include <string_view>
|
2013-01-15 16:28:30 +01:00
|
|
|
#include <vector>
|
|
|
|
|
2014-06-04 16:23:19 +02:00
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
#include <com/sun/star/beans/XPropertySetInfo.hpp>
|
|
|
|
#include <com/sun/star/container/XContentEnumerationAccess.hpp>
|
|
|
|
#include <com/sun/star/container/XSet.hpp>
|
|
|
|
#include <com/sun/star/lang/XEventListener.hpp>
|
2016-02-25 15:33:22 +01:00
|
|
|
#include <com/sun/star/lang/XInitialization.hpp>
|
2014-06-04 16:23:19 +02:00
|
|
|
#include <com/sun/star/lang/XMultiComponentFactory.hpp>
|
|
|
|
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
|
|
|
|
#include <com/sun/star/lang/XServiceInfo.hpp>
|
|
|
|
#include <com/sun/star/uno/Reference.hxx>
|
|
|
|
#include <cppuhelper/basemutex.hxx>
|
2016-02-25 15:33:22 +01:00
|
|
|
#include <cppuhelper/compbase.hxx>
|
2014-06-04 16:23:19 +02:00
|
|
|
#include <osl/mutex.hxx>
|
|
|
|
#include <rtl/ustring.hxx>
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2020-05-08 10:59:40 +02:00
|
|
|
namespace com::sun::star::lang {
|
2013-12-19 08:48:56 +01:00
|
|
|
class XSingleComponentFactory;
|
2020-05-08 10:59:40 +02:00
|
|
|
}
|
2013-01-16 13:57:03 +01:00
|
|
|
namespace cppu { struct ContextEntry_Init; }
|
2019-02-06 20:59:05 +01:00
|
|
|
namespace com :: sun :: star :: lang { class XSingleServiceFactory; }
|
|
|
|
namespace com :: sun :: star :: uno { class XComponentContext; }
|
|
|
|
|
|
|
|
class RegistryKey;
|
2013-01-16 13:57:03 +01:00
|
|
|
|
2013-01-15 16:28:30 +01:00
|
|
|
namespace cppuhelper {
|
|
|
|
|
2013-12-19 08:48:56 +01:00
|
|
|
extern "C" {
|
|
|
|
|
2017-12-08 15:58:41 +02:00
|
|
|
typedef css::uno::XInterface * ImplementationConstructorFn(
|
2014-01-22 11:54:19 +01:00
|
|
|
css::uno::XComponentContext *, css::uno::Sequence<css::uno::Any> const &);
|
2013-12-19 08:48:56 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-01-13 23:40:51 +01:00
|
|
|
typedef std::function<css::uno::XInterface * (css::uno::XComponentContext *, css::uno::Sequence<css::uno::Any> const&)> WrapperConstructorFn;
|
|
|
|
|
2016-02-25 15:33:22 +01:00
|
|
|
typedef cppu::WeakComponentImplHelper<
|
2013-01-15 16:28:30 +01:00
|
|
|
css::lang::XServiceInfo, css::lang::XMultiServiceFactory,
|
|
|
|
css::lang::XMultiComponentFactory, css::container::XSet,
|
|
|
|
css::container::XContentEnumerationAccess, css::beans::XPropertySet,
|
2016-02-25 15:33:22 +01:00
|
|
|
css::beans::XPropertySetInfo, css::lang::XEventListener,
|
|
|
|
css::lang::XInitialization>
|
2013-01-15 16:28:30 +01:00
|
|
|
ServiceManagerBase;
|
|
|
|
|
|
|
|
class ServiceManager:
|
2016-04-07 20:26:54 +02:00
|
|
|
private cppu::BaseMutex, public ServiceManagerBase
|
2013-01-15 16:28:30 +01:00
|
|
|
{
|
|
|
|
public:
|
2016-04-07 20:26:54 +02:00
|
|
|
struct Data {
|
|
|
|
Data() = default;
|
|
|
|
Data(const Data&) = delete;
|
|
|
|
const Data& operator=(const Data&) = delete;
|
|
|
|
|
2019-12-30 16:36:57 +01:00
|
|
|
struct Implementation {
|
|
|
|
Implementation(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & theName, OUString const & theLoader,
|
2019-12-30 16:36:57 +01:00
|
|
|
OUString const & theUri, OUString const & theEnvironment,
|
|
|
|
OUString const & theConstructorName,
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & thePrefix,
|
Add single-instance attribute for *.compoonent <implementation>s
...to ease the implementation in C++ code of constructor-based <implementation>s
that shall be single-instance (and which would have been implemented with e.g.
cppu::creaetOneInstanceFactory for non--constructor-based <implementation>s).
See e.g. 6e35794cad555485955c3b43593497dcdbf29840 "terminate XDesktop properly
in unit tests" and 6362ebab298549e8616c32cafd75cb3959ba7d65 "dbaccess: create
instances with uno constructors" for the clumsy approach used until now, where
the C++ constructor function uses a static instance that is cleared in
dispose(), adding fake <singleton> entries to <implementation>s where necessary
so that the ServiceManager will call those XComponent::dispose() functions when
it itself gets disposed.
For every <implementation>, the ServiceManager already holds an Implementation
data structure, so it can easily hold a singleInstance there and clear it when
the ServiceManager gets disposed. (One consequence is that single-instance
implementations are now created with their Instance.mutex locked, but that
should not cause problems in practice, given that the construction of a single-
instance implementation should not recursively request its own construction
anyway.)
The new single-instance="true" attribute is mostly useful in combination with
the constructor attribute (see above), but it can also be used for non--
constructor-based <implementation>s, at least in theory.
(The single-instance="true" attribute is orthogonal to <singleton> elements.
There are existing single-instance services---even if those should arguably have
been defined as singletons in the first place---that can benefit from
single-instance="true". And there are <implementation>s that support one or
more <singleton>s alongside one or more <service>s, where the latter are not
single-instance.)
This new single-instance="true" attribute in *.component files should not
interfere with the lo_get_constructor_map machinery in the DISABLE_DYNLOADING
branch of cppuhelper::detail::loadSharedLibComponentFactory
(cppuhelper/source/shlib.cxx) used by Android, iOS and some fuzzer code.
AFAIU, the lo_get_constructor_map machinery should only ever come into play
after the ServiceManager has decided whether or not to create a new instance
based on the single-instance attributes in the *.component files.
This commit only provides the new single-instance="true" attribute. Actual
changes of <implementation>s and their C++ constructor functions are delegated
to a series of follow-up commits. (So that they can easily be reverted
individually should the need arise.)
Change-Id: Iea6c0fc539d74477b7a536dc771b198df6b0510e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103734
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-09-30 21:31:10 +02:00
|
|
|
bool theIsSingleInstance,
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const &
|
|
|
|
theAlienContext,
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & theRdbFile):
|
2019-12-30 16:36:57 +01:00
|
|
|
name(theName), loader(theLoader), uri(theUri), environment(theEnvironment),
|
|
|
|
constructorName(theConstructorName), prefix(thePrefix),
|
Add single-instance attribute for *.compoonent <implementation>s
...to ease the implementation in C++ code of constructor-based <implementation>s
that shall be single-instance (and which would have been implemented with e.g.
cppu::creaetOneInstanceFactory for non--constructor-based <implementation>s).
See e.g. 6e35794cad555485955c3b43593497dcdbf29840 "terminate XDesktop properly
in unit tests" and 6362ebab298549e8616c32cafd75cb3959ba7d65 "dbaccess: create
instances with uno constructors" for the clumsy approach used until now, where
the C++ constructor function uses a static instance that is cleared in
dispose(), adding fake <singleton> entries to <implementation>s where necessary
so that the ServiceManager will call those XComponent::dispose() functions when
it itself gets disposed.
For every <implementation>, the ServiceManager already holds an Implementation
data structure, so it can easily hold a singleInstance there and clear it when
the ServiceManager gets disposed. (One consequence is that single-instance
implementations are now created with their Instance.mutex locked, but that
should not cause problems in practice, given that the construction of a single-
instance implementation should not recursively request its own construction
anyway.)
The new single-instance="true" attribute is mostly useful in combination with
the constructor attribute (see above), but it can also be used for non--
constructor-based <implementation>s, at least in theory.
(The single-instance="true" attribute is orthogonal to <singleton> elements.
There are existing single-instance services---even if those should arguably have
been defined as singletons in the first place---that can benefit from
single-instance="true". And there are <implementation>s that support one or
more <singleton>s alongside one or more <service>s, where the latter are not
single-instance.)
This new single-instance="true" attribute in *.component files should not
interfere with the lo_get_constructor_map machinery in the DISABLE_DYNLOADING
branch of cppuhelper::detail::loadSharedLibComponentFactory
(cppuhelper/source/shlib.cxx) used by Android, iOS and some fuzzer code.
AFAIU, the lo_get_constructor_map machinery should only ever come into play
after the ServiceManager has decided whether or not to create a new instance
based on the single-instance attributes in the *.component files.
This commit only provides the new single-instance="true" attribute. Actual
changes of <implementation>s and their C++ constructor functions are delegated
to a series of follow-up commits. (So that they can easily be reverted
individually should the need arise.)
Change-Id: Iea6c0fc539d74477b7a536dc771b198df6b0510e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103734
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-09-30 21:31:10 +02:00
|
|
|
isSingleInstance(theIsSingleInstance),
|
2019-12-30 16:36:57 +01:00
|
|
|
alienContext(theAlienContext), rdbFile(theRdbFile),
|
|
|
|
constructorFn(nullptr), status(STATUS_NEW), dispose(true)
|
2013-01-15 16:28:30 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
Implementation(
|
2019-12-30 16:36:57 +01:00
|
|
|
OUString const & theName,
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::lang::XSingleComponentFactory >
|
|
|
|
const & theFactory1,
|
|
|
|
css::uno::Reference< css::lang::XSingleServiceFactory > const &
|
|
|
|
theFactory2,
|
|
|
|
css::uno::Reference< css::lang::XComponent > const &
|
|
|
|
theComponent):
|
Add single-instance attribute for *.compoonent <implementation>s
...to ease the implementation in C++ code of constructor-based <implementation>s
that shall be single-instance (and which would have been implemented with e.g.
cppu::creaetOneInstanceFactory for non--constructor-based <implementation>s).
See e.g. 6e35794cad555485955c3b43593497dcdbf29840 "terminate XDesktop properly
in unit tests" and 6362ebab298549e8616c32cafd75cb3959ba7d65 "dbaccess: create
instances with uno constructors" for the clumsy approach used until now, where
the C++ constructor function uses a static instance that is cleared in
dispose(), adding fake <singleton> entries to <implementation>s where necessary
so that the ServiceManager will call those XComponent::dispose() functions when
it itself gets disposed.
For every <implementation>, the ServiceManager already holds an Implementation
data structure, so it can easily hold a singleInstance there and clear it when
the ServiceManager gets disposed. (One consequence is that single-instance
implementations are now created with their Instance.mutex locked, but that
should not cause problems in practice, given that the construction of a single-
instance implementation should not recursively request its own construction
anyway.)
The new single-instance="true" attribute is mostly useful in combination with
the constructor attribute (see above), but it can also be used for non--
constructor-based <implementation>s, at least in theory.
(The single-instance="true" attribute is orthogonal to <singleton> elements.
There are existing single-instance services---even if those should arguably have
been defined as singletons in the first place---that can benefit from
single-instance="true". And there are <implementation>s that support one or
more <singleton>s alongside one or more <service>s, where the latter are not
single-instance.)
This new single-instance="true" attribute in *.component files should not
interfere with the lo_get_constructor_map machinery in the DISABLE_DYNLOADING
branch of cppuhelper::detail::loadSharedLibComponentFactory
(cppuhelper/source/shlib.cxx) used by Android, iOS and some fuzzer code.
AFAIU, the lo_get_constructor_map machinery should only ever come into play
after the ServiceManager has decided whether or not to create a new instance
based on the single-instance attributes in the *.component files.
This commit only provides the new single-instance="true" attribute. Actual
changes of <implementation>s and their C++ constructor functions are delegated
to a series of follow-up commits. (So that they can easily be reverted
individually should the need arise.)
Change-Id: Iea6c0fc539d74477b7a536dc771b198df6b0510e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103734
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-09-30 21:31:10 +02:00
|
|
|
name(theName), isSingleInstance(false), constructorFn(nullptr),
|
2013-12-19 08:48:56 +01:00
|
|
|
factory1(theFactory1), factory2(theFactory2),
|
2014-02-07 11:10:06 +01:00
|
|
|
component(theComponent), status(STATUS_LOADED), dispose(true)
|
2014-01-20 23:30:49 +01:00
|
|
|
{ assert(theFactory1.is() || theFactory2.is()); }
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2016-04-07 20:26:54 +02:00
|
|
|
Implementation(const Implementation&) = delete;
|
|
|
|
const Implementation& operator=(const Implementation&) = delete;
|
|
|
|
|
2014-01-16 15:29:41 +01:00
|
|
|
css::uno::Reference<css::uno::XInterface> createInstance(
|
|
|
|
css::uno::Reference<css::uno::XComponentContext> const &
|
|
|
|
context,
|
|
|
|
bool singletonRequest);
|
|
|
|
|
|
|
|
css::uno::Reference<css::uno::XInterface>
|
|
|
|
createInstanceWithArguments(
|
|
|
|
css::uno::Reference<css::uno::XComponentContext> const &
|
|
|
|
context,
|
|
|
|
bool singletonRequest,
|
|
|
|
css::uno::Sequence<css::uno::Any> const & arguments);
|
|
|
|
|
Add single-instance attribute for *.compoonent <implementation>s
...to ease the implementation in C++ code of constructor-based <implementation>s
that shall be single-instance (and which would have been implemented with e.g.
cppu::creaetOneInstanceFactory for non--constructor-based <implementation>s).
See e.g. 6e35794cad555485955c3b43593497dcdbf29840 "terminate XDesktop properly
in unit tests" and 6362ebab298549e8616c32cafd75cb3959ba7d65 "dbaccess: create
instances with uno constructors" for the clumsy approach used until now, where
the C++ constructor function uses a static instance that is cleared in
dispose(), adding fake <singleton> entries to <implementation>s where necessary
so that the ServiceManager will call those XComponent::dispose() functions when
it itself gets disposed.
For every <implementation>, the ServiceManager already holds an Implementation
data structure, so it can easily hold a singleInstance there and clear it when
the ServiceManager gets disposed. (One consequence is that single-instance
implementations are now created with their Instance.mutex locked, but that
should not cause problems in practice, given that the construction of a single-
instance implementation should not recursively request its own construction
anyway.)
The new single-instance="true" attribute is mostly useful in combination with
the constructor attribute (see above), but it can also be used for non--
constructor-based <implementation>s, at least in theory.
(The single-instance="true" attribute is orthogonal to <singleton> elements.
There are existing single-instance services---even if those should arguably have
been defined as singletons in the first place---that can benefit from
single-instance="true". And there are <implementation>s that support one or
more <singleton>s alongside one or more <service>s, where the latter are not
single-instance.)
This new single-instance="true" attribute in *.component files should not
interfere with the lo_get_constructor_map machinery in the DISABLE_DYNLOADING
branch of cppuhelper::detail::loadSharedLibComponentFactory
(cppuhelper/source/shlib.cxx) used by Android, iOS and some fuzzer code.
AFAIU, the lo_get_constructor_map machinery should only ever come into play
after the ServiceManager has decided whether or not to create a new instance
based on the single-instance attributes in the *.component files.
This commit only provides the new single-instance="true" attribute. Actual
changes of <implementation>s and their C++ constructor functions are delegated
to a series of follow-up commits. (So that they can easily be reverted
individually should the need arise.)
Change-Id: Iea6c0fc539d74477b7a536dc771b198df6b0510e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103734
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-09-30 21:31:10 +02:00
|
|
|
bool shallDispose() const { return isSingleInstance || !singletons.empty(); }
|
|
|
|
|
2014-01-16 15:29:41 +01:00
|
|
|
enum Status { STATUS_NEW, STATUS_WRAPPER, STATUS_LOADED };
|
|
|
|
|
2019-12-30 16:36:57 +01:00
|
|
|
// Logically, exactly one of constructorFn, factory1, factory2 should
|
2017-10-27 10:37:26 +02:00
|
|
|
// be set. However, there are two exceptions: For one, when
|
2019-12-30 16:36:57 +01:00
|
|
|
// constructorFn is set, ServiceManager::createContentEnumeration will
|
2017-10-27 10:37:26 +02:00
|
|
|
// store the necessary ImplementationWrapper in factory1 (so that
|
|
|
|
// multiple calls to createContentEnumeration will return the same
|
|
|
|
// wrapper). For another, when factory1 should be set but status is
|
|
|
|
// STATUS_NEW, factory1 is not yet set (and when status is
|
|
|
|
// STATUS_WRAPPER, factory1 is merely set to an
|
|
|
|
// ImplementationWrapper---also due to a
|
|
|
|
// ServiceManager::createContentEnumeration call---and will be
|
|
|
|
// loaded later).
|
2019-12-30 16:36:57 +01:00
|
|
|
OUString name;
|
|
|
|
OUString loader;
|
|
|
|
OUString uri;
|
|
|
|
OUString environment;
|
|
|
|
OUString constructorName;
|
|
|
|
OUString prefix;
|
Add single-instance attribute for *.compoonent <implementation>s
...to ease the implementation in C++ code of constructor-based <implementation>s
that shall be single-instance (and which would have been implemented with e.g.
cppu::creaetOneInstanceFactory for non--constructor-based <implementation>s).
See e.g. 6e35794cad555485955c3b43593497dcdbf29840 "terminate XDesktop properly
in unit tests" and 6362ebab298549e8616c32cafd75cb3959ba7d65 "dbaccess: create
instances with uno constructors" for the clumsy approach used until now, where
the C++ constructor function uses a static instance that is cleared in
dispose(), adding fake <singleton> entries to <implementation>s where necessary
so that the ServiceManager will call those XComponent::dispose() functions when
it itself gets disposed.
For every <implementation>, the ServiceManager already holds an Implementation
data structure, so it can easily hold a singleInstance there and clear it when
the ServiceManager gets disposed. (One consequence is that single-instance
implementations are now created with their Instance.mutex locked, but that
should not cause problems in practice, given that the construction of a single-
instance implementation should not recursively request its own construction
anyway.)
The new single-instance="true" attribute is mostly useful in combination with
the constructor attribute (see above), but it can also be used for non--
constructor-based <implementation>s, at least in theory.
(The single-instance="true" attribute is orthogonal to <singleton> elements.
There are existing single-instance services---even if those should arguably have
been defined as singletons in the first place---that can benefit from
single-instance="true". And there are <implementation>s that support one or
more <singleton>s alongside one or more <service>s, where the latter are not
single-instance.)
This new single-instance="true" attribute in *.component files should not
interfere with the lo_get_constructor_map machinery in the DISABLE_DYNLOADING
branch of cppuhelper::detail::loadSharedLibComponentFactory
(cppuhelper/source/shlib.cxx) used by Android, iOS and some fuzzer code.
AFAIU, the lo_get_constructor_map machinery should only ever come into play
after the ServiceManager has decided whether or not to create a new instance
based on the single-instance attributes in the *.component files.
This commit only provides the new single-instance="true" attribute. Actual
changes of <implementation>s and their C++ constructor functions are delegated
to a series of follow-up commits. (So that they can easily be reverted
individually should the need arise.)
Change-Id: Iea6c0fc539d74477b7a536dc771b198df6b0510e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103734
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-09-30 21:31:10 +02:00
|
|
|
bool isSingleInstance;
|
2019-12-30 16:36:57 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > alienContext;
|
|
|
|
OUString rdbFile;
|
|
|
|
std::vector< OUString > services;
|
|
|
|
std::vector< OUString > singletons;
|
|
|
|
WrapperConstructorFn constructorFn;
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::lang::XSingleComponentFactory > factory1;
|
|
|
|
css::uno::Reference< css::lang::XSingleServiceFactory > factory2;
|
|
|
|
css::uno::Reference< css::lang::XComponent > component;
|
2014-01-16 15:29:41 +01:00
|
|
|
Status status;
|
|
|
|
|
|
|
|
osl::Mutex mutex;
|
Add single-instance attribute for *.compoonent <implementation>s
...to ease the implementation in C++ code of constructor-based <implementation>s
that shall be single-instance (and which would have been implemented with e.g.
cppu::creaetOneInstanceFactory for non--constructor-based <implementation>s).
See e.g. 6e35794cad555485955c3b43593497dcdbf29840 "terminate XDesktop properly
in unit tests" and 6362ebab298549e8616c32cafd75cb3959ba7d65 "dbaccess: create
instances with uno constructors" for the clumsy approach used until now, where
the C++ constructor function uses a static instance that is cleared in
dispose(), adding fake <singleton> entries to <implementation>s where necessary
so that the ServiceManager will call those XComponent::dispose() functions when
it itself gets disposed.
For every <implementation>, the ServiceManager already holds an Implementation
data structure, so it can easily hold a singleInstance there and clear it when
the ServiceManager gets disposed. (One consequence is that single-instance
implementations are now created with their Instance.mutex locked, but that
should not cause problems in practice, given that the construction of a single-
instance implementation should not recursively request its own construction
anyway.)
The new single-instance="true" attribute is mostly useful in combination with
the constructor attribute (see above), but it can also be used for non--
constructor-based <implementation>s, at least in theory.
(The single-instance="true" attribute is orthogonal to <singleton> elements.
There are existing single-instance services---even if those should arguably have
been defined as singletons in the first place---that can benefit from
single-instance="true". And there are <implementation>s that support one or
more <singleton>s alongside one or more <service>s, where the latter are not
single-instance.)
This new single-instance="true" attribute in *.component files should not
interfere with the lo_get_constructor_map machinery in the DISABLE_DYNLOADING
branch of cppuhelper::detail::loadSharedLibComponentFactory
(cppuhelper/source/shlib.cxx) used by Android, iOS and some fuzzer code.
AFAIU, the lo_get_constructor_map machinery should only ever come into play
after the ServiceManager has decided whether or not to create a new instance
based on the single-instance attributes in the *.component files.
This commit only provides the new single-instance="true" attribute. Actual
changes of <implementation>s and their C++ constructor functions are delegated
to a series of follow-up commits. (So that they can easily be reverted
individually should the need arise.)
Change-Id: Iea6c0fc539d74477b7a536dc771b198df6b0510e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103734
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-09-30 21:31:10 +02:00
|
|
|
css::uno::Reference<css::uno::XInterface> singleInstance;
|
|
|
|
css::uno::Reference< css::lang::XComponent > disposeInstance;
|
2014-01-16 15:29:41 +01:00
|
|
|
bool dispose;
|
2014-02-07 11:10:06 +01:00
|
|
|
|
|
|
|
private:
|
Add single-instance attribute for *.compoonent <implementation>s
...to ease the implementation in C++ code of constructor-based <implementation>s
that shall be single-instance (and which would have been implemented with e.g.
cppu::creaetOneInstanceFactory for non--constructor-based <implementation>s).
See e.g. 6e35794cad555485955c3b43593497dcdbf29840 "terminate XDesktop properly
in unit tests" and 6362ebab298549e8616c32cafd75cb3959ba7d65 "dbaccess: create
instances with uno constructors" for the clumsy approach used until now, where
the C++ constructor function uses a static instance that is cleared in
dispose(), adding fake <singleton> entries to <implementation>s where necessary
so that the ServiceManager will call those XComponent::dispose() functions when
it itself gets disposed.
For every <implementation>, the ServiceManager already holds an Implementation
data structure, so it can easily hold a singleInstance there and clear it when
the ServiceManager gets disposed. (One consequence is that single-instance
implementations are now created with their Instance.mutex locked, but that
should not cause problems in practice, given that the construction of a single-
instance implementation should not recursively request its own construction
anyway.)
The new single-instance="true" attribute is mostly useful in combination with
the constructor attribute (see above), but it can also be used for non--
constructor-based <implementation>s, at least in theory.
(The single-instance="true" attribute is orthogonal to <singleton> elements.
There are existing single-instance services---even if those should arguably have
been defined as singletons in the first place---that can benefit from
single-instance="true". And there are <implementation>s that support one or
more <singleton>s alongside one or more <service>s, where the latter are not
single-instance.)
This new single-instance="true" attribute in *.component files should not
interfere with the lo_get_constructor_map machinery in the DISABLE_DYNLOADING
branch of cppuhelper::detail::loadSharedLibComponentFactory
(cppuhelper/source/shlib.cxx) used by Android, iOS and some fuzzer code.
AFAIU, the lo_get_constructor_map machinery should only ever come into play
after the ServiceManager has decided whether or not to create a new instance
based on the single-instance attributes in the *.component files.
This commit only provides the new single-instance="true" attribute. Actual
changes of <implementation>s and their C++ constructor functions are delegated
to a series of follow-up commits. (So that they can easily be reverted
individually should the need arise.)
Change-Id: Iea6c0fc539d74477b7a536dc771b198df6b0510e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103734
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-09-30 21:31:10 +02:00
|
|
|
css::uno::Reference<css::uno::XInterface> doCreateInstance(
|
|
|
|
css::uno::Reference<css::uno::XComponentContext> const & context);
|
|
|
|
|
|
|
|
css::uno::Reference<css::uno::XInterface> doCreateInstanceWithArguments(
|
|
|
|
css::uno::Reference<css::uno::XComponentContext> const & context,
|
|
|
|
css::uno::Sequence<css::uno::Any> const & arguments);
|
|
|
|
|
|
|
|
void updateDisposeInstance(
|
2014-02-07 11:10:06 +01:00
|
|
|
bool singletonRequest,
|
|
|
|
css::uno::Reference<css::uno::XInterface> const & instance);
|
2013-01-15 16:28:30 +01:00
|
|
|
};
|
|
|
|
|
2021-03-10 19:19:26 +01:00
|
|
|
typedef std::unordered_map< OUString, std::shared_ptr< Implementation > >
|
2013-01-15 16:28:30 +01:00
|
|
|
NamedImplementations;
|
|
|
|
|
|
|
|
typedef
|
2021-03-10 19:19:26 +01:00
|
|
|
std::unordered_map<
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::lang::XServiceInfo >,
|
2015-09-14 09:21:33 +01:00
|
|
|
std::shared_ptr< Implementation > >
|
2013-01-15 16:28:30 +01:00
|
|
|
DynamicImplementations;
|
|
|
|
|
|
|
|
typedef
|
2021-03-10 19:19:26 +01:00
|
|
|
std::unordered_map<
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString,
|
2015-09-14 09:21:33 +01:00
|
|
|
std::vector< std::shared_ptr< Implementation > > >
|
2013-01-15 16:28:30 +01:00
|
|
|
ImplementationMap;
|
|
|
|
|
|
|
|
NamedImplementations namedImplementations;
|
|
|
|
DynamicImplementations dynamicImplementations;
|
|
|
|
ImplementationMap services;
|
|
|
|
ImplementationMap singletons;
|
|
|
|
};
|
|
|
|
|
2014-03-18 12:58:46 +01:00
|
|
|
ServiceManager(): ServiceManagerBase(m_aMutex) {}
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2016-04-07 20:26:54 +02:00
|
|
|
ServiceManager(const ServiceManager&) = delete;
|
|
|
|
const ServiceManager& operator=(const ServiceManager&) = delete;
|
|
|
|
|
2013-01-15 16:28:30 +01:00
|
|
|
using ServiceManagerBase::acquire;
|
|
|
|
using ServiceManagerBase::release;
|
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
void init(OUString const & rdbUris);
|
2013-05-08 12:29:53 +02:00
|
|
|
|
2013-01-15 16:28:30 +01:00
|
|
|
void setContext(
|
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context)
|
|
|
|
{
|
|
|
|
assert(context.is());
|
|
|
|
assert(!context_.is());
|
|
|
|
context_ = context;
|
|
|
|
}
|
|
|
|
|
2013-01-16 13:57:03 +01:00
|
|
|
void addSingletonContextEntries(
|
2014-01-16 15:29:41 +01:00
|
|
|
std::vector< cppu::ContextEntry_Init > * entries);
|
2013-01-16 13:57:03 +01:00
|
|
|
|
2016-05-12 14:23:23 +02:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & getContext()
|
|
|
|
const
|
|
|
|
{
|
2013-01-15 16:28:30 +01:00
|
|
|
assert(context_.is());
|
|
|
|
return context_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void loadImplementation(
|
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context,
|
2017-07-21 11:52:04 +02:00
|
|
|
std::shared_ptr< Data::Implementation > const & implementation);
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2013-01-16 13:35:29 +01:00
|
|
|
private:
|
2016-09-13 13:09:01 +02:00
|
|
|
virtual ~ServiceManager() override;
|
2013-01-16 13:35:29 +01:00
|
|
|
|
2015-10-12 16:04:04 +02:00
|
|
|
virtual void SAL_CALL disposing() override;
|
2013-01-16 13:35:29 +01:00
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
virtual OUString SAL_CALL getImplementationName() override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
virtual css::uno::Sequence< OUString > SAL_CALL
|
2017-01-26 12:28:58 +01:00
|
|
|
getSupportedServiceNames() override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & aServiceSpecifier) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
|
|
|
|
createInstanceWithArguments(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & ServiceSpecifier,
|
2017-01-26 12:28:58 +01:00
|
|
|
css::uno::Sequence< css::uno::Any > const & Arguments) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
virtual css::uno::Sequence< OUString > SAL_CALL
|
2017-01-26 12:28:58 +01:00
|
|
|
getAvailableServiceNames() override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
|
|
|
|
createInstanceWithContext(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & aServiceSpecifier,
|
2017-01-26 12:28:58 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & Context) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL
|
|
|
|
createInstanceWithArgumentsAndContext(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & ServiceSpecifier,
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Sequence< css::uno::Any > const & Arguments,
|
2017-01-26 12:28:58 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & Context) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual css::uno::Type SAL_CALL getElementType() override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual sal_Bool SAL_CALL hasElements() override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
|
2017-01-26 12:28:58 +01:00
|
|
|
createEnumeration() override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual sal_Bool SAL_CALL has(css::uno::Any const & aElement) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual void SAL_CALL insert(css::uno::Any const & aElement) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual void SAL_CALL remove(css::uno::Any const & aElement) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
|
2018-10-23 12:06:00 +02:00
|
|
|
createContentEnumeration(OUString const & aServiceName) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
|
2017-01-26 12:28:58 +01:00
|
|
|
getPropertySetInfo() override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual void SAL_CALL setPropertyValue(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & aPropertyName, css::uno::Any const & aValue) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual css::uno::Any SAL_CALL getPropertyValue(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & PropertyName) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual void SAL_CALL addPropertyChangeListener(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & aPropertyName,
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::beans::XPropertyChangeListener > const &
|
2017-01-26 12:28:58 +01:00
|
|
|
xListener) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual void SAL_CALL removePropertyChangeListener(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & aPropertyName,
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::beans::XPropertyChangeListener > const &
|
2017-01-26 12:28:58 +01:00
|
|
|
aListener) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual void SAL_CALL addVetoableChangeListener(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & PropertyName,
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::beans::XVetoableChangeListener > const &
|
2017-01-26 12:28:58 +01:00
|
|
|
aListener) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual void SAL_CALL removeVetoableChangeListener(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & PropertyName,
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::beans::XVetoableChangeListener > const &
|
2017-01-26 12:28:58 +01:00
|
|
|
aListener) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual css::uno::Sequence< css::beans::Property > SAL_CALL getProperties() override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
virtual css::beans::Property SAL_CALL getPropertyByName(
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & aName) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
virtual sal_Bool SAL_CALL hasPropertyByName(OUString const & Name) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2017-01-26 12:28:58 +01:00
|
|
|
virtual void SAL_CALL disposing(css::lang::EventObject const & Source) override;
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2016-02-25 15:33:22 +01:00
|
|
|
virtual void SAL_CALL initialize(
|
|
|
|
css::uno::Sequence<css::uno::Any> const & aArguments)
|
|
|
|
override;
|
|
|
|
|
2013-01-15 16:28:30 +01:00
|
|
|
// needs to be called with rBHelper.rMutex locked:
|
2017-10-21 18:04:51 +02:00
|
|
|
bool isDisposed() const { return rBHelper.bDisposed || rBHelper.bInDispose; }
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
void removeEventListenerFromComponent(
|
|
|
|
css::uno::Reference< css::lang::XComponent > const & component);
|
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
void readRdbDirectory(OUString const & uri, bool optional);
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
void readRdbFile(OUString const & uri, bool optional);
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
bool readLegacyRdbFile(OUString const & uri);
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString readLegacyRdbString(
|
2020-12-28 17:56:40 +01:00
|
|
|
std::u16string_view uri, RegistryKey & key,
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & path);
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
void readLegacyRdbStrings(
|
2020-12-28 17:56:40 +01:00
|
|
|
std::u16string_view uri, RegistryKey & key,
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & path, std::vector< OUString > * strings);
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
void insertRdbFiles(
|
2018-10-23 12:06:00 +02:00
|
|
|
std::vector< OUString > const & uris,
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const &
|
|
|
|
alientContext);
|
|
|
|
|
|
|
|
void insertLegacyFactory(
|
|
|
|
css::uno::Reference< css::lang::XServiceInfo > const & factoryInfo);
|
|
|
|
|
|
|
|
bool insertExtraData(Data const & extra);
|
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
void removeRdbFiles(std::vector< OUString > const & uris);
|
2013-01-15 16:28:30 +01:00
|
|
|
|
|
|
|
bool removeLegacyFactory(
|
|
|
|
css::uno::Reference< css::lang::XServiceInfo > const & factoryInfo,
|
|
|
|
bool removeListener);
|
|
|
|
|
2018-10-23 12:06:00 +02:00
|
|
|
void removeImplementation(const OUString & name);
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2015-09-14 09:21:33 +01:00
|
|
|
std::shared_ptr< Data::Implementation > findServiceImplementation(
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > const & context,
|
2018-10-23 12:06:00 +02:00
|
|
|
OUString const & specifier);
|
2013-01-15 16:28:30 +01:00
|
|
|
|
2016-02-25 15:33:22 +01:00
|
|
|
void preloadImplementations();
|
|
|
|
|
2013-01-15 16:28:30 +01:00
|
|
|
css::uno::Reference< css::uno::XComponentContext > context_;
|
|
|
|
Data data_;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|