[Libreoffice-commits] core.git: sfx2/source

Stephan Bergmann sbergman at redhat.com
Fri Jan 17 01:15:26 PST 2014


 sfx2/source/notify/globalevents.cxx |   20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

New commits:
commit d7a397ca101999a2910c9087d708e0a8c0ea4c2e
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Fri Jan 17 10:05:15 2014 +0100

    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

diff --git a/sfx2/source/notify/globalevents.cxx b/sfx2/source/notify/globalevents.cxx
index b8f5c42..173e0b1 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: */


More information about the Libreoffice-commits mailing list