LCOV - code coverage report
Current view: top level - configmgr/source - rootaccess.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 114 148 77.0 %
Date: 2015-06-13 12:38:46 Functions: 21 27 77.8 %
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/sequence.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    26826746 : RootAccess::RootAccess(
      61             :     Components & components, OUString const & pathRepresentation,
      62             :     OUString const & locale, bool update):
      63             :     Access(components), pathRepresentation_(pathRepresentation),
      64    26826746 :     locale_(locale), update_(update), finalized_(false), alive_(true)
      65             : {
      66    26826746 :     lock_ = lock();
      67    26826746 : }
      68             : 
      69     2693403 : Path RootAccess::getAbsolutePath() {
      70     2693403 :     getNode();
      71     2693403 :     return path_;
      72             : }
      73             : 
      74      281027 : void RootAccess::initBroadcaster(
      75             :     Modifications::Node const & modifications, Broadcaster * broadcaster)
      76             : {
      77             :     assert(broadcaster != 0);
      78      281027 :     std::vector< css::util::ElementChange > changes;
      79             :     initBroadcasterAndChanges(
      80      281027 :         modifications, broadcaster, changesListeners_.empty() ? 0 : &changes);
      81      281027 :     if (!changes.empty()) {
      82        8060 :         css::util::ChangesSet set(comphelper::containerToSequence(changes));
      83       48360 :         for (ChangesListeners::iterator i(changesListeners_.begin());
      84       32240 :              i != changesListeners_.end(); ++i)
      85             :         {
      86        8060 :             cppu::OWeakObject* pSource = static_cast< cppu::OWeakObject * >(this);
      87        8060 :             css::uno::Reference< css::uno::XInterface > xBase( pSource, css::uno::UNO_QUERY );
      88             :             broadcaster->addChangesNotification(
      89        8060 :                 *i,
      90             :                 css::util::ChangesEvent(
      91       16120 :                     pSource, makeAny( xBase ), set));
      92       16120 :         }
      93      281027 :     }
      94      281027 : }
      95             : 
      96   428001707 : void RootAccess::acquire() throw () {
      97   428001707 :     Access::acquire();
      98   428001707 : }
      99             : 
     100   427999095 : void RootAccess::release() throw () {
     101   427999095 :     Access::release();
     102   427999095 : }
     103             : 
     104           0 : OUString RootAccess::getAbsolutePathRepresentation() {
     105           0 :     getNode(); // turn pathRepresentation_ into canonic form
     106           0 :     return pathRepresentation_;
     107             : }
     108             : 
     109             : 
     110             : 
     111        1816 : void RootAccess::setAlive(bool b) {
     112        1816 :     alive_ = b;
     113        1816 : }
     114             : 
     115       15116 : 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       15116 :         osl::MutexGuard g(*lock_);
     122       15116 :         checkLocalizedPropertyAccess();
     123       15116 :         if (!aListener.is()) {
     124             :             throw css::uno::RuntimeException(
     125           0 :                 "null listener", static_cast< cppu::OWeakObject * >(this));
     126             :         }
     127       15116 :         if (!isDisposed()) {
     128       15116 :             changesListeners_.insert(aListener);
     129       30232 :             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       13854 : 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       13854 :     osl::MutexGuard g(*lock_);
     144       13854 :     checkLocalizedPropertyAccess();
     145       13854 :     ChangesListeners::iterator i(changesListeners_.find(aListener));
     146       13854 :     if (i != changesListeners_.end()) {
     147       12545 :         changesListeners_.erase(i);
     148       13854 :     }
     149       13854 : }
     150             : 
     151       37476 : void RootAccess::commitChanges()
     152             :     throw (css::lang::WrappedTargetException,
     153             :            css::uno::RuntimeException,
     154             :            std::exception)
     155             : {
     156             :     assert(thisIs(IS_UPDATE));
     157       37476 :     if (!alive_)
     158             :     {
     159       37476 :         return;
     160             :     }
     161       37476 :     Broadcaster bc;
     162             :     {
     163       37476 :         osl::MutexGuard g(*lock_);
     164             : 
     165       37476 :         checkLocalizedPropertyAccess();
     166             :         int finalizedLayer;
     167       74952 :         Modifications globalMods;
     168             :         commitChildChanges(
     169       37476 :             ((getComponents().resolvePathRepresentation(
     170             :                   pathRepresentation_, 0, 0, &finalizedLayer)
     171      187380 :               == node_) &&
     172       37476 :              finalizedLayer == Data::NO_LAYER),
     173       37476 :             &globalMods);
     174       37476 :         getComponents().writeModifications();
     175       74952 :         getComponents().initGlobalBroadcaster(globalMods, this, &bc);
     176             :     }
     177       37476 :     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 :     std::vector< css::util::ElementChange > changes;
     197           0 :     reportChildChanges(&changes);
     198           0 :     return comphelper::containerToSequence(changes);
     199             : }
     200             : 
     201    80474790 : RootAccess::~RootAccess()
     202             : {
     203    26824930 :     osl::MutexGuard g(*lock_);
     204    26824930 :     if (alive_)
     205    26824930 :         getComponents().removeRootAccess(this);
     206    53649860 : }
     207             : 
     208      113973 : Path RootAccess::getRelativePath() {
     209      113973 :     return Path();
     210             : }
     211             : 
     212       10204 : OUString RootAccess::getRelativePathRepresentation() {
     213       10204 :     return OUString();
     214             : }
     215             : 
     216   330451704 : rtl::Reference< Node > RootAccess::getNode() {
     217   330451704 :     if (!node_.is()) {
     218    26822845 :         OUString canonic;
     219             :         int finalizedLayer;
     220    53645690 :         node_ = getComponents().resolvePathRepresentation(
     221    26822845 :             pathRepresentation_, &canonic, &path_, &finalizedLayer);
     222    26822845 :         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    26822845 :         pathRepresentation_ = canonic;
     232             :         assert(!path_.empty() || node_->kind() == Node::KIND_ROOT);
     233    26822845 :         if (!path_.empty()) {
     234    26817660 :             name_ = path_.back();
     235             :         }
     236    26822845 :         finalized_ = finalizedLayer != Data::NO_LAYER;
     237             :     }
     238   330451704 :     return node_;
     239             : }
     240             : 
     241      365252 : bool RootAccess::isFinalized() {
     242      365252 :     getNode();
     243      365252 :     return finalized_;
     244             : }
     245             : 
     246           0 : OUString RootAccess::getNameInternal() {
     247           0 :     getNode();
     248           0 :     return name_;
     249             : }
     250             : 
     251    55376052 : rtl::Reference< RootAccess > RootAccess::getRootAccess() {
     252    55376052 :     return this;
     253             : }
     254             : 
     255      228066 : rtl::Reference< Access > RootAccess::getParentAccess() {
     256      228066 :     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        1740 : void RootAccess::addSupportedServiceNames(
     266             :     std::vector< OUString > * services)
     267             : {
     268             :     assert(services != 0);
     269        1740 :     services->push_back("com.sun.star.configuration.AccessRootElement");
     270        1740 :     if (update_) {
     271        1350 :         services->push_back("com.sun.star.configuration.UpdateRootElement");
     272             :     }
     273        1740 : }
     274             : 
     275         121 : void RootAccess::initDisposeBroadcaster(Broadcaster * broadcaster) {
     276             :     assert(broadcaster != 0);
     277         363 :     for (ChangesListeners::iterator i(changesListeners_.begin());
     278         242 :          i != changesListeners_.end(); ++i)
     279             :     {
     280             :         broadcaster->addDisposeNotification(
     281           0 :             i->get(),
     282           0 :             css::lang::EventObject(static_cast< cppu::OWeakObject * >(this)));
     283             :     }
     284         121 :     Access::initDisposeBroadcaster(broadcaster);
     285         121 : }
     286             : 
     287         121 : void RootAccess::clearListeners() throw() {
     288         121 :     changesListeners_.clear();
     289         121 :     Access::clearListeners();
     290         121 : }
     291             : 
     292    53983417 : css::uno::Any RootAccess::queryInterface(css::uno::Type const & aType)
     293             :     throw (css::uno::RuntimeException, std::exception)
     294             : {
     295             :     assert(thisIs(IS_ANY));
     296    53983417 :     osl::MutexGuard g(*lock_);
     297    53983417 :     checkLocalizedPropertyAccess();
     298    53983417 :     css::uno::Any res(Access::queryInterface(aType));
     299    53983417 :     if (res.hasValue()) {
     300    27180713 :         return res;
     301             :     }
     302    53605408 :     res = cppu::queryInterface(
     303    26802704 :         aType, static_cast< css::util::XChangesNotifier * >(this));
     304    26802704 :     if (res.hasValue()) {
     305       42665 :         return res;
     306             :     }
     307    26760039 :     if (!res.hasValue() && update_) {
     308    53514696 :         res = cppu::queryInterface(
     309    26757348 :             aType, static_cast< css::util::XChangesBatch * >(this));
     310             :     }
     311    26760039 :     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.11