LCOV - code coverage report
Current view: top level - configmgr/source - readonlyaccess.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 26 37 70.3 %
Date: 2015-06-13 12:38:46 Functions: 9 13 69.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             :  * 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 <com/sun/star/container/NoSuchElementException.hpp>
      13             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      14             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      15             : #include <com/sun/star/lang/NotInitializedException.hpp>
      16             : #include <com/sun/star/lang/XInitialization.hpp>
      17             : #include <com/sun/star/lang/XServiceInfo.hpp>
      18             : #include <com/sun/star/uno/Any.hxx>
      19             : #include <com/sun/star/uno/Exception.hpp>
      20             : #include <com/sun/star/uno/Reference.hxx>
      21             : #include <com/sun/star/uno/RuntimeException.hpp>
      22             : #include <com/sun/star/uno/Sequence.hxx>
      23             : #include <com/sun/star/uno/XComponentContext.hpp>
      24             : #include <com/sun/star/uno/XInterface.hpp>
      25             : #include <cppuhelper/implbase3.hxx>
      26             : #include <cppuhelper/supportsservice.hxx>
      27             : #include <cppuhelper/weak.hxx>
      28             : #include <osl/mutex.hxx>
      29             : #include <rtl/ref.hxx>
      30             : #include <rtl/ustring.h>
      31             : #include <rtl/ustring.hxx>
      32             : #include <sal/types.h>
      33             : 
      34             : #include "components.hxx"
      35             : #include "lock.hxx"
      36             : #include "readonlyaccess.hxx"
      37             : #include "rootaccess.hxx"
      38             : 
      39             : namespace configmgr { namespace read_only_access {
      40             : 
      41             : namespace {
      42             : 
      43             : class Service:
      44             :     public cppu::WeakImplHelper3<
      45             :         css::lang::XServiceInfo, css::lang::XInitialization,
      46             :         css::container::XHierarchicalNameAccess >
      47             : {
      48             : public:
      49        4462 :     explicit Service(
      50             :         css::uno::Reference< css::uno::XComponentContext > const & context):
      51        4462 :         context_(context) {}
      52             : 
      53             : private:
      54             :     Service(const Service&) SAL_DELETED_FUNCTION;
      55             :     Service& operator=(const Service&) SAL_DELETED_FUNCTION;
      56             : 
      57        8924 :     virtual ~Service() {}
      58             : 
      59           0 :     virtual OUString SAL_CALL getImplementationName()
      60             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      61           0 :     { return read_only_access::getImplementationName(); }
      62             : 
      63           0 :     virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
      64             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      65           0 :     { return cppu::supportsService(this, ServiceName); }
      66             : 
      67             :     virtual css::uno::Sequence< OUString > SAL_CALL
      68           0 :     getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      69           0 :     { return read_only_access::getSupportedServiceNames(); }
      70             : 
      71             :     virtual void SAL_CALL initialize(
      72             :         css::uno::Sequence< css::uno::Any > const & aArguments)
      73             :         throw (css::uno::Exception, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      74             : 
      75        4462 :     virtual css::uno::Any SAL_CALL getByHierarchicalName(
      76             :         OUString const & aName)
      77             :         throw (
      78             :             css::container::NoSuchElementException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      79        4462 :     { return getRoot()->getByHierarchicalName(aName); }
      80             : 
      81           0 :     virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName)
      82             :         throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
      83           0 :     { return getRoot()->hasByHierarchicalName(aName); }
      84             : 
      85             :     rtl::Reference< RootAccess > getRoot();
      86             : 
      87             :     css::uno::Reference< css::uno::XComponentContext > context_;
      88             : 
      89             :     osl::Mutex mutex_;
      90             :     rtl::Reference< RootAccess > root_;
      91             : };
      92             : 
      93        4462 : void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
      94             :     throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
      95             : {
      96        4462 :     OUString locale;
      97        4462 :     if (aArguments.getLength() != 1 || !(aArguments[0] >>= locale)) {
      98             :         throw css::lang::IllegalArgumentException(
      99             :             "not exactly one string argument",
     100           0 :             static_cast< cppu::OWeakObject * >(this), -1);
     101             :     }
     102        8924 :     osl::MutexGuard g1(mutex_);
     103        4462 :     if (root_.is()) {
     104             :         throw css::uno::RuntimeException(
     105           0 :             "already initialized", static_cast< cppu::OWeakObject * >(this));
     106             :     }
     107        8924 :     osl::MutexGuard g2(*lock());
     108        4462 :     Components & components = Components::getSingleton(context_);
     109        4462 :     root_ = new RootAccess(components, "/", locale, false);
     110        8924 :     components.addRootAccess(root_);
     111        4462 : }
     112             : 
     113        4462 : rtl::Reference< RootAccess > Service::getRoot() {
     114        4462 :     osl::MutexGuard g(mutex_);
     115        4462 :     if (!root_.is()) {
     116             :         throw css::lang::NotInitializedException(
     117           0 :             "not initialized", static_cast< cppu::OWeakObject * >(this));
     118             :     }
     119        4462 :     return root_;
     120             : }
     121             : 
     122             : }
     123             : 
     124        4462 : css::uno::Reference< css::uno::XInterface > create(
     125             :     css::uno::Reference< css::uno::XComponentContext > const & context)
     126             : {
     127        4462 :     return static_cast< cppu::OWeakObject * >(new Service(context));
     128             : }
     129             : 
     130         686 : OUString getImplementationName() {
     131         686 :     return OUString("com.sun.star.comp.configuration.ReadOnlyAccess");
     132             : }
     133             : 
     134         211 : css::uno::Sequence< OUString > getSupportedServiceNames() {
     135         211 :     OUString name("com.sun.star.configuration.ReadOnlyAccess");
     136         211 :     return css::uno::Sequence< OUString >(&name, 1);
     137             : }
     138             : 
     139             : } }
     140             : 
     141             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11