LCOV - code coverage report
Current view: top level - configmgr/source - childaccess.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 143 154 92.9 %
Date: 2012-08-25 Functions: 26 28 92.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 114 215 53.0 %

           Branch data     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/container/XChild.hpp"
      26                 :            : #include "com/sun/star/lang/NoSupportException.hpp"
      27                 :            : #include "com/sun/star/lang/XUnoTunnel.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/Sequence.hxx"
      32                 :            : #include "com/sun/star/uno/Type.hxx"
      33                 :            : #include "com/sun/star/uno/XInterface.hpp"
      34                 :            : #include "cppu/unotype.hxx"
      35                 :            : #include "cppuhelper/queryinterface.hxx"
      36                 :            : #include "cppuhelper/weak.hxx"
      37                 :            : #include "comphelper/servicehelper.hxx"
      38                 :            : #include "osl/mutex.hxx"
      39                 :            : #include "rtl/ref.hxx"
      40                 :            : #include "rtl/string.h"
      41                 :            : #include "rtl/ustrbuf.hxx"
      42                 :            : #include "rtl/ustring.h"
      43                 :            : #include "rtl/ustring.hxx"
      44                 :            : #include "sal/types.h"
      45                 :            : 
      46                 :            : #include "access.hxx"
      47                 :            : #include "childaccess.hxx"
      48                 :            : #include "components.hxx"
      49                 :            : #include "data.hxx"
      50                 :            : #include "groupnode.hxx"
      51                 :            : #include "localizedpropertynode.hxx"
      52                 :            : #include "localizedvaluenode.hxx"
      53                 :            : #include "lock.hxx"
      54                 :            : #include "modifications.hxx"
      55                 :            : #include "node.hxx"
      56                 :            : #include "path.hxx"
      57                 :            : #include "propertynode.hxx"
      58                 :            : #include "rootaccess.hxx"
      59                 :            : #include "setnode.hxx"
      60                 :            : #include "type.hxx"
      61                 :            : 
      62                 :            : namespace configmgr {
      63                 :            : 
      64                 :            : namespace {
      65                 :            : 
      66                 :            : namespace css = com::sun::star;
      67                 :            : 
      68                 :            : }
      69                 :            : 
      70                 :            : namespace
      71                 :            : {
      72                 :            :     class theChildAccessUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theChildAccessUnoTunnelId > {};
      73                 :            : }
      74                 :            : 
      75                 :       3806 : css::uno::Sequence< sal_Int8 > ChildAccess::getTunnelId()
      76                 :            : {
      77                 :       3806 :     return theChildAccessUnoTunnelId::get().getSeq();
      78                 :            : }
      79                 :            : 
      80                 :    4899804 : ChildAccess::ChildAccess(
      81                 :            :     Components & components, rtl::Reference< RootAccess > const & root,
      82                 :            :     rtl::Reference< Access > const & parent, rtl::OUString const & name,
      83                 :            :     rtl::Reference< Node > const & node):
      84                 :            :     Access(components), root_(root), parent_(parent), name_(name), node_(node),
      85 [ +  - ][ +  - ]:    4899804 :     inTransaction_(false)
      86                 :            : {
      87 [ +  - ][ +  - ]:    4899804 :     lock_ = lock();
                 [ +  - ]
      88                 :            :     assert(root.is() && parent.is() && node.is());
      89                 :    4899804 : }
      90                 :            : 
      91                 :       1838 : ChildAccess::ChildAccess(
      92                 :            :     Components & components, rtl::Reference< RootAccess > const & root,
      93                 :            :     rtl::Reference< Node > const & node):
      94 [ +  - ][ +  - ]:       1838 :     Access(components), root_(root), node_(node), inTransaction_(false)
      95                 :            : {
      96 [ +  - ][ +  - ]:       1838 :     lock_ = lock();
                 [ +  - ]
      97                 :            :     assert(root.is() && node.is());
      98                 :       1838 : }
      99                 :            : 
     100                 :     358247 : Path ChildAccess::getAbsolutePath() {
     101                 :            :     assert(getParentAccess().is());
     102         [ +  - ]:     358247 :     Path path(getParentAccess()->getAbsolutePath());
     103         [ +  - ]:     358247 :     path.push_back(name_);
     104                 :     358247 :     return path;
     105                 :            : }
     106                 :            : 
     107                 :     248486 : Path ChildAccess::getRelativePath() {
     108         [ +  - ]:     248486 :     Path path;
     109         [ +  - ]:     248486 :     rtl::Reference< Access > parent(getParentAccess());
     110         [ +  + ]:     248486 :     if (parent.is()) {
     111         [ +  - ]:     248268 :         path = parent->getRelativePath();
     112                 :            :     }
     113         [ +  - ]:     248486 :     path.push_back(name_);
     114                 :     248486 :     return path;
     115                 :            : }
     116                 :            : 
     117                 :     118145 : rtl::OUString ChildAccess::getRelativePathRepresentation() {
     118                 :     118145 :     rtl::OUStringBuffer path;
     119         [ +  - ]:     118145 :     rtl::Reference< Access > parent(getParentAccess());
     120         [ +  - ]:     118145 :     if (parent.is()) {
     121 [ +  - ][ +  - ]:     118145 :         path.append(parent->getRelativePathRepresentation());
     122         [ +  + ]:     118145 :         if (path.getLength() != 0) {
     123         [ +  - ]:      69445 :             path.append(sal_Unicode('/'));
     124                 :            :         }
     125                 :            :     }
     126 [ +  - ][ +  - ]:     118145 :     path.append(Data::createSegment(node_->getTemplateName(), name_));
                 [ +  - ]
     127         [ +  - ]:     118145 :     return path.makeStringAndClear();
     128                 :            : }
     129                 :            : 
     130                 :   14163360 : rtl::Reference< Node > ChildAccess::getNode() {
     131                 :   14163360 :     return node_;
     132                 :            : }
     133                 :            : 
     134                 :     572417 : bool ChildAccess::isFinalized() {
     135                 :     572417 :     return node_->getFinalized() != Data::NO_LAYER ||
     136 [ +  + ][ -  + ]:     572417 :         (parent_.is() && parent_->isFinalized());
                 [ +  - ]
     137                 :            : }
     138                 :            : 
     139                 :    1750078 : rtl::OUString ChildAccess::getNameInternal() {
     140                 :    1750078 :     return name_;
     141                 :            : }
     142                 :            : 
     143                 :    4808307 : rtl::Reference< RootAccess > ChildAccess::getRootAccess() {
     144                 :    4808307 :     return root_;
     145                 :            : }
     146                 :            : 
     147                 :    1534462 : rtl::Reference< Access > ChildAccess::getParentAccess() {
     148                 :    1534462 :     return parent_;
     149                 :            : }
     150                 :            : 
     151                 :   27041218 : void ChildAccess::acquire() throw () {
     152                 :   27041218 :     Access::acquire();
     153                 :   27041217 : }
     154                 :            : 
     155                 :   27040918 : void ChildAccess::release() throw () {
     156                 :   27040918 :     Access::release();
     157                 :   27040918 : }
     158                 :            : 
     159                 :          0 : css::uno::Reference< css::uno::XInterface > ChildAccess::getParent()
     160                 :            :     throw (css::uno::RuntimeException)
     161                 :            : {
     162                 :            :     assert(thisIs(IS_ANY));
     163         [ #  # ]:          0 :     osl::MutexGuard g(*lock_);
     164         [ #  # ]:          0 :     checkLocalizedPropertyAccess();
     165 [ #  # ][ #  # ]:          0 :     return static_cast< cppu::OWeakObject * >(parent_.get());
     166                 :            : }
     167                 :            : 
     168                 :          0 : void ChildAccess::setParent(css::uno::Reference< css::uno::XInterface > const &)
     169                 :            :     throw (css::lang::NoSupportException, css::uno::RuntimeException)
     170                 :            : {
     171                 :            :     assert(thisIs(IS_ANY));
     172         [ #  # ]:          0 :     osl::MutexGuard g(*lock_);
     173         [ #  # ]:          0 :     checkLocalizedPropertyAccess();
     174                 :            :     throw css::lang::NoSupportException(
     175                 :            :         rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("setParent")),
     176 [ #  # ][ #  # ]:          0 :         static_cast< cppu::OWeakObject * >(this));
                 [ #  # ]
     177                 :            : }
     178                 :            : 
     179                 :       1968 : sal_Int64 ChildAccess::getSomething(
     180                 :            :     css::uno::Sequence< sal_Int8 > const & aIdentifier)
     181                 :            :     throw (css::uno::RuntimeException)
     182                 :            : {
     183                 :            :     assert(thisIs(IS_ANY));
     184         [ +  - ]:       1968 :     osl::MutexGuard g(*lock_);
     185         [ +  - ]:       1968 :     checkLocalizedPropertyAccess();
     186 [ +  - ][ +  - ]:       3936 :     return aIdentifier == getTunnelId()
                 [ +  - ]
     187 [ +  + ][ +  - ]:       3936 :         ? reinterpret_cast< sal_Int64 >(this) : 0;
     188                 :            : }
     189                 :            : 
     190                 :       1838 : void ChildAccess::bind(
     191                 :            :     rtl::Reference< RootAccess > const & root,
     192                 :            :     rtl::Reference< Access > const & parent, rtl::OUString const & name)
     193                 :            :     throw ()
     194                 :            : {
     195                 :            :     assert(!parent_.is() && root.is() && parent.is() && !name.isEmpty());
     196                 :       1838 :     root_ = root;
     197                 :       1838 :     parent_ = parent;
     198                 :       1838 :     name_ = name;
     199                 :       1838 : }
     200                 :            : 
     201                 :        579 : void ChildAccess::unbind() throw () {
     202                 :            :     assert(parent_.is());
     203                 :        579 :     parent_->releaseChild(name_);
     204                 :        579 :     parent_.clear();
     205                 :        579 :     inTransaction_ = true;
     206                 :        579 : }
     207                 :            : 
     208                 :     148673 : void ChildAccess::committed() {
     209                 :     148673 :     inTransaction_ = false;
     210                 :     148673 : }
     211                 :            : 
     212                 :      22820 : void ChildAccess::setNode(rtl::Reference< Node > const & node) {
     213                 :      22820 :     node_ = node;
     214                 :      22820 : }
     215                 :            : 
     216                 :      94161 : void ChildAccess::setProperty(
     217                 :            :     css::uno::Any const & value, Modifications * localModifications)
     218                 :            : {
     219                 :            :     assert(localModifications != 0);
     220                 :      94161 :     Type type = TYPE_ERROR;
     221                 :      94161 :     bool nillable = false;
     222   [ +  +  +  - ]:      94161 :     switch (node_->kind()) {
     223                 :            :     case Node::KIND_PROPERTY:
     224                 :            :         {
     225         [ -  + ]:      86865 :             PropertyNode * prop = dynamic_cast< PropertyNode * >(node_.get());
     226                 :      86865 :             type = prop->getStaticType();
     227                 :      86865 :             nillable = prop->isNillable();
     228                 :            :         }
     229                 :      86865 :         break;
     230                 :            :     case Node::KIND_LOCALIZED_PROPERTY:
     231                 :            :         {
     232 [ +  - ][ +  - ]:       3648 :             rtl::OUString locale(getRootAccess()->getLocale());
     233 [ +  - ][ +  - ]:       3648 :             if (!Components::allLocales(locale)) {
     234         [ +  - ]:       3648 :                 rtl::Reference< ChildAccess > child(getChild(locale));
     235         [ +  - ]:       3648 :                 if (child.is()) {
     236         [ +  - ]:       3648 :                     child->setProperty(value, localModifications);
     237                 :            :                 } else {
     238                 :            :                     insertLocalizedValueChild(
     239         [ #  # ]:          0 :                         locale, value, localModifications);
     240                 :            :                 }
     241                 :      97809 :                 return;
     242         [ -  + ]:       3648 :             }
     243                 :            :         }
     244                 :       3648 :         break;
     245                 :            :     case Node::KIND_LOCALIZED_VALUE:
     246                 :            :         {
     247                 :            :             LocalizedPropertyNode * locprop =
     248         [ -  + ]:       3648 :                 dynamic_cast< LocalizedPropertyNode * >(getParentNode().get());
     249                 :       3648 :             type = locprop->getStaticType();
     250                 :       3648 :             nillable = locprop->isNillable();
     251                 :            :         }
     252                 :       3648 :         break;
     253                 :            :     default:
     254                 :          0 :         break;
     255                 :            :     }
     256                 :      90513 :     checkValue(value, type, nillable);
     257 [ +  - ][ +  - ]:      90513 :     getParentAccess()->markChildAsModified(this);
     258                 :      90513 :     changedValue_.reset(new css::uno::Any(value));
     259         [ +  - ]:      90513 :     localModifications->add(getRelativePath());
     260                 :            : }
     261                 :            : 
     262                 :    2736934 : css::uno::Any ChildAccess::asValue() {
     263         [ +  + ]:    2736934 :     if (changedValue_.get() != 0) {
     264                 :      19564 :         return *changedValue_;
     265                 :            :     }
     266   [ +  +  +  + ]:    2717370 :     switch (node_->kind()) {
     267                 :            :     case Node::KIND_PROPERTY:
     268                 :    1698643 :         return dynamic_cast< PropertyNode * >(node_.get())->getValue(
     269         [ -  + ]:    3397286 :             getComponents());
     270                 :            :     case Node::KIND_LOCALIZED_PROPERTY:
     271                 :            :         {
     272 [ +  - ][ +  - ]:     303856 :             OUString locale(getRootAccess()->getLocale());
     273 [ +  + ][ +  - ]:     303856 :             if (!Components::allLocales(locale)) {
     274         [ +  - ]:     164603 :                 rtl::Reference< ChildAccess > child(getChild("*" + locale));
     275                 :            :                 // As a last resort, return a nil value even though it may be
     276                 :            :                 // illegal for the given property:
     277 [ +  - ][ +  + ]:     303856 :                 return child.is() ? child->asValue() : css::uno::Any();
     278         [ +  + ]:     303856 :             }
     279                 :            :         }
     280                 :     303856 :         break;
     281                 :            :     case Node::KIND_LOCALIZED_VALUE:
     282         [ -  + ]:     214328 :         return dynamic_cast< LocalizedValueNode * >(node_.get())->getValue();
     283                 :            :     default:
     284                 :     500543 :         break;
     285                 :            :     }
     286                 :            :     return css::uno::makeAny(
     287                 :            :         css::uno::Reference< css::uno::XInterface >(
     288         [ +  - ]:    2736934 :             static_cast< cppu::OWeakObject * >(this)));
     289                 :            : }
     290                 :            : 
     291                 :     148094 : void ChildAccess::commitChanges(bool valid, Modifications * globalModifications)
     292                 :            : {
     293                 :            :     assert(globalModifications != 0);
     294                 :     148094 :     commitChildChanges(valid, globalModifications);
     295 [ +  + ][ +  + ]:     148094 :     if (valid && changedValue_.get() != 0) {
                 [ +  - ]
     296         [ +  - ]:      90513 :         Path path(getAbsolutePath());
     297 [ +  - ][ +  - ]:      90513 :         getComponents().addModification(path);
     298         [ +  - ]:      90513 :         globalModifications->add(path);
     299         [ +  - ]:      90513 :         switch (node_->kind()) {
              [ +  +  - ]
     300                 :            :         case Node::KIND_PROPERTY:
     301                 :      86865 :             dynamic_cast< PropertyNode * >(node_.get())->setValue(
     302 [ -  + ][ +  - ]:     173730 :                 Data::NO_LAYER, *changedValue_);
     303                 :      86865 :             break;
     304                 :            :         case Node::KIND_LOCALIZED_VALUE:
     305                 :       3648 :             dynamic_cast< LocalizedValueNode * >(node_.get())->setValue(
     306 [ -  + ][ +  - ]:       7296 :                 Data::NO_LAYER, *changedValue_);
     307                 :       3648 :             break;
     308                 :            :         default:
     309                 :            :             assert(false); // this cannot happen
     310                 :          0 :             break;
     311                 :      90513 :         }
     312                 :            :     }
     313                 :     148094 :     changedValue_.reset();
     314                 :     148094 : }
     315                 :            : 
     316 [ +  - ][ +  - ]:    4901342 : ChildAccess::~ChildAccess() {
     317         [ +  - ]:    4901342 :     osl::MutexGuard g(*lock_);
     318         [ +  + ]:    4901342 :     if (parent_.is()) {
     319         [ +  - ]:    4900763 :         parent_->releaseChild(name_);
     320         [ +  - ]:    4901342 :     }
     321         [ -  + ]:    9802684 : }
     322                 :            : 
     323                 :        130 : void ChildAccess::addTypes(std::vector< css::uno::Type > * types) const {
     324                 :            :     assert(types != 0);
     325                 :        130 :     types->push_back(cppu::UnoType< css::container::XChild >::get());
     326                 :        130 :     types->push_back(cppu::UnoType< css::lang::XUnoTunnel >::get());
     327                 :        130 : }
     328                 :            : 
     329                 :       3935 : void ChildAccess::addSupportedServiceNames(
     330                 :            :     std::vector< rtl::OUString > * services)
     331                 :            : {
     332                 :            :     assert(services != 0);
     333                 :            :     services->push_back(
     334         [ +  - ]:       7870 :         getParentNode()->kind() == Node::KIND_GROUP
     335                 :            :         ? rtl::OUString(
     336                 :            :             RTL_CONSTASCII_USTRINGPARAM(
     337                 :            :                 "com.sun.star.configuration.GroupElement"))
     338                 :            :         : rtl::OUString(
     339                 :            :             RTL_CONSTASCII_USTRINGPARAM(
     340 [ +  + ][ +  - ]:       3935 :                 "com.sun.star.configuration.SetElement")));
         [ +  - ][ +  - ]
     341                 :       3935 : }
     342                 :            : 
     343                 :     679734 : css::uno::Any ChildAccess::queryInterface(css::uno::Type const & aType)
     344                 :            :     throw (css::uno::RuntimeException)
     345                 :            : {
     346                 :            :     assert(thisIs(IS_ANY));
     347         [ +  - ]:     679734 :     osl::MutexGuard g(*lock_);
     348         [ +  - ]:     679734 :     checkLocalizedPropertyAccess();
     349         [ +  - ]:     679734 :     css::uno::Any res(Access::queryInterface(aType));
     350                 :     679734 :     return res.hasValue()
     351                 :            :         ? res
     352                 :            :         : cppu::queryInterface(
     353                 :            :             aType, static_cast< css::container::XChild * >(this),
     354 [ +  - ][ +  - ]:     679734 :             static_cast< css::lang::XUnoTunnel * >(this));
                 [ +  + ]
     355                 :            : }
     356                 :            : 
     357                 :            : }
     358                 :            : 
     359                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10