LCOV - code coverage report
Current view: top level - libreoffice/configmgr/source - readwriteaccess.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 20 45 44.4 %
Date: 2012-12-27 Functions: 7 17 41.2 %
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             :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4             :  *
       5             :  * The contents of this file are subject to the Mozilla Public License Version
       6             :  * 1.1 (the "License"); you may not use this file except in compliance with
       7             :  * the License or as specified alternatively below. You may obtain a copy of
       8             :  * the License at http://www.mozilla.org/MPL/
       9             :  *
      10             :  * Software distributed under the License is distributed on an "AS IS" basis,
      11             :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12             :  * for the specific language governing rights and limitations under the
      13             :  * License.
      14             :  *
      15             :  * Major Contributor(s):
      16             :  * Copyright (C) 2011 Red Hat, Inc., Stephan Bergmann <sbergman@redhat.com>
      17             :  * (initial developer)
      18             :  *
      19             :  * All Rights Reserved.
      20             :  *
      21             :  * For minor contributions see the git repository.
      22             :  *
      23             :  * Alternatively, the contents of this file may be used under the terms of
      24             :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      25             :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      26             :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      27             :  * instead of those above.
      28             :  */
      29             : 
      30             : #include "sal/config.h"
      31             : 
      32             : #include "boost/noncopyable.hpp"
      33             : #include "com/sun/star/configuration/XReadWriteAccess.hpp"
      34             : #include "com/sun/star/container/NoSuchElementException.hpp"
      35             : #include "com/sun/star/lang/IllegalArgumentException.hpp"
      36             : #include "com/sun/star/lang/NotInitializedException.hpp"
      37             : #include "com/sun/star/lang/WrappedTargetException.hpp"
      38             : #include "com/sun/star/lang/XInitialization.hpp"
      39             : #include "com/sun/star/lang/XServiceInfo.hpp"
      40             : #include "com/sun/star/uno/Any.hxx"
      41             : #include "com/sun/star/uno/Exception.hpp"
      42             : #include "com/sun/star/uno/Reference.hxx"
      43             : #include "com/sun/star/uno/RuntimeException.hpp"
      44             : #include "com/sun/star/uno/Sequence.hxx"
      45             : #include "com/sun/star/uno/XComponentContext.hpp"
      46             : #include "com/sun/star/uno/XInterface.hpp"
      47             : #include "com/sun/star/util/ChangesSet.hpp"
      48             : #include "cppuhelper/implbase3.hxx"
      49             : #include "cppuhelper/weak.hxx"
      50             : #include "osl/mutex.hxx"
      51             : #include "rtl/ref.hxx"
      52             : #include "rtl/ustring.h"
      53             : #include "rtl/ustring.hxx"
      54             : #include "sal/types.h"
      55             : 
      56             : #include "components.hxx"
      57             : #include "lock.hxx"
      58             : #include "readwriteaccess.hxx"
      59             : #include "rootaccess.hxx"
      60             : 
      61             : namespace configmgr { namespace read_write_access {
      62             : 
      63             : namespace {
      64             : 
      65             : class Service:
      66             :     public cppu::WeakImplHelper3<
      67             :         css::lang::XServiceInfo, css::lang::XInitialization,
      68             :         css::configuration::XReadWriteAccess >,
      69             :     private boost::noncopyable
      70             : {
      71             : public:
      72         395 :     explicit Service(
      73             :         css::uno::Reference< css::uno::XComponentContext > const & context):
      74         395 :         context_(context) {}
      75             : 
      76             : private:
      77         790 :     virtual ~Service() {}
      78             : 
      79           0 :     virtual OUString SAL_CALL getImplementationName()
      80             :         throw (css::uno::RuntimeException)
      81           0 :     { return read_write_access::getImplementationName(); }
      82             : 
      83           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const &)
      84             :         throw (css::uno::RuntimeException)
      85           0 :     { return false; }
      86             : 
      87             :     virtual css::uno::Sequence< OUString > SAL_CALL
      88           0 :     getSupportedServiceNames() throw (css::uno::RuntimeException)
      89           0 :     { return read_write_access::getSupportedServiceNames(); }
      90             : 
      91             :     virtual void SAL_CALL initialize(
      92             :         css::uno::Sequence< css::uno::Any > const & aArguments)
      93             :         throw (css::uno::Exception, css::uno::RuntimeException);
      94             : 
      95           0 :     virtual css::uno::Any SAL_CALL getByHierarchicalName(
      96             :         OUString const & aName)
      97             :         throw (
      98             :             css::container::NoSuchElementException, css::uno::RuntimeException)
      99           0 :     { return getRoot()->getByHierarchicalName(aName); }
     100             : 
     101           0 :     virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName)
     102             :         throw (css::uno::RuntimeException)
     103           0 :     { return getRoot()->hasByHierarchicalName(aName); }
     104             : 
     105           0 :     virtual void SAL_CALL replaceByHierarchicalName(
     106             :         OUString const & aName, css::uno::Any const & aElement)
     107             :         throw (
     108             :             css::lang::IllegalArgumentException,
     109             :             css::container::NoSuchElementException,
     110             :             css::lang::WrappedTargetException, css::uno::RuntimeException)
     111           0 :     { getRoot()->replaceByHierarchicalName(aName, aElement); }
     112             : 
     113           0 :     virtual void SAL_CALL commitChanges()
     114             :         throw (css::lang::WrappedTargetException, css::uno::RuntimeException)
     115           0 :     { getRoot()->commitChanges(); }
     116             : 
     117           0 :     virtual sal_Bool SAL_CALL hasPendingChanges()
     118             :         throw (css::uno::RuntimeException)
     119           0 :     { return getRoot()->hasPendingChanges(); }
     120             : 
     121           0 :     virtual css::util::ChangesSet SAL_CALL getPendingChanges()
     122             :         throw (css::uno::RuntimeException)
     123           0 :     { return getRoot()->getPendingChanges(); }
     124             : 
     125             :     rtl::Reference< RootAccess > getRoot();
     126             : 
     127             :     css::uno::Reference< css::uno::XComponentContext > context_;
     128             : 
     129             :     osl::Mutex mutex_;
     130             :     rtl::Reference< RootAccess > root_;
     131             : };
     132             : 
     133         395 : void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
     134             :     throw (css::uno::Exception, css::uno::RuntimeException)
     135             : {
     136         395 :     OUString locale;
     137         395 :     if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
     138             :         throw css::lang::IllegalArgumentException(
     139             :             "not exactly one string argument",
     140           0 :             static_cast< cppu::OWeakObject * >(this), -1);
     141             :     }
     142         395 :     osl::MutexGuard g1(mutex_);
     143         395 :     if (root_.is()) {
     144             :         throw css::uno::RuntimeException(
     145           0 :             "already initialized", static_cast< cppu::OWeakObject * >(this));
     146             :     }
     147         395 :     osl::MutexGuard g2(*lock());
     148         395 :     Components & components = Components::getSingleton(context_);
     149         395 :     root_ = new RootAccess(components, "/", locale, true);
     150         395 :     components.addRootAccess(root_);
     151         395 : }
     152             : 
     153           0 : rtl::Reference< RootAccess > Service::getRoot() {
     154           0 :     osl::MutexGuard g(mutex_);
     155           0 :     if (!root_.is()) {
     156             :         throw css::lang::NotInitializedException(
     157           0 :             "not initialized", static_cast< cppu::OWeakObject * >(this));
     158             :     }
     159           0 :     return root_;
     160             : }
     161             : 
     162             : }
     163             : 
     164         395 : css::uno::Reference< css::uno::XInterface > create(
     165             :     css::uno::Reference< css::uno::XComponentContext > const & context)
     166             : {
     167         395 :     return static_cast< cppu::OWeakObject * >(new Service(context));
     168             : }
     169             : 
     170          66 : OUString getImplementationName() {
     171          66 :     return OUString("com.sun.star.comp.configuration.ReadWriteAccess");
     172             : }
     173             : 
     174          12 : css::uno::Sequence< OUString > getSupportedServiceNames() {
     175          12 :     OUString name("com.sun.star.configuration.ReadWriteAccess");
     176          12 :     return css::uno::Sequence< OUString >(&name, 1);
     177             : }
     178             : 
     179             : } }
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10