summaryrefslogtreecommitdiff
path: root/cppuhelper
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2014-01-22 11:54:19 +0100
committerJan Holesovsky <kendy@collabora.com>2014-01-22 15:09:28 +0100
commitc2c530da69152ff9192b9726aa95961803ce9b29 (patch)
tree15e514573f35d9f376520fc2c015634dc4ee8c25 /cppuhelper
parent219a2939c9f58690356b2a3f64c580a0865fdc64 (diff)
Introduce static inline cppu::acquire(), and make use of that.
This is much better approach compared to the callback function, as it allows passing arguments to the c++ constructor directly, while still allowing some additional initialization after having acquired the instance. Change-Id: I5a0f981915dd58f1522ee6054e53a3550b29d624
Diffstat (limited to 'cppuhelper')
-rw-r--r--cppuhelper/source/servicemanager.cxx80
-rw-r--r--cppuhelper/source/servicemanager.hxx2
2 files changed, 33 insertions, 49 deletions
diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx
index 3d81b8b68dc6..e6c31fc53302 100644
--- a/cppuhelper/source/servicemanager.cxx
+++ b/cppuhelper/source/servicemanager.cxx
@@ -704,14 +704,11 @@ cppuhelper::ServiceManager::Data::Implementation::createInstance(
if (info->singletons.empty()) {
assert(!singletonRequest);
if (constructor != 0) {
- cppu::constructor_InitializationFunc init = NULL;
- css::uno::Reference<css::uno::XInterface> inst(
- (*constructor)(context.get(), init));
- // call the initialization on the acquired instance
- if (init)
- (static_cast<OWeakObject*>(inst.get())->*init)(
- css::uno::Sequence<css::uno::Any>());
- return inst;
+ // the interface is already acquired, don't acquire here
+ return css::uno::Reference<css::uno::XInterface>(
+ (*constructor)(context.get(),
+ css::uno::Sequence<css::uno::Any>()),
+ SAL_NO_ACQUIRE);
}
if (factory1.is()) {
return factory1->createInstanceWithContext(context);
@@ -727,13 +724,11 @@ cppuhelper::ServiceManager::Data::Implementation::createInstance(
return singleton;
}
if (constructor != 0) {
- cppu::constructor_InitializationFunc init = NULL;
+ // the interface is already acquired, don't acquire here
singleton.set(
- (*constructor)(context.get(), init));
- // call the initialization on the acquired instance
- if (init)
- (static_cast<OWeakObject*>(singleton.get())->*init)(
- css::uno::Sequence<css::uno::Any>());
+ (*constructor)(context.get(),
+ css::uno::Sequence<css::uno::Any>()),
+ SAL_NO_ACQUIRE);
} else if (factory1.is()) {
singleton = factory1->createInstanceWithContext(context);
} else {
@@ -753,24 +748,18 @@ cppuhelper::ServiceManager::Data::Implementation::createInstanceWithArguments(
if (info->singletons.empty()) {
assert(!singletonRequest);
if (constructor != 0) {
- cppu::constructor_InitializationFunc init = NULL;
+ // the interface is already acquired, don't acquire here
css::uno::Reference<css::uno::XInterface> inst(
- (*constructor)(context.get(), init));
- // call the initialization on the acquired instance
- if (init)
- (static_cast<OWeakObject*>(inst.get())->*init)(
- arguments);
- else {
- // The service can implement XInitialization, and it is just
- // too easy to do a mistake during conversion to the
- // constructor-based initialization, and forget to add the
- // above callback that would call it; so allow initialization
- // through XInitialization still too.
- css::uno::Reference<css::lang::XInitialization> xinit(
- inst, css::uno::UNO_QUERY);
- if (xinit.is()) {
- xinit->initialize(arguments);
- }
+ (*constructor)(context.get(), arguments), SAL_NO_ACQUIRE);
+
+ // HACK: The service can implement XInitialization too.
+ // It should be removed when converting to constructor-based
+ // initialization, but in case somebody forgets, be safe, and
+ // call it anyway for the moment.
+ css::uno::Reference<css::lang::XInitialization> xinit(
+ inst, css::uno::UNO_QUERY);
+ if (xinit.is()) {
+ xinit->initialize(arguments);
}
return inst;
}
@@ -793,23 +782,18 @@ cppuhelper::ServiceManager::Data::Implementation::createInstanceWithArguments(
return singleton;
}
if (constructor != 0) {
- cppu::constructor_InitializationFunc init = NULL;
- singleton.set((*constructor)(context.get(), init));
- // call the initialization on the acquired instance
- if (init)
- (static_cast<OWeakObject*>(singleton.get())->*init)(
- arguments);
- else {
- // The service can implement XInitialization, and it is just
- // too easy to do a mistake during conversion to the
- // constructor-based initialization, and forget to add the
- // above callback that would call it; so allow initialization
- // through XInitialization still too.
- css::uno::Reference<css::lang::XInitialization> xinit(
- singleton, css::uno::UNO_QUERY);
- if (xinit.is()) {
- xinit->initialize(arguments);
- }
+ // the interface is already acquired, don't acquire here
+ singleton.set(
+ (*constructor)(context.get(), arguments), SAL_NO_ACQUIRE);
+
+ // HACK: The service can implement XInitialization too.
+ // It should be removed when converting to constructor-based
+ // initialization, but in case somebody forgets, be safe, and
+ // call it anyway for the moment.
+ css::uno::Reference<css::lang::XInitialization> xinit(
+ singleton, css::uno::UNO_QUERY);
+ if (xinit.is()) {
+ xinit->initialize(arguments);
}
} else if (factory1.is()) {
singleton = factory1->createInstanceWithArgumentsAndContext(
diff --git a/cppuhelper/source/servicemanager.hxx b/cppuhelper/source/servicemanager.hxx
index 2d29f58b48ca..b6e506bfbd47 100644
--- a/cppuhelper/source/servicemanager.hxx
+++ b/cppuhelper/source/servicemanager.hxx
@@ -45,7 +45,7 @@ namespace cppuhelper {
extern "C" {
typedef css::uno::XInterface * SAL_CALL ImplementationConstructorFn(
- css::uno::XComponentContext *, cppu::constructor_InitializationFunc &);
+ css::uno::XComponentContext *, css::uno::Sequence<css::uno::Any> const &);
}