LCOV - code coverage report
Current view: top level - configmgr/source - rootaccess.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 109 152 71.7 %
Date: 2014-04-11 Functions: 21 29 72.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       69084 : RootAccess::RootAccess(
      61             :     Components & components, OUString const & pathRepresentation,
      62             :     OUString const & locale, bool update):
      63             :     Access(components), pathRepresentation_(pathRepresentation),
      64       69084 :     locale_(locale), update_(update), finalized_(false), alive_(true)
      65             : {
      66       69084 :     lock_ = lock();
      67       69084 : }
      68             : 
      69     1875455 : Path RootAccess::getAbsolutePath() {
      70     1875455 :     getNode();
      71     1875455 :     return path_;
      72             : }
      73             : 
      74      169362 : void RootAccess::initBroadcaster(
      75             :     Modifications::Node const & modifications, Broadcaster * broadcaster)
      76             : {
      77             :     assert(broadcaster != 0);
      78      169362 :     comphelper::SequenceAsVector< css::util::ElementChange > changes;
      79             :     initBroadcasterAndChanges(
      80      169362 :         modifications, broadcaster, changesListeners_.empty() ? 0 : &changes);
      81      169362 :     if (!changes.empty()) {
      82       12384 :         css::util::ChangesSet set(changes.getAsConstList());
      83       74304 :         for (ChangesListeners::iterator i(changesListeners_.begin());
      84       49536 :              i != changesListeners_.end(); ++i)
      85             :         {
      86       12384 :             cppu::OWeakObject* pSource = static_cast< cppu::OWeakObject * >(this);
      87       12384 :             css::uno::Reference< css::uno::XInterface > xBase( pSource, css::uno::UNO_QUERY );
      88             :             broadcaster->addChangesNotification(
      89       12384 :                 *i,
      90             :                 css::util::ChangesEvent(
      91       24768 :                     pSource, makeAny( xBase ), set));
      92       24768 :         }
      93      169362 :     }
      94      169362 : }
      95             : 
      96    21874152 : void RootAccess::acquire() throw () {
      97    21874152 :     Access::acquire();
      98    21874152 : }
      99             : 
     100    21872357 : void RootAccess::release() throw () {
     101    21872357 :     Access::release();
     102    21872357 : }
     103             : 
     104           0 : OUString RootAccess::getAbsolutePathRepresentation() {
     105           0 :     getNode(); // turn pathRepresentation_ into canonic form
     106           0 :     return pathRepresentation_;
     107             : }
     108             : 
     109      503642 : OUString RootAccess::getLocale() const {
     110      503642 :     return locale_;
     111             : }
     112             : 
     113      217420 : bool RootAccess::isUpdate() const {
     114      217420 :     return update_;
     115             : }
     116             : 
     117        1267 : void RootAccess::setAlive(bool b) {
     118        1267 :     alive_ = b;
     119        1267 : }
     120             : 
     121       10243 : void RootAccess::addChangesListener(
     122             :     css::uno::Reference< css::util::XChangesListener > const & aListener)
     123             :     throw (css::uno::RuntimeException, std::exception)
     124             : {
     125             :     assert(thisIs(IS_ANY));
     126             :     {
     127       10243 :         osl::MutexGuard g(*lock_);
     128       10243 :         checkLocalizedPropertyAccess();
     129       10243 :         if (!aListener.is()) {
     130             :             throw css::uno::RuntimeException(
     131           0 :                 "null listener", static_cast< cppu::OWeakObject * >(this));
     132             :         }
     133       10243 :         if (!isDisposed()) {
     134       10243 :             changesListeners_.insert(aListener);
     135       20486 :             return;
     136           0 :         }
     137             :     }
     138             :     try {
     139           0 :         aListener->disposing(
     140           0 :             css::lang::EventObject(static_cast< cppu::OWeakObject * >(this)));
     141           0 :     } catch (css::lang::DisposedException &) {}
     142             : }
     143             : 
     144        9414 : void RootAccess::removeChangesListener(
     145             :     css::uno::Reference< css::util::XChangesListener > const & aListener)
     146             :     throw (css::uno::RuntimeException, std::exception)
     147             : {
     148             :     assert(thisIs(IS_ANY));
     149        9414 :     osl::MutexGuard g(*lock_);
     150        9414 :     checkLocalizedPropertyAccess();
     151        9414 :     ChangesListeners::iterator i(changesListeners_.find(aListener));
     152        9414 :     if (i != changesListeners_.end()) {
     153        7919 :         changesListeners_.erase(i);
     154        9414 :     }
     155        9414 : }
     156             : 
     157       21416 : void RootAccess::commitChanges()
     158             :     throw (css::lang::WrappedTargetException,
     159             :            css::uno::RuntimeException,
     160             :            std::exception)
     161             : {
     162             :     assert(thisIs(IS_UPDATE));
     163       21416 :     if (!alive_)
     164             :     {
     165       21416 :         return;
     166             :     }
     167       21416 :     Broadcaster bc;
     168             :     {
     169       21416 :         osl::MutexGuard g(*lock_);
     170             : 
     171       21416 :         checkLocalizedPropertyAccess();
     172             :         int finalizedLayer;
     173       42832 :         Modifications globalMods;
     174             :         commitChildChanges(
     175       21416 :             ((getComponents().resolvePathRepresentation(
     176             :                   pathRepresentation_, 0, 0, &finalizedLayer)
     177      107080 :               == node_) &&
     178       21416 :              finalizedLayer == Data::NO_LAYER),
     179       21416 :             &globalMods);
     180       21416 :         getComponents().writeModifications();
     181       42832 :         getComponents().initGlobalBroadcaster(globalMods, this, &bc);
     182             :     }
     183       21416 :     bc.send();
     184             : }
     185             : 
     186           0 : sal_Bool RootAccess::hasPendingChanges() throw (css::uno::RuntimeException, std::exception) {
     187             :     assert(thisIs(IS_UPDATE));
     188           0 :     osl::MutexGuard g(*lock_);
     189           0 :     checkLocalizedPropertyAccess();
     190             :     //TODO: Optimize:
     191           0 :     std::vector< css::util::ElementChange > changes;
     192           0 :     reportChildChanges(&changes);
     193           0 :     return !changes.empty();
     194             : }
     195             : 
     196           0 : css::util::ChangesSet RootAccess::getPendingChanges()
     197             :     throw (css::uno::RuntimeException, std::exception)
     198             : {
     199             :     assert(thisIs(IS_UPDATE));
     200           0 :     osl::MutexGuard g(*lock_);
     201           0 :     checkLocalizedPropertyAccess();
     202           0 :     comphelper::SequenceAsVector< css::util::ElementChange > changes;
     203           0 :     reportChildChanges(&changes);
     204           0 :     return changes.getAsConstList();
     205             : }
     206             : 
     207      203451 : RootAccess::~RootAccess()
     208             : {
     209       67817 :     osl::MutexGuard g(*lock_);
     210       67817 :     if (alive_)
     211       67817 :         getComponents().removeRootAccess(this);
     212      135634 : }
     213             : 
     214       83067 : Path RootAccess::getRelativePath() {
     215       83067 :     return Path();
     216             : }
     217             : 
     218       14584 : OUString RootAccess::getRelativePathRepresentation() {
     219       14584 :     return OUString();
     220             : }
     221             : 
     222     6828183 : rtl::Reference< Node > RootAccess::getNode() {
     223     6828183 :     if (!node_.is()) {
     224       66569 :         OUString canonic;
     225             :         int finalizedLayer;
     226      133138 :         node_ = getComponents().resolvePathRepresentation(
     227       66569 :             pathRepresentation_, &canonic, &path_, &finalizedLayer);
     228       66569 :         if (!node_.is()) {
     229             :             throw css::uno::RuntimeException(
     230           0 :                 "cannot find " + pathRepresentation_, 0);
     231             :                 // RootAccess::queryInterface indirectly calls
     232             :                 // RootAccess::getNode, so if this RootAccess were passed out in
     233             :                 // RuntimeException.Context, client code that called
     234             :                 // queryInterface on it would cause trouble; therefore,
     235             :                 // RuntimeException.Context is left null here
     236             :         }
     237       66569 :         pathRepresentation_ = canonic;
     238             :         assert(!path_.empty() || node_->kind() == Node::KIND_ROOT);
     239       66569 :         if (!path_.empty()) {
     240       63349 :             name_ = path_.back();
     241             :         }
     242       66569 :         finalized_ = finalizedLayer != Data::NO_LAYER;
     243             :     }
     244     6828183 :     return node_;
     245             : }
     246             : 
     247      240554 : bool RootAccess::isFinalized() {
     248      240554 :     getNode();
     249      240554 :     return finalized_;
     250             : }
     251             : 
     252           0 : OUString RootAccess::getNameInternal() {
     253           0 :     getNode();
     254           0 :     return name_;
     255             : }
     256             : 
     257     1750126 : rtl::Reference< RootAccess > RootAccess::getRootAccess() {
     258     1750126 :     return this;
     259             : }
     260             : 
     261      166134 : rtl::Reference< Access > RootAccess::getParentAccess() {
     262      166134 :     return rtl::Reference< Access >();
     263             : }
     264             : 
     265           0 : void RootAccess::addTypes(std::vector< css::uno::Type > * types) const {
     266             :     assert(types != 0);
     267           0 :     types->push_back(cppu::UnoType< css::util::XChangesNotifier >::get());
     268           0 :     types->push_back(cppu::UnoType< css::util::XChangesBatch >::get());
     269           0 : }
     270             : 
     271        1087 : void RootAccess::addSupportedServiceNames(
     272             :     std::vector< OUString > * services)
     273             : {
     274             :     assert(services != 0);
     275        1087 :     services->push_back("com.sun.star.configuration.AccessRootElement");
     276        1087 :     if (update_) {
     277        1042 :         services->push_back("com.sun.star.configuration.UpdateRootElement");
     278             :     }
     279        1087 : }
     280             : 
     281           0 : void RootAccess::initDisposeBroadcaster(Broadcaster * broadcaster) {
     282             :     assert(broadcaster != 0);
     283           0 :     for (ChangesListeners::iterator i(changesListeners_.begin());
     284           0 :          i != changesListeners_.end(); ++i)
     285             :     {
     286             :         broadcaster->addDisposeNotification(
     287           0 :             i->get(),
     288           0 :             css::lang::EventObject(static_cast< cppu::OWeakObject * >(this)));
     289             :     }
     290           0 :     Access::initDisposeBroadcaster(broadcaster);
     291           0 : }
     292             : 
     293           0 : void RootAccess::clearListeners() throw() {
     294           0 :     changesListeners_.clear();
     295           0 :     Access::clearListeners();
     296           0 : }
     297             : 
     298      339387 : css::uno::Any RootAccess::queryInterface(css::uno::Type const & aType)
     299             :     throw (css::uno::RuntimeException, std::exception)
     300             : {
     301             :     assert(thisIs(IS_ANY));
     302      339387 :     osl::MutexGuard g(*lock_);
     303      339387 :     checkLocalizedPropertyAccess();
     304      339387 :     css::uno::Any res(Access::queryInterface(aType));
     305      339387 :     if (res.hasValue()) {
     306      285953 :         return res;
     307             :     }
     308      106868 :     res = cppu::queryInterface(
     309       53434 :         aType, static_cast< css::util::XChangesNotifier * >(this));
     310       53434 :     if (res.hasValue()) {
     311       28099 :         return res;
     312             :     }
     313       25335 :     if (!res.hasValue() && update_) {
     314       47516 :         res = cppu::queryInterface(
     315       23758 :             aType, static_cast< css::util::XChangesBatch * >(this));
     316             :     }
     317       25335 :     return res;
     318             : }
     319             : 
     320           0 : OUString RootAccess::getImplementationName()
     321             :     throw (css::uno::RuntimeException, std::exception)
     322             : {
     323             :     assert(thisIs(IS_ANY));
     324           0 :     osl::MutexGuard g(*lock_);
     325           0 :     checkLocalizedPropertyAccess();
     326           0 :     return OUString("configmgr.RootAccess");
     327             : }
     328             : 
     329             : }
     330             : 
     331             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10