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

Generated by: LCOV version 1.10