[Libreoffice-commits] .: desktop/source

Stephan Bergmann sbergmann at kemper.freedesktop.org
Wed Apr 18 05:59:17 PDT 2012


 desktop/source/deployment/registry/component/dp_component.cxx |  137 +++++-----
 1 file changed, 73 insertions(+), 64 deletions(-)

New commits:
commit fcc9611770e55b0c6ff0f23d2345f3e4f0ef7838
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Wed Apr 18 14:58:51 2012 +0200

    Do all of componentLiveInsertion/Removal at the root context

diff --git a/desktop/source/deployment/registry/component/dp_component.cxx b/desktop/source/deployment/registry/component/dp_component.cxx
index 7a97fbb..8bfcbd5 100644
--- a/desktop/source/deployment/registry/component/dp_component.cxx
+++ b/desktop/source/deployment/registry/component/dp_component.cxx
@@ -354,6 +354,8 @@ class BackendImpl : public ::dp_registry::backend::PackageRegistryBackend
 
     void componentLiveRemoval(ComponentBackendDb::Data const & data);
 
+    css::uno::Reference< css::uno::XComponentContext > getRootContext() const;
+
 public:
     BackendImpl( Sequence<Any> const & args,
                  Reference<XComponentContext> const & xComponentContext );
@@ -1252,8 +1254,10 @@ void BackendImpl::componentLiveInsertion(
     std::vector< css::uno::Reference< css::uno::XInterface > > const &
         factories)
 {
+    css::uno::Reference< css::uno::XComponentContext > rootContext(
+        getRootContext());
     css::uno::Reference< css::container::XSet > set(
-        getComponentContext()->getServiceManager(), css::uno::UNO_QUERY_THROW);
+        rootContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
     std::vector< css::uno::Reference< css::uno::XInterface > >::const_iterator
         factory(factories.begin());
     for (t_stringlist::const_iterator i(data.implementationNames.begin());
@@ -1268,54 +1272,49 @@ void BackendImpl::componentLiveInsertion(
         }
     }
     if (!data.singletons.empty()) {
-        css::uno::Reference< css::container::XNameContainer >
-            rootContext(
-                getComponentContext()->getValueByName(
-                    rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_root"))),
-                css::uno::UNO_QUERY);
-        if (rootContext.is()) {
-            for (t_stringpairvec::const_iterator i(data.singletons.begin());
-                 i != data.singletons.end(); ++i)
-            {
-                rtl::OUString name(
-                    rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
-                    i->first);
-                try {
-                    rootContext->removeByName(
-                        name +
-                        rtl::OUString(
-                            RTL_CONSTASCII_USTRINGPARAM("/arguments")));
-                } catch (const container::NoSuchElementException &) {}
-                try {
-                    rootContext->insertByName(
-                        (name +
-                         rtl::OUString(
-                             RTL_CONSTASCII_USTRINGPARAM("/service"))),
-                        css::uno::Any(i->second));
-                } catch (const container::ElementExistException &) {
-                    rootContext->replaceByName(
-                        (name +
-                         rtl::OUString(
-                             RTL_CONSTASCII_USTRINGPARAM("/service"))),
-                        css::uno::Any(i->second));
-                }
-                try {
-                    rootContext->insertByName(name, css::uno::Any());
-                } catch (const container::ElementExistException &) {
-                    OSL_TRACE(
-                        "singleton %s already registered",
-                        rtl::OUStringToOString(
-                            i->first, RTL_TEXTENCODING_UTF8).getStr());
-                    rootContext->replaceByName(name, css::uno::Any());
-                }
+        css::uno::Reference< css::container::XNameContainer > cont(
+            rootContext, css::uno::UNO_QUERY_THROW);
+        for (t_stringpairvec::const_iterator i(data.singletons.begin());
+             i != data.singletons.end(); ++i)
+        {
+            rtl::OUString name(
+                rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
+                i->first);
+            //TODO: Update should be atomic:
+            try {
+                cont->removeByName(
+                    name +
+                    rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/arguments")));
+            } catch (const container::NoSuchElementException &) {}
+            try {
+                cont->insertByName(
+                    (name +
+                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/service"))),
+                    css::uno::Any(i->second));
+            } catch (const container::ElementExistException &) {
+                cont->replaceByName(
+                    (name +
+                     rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/service"))),
+                    css::uno::Any(i->second));
+            }
+            try {
+                cont->insertByName(name, css::uno::Any());
+            } catch (const container::ElementExistException &) {
+                OSL_TRACE(
+                    "singleton %s already registered",
+                    rtl::OUStringToOString(
+                        i->first, RTL_TEXTENCODING_UTF8).getStr());
+                cont->replaceByName(name, css::uno::Any());
             }
         }
     }
 }
 
 void BackendImpl::componentLiveRemoval(ComponentBackendDb::Data const & data) {
+    css::uno::Reference< css::uno::XComponentContext > rootContext(
+        getRootContext());
     css::uno::Reference< css::container::XSet > set(
-        getComponentContext()->getServiceManager(), css::uno::UNO_QUERY_THROW);
+        rootContext->getServiceManager(), css::uno::UNO_QUERY_THROW);
     for (t_stringlist::const_iterator i(data.implementationNames.begin());
          i != data.implementationNames.end(); ++i)
     {
@@ -1326,32 +1325,42 @@ void BackendImpl::componentLiveRemoval(ComponentBackendDb::Data const & data) {
         }
     }
     if (!data.singletons.empty()) {
-        css::uno::Reference< css::container::XNameContainer > rootContext(
-            getComponentContext()->getValueByName(
-                rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_root"))),
-            css::uno::UNO_QUERY);
-        if (rootContext.is()) {
-            for (t_stringpairvec::const_iterator i(data.singletons.begin());
-                 i != data.singletons.end(); ++i)
-            {
-                rtl::OUString name(
-                    rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
-                    i->first);
-                try {
-                    rootContext->removeByName(
-                        name +
-                        rtl::OUString(
-                            RTL_CONSTASCII_USTRINGPARAM("/arguments")));
-                    rootContext->removeByName(
-                        name +
-                        rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/service")));
-                    rootContext->removeByName(name);
-                } catch (const container::NoSuchElementException &) {}
-            }
+        css::uno::Reference< css::container::XNameContainer > cont(
+            rootContext, css::uno::UNO_QUERY_THROW);
+        for (t_stringpairvec::const_iterator i(data.singletons.begin());
+             i != data.singletons.end(); ++i)
+        {
+            rtl::OUString name(
+                rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/singletons/")) +
+                i->first);
+            //TODO: Removal should be atomic:
+            try {
+                cont->removeByName(name);
+            } catch (const container::NoSuchElementException &) {}
+            try {
+                cont->removeByName(
+                    name +
+                    rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/service")));
+            } catch (const container::NoSuchElementException &) {}
+            try {
+                cont->removeByName(
+                    name +
+                    rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/arguments")));
+            } catch (const container::NoSuchElementException &) {}
         }
     }
 }
 
+css::uno::Reference< css::uno::XComponentContext > BackendImpl::getRootContext()
+    const
+{
+    css::uno::Reference< css::uno::XComponentContext > rootContext(
+        getComponentContext()->getValueByName(
+            rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("_root"))),
+        css::uno::UNO_QUERY);
+    return rootContext.is() ? rootContext : getComponentContext();
+}
+
 //______________________________________________________________________________
 void BackendImpl::releaseObject( OUString const & id )
 {


More information about the Libreoffice-commits mailing list