LCOV - code coverage report
Current view: top level - configmgr/source - readonlyaccess.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 36 69.4 %
Date: 2012-08-25 Functions: 9 13 69.2 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 22 58 37.9 %

           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/container/NoSuchElementException.hpp"
      34                 :            : #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
      35                 :            : #include "com/sun/star/lang/IllegalArgumentException.hpp"
      36                 :            : #include "com/sun/star/lang/NotInitializedException.hpp"
      37                 :            : #include "com/sun/star/lang/XInitialization.hpp"
      38                 :            : #include "com/sun/star/lang/XServiceInfo.hpp"
      39                 :            : #include "com/sun/star/uno/Any.hxx"
      40                 :            : #include "com/sun/star/uno/Exception.hpp"
      41                 :            : #include "com/sun/star/uno/Reference.hxx"
      42                 :            : #include "com/sun/star/uno/RuntimeException.hpp"
      43                 :            : #include "com/sun/star/uno/Sequence.hxx"
      44                 :            : #include "com/sun/star/uno/XComponentContext.hpp"
      45                 :            : #include "com/sun/star/uno/XInterface.hpp"
      46                 :            : #include "cppuhelper/implbase3.hxx"
      47                 :            : #include "cppuhelper/weak.hxx"
      48                 :            : #include "osl/mutex.hxx"
      49                 :            : #include "rtl/ref.hxx"
      50                 :            : #include "rtl/ustring.h"
      51                 :            : #include "rtl/ustring.hxx"
      52                 :            : #include "sal/types.h"
      53                 :            : 
      54                 :            : #include "components.hxx"
      55                 :            : #include "lock.hxx"
      56                 :            : #include "readonlyaccess.hxx"
      57                 :            : #include "rootaccess.hxx"
      58                 :            : 
      59                 :            : namespace configmgr { namespace read_only_access {
      60                 :            : 
      61                 :            : namespace {
      62                 :            : 
      63                 :            : namespace css = com::sun::star;
      64                 :            : 
      65                 :            : class Service:
      66                 :            :     public cppu::WeakImplHelper3<
      67                 :            :         css::lang::XServiceInfo, css::lang::XInitialization,
      68                 :            :         css::container::XHierarchicalNameAccess >,
      69                 :            :     private boost::noncopyable
      70                 :            : {
      71                 :            : public:
      72                 :       2691 :     explicit Service(
      73                 :            :         css::uno::Reference< css::uno::XComponentContext > const & context):
      74         [ +  - ]:       2691 :         context_(context) {}
      75                 :            : 
      76                 :            : private:
      77 [ +  - ][ -  + ]:       5382 :     virtual ~Service() {}
      78                 :            : 
      79                 :          0 :     virtual rtl::OUString SAL_CALL getImplementationName()
      80                 :            :         throw (css::uno::RuntimeException)
      81                 :          0 :     { return read_only_access::getImplementationName(); }
      82                 :            : 
      83                 :          0 :     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const &)
      84                 :            :         throw (css::uno::RuntimeException)
      85                 :          0 :     { return false; }
      86                 :            : 
      87                 :            :     virtual css::uno::Sequence< rtl::OUString > SAL_CALL
      88                 :          0 :     getSupportedServiceNames() throw (css::uno::RuntimeException)
      89                 :          0 :     { return read_only_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                 :      26332 :     virtual css::uno::Any SAL_CALL getByHierarchicalName(
      96                 :            :         rtl::OUString const & aName)
      97                 :            :         throw (
      98                 :            :             css::container::NoSuchElementException, css::uno::RuntimeException)
      99         [ +  - ]:      26332 :     { return getRoot()->getByHierarchicalName(aName); }
     100                 :            : 
     101                 :          0 :     virtual sal_Bool SAL_CALL hasByHierarchicalName(rtl::OUString const & aName)
     102                 :            :         throw (css::uno::RuntimeException)
     103         [ #  # ]:          0 :     { return getRoot()->hasByHierarchicalName(aName); }
     104                 :            : 
     105                 :            :     rtl::Reference< RootAccess > getRoot();
     106                 :            : 
     107                 :            :     css::uno::Reference< css::uno::XComponentContext > context_;
     108                 :            : 
     109                 :            :     osl::Mutex mutex_;
     110                 :            :     rtl::Reference< RootAccess > root_;
     111                 :            : };
     112                 :            : 
     113                 :       2691 : void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
     114                 :            :     throw (css::uno::Exception, css::uno::RuntimeException)
     115                 :            : {
     116                 :       2691 :     OUString locale;
     117 [ -  + ][ -  + ]:       2691 :     if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
                 [ +  - ]
     118                 :            :         throw css::lang::IllegalArgumentException(
     119                 :            :             "not exactly one string argument",
     120 [ #  # ][ #  # ]:          0 :             static_cast< cppu::OWeakObject * >(this), -1);
     121                 :            :     }
     122         [ +  - ]:       2691 :     osl::MutexGuard g1(mutex_);
     123         [ -  + ]:       2691 :     if (root_.is()) {
     124                 :            :         throw css::uno::RuntimeException(
     125 [ #  # ][ #  # ]:          0 :             "already initialized", static_cast< cppu::OWeakObject * >(this));
     126                 :            :     }
     127 [ +  - ][ +  - ]:       2691 :     osl::MutexGuard g2(*lock());
                 [ +  - ]
     128         [ +  - ]:       2691 :     Components & components = Components::getSingleton(context_);
     129 [ +  - ][ +  - ]:       2691 :     root_ = new RootAccess(components, "/", locale, false);
     130 [ +  - ][ +  - ]:       2691 :     components.addRootAccess(root_);
                 [ +  - ]
     131                 :       2691 : }
     132                 :            : 
     133                 :      26332 : rtl::Reference< RootAccess > Service::getRoot() {
     134         [ +  - ]:      26332 :     osl::MutexGuard g(mutex_);
     135         [ -  + ]:      26332 :     if (!root_.is()) {
     136                 :            :         throw css::lang::NotInitializedException(
     137 [ #  # ][ #  # ]:          0 :             "not initialized", static_cast< cppu::OWeakObject * >(this));
     138                 :            :     }
     139         [ +  - ]:      26332 :     return root_;
     140                 :            : }
     141                 :            : 
     142                 :            : }
     143                 :            : 
     144                 :       2691 : css::uno::Reference< css::uno::XInterface > create(
     145                 :            :     css::uno::Reference< css::uno::XComponentContext > const & context)
     146                 :            : {
     147         [ +  - ]:       2691 :     return static_cast< cppu::OWeakObject * >(new Service(context));
     148                 :            : }
     149                 :            : 
     150                 :        954 : rtl::OUString getImplementationName() {
     151                 :            :     return rtl::OUString(
     152                 :            :         RTL_CONSTASCII_USTRINGPARAM(
     153                 :        954 :             "com.sun.star.comp.configuration.ReadOnlyAccess"));
     154                 :            : }
     155                 :            : 
     156                 :        236 : css::uno::Sequence< rtl::OUString > getSupportedServiceNames() {
     157                 :        236 :     return css::uno::Sequence< rtl::OUString >();
     158                 :            : }
     159                 :            : 
     160                 :            : } }
     161                 :            : 
     162                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10