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

Generated by: LCOV version 1.10