summaryrefslogtreecommitdiff
path: root/cppuhelper/source/servicemanager.hxx
diff options
context:
space:
mode:
Diffstat (limited to 'cppuhelper/source/servicemanager.hxx')
-rw-r--r--cppuhelper/source/servicemanager.hxx88
1 files changed, 47 insertions, 41 deletions
diff --git a/cppuhelper/source/servicemanager.hxx b/cppuhelper/source/servicemanager.hxx
index ceac7c15a698..af80be25a183 100644
--- a/cppuhelper/source/servicemanager.hxx
+++ b/cppuhelper/source/servicemanager.hxx
@@ -7,14 +7,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-#ifndef INCLUDED_CPPUHELPER_SOURCE_SERVICEMANAGER_HXX
-#define INCLUDED_CPPUHELPER_SOURCE_SERVICEMANAGER_HXX
+#pragma once
#include <sal/config.h>
#include <cassert>
-#include <map>
+#include <functional>
#include <memory>
+#include <mutex>
+#include <string_view>
+#include <unordered_map>
+#include <utility>
#include <vector>
#include <com/sun/star/beans/XPropertySet.hpp>
@@ -27,9 +30,7 @@
#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>
-#include <cppuhelper/compbase.hxx>
-#include <osl/mutex.hxx>
+#include <compbase2.hxx>
#include <rtl/ustring.hxx>
namespace com::sun::star::lang {
@@ -52,7 +53,7 @@ typedef css::uno::XInterface * ImplementationConstructorFn(
typedef std::function<css::uno::XInterface * (css::uno::XComponentContext *, css::uno::Sequence<css::uno::Any> const&)> WrapperConstructorFn;
-typedef cppu::WeakComponentImplHelper<
+typedef WeakComponentImplHelper2<
css::lang::XServiceInfo, css::lang::XMultiServiceFactory,
css::lang::XMultiComponentFactory, css::container::XSet,
css::container::XContentEnumerationAccess, css::beans::XPropertySet,
@@ -60,8 +61,7 @@ typedef cppu::WeakComponentImplHelper<
css::lang::XInitialization>
ServiceManagerBase;
-class ServiceManager:
- private cppu::BaseMutex, public ServiceManagerBase
+class ServiceManager : public ServiceManagerBase
{
public:
struct Data {
@@ -71,30 +71,30 @@ public:
struct Implementation {
Implementation(
- OUString const & theName, OUString const & theLoader,
- OUString const & theUri, OUString const & theEnvironment,
- OUString const & theConstructorName,
- OUString const & thePrefix,
- css::uno::Reference< css::uno::XComponentContext > const &
- theAlienContext,
- OUString const & theRdbFile):
- name(theName), loader(theLoader), uri(theUri), environment(theEnvironment),
- constructorName(theConstructorName), prefix(thePrefix),
- alienContext(theAlienContext), rdbFile(theRdbFile),
+ OUString theName, OUString theLoader,
+ OUString theUri, OUString theEnvironment,
+ OUString theConstructorName,
+ OUString thePrefix,
+ bool theIsSingleInstance,
+ css::uno::Reference< css::uno::XComponentContext > theAlienContext,
+ OUString theRdbFile):
+ name(std::move(theName)), loader(std::move(theLoader)), uri(std::move(theUri)), environment(std::move(theEnvironment)),
+ constructorName(std::move(theConstructorName)), prefix(std::move(thePrefix)),
+ isSingleInstance(theIsSingleInstance),
+ alienContext(std::move(theAlienContext)), rdbFile(std::move(theRdbFile)),
constructorFn(nullptr), status(STATUS_NEW), dispose(true)
{}
Implementation(
- OUString const & theName,
+ OUString theName,
css::uno::Reference< css::lang::XSingleComponentFactory >
const & theFactory1,
css::uno::Reference< css::lang::XSingleServiceFactory > const &
theFactory2,
- css::uno::Reference< css::lang::XComponent > const &
- theComponent):
- name(theName), constructorFn(nullptr),
+ css::uno::Reference< css::lang::XComponent > theComponent):
+ name(std::move(theName)), isSingleInstance(false), constructorFn(nullptr),
factory1(theFactory1), factory2(theFactory2),
- component(theComponent), status(STATUS_LOADED), dispose(true)
+ component(std::move(theComponent)), status(STATUS_LOADED), dispose(true)
{ assert(theFactory1.is() || theFactory2.is()); }
Implementation(const Implementation&) = delete;
@@ -112,6 +112,8 @@ public:
bool singletonRequest,
css::uno::Sequence<css::uno::Any> const & arguments);
+ bool shallDispose() const { return isSingleInstance || !singletons.empty(); }
+
enum Status { STATUS_NEW, STATUS_WRAPPER, STATUS_LOADED };
// Logically, exactly one of constructorFn, factory1, factory2 should
@@ -131,6 +133,7 @@ public:
OUString environment;
OUString constructorName;
OUString prefix;
+ bool isSingleInstance;
css::uno::Reference< css::uno::XComponentContext > alienContext;
OUString rdbFile;
std::vector< OUString > services;
@@ -141,27 +144,35 @@ public:
css::uno::Reference< css::lang::XComponent > component;
Status status;
- osl::Mutex mutex;
- css::uno::Reference< css::lang::XComponent > disposeSingleton;
+ std::mutex mutex;
+ css::uno::Reference<css::uno::XInterface> singleInstance;
+ css::uno::Reference< css::lang::XComponent > disposeInstance;
bool dispose;
private:
- void updateDisposeSingleton(
+ 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(
bool singletonRequest,
css::uno::Reference<css::uno::XInterface> const & instance);
};
- typedef std::map< OUString, std::shared_ptr< Implementation > >
+ typedef std::unordered_map< OUString, std::shared_ptr< Implementation > >
NamedImplementations;
typedef
- std::map<
+ std::unordered_map<
css::uno::Reference< css::lang::XServiceInfo >,
std::shared_ptr< Implementation > >
DynamicImplementations;
typedef
- std::map<
+ std::unordered_map<
OUString,
std::vector< std::shared_ptr< Implementation > > >
ImplementationMap;
@@ -172,7 +183,7 @@ public:
ImplementationMap singletons;
};
- ServiceManager(): ServiceManagerBase(m_aMutex) {}
+ ServiceManager() {}
ServiceManager(const ServiceManager&) = delete;
const ServiceManager& operator=(const ServiceManager&) = delete;
@@ -180,7 +191,7 @@ public:
using ServiceManagerBase::acquire;
using ServiceManagerBase::release;
- void init(OUString const & rdbUris);
+ void init(std::u16string_view rdbUris);
void setContext(
css::uno::Reference< css::uno::XComponentContext > const & context)
@@ -207,7 +218,7 @@ public:
private:
virtual ~ServiceManager() override;
- virtual void SAL_CALL disposing() override;
+ virtual void disposing(std::unique_lock<std::mutex>&) override;
virtual OUString SAL_CALL getImplementationName() override;
@@ -296,24 +307,21 @@ private:
css::uno::Sequence<css::uno::Any> const & aArguments)
override;
- // needs to be called with rBHelper.rMutex locked:
- bool isDisposed() const { return rBHelper.bDisposed || rBHelper.bInDispose; }
-
void removeEventListenerFromComponent(
css::uno::Reference< css::lang::XComponent > const & component);
- void readRdbDirectory(OUString const & uri, bool optional);
+ void readRdbDirectory(std::u16string_view uri, bool optional);
void readRdbFile(OUString const & uri, bool optional);
bool readLegacyRdbFile(OUString const & uri);
OUString readLegacyRdbString(
- OUString const & uri, RegistryKey & key,
+ std::u16string_view uri, RegistryKey & key,
OUString const & path);
void readLegacyRdbStrings(
- OUString const & uri, RegistryKey & key,
+ std::u16string_view uri, RegistryKey & key,
OUString const & path, std::vector< OUString > * strings);
void insertRdbFiles(
@@ -346,6 +354,4 @@ private:
}
-#endif
-
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */