LCOV - code coverage report
Current view: top level - configmgr/source - readwriteaccess.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 28 45 62.2 %
Date: 2012-08-25 Functions: 10 17 58.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 70 35.7 %

           Branch data     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                 :            : namespace css = com::sun::star;
      66                 :            : 
      67                 :            : class Service:
      68                 :            :     public cppu::WeakImplHelper3<
      69                 :            :         css::lang::XServiceInfo, css::lang::XInitialization,
      70                 :            :         css::configuration::XReadWriteAccess >,
      71                 :            :     private boost::noncopyable
      72                 :            : {
      73                 :            : public:
      74                 :       2359 :     explicit Service(
      75                 :            :         css::uno::Reference< css::uno::XComponentContext > const & context):
      76         [ +  - ]:       2359 :         context_(context) {}
      77                 :            : 
      78                 :            : private:
      79 [ +  - ][ -  + ]:       4718 :     virtual ~Service() {}
      80                 :            : 
      81                 :          0 :     virtual rtl::OUString SAL_CALL getImplementationName()
      82                 :            :         throw (css::uno::RuntimeException)
      83                 :          0 :     { return read_write_access::getImplementationName(); }
      84                 :            : 
      85                 :          0 :     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const &)
      86                 :            :         throw (css::uno::RuntimeException)
      87                 :          0 :     { return false; }
      88                 :            : 
      89                 :            :     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
      90                 :          0 :     getSupportedServiceNames() throw (css::uno::RuntimeException)
      91                 :          0 :     { return read_write_access::getSupportedServiceNames(); }
      92                 :            : 
      93                 :            :     virtual void SAL_CALL initialize(
      94                 :            :         css::uno::Sequence< css::uno::Any > const & aArguments)
      95                 :            :         throw (css::uno::Exception, css::uno::RuntimeException);
      96                 :            : 
      97                 :          0 :     virtual css::uno::Any SAL_CALL getByHierarchicalName(
      98                 :            :         rtl::OUString const & aName)
      99                 :            :         throw (
     100                 :            :             css::container::NoSuchElementException, css::uno::RuntimeException)
     101         [ #  # ]:          0 :     { return getRoot()->getByHierarchicalName(aName); }
     102                 :            : 
     103                 :          0 :     virtual sal_Bool SAL_CALL hasByHierarchicalName(rtl::OUString const & aName)
     104                 :            :         throw (css::uno::RuntimeException)
     105         [ #  # ]:          0 :     { return getRoot()->hasByHierarchicalName(aName); }
     106                 :            : 
     107                 :         62 :     virtual void SAL_CALL replaceByHierarchicalName(
     108                 :            :         rtl::OUString const & aName, css::uno::Any const & aElement)
     109                 :            :         throw (
     110                 :            :             css::lang::IllegalArgumentException,
     111                 :            :             css::container::NoSuchElementException,
     112                 :            :             css::lang::WrappedTargetException, css::uno::RuntimeException)
     113         [ +  - ]:         62 :     { getRoot()->replaceByHierarchicalName(aName, aElement); }
     114                 :            : 
     115                 :         62 :     virtual void SAL_CALL commitChanges()
     116                 :            :         throw (css::lang::WrappedTargetException, css::uno::RuntimeException)
     117         [ +  - ]:         62 :     { getRoot()->commitChanges(); }
     118                 :            : 
     119                 :          0 :     virtual sal_Bool SAL_CALL hasPendingChanges()
     120                 :            :         throw (css::uno::RuntimeException)
     121         [ #  # ]:          0 :     { return getRoot()->hasPendingChanges(); }
     122                 :            : 
     123                 :          0 :     virtual css::util::ChangesSet SAL_CALL getPendingChanges()
     124                 :            :         throw (css::uno::RuntimeException)
     125         [ #  # ]:          0 :     { return getRoot()->getPendingChanges(); }
     126                 :            : 
     127                 :            :     rtl::Reference< RootAccess > getRoot();
     128                 :            : 
     129                 :            :     css::uno::Reference< css::uno::XComponentContext > context_;
     130                 :            : 
     131                 :            :     osl::Mutex mutex_;
     132                 :            :     rtl::Reference< RootAccess > root_;
     133                 :            : };
     134                 :            : 
     135                 :       2359 : void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
     136                 :            :     throw (css::uno::Exception, css::uno::RuntimeException)
     137                 :            : {
     138                 :       2359 :     OUString locale;
     139 [ -  + ][ -  + ]:       2359 :     if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
                 [ +  - ]
     140                 :            :         throw css::lang::IllegalArgumentException(
     141                 :            :             "not exactly one string argument",
     142 [ #  # ][ #  # ]:          0 :             static_cast< cppu::OWeakObject * >(this), -1);
     143                 :            :     }
     144         [ +  - ]:       2359 :     osl::MutexGuard g1(mutex_);
     145         [ -  + ]:       2359 :     if (root_.is()) {
     146                 :            :         throw css::uno::RuntimeException(
     147 [ #  # ][ #  # ]:          0 :             "already initialized", static_cast< cppu::OWeakObject * >(this));
     148                 :            :     }
     149 [ +  - ][ +  - ]:       2359 :     osl::MutexGuard g2(*lock());
                 [ +  - ]
     150         [ +  - ]:       2359 :     Components & components = Components::getSingleton(context_);
     151 [ +  - ][ +  - ]:       2359 :     root_ = new RootAccess(components, "/", locale, true);
     152 [ +  - ][ +  - ]:       2359 :     components.addRootAccess(root_);
                 [ +  - ]
     153                 :       2359 : }
     154                 :            : 
     155                 :        124 : rtl::Reference< RootAccess > Service::getRoot() {
     156         [ +  - ]:        124 :     osl::MutexGuard g(mutex_);
     157         [ -  + ]:        124 :     if (!root_.is()) {
     158                 :            :         throw css::lang::NotInitializedException(
     159 [ #  # ][ #  # ]:          0 :             "not initialized", static_cast< cppu::OWeakObject * >(this));
     160                 :            :     }
     161         [ +  - ]:        124 :     return root_;
     162                 :            : }
     163                 :            : 
     164                 :            : }
     165                 :            : 
     166                 :       2359 : css::uno::Reference< css::uno::XInterface > create(
     167                 :            :     css::uno::Reference< css::uno::XComponentContext > const & context)
     168                 :            : {
     169         [ +  - ]:       2359 :     return static_cast< cppu::OWeakObject * >(new Service(context));
     170                 :            : }
     171                 :            : 
     172                 :        954 : rtl::OUString getImplementationName() {
     173                 :            :     return rtl::OUString(
     174                 :            :         RTL_CONSTASCII_USTRINGPARAM(
     175                 :        954 :             "com.sun.star.comp.configuration.ReadWriteAccess"));
     176                 :            : }
     177                 :            : 
     178                 :        172 : css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
     179                 :            :     rtl::OUString name(
     180                 :            :         RTL_CONSTASCII_USTRINGPARAM(
     181         [ +  - ]:        172 :             "com.sun.star.configuration.ReadWriteAccess"));
     182         [ +  - ]:        172 :     return css::uno::Sequence< rtl::OUString >(&name, 1);
     183                 :            : }
     184                 :            : 
     185                 :            : } }
     186                 :            : 
     187                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10