LCOV - code coverage report
Current view: top level - filter/source/config/cache - cacheupdatelistener.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 21 75 28.0 %
Date: 2014-04-11 Functions: 5 7 71.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             : 
      21             : #include "cacheupdatelistener.hxx"
      22             : #include "constant.hxx"
      23             : 
      24             : #include <com/sun/star/util/XChangesNotifier.hpp>
      25             : #include <com/sun/star/util/XRefreshable.hpp>
      26             : #include <com/sun/star/document/FilterConfigRefresh.hpp>
      27             : #include <salhelper/singletonref.hxx>
      28             : #include <unotools/configpaths.hxx>
      29             : #include <rtl/ustring.hxx>
      30             : #include <comphelper/processfactory.hxx>
      31             : 
      32             : 
      33             : namespace filter{
      34             :     namespace config{
      35             : 
      36         149 : CacheUpdateListener::CacheUpdateListener(FilterCache &rFilterCache,
      37             :                                          const css::uno::Reference< css::uno::XInterface >& xConfigAccess,
      38             :                                          FilterCache::EItemType eConfigType)
      39             :     : BaseLock()
      40             :     , m_rCache(rFilterCache)
      41             :     , m_xConfig(xConfigAccess)
      42         149 :     , m_eConfigType(eConfigType)
      43             : {
      44         149 : }
      45             : 
      46         298 : CacheUpdateListener::~CacheUpdateListener()
      47             : {
      48         298 : }
      49             : 
      50         149 : void CacheUpdateListener::startListening()
      51             : {
      52             :     // SAFE ->
      53         149 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      54         298 :     css::uno::Reference< css::util::XChangesNotifier > xNotifier(m_xConfig, css::uno::UNO_QUERY);
      55         149 :     aLock.clear();
      56             :     // <- SAFE
      57             : 
      58         149 :     if (!xNotifier.is())
      59         149 :         return;
      60             : 
      61         298 :     css::uno::Reference< css::util::XChangesListener > xThis(static_cast< css::util::XChangesListener* >(this), css::uno::UNO_QUERY_THROW);
      62         298 :     xNotifier->addChangesListener(xThis);
      63             : }
      64             : 
      65             : 
      66             : 
      67         149 : void CacheUpdateListener::stopListening()
      68             : {
      69             :     // SAFE ->
      70         149 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      71         298 :     css::uno::Reference< css::util::XChangesNotifier > xNotifier(m_xConfig, css::uno::UNO_QUERY);
      72         149 :     aLock.clear();
      73             :     // <- SAFE
      74             : 
      75         149 :     if (!xNotifier.is())
      76         149 :         return;
      77             : 
      78         298 :     css::uno::Reference< css::util::XChangesListener > xThis(static_cast< css::util::XChangesListener* >(this), css::uno::UNO_QUERY);
      79         298 :     xNotifier->removeChangesListener(xThis);
      80             : }
      81             : 
      82             : 
      83             : 
      84           0 : void SAL_CALL  CacheUpdateListener::changesOccurred(const css::util::ChangesEvent& aEvent)
      85             :     throw(css::uno::RuntimeException, std::exception)
      86             : {
      87             :     // SAFE ->
      88           0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      89             : 
      90             :     // disposed ?
      91           0 :     if ( ! m_xConfig.is())
      92           0 :         return;
      93             : 
      94           0 :     FilterCache::EItemType                             eType = m_eConfigType;
      95             : 
      96           0 :     aLock.clear();
      97             :     // <- SAFE
      98             : 
      99           0 :     OUStringList lChangedItems;
     100           0 :     sal_Int32    c = aEvent.Changes.getLength();
     101           0 :     sal_Int32    i = 0;
     102             : 
     103           0 :     for (i=0; i<c; ++i)
     104             :     {
     105           0 :         const css::util::ElementChange& aChange = aEvent.Changes[i];
     106             : 
     107           0 :         OUString sOrgPath ;
     108           0 :         OUString sTempPath;
     109             : 
     110           0 :         OUString sProperty;
     111           0 :         OUString sNode    ;
     112           0 :         OUString sLocale  ;
     113             : 
     114             :         /*  at least we must be able to retrieve 2 path elements
     115             :             But sometimes the original path can contain 3 of them ... in case
     116             :             a localized value was changed.
     117             :             =>
     118             :             1) Filters/Filter["filtername"]/Property
     119             :             2) Filters/Filter["filtername"]/LocalizedProperty/Locale
     120             :         */
     121             : 
     122           0 :         aChange.Accessor >>= sOrgPath;
     123           0 :         if ( ! ::utl::splitLastFromConfigurationPath(sOrgPath, sTempPath, sLocale))
     124           0 :             continue;
     125           0 :         sOrgPath = sTempPath;
     126           0 :         if ( ! ::utl::splitLastFromConfigurationPath(sOrgPath, sTempPath, sProperty))
     127             :         {
     128           0 :             sNode     = sLocale;
     129           0 :             sProperty = OUString();
     130           0 :             sLocale   = OUString();
     131             :         }
     132             :         else
     133             :         {
     134           0 :             sOrgPath = sTempPath;
     135           0 :             if ( ! ::utl::splitLastFromConfigurationPath(sOrgPath, sTempPath, sNode))
     136             :             {
     137           0 :                 sNode     = sProperty;
     138           0 :                 sProperty = sLocale;
     139           0 :                 sLocale   = OUString();
     140             :             }
     141             :         }
     142             : 
     143           0 :         if ( sNode.isEmpty() )
     144           0 :             continue;
     145             : 
     146           0 :         OUStringList::const_iterator pIt = ::std::find(lChangedItems.begin(), lChangedItems.end(), sNode);
     147           0 :         if (pIt == lChangedItems.end())
     148           0 :             lChangedItems.push_back(sNode);
     149           0 :     }
     150             : 
     151           0 :     sal_Bool                     bNotifyRefresh = sal_False;
     152           0 :     OUStringList::const_iterator pIt;
     153           0 :     for (  pIt  = lChangedItems.begin();
     154           0 :            pIt != lChangedItems.end()  ;
     155             :          ++pIt                         )
     156             :     {
     157           0 :         const OUString& sItem = *pIt;
     158             :         try
     159             :         {
     160           0 :             m_rCache.refreshItem(eType, sItem);
     161             :         }
     162           0 :         catch(const css::container::NoSuchElementException&)
     163             :             {
     164             :                 // can be ignored! Because we must be aware that
     165             :                 // sItem was removed from the configuration and we forced an update of the cache.
     166             :                 // But we know, that the cache is up-to-date know and has thrown this exception afterwards .-)
     167             :             }
     168             :         // NO FLUSH! Otherwise we start a never ending story here .-)
     169           0 :         bNotifyRefresh = sal_True;
     170             :     }
     171             : 
     172             :     // notify sfx cache about the changed filter cache .-)
     173           0 :     if (bNotifyRefresh)
     174             :     {
     175           0 :         css::uno::Reference< css::uno::XComponentContext > xContext = comphelper::getProcessComponentContext();
     176             :         css::uno::Reference< css::util::XRefreshable > xRefreshBroadcaster =
     177           0 :             css::document::FilterConfigRefresh::create(xContext);
     178           0 :         xRefreshBroadcaster->refresh();
     179           0 :     }
     180             : }
     181             : 
     182             : 
     183             : 
     184           0 : void SAL_CALL CacheUpdateListener::disposing(const css::lang::EventObject& aEvent)
     185             :     throw(css::uno::RuntimeException, std::exception)
     186             : {
     187             :     // SAFE ->
     188           0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     189           0 :     if (aEvent.Source == m_xConfig)
     190           0 :         m_xConfig.clear();
     191           0 :     aLock.clear();
     192             :     // <- SAFE
     193           0 : }
     194             : 
     195             :     } // namespace config
     196             : } // namespace filter
     197             : 
     198             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10