LCOV - code coverage report
Current view: top level - configmgr/source - readonlyaccess.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 26 37 70.3 %
Date: 2014-04-11 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        3044 :     explicit Service(
      52             :         css::uno::Reference< css::uno::XComponentContext > const & context):
      53        3044 :         context_(context) {}
      54             : 
      55             : private:
      56        6088 :     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      346665 :     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      346665 :     { 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        3044 : void Service::initialize(css::uno::Sequence< css::uno::Any > const & aArguments)
      93             :     throw (css::uno::Exception, css::uno::RuntimeException, std::exception)
      94             : {
      95        3044 :     OUString locale;
      96        3044 :     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        6088 :     osl::MutexGuard g1(mutex_);
     102        3044 :     if (root_.is()) {
     103             :         throw css::uno::RuntimeException(
     104           0 :             "already initialized", static_cast< cppu::OWeakObject * >(this));
     105             :     }
     106        6088 :     osl::MutexGuard g2(*lock());
     107        3044 :     Components & components = Components::getSingleton(context_);
     108        3044 :     root_ = new RootAccess(components, "/", locale, false);
     109        6088 :     components.addRootAccess(root_);
     110        3044 : }
     111             : 
     112      346665 : rtl::Reference< RootAccess > Service::getRoot() {
     113      346665 :     osl::MutexGuard g(mutex_);
     114      346665 :     if (!root_.is()) {
     115             :         throw css::lang::NotInitializedException(
     116           0 :             "not initialized", static_cast< cppu::OWeakObject * >(this));
     117             :     }
     118      346665 :     return root_;
     119             : }
     120             : 
     121             : }
     122             : 
     123        3044 : css::uno::Reference< css::uno::XInterface > create(
     124             :     css::uno::Reference< css::uno::XComponentContext > const & context)
     125             : {
     126        3044 :     return static_cast< cppu::OWeakObject * >(new Service(context));
     127             : }
     128             : 
     129         442 : OUString getImplementationName() {
     130         442 :     return OUString("com.sun.star.comp.configuration.ReadOnlyAccess");
     131             : }
     132             : 
     133         148 : css::uno::Sequence< OUString > getSupportedServiceNames() {
     134         148 :     OUString name("com.sun.star.configuration.ReadOnlyAccess");
     135         148 :     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