LCOV - code coverage report
Current view: top level - configmgr/source - readwriteaccess.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 28 45 62.2 %
Date: 2014-04-11 Functions: 10 17 58.8 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include "sal/config.h"
      11             : 
      12             : #include "boost/noncopyable.hpp"
      13             : #include "com/sun/star/configuration/XReadWriteAccess.hpp"
      14             : #include "com/sun/star/container/NoSuchElementException.hpp"
      15             : #include "com/sun/star/lang/IllegalArgumentException.hpp"
      16             : #include "com/sun/star/lang/NotInitializedException.hpp"
      17             : #include "com/sun/star/lang/WrappedTargetException.hpp"
      18             : #include "com/sun/star/lang/XInitialization.hpp"
      19             : #include "com/sun/star/lang/XServiceInfo.hpp"
      20             : #include "com/sun/star/uno/Any.hxx"
      21             : #include "com/sun/star/uno/Exception.hpp"
      22             : #include "com/sun/star/uno/Reference.hxx"
      23             : #include "com/sun/star/uno/RuntimeException.hpp"
      24             : #include "com/sun/star/uno/Sequence.hxx"
      25             : #include "com/sun/star/uno/XComponentContext.hpp"
      26             : #include "com/sun/star/uno/XInterface.hpp"
      27             : #include "com/sun/star/util/ChangesSet.hpp"
      28             : #include "cppuhelper/implbase3.hxx"
      29             : #include "cppuhelper/supportsservice.hxx"
      30             : #include "cppuhelper/weak.hxx"
      31             : #include "osl/mutex.hxx"
      32             : #include "rtl/ref.hxx"
      33             : #include "rtl/ustring.h"
      34             : #include "rtl/ustring.hxx"
      35             : #include "sal/types.h"
      36             : 
      37             : #include "components.hxx"
      38             : #include "lock.hxx"
      39             : #include "readwriteaccess.hxx"
      40             : #include "rootaccess.hxx"
      41             : 
      42             : namespace configmgr { namespace read_write_access {
      43             : 
      44             : namespace {
      45             : 
      46             : class Service:
      47             :     public cppu::WeakImplHelper3<
      48             :         css::lang::XServiceInfo, css::lang::XInitialization,
      49             :         css::configuration::XReadWriteAccess >,
      50             :     private boost::noncopyable
      51             : {
      52             : public:
      53        2691 :     explicit Service(
      54             :         css::uno::Reference< css::uno::XComponentContext > const & context):
      55        2691 :         context_(context) {}
      56             : 
      57             : private:
      58        5382 :     virtual ~Service() {}
      59             : 
      60           0 :     virtual OUString SAL_CALL getImplementationName()
      61             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      62           0 :     { return read_write_access::getImplementationName(); }
      63             : 
      64           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
      65             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      66           0 :     { return cppu::supportsService(this, ServiceName); }
      67             : 
      68             :     virtual css::uno::Sequence< OUString > SAL_CALL
      69           0 :     getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      70           0 :     { return read_write_access::getSupportedServiceNames(); }
      71             : 
      72             :     virtual void SAL_CALL initialize(
      73             :         css::uno::Sequence< css::uno::Any > const & aArguments)
      74             :         throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      75             : 
      76           0 :     virtual css::uno::Any SAL_CALL getByHierarchicalName(
      77             :         OUString const & aName)
      78             :         throw (
      79             :             css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      80           0 :     { return getRoot()->getByHierarchicalName(aName); }
      81             : 
      82           0 :     virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName)
      83             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      84           0 :     { return getRoot()->hasByHierarchicalName(aName); }
      85             : 
      86         176 :     virtual void SAL_CALL replaceByHierarchicalName(
      87             :         OUString const & aName, css::uno::Any const & aElement)
      88             :         throw (
      89             :             css::lang::IllegalArgumentException,
      90             :             css::container::NoSuchElementException,
      91             :             css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      92         176 :     { getRoot()->replaceByHierarchicalName(aName, aElement); }
      93             : 
      94         176 :     virtual void SAL_CALL commitChanges()
      95             :         throw (css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      96         176 :     { getRoot()->commitChanges(); }
      97             : 
      98           0 :     virtual sal_Bool SAL_CALL hasPendingChanges()
      99             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     100           0 :     { return getRoot()->hasPendingChanges(); }
     101             : 
     102           0 :     virtual css::util::ChangesSet SAL_CALL getPendingChanges()
     103             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
     104           0 :     { return getRoot()->getPendingChanges(); }
     105             : 
     106             :     rtl::Reference< RootAccess > getRoot();
     107             : 
     108             :     css::uno::Reference< css::uno::XComponentContext > context_;
     109             : 
     110             :     osl::Mutex mutex_;
     111             :     rtl::Reference< RootAccess > root_;
     112             : };
     113             : 
     114        2691 : void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
     115             :     throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
     116             : {
     117        2691 :     OUString locale;
     118        2691 :     if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
     119             :         throw css::lang::IllegalArgumentException(
     120             :             "not exactly one string argument",
     121           0 :             static_cast< cppu::OWeakObject * >(this), -1);
     122             :     }
     123        5382 :     osl::MutexGuard g1(mutex_);
     124        2691 :     if (root_.is()) {
     125             :         throw css::uno::RuntimeException(
     126           0 :             "already initialized", static_cast< cppu::OWeakObject * >(this));
     127             :     }
     128        5382 :     osl::MutexGuard g2(*lock());
     129        2691 :     Components & components = Components::getSingleton(context_);
     130        2691 :     root_ = new RootAccess(components, "/", locale, true);
     131        5382 :     components.addRootAccess(root_);
     132        2691 : }
     133             : 
     134         352 : rtl::Reference< RootAccess > Service::getRoot() {
     135         352 :     osl::MutexGuard g(mutex_);
     136         352 :     if (!root_.is()) {
     137             :         throw css::lang::NotInitializedException(
     138           0 :             "not initialized", static_cast< cppu::OWeakObject * >(this));
     139             :     }
     140         352 :     return root_;
     141             : }
     142             : 
     143             : }
     144             : 
     145        2691 : css::uno::Reference< css::uno::XInterface > create(
     146             :     css::uno::Reference< css::uno::XComponentContext > const & context)
     147             : {
     148        2691 :     return static_cast< cppu::OWeakObject * >(new Service(context));
     149             : }
     150             : 
     151         442 : OUString getImplementationName() {
     152         442 :     return OUString("com.sun.star.comp.configuration.ReadWriteAccess");
     153             : }
     154             : 
     155         117 : css::uno::Sequence< OUString > getSupportedServiceNames() {
     156         117 :     OUString name("com.sun.star.configuration.ReadWriteAccess");
     157         117 :     return css::uno::Sequence< OUString >(&name, 1);
     158             : }
     159             : 
     160             : } }
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10