summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2014-01-17 10:05:15 +0100
committerStephan Bergmann <sbergman@redhat.com>2014-01-17 10:14:53 +0100
commitd7a397ca101999a2910c9087d708e0a8c0ea4c2e (patch)
treea044dc300e79256c1190a9442fce8e642c30ef80
parentebf23a7dde605b6aaca79f56170f6ca690829de4 (diff)
Constructor functions for singletons still need to pass out single instances
...as they are not only called from the service manager (which takes care of singleton constructor functions since 997d21183322a0a94b96868073808841d2773902 "Support for singleton constructor functions") but potentially also directly from cppumaker-generated code (which is the raison d'ĂȘtre for constructor functions, after all). However, this change: * postpones the instance's destruction to atexit, with all dreaded consequences; lets see how that pans out. * makes it questionable whether the service manager holding references of these singletons (introduced in 997d21183322a0a94b96868073808841d2773902) is necessary after all; lets revisit that in another commit. Change-Id: I0a2c902ab62045df1af382d190747e34b80236d3
-rw-r--r--sfx2/source/notify/globalevents.cxx20
1 files changed, 18 insertions, 2 deletions
diff --git a/sfx2/source/notify/globalevents.cxx b/sfx2/source/notify/globalevents.cxx
index b8f5c428798b..173e0b104ce5 100644
--- a/sfx2/source/notify/globalevents.cxx
+++ b/sfx2/source/notify/globalevents.cxx
@@ -527,6 +527,21 @@ TModelList::iterator SfxGlobalEvents_Impl::impl_searchDoc(const uno::Reference<
return pIt;
}
+struct Instance {
+ explicit Instance(
+ css::uno::Reference<css::uno::XComponentContext> const & context):
+ instance(
+ static_cast<cppu::OWeakObject *>(new SfxGlobalEvents_Impl(context)))
+ {}
+
+ css::uno::Reference<css::uno::XInterface> instance;
+};
+
+struct Singleton:
+ public rtl::StaticWithArg<
+ Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton>
+{};
+
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
@@ -534,9 +549,10 @@ com_sun_star_comp_sfx2_GlobalEventBroadcaster_get_implementation(
css::uno::XComponentContext *context,
css::uno::Sequence<css::uno::Any> const &)
{
- rtl::Reference<SfxGlobalEvents_Impl> x(new SfxGlobalEvents_Impl(context));
+ css::uno::Reference<css::uno::XInterface> x(
+ Singleton::get(context).instance);
x->acquire();
- return static_cast<cppu::OWeakObject *>(x.get());
+ return x.get();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */