LCOV - code coverage report
Current view: top level - configmgr/source - rootaccess.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 105 148 70.9 %
Date: 2014-11-03 Functions: 19 27 70.4 %
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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <sal/config.h>
      21             : 
      22             : #include <cassert>
      23             : #include <vector>
      24             : 
      25             : #include <com/sun/star/lang/DisposedException.hpp>
      26             : #include <com/sun/star/lang/EventObject.hpp>
      27             : #include <com/sun/star/lang/WrappedTargetException.hpp>
      28             : #include <com/sun/star/uno/Any.hxx>
      29             : #include <com/sun/star/uno/Reference.hxx>
      30             : #include <com/sun/star/uno/RuntimeException.hpp>
      31             : #include <com/sun/star/uno/Type.hxx>
      32             : #include <com/sun/star/uno/XInterface.hpp>
      33             : #include <com/sun/star/util/ChangesEvent.hpp>
      34             : #include <com/sun/star/util/ChangesSet.hpp>
      35             : #include <com/sun/star/util/ElementChange.hpp>
      36             : #include <com/sun/star/util/XChangesBatch.hpp>
      37             : #include <com/sun/star/util/XChangesListener.hpp>
      38             : #include <com/sun/star/util/XChangesNotifier.hpp>
      39             : #include <comphelper/sequenceasvector.hxx>
      40             : #include <cppu/unotype.hxx>
      41             : #include <cppuhelper/queryinterface.hxx>
      42             : #include <cppuhelper/weak.hxx>
      43             : #include <osl/mutex.hxx>
      44             : #include <rtl/ref.hxx>
      45             : #include <rtl/ustring.h>
      46             : #include <rtl/ustring.hxx>
      47             : 
      48             : #include "broadcaster.hxx"
      49             : #include "childaccess.hxx"
      50             : #include "components.hxx"
      51             : #include "data.hxx"
      52             : #include "lock.hxx"
      53             : #include "modifications.hxx"
      54             : #include "node.hxx"
      55             : #include "path.hxx"
      56             : #include "rootaccess.hxx"
      57             : 
      58             : namespace configmgr {
      59             : 
      60      178200 : RootAccess::RootAccess(
      61             :     Components & components, OUString const & pathRepresentation,
      62             :     OUString const & locale, bool update):
      63             :     Access(components), pathRepresentation_(pathRepresentation),
      64      178200 :     locale_(locale), update_(update), finalized_(false), alive_(true)
      65             : {
      66      178200 :     lock_ = lock();
      67      178200 : }
      68             : 
      69     4668421 : Path RootAccess::getAbsolutePath() {
      70     4668421 :     getNode();
      71     4668421 :     return path_;
      72             : }
      73             : 
      74      499472 : void RootAccess::initBroadcaster(
      75             :     Modifications::Node const & modifications, Broadcaster * broadcaster)
      76             : {
      77             :     assert(broadcaster != 0);
      78      499472 :     comphelper::SequenceAsVector< css::util::ElementChange > changes;
      79             :     initBroadcasterAndChanges(
      80      499472 :         modifications, broadcaster, changesListeners_.empty() ? 0 : &changes);
      81      499472 :     if (!changes.empty()) {
      82       36248 :         css::util::ChangesSet set(changes.getAsConstList());
      83      217488 :         for (ChangesListeners::iterator i(changesListeners_.begin());
      84      144992 :              i != changesListeners_.end(); ++i)
      85             :         {
      86       36248 :             cppu::OWeakObject* pSource = static_cast< cppu::OWeakObject * >(this);
      87       36248 :             css::uno::Reference< css::uno::XInterface > xBase( pSource, css::uno::UNO_QUERY );
      88             :             broadcaster->addChangesNotification(
      89       36248 :                 *i,
      90             :                 css::util::ChangesEvent(
      91       72496 :                     pSource, makeAny( xBase ), set));
      92       72496 :         }
      93      499472 :     }
      94      499472 : }
      95             : 
      96    44469957 : void RootAccess::acquire() throw () {
      97    44469957 :     Access::acquire();
      98    44469957 : }
      99             : 
     100    44466218 : void RootAccess::release() throw () {
     101    44466218 :     Access::release();
     102    44466218 : }
     103             : 
     104           0 : OUString RootAccess::getAbsolutePathRepresentation() {
     105           0 :     getNode(); // turn pathRepresentation_ into canonic form
     106           0 :     return pathRepresentation_;
     107             : }
     108             : 
     109             : 
     110             : 
     111        2539 : void RootAccess::setAlive(bool b) {
     112        2539 :     alive_ = b;
     113        2539 : }
     114             : 
     115       25244 : void RootAccess::addChangesListener(
     116             :     css::uno::Reference< css::util::XChangesListener > const & aListener)
     117             :     throw (css::uno::RuntimeException, std::exception)
     118             : {
     119             :     assert(thisIs(IS_ANY));
     120             :     {
     121       25244 :         osl::MutexGuard g(*lock_);
     122       25244 :         checkLocalizedPropertyAccess();
     123       25244 :         if (!aListener.is()) {
     124             :             throw css::uno::RuntimeException(
     125           0 :                 "null listener", static_cast< cppu::OWeakObject * >(this));
     126             :         }
     127       25244 :         if (!isDisposed()) {
     128       25244 :             changesListeners_.insert(aListener);
     129       50488 :             return;
     130           0 :         }
     131             :     }
     132             :     try {
     133           0 :         aListener->disposing(
     134           0 :             css::lang::EventObject(static_cast< cppu::OWeakObject * >(this)));
     135           0 :     } catch (css::lang::DisposedException &) {}
     136             : }
     137             : 
     138       23528 : void RootAccess::removeChangesListener(
     139             :     css::uno::Reference< css::util::XChangesListener > const & aListener)
     140             :     throw (css::uno::RuntimeException, std::exception)
     141             : {
     142             :     assert(thisIs(IS_ANY));
     143       23528 :     osl::MutexGuard g(*lock_);
     144       23528 :     checkLocalizedPropertyAccess();
     145       23528 :     ChangesListeners::iterator i(changesListeners_.find(aListener));
     146       23528 :     if (i != changesListeners_.end()) {
     147       20290 :         changesListeners_.erase(i);
     148       23528 :     }
     149       23528 : }
     150             : 
     151       65721 : void RootAccess::commitChanges()
     152             :     throw (css::lang::WrappedTargetException,
     153             :            css::uno::RuntimeException,
     154             :            std::exception)
     155             : {
     156             :     assert(thisIs(IS_UPDATE));
     157       65721 :     if (!alive_)
     158             :     {
     159       65721 :         return;
     160             :     }
     161       65721 :     Broadcaster bc;
     162             :     {
     163       65721 :         osl::MutexGuard g(*lock_);
     164             : 
     165       65721 :         checkLocalizedPropertyAccess();
     166             :         int finalizedLayer;
     167      131442 :         Modifications globalMods;
     168             :         commitChildChanges(
     169       65721 :             ((getComponents().resolvePathRepresentation(
     170             :                   pathRepresentation_, 0, 0, &finalizedLayer)
     171      328605 :               == node_) &&
     172       65721 :              finalizedLayer == Data::NO_LAYER),
     173       65721 :             &globalMods);
     174       65721 :         getComponents().writeModifications();
     175      131442 :         getComponents().initGlobalBroadcaster(globalMods, this, &bc);
     176             :     }
     177       65721 :     bc.send();
     178             : }
     179             : 
     180           0 : sal_Bool RootAccess::hasPendingChanges() throw (css::uno::RuntimeException, std::exception) {
     181             :     assert(thisIs(IS_UPDATE));
     182           0 :     osl::MutexGuard g(*lock_);
     183           0 :     checkLocalizedPropertyAccess();
     184             :     //TODO: Optimize:
     185           0 :     std::vector< css::util::ElementChange > changes;
     186           0 :     reportChildChanges(&changes);
     187           0 :     return !changes.empty();
     188             : }
     189             : 
     190           0 : css::util::ChangesSet RootAccess::getPendingChanges()
     191             :     throw (css::uno::RuntimeException, std::exception)
     192             : {
     193             :     assert(thisIs(IS_UPDATE));
     194           0 :     osl::MutexGuard g(*lock_);
     195           0 :     checkLocalizedPropertyAccess();
     196           0 :     comphelper::SequenceAsVector< css::util::ElementChange > changes;
     197           0 :     reportChildChanges(&changes);
     198           0 :     return changes.getAsConstList();
     199             : }
     200             : 
     201      526983 : RootAccess::~RootAccess()
     202             : {
     203      175661 :     osl::MutexGuard g(*lock_);
     204      175661 :     if (alive_)
     205      175661 :         getComponents().removeRootAccess(this);
     206      351322 : }
     207             : 
     208      223464 : Path RootAccess::getRelativePath() {
     209      223464 :     return Path();
     210             : }
     211             : 
     212       44858 : OUString RootAccess::getRelativePathRepresentation() {
     213       44858 :     return OUString();
     214             : }
     215             : 
     216    15657911 : rtl::Reference< Node > RootAccess::getNode() {
     217    15657911 :     if (!node_.is()) {
     218      171552 :         OUString canonic;
     219             :         int finalizedLayer;
     220      343104 :         node_ = getComponents().resolvePathRepresentation(
     221      171552 :             pathRepresentation_, &canonic, &path_, &finalizedLayer);
     222      171552 :         if (!node_.is()) {
     223             :             throw css::uno::RuntimeException(
     224           0 :                 "cannot find " + pathRepresentation_, 0);
     225             :                 // RootAccess::queryInterface indirectly calls
     226             :                 // RootAccess::getNode, so if this RootAccess were passed out in
     227             :                 // RuntimeException.Context, client code that called
     228             :                 // queryInterface on it would cause trouble; therefore,
     229             :                 // RuntimeException.Context is left null here
     230             :         }
     231      171552 :         pathRepresentation_ = canonic;
     232             :         assert(!path_.empty() || node_->kind() == Node::KIND_ROOT);
     233      171552 :         if (!path_.empty()) {
     234      163338 :             name_ = path_.back();
     235             :         }
     236      171552 :         finalized_ = finalizedLayer != Data::NO_LAYER;
     237             :     }
     238    15657911 :     return node_;
     239             : }
     240             : 
     241      672051 : bool RootAccess::isFinalized() {
     242      672051 :     getNode();
     243      672051 :     return finalized_;
     244             : }
     245             : 
     246           0 : OUString RootAccess::getNameInternal() {
     247           0 :     getNode();
     248           0 :     return name_;
     249             : }
     250             : 
     251     2908252 : rtl::Reference< RootAccess > RootAccess::getRootAccess() {
     252     2908252 :     return this;
     253             : }
     254             : 
     255      446928 : rtl::Reference< Access > RootAccess::getParentAccess() {
     256      446928 :     return rtl::Reference< Access >();
     257             : }
     258             : 
     259           0 : void RootAccess::addTypes(std::vector< css::uno::Type > * types) const {
     260             :     assert(types != 0);
     261           0 :     types->push_back(cppu::UnoType< css::util::XChangesNotifier >::get());
     262           0 :     types->push_back(cppu::UnoType< css::util::XChangesBatch >::get());
     263           0 : }
     264             : 
     265        2596 : void RootAccess::addSupportedServiceNames(
     266             :     std::vector< OUString > * services)
     267             : {
     268             :     assert(services != 0);
     269        2596 :     services->push_back("com.sun.star.configuration.AccessRootElement");
     270        2596 :     if (update_) {
     271        2250 :         services->push_back("com.sun.star.configuration.UpdateRootElement");
     272             :     }
     273        2596 : }
     274             : 
     275           0 : void RootAccess::initDisposeBroadcaster(Broadcaster * broadcaster) {
     276             :     assert(broadcaster != 0);
     277           0 :     for (ChangesListeners::iterator i(changesListeners_.begin());
     278           0 :          i != changesListeners_.end(); ++i)
     279             :     {
     280             :         broadcaster->addDisposeNotification(
     281           0 :             i->get(),
     282           0 :             css::lang::EventObject(static_cast< cppu::OWeakObject * >(this)));
     283             :     }
     284           0 :     Access::initDisposeBroadcaster(broadcaster);
     285           0 : }
     286             : 
     287           0 : void RootAccess::clearListeners() throw() {
     288           0 :     changesListeners_.clear();
     289           0 :     Access::clearListeners();
     290           0 : }
     291             : 
     292      798006 : css::uno::Any RootAccess::queryInterface(css::uno::Type const & aType)
     293             :     throw (css::uno::RuntimeException, std::exception)
     294             : {
     295             :     assert(thisIs(IS_ANY));
     296      798006 :     osl::MutexGuard g(*lock_);
     297      798006 :     checkLocalizedPropertyAccess();
     298      798006 :     css::uno::Any res(Access::queryInterface(aType));
     299      798006 :     if (res.hasValue()) {
     300      653415 :         return res;
     301             :     }
     302      289182 :     res = cppu::queryInterface(
     303      144591 :         aType, static_cast< css::util::XChangesNotifier * >(this));
     304      144591 :     if (res.hasValue()) {
     305       71540 :         return res;
     306             :     }
     307       73051 :     if (!res.hasValue() && update_) {
     308      138158 :         res = cppu::queryInterface(
     309       69079 :             aType, static_cast< css::util::XChangesBatch * >(this));
     310             :     }
     311       73051 :     return res;
     312             : }
     313             : 
     314           0 : OUString RootAccess::getImplementationName()
     315             :     throw (css::uno::RuntimeException, std::exception)
     316             : {
     317             :     assert(thisIs(IS_ANY));
     318           0 :     osl::MutexGuard g(*lock_);
     319           0 :     checkLocalizedPropertyAccess();
     320           0 :     return OUString("configmgr.RootAccess");
     321             : }
     322             : 
     323             : }
     324             : 
     325             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10