LCOV - code coverage report
Current view: top level - filter/source/config/cache - cacheupdatelistener.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 77 27.3 %
Date: 2012-08-25 Functions: 5 7 71.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 23 132 17.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "cacheupdatelistener.hxx"
      31                 :            : #include "constant.hxx"
      32                 :            : 
      33                 :            : #include <com/sun/star/util/XChangesNotifier.hpp>
      34                 :            : #include <com/sun/star/util/XRefreshable.hpp>
      35                 :            : #include <salhelper/singletonref.hxx>
      36                 :            : #include <unotools/configpaths.hxx>
      37                 :            : #include <rtl/ustring.hxx>
      38                 :            : 
      39                 :            : 
      40                 :            : namespace filter{
      41                 :            :     namespace config{
      42                 :            : 
      43                 :            : namespace css = ::com::sun::star;
      44                 :            : 
      45                 :            : 
      46                 :            : 
      47                 :            : 
      48                 :        254 : CacheUpdateListener::CacheUpdateListener(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR,
      49                 :            :                                          FilterCache &rFilterCache,
      50                 :            :                                          const css::uno::Reference< css::uno::XInterface >& xConfigAccess,
      51                 :            :                                          FilterCache::EItemType eConfigType)
      52                 :            :     : BaseLock()
      53                 :            :     , m_xSMGR(xSMGR)
      54                 :            :     , m_rCache(rFilterCache)
      55                 :            :     , m_xConfig(xConfigAccess)
      56         [ +  - ]:        254 :     , m_eConfigType(eConfigType)
      57                 :            : {
      58                 :        254 : }
      59                 :            : 
      60         [ +  - ]:        254 : CacheUpdateListener::~CacheUpdateListener()
      61                 :            : {
      62         [ -  + ]:        508 : }
      63                 :            : 
      64                 :        254 : void CacheUpdateListener::startListening()
      65                 :            : {
      66                 :            :     // SAFE ->
      67         [ +  - ]:        254 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      68         [ +  - ]:        254 :     css::uno::Reference< css::util::XChangesNotifier > xNotifier(m_xConfig, css::uno::UNO_QUERY);
      69         [ +  - ]:        254 :     aLock.clear();
      70                 :            :     // <- SAFE
      71                 :            : 
      72         [ -  + ]:        254 :     if (!xNotifier.is())
      73                 :        254 :         return;
      74                 :            : 
      75         [ +  - ]:        254 :     css::uno::Reference< css::util::XChangesListener > xThis(static_cast< css::util::XChangesListener* >(this), css::uno::UNO_QUERY_THROW);
      76 [ +  - ][ +  - ]:        254 :     xNotifier->addChangesListener(xThis);
         [ -  + ][ +  - ]
                 [ +  - ]
      77                 :            : }
      78                 :            : 
      79                 :            : 
      80                 :            : 
      81                 :        254 : void CacheUpdateListener::stopListening()
      82                 :            : {
      83                 :            :     // SAFE ->
      84         [ +  - ]:        254 :     ::osl::ResettableMutexGuard aLock(m_aLock);
      85         [ +  - ]:        254 :     css::uno::Reference< css::util::XChangesNotifier > xNotifier(m_xConfig, css::uno::UNO_QUERY);
      86         [ +  - ]:        254 :     aLock.clear();
      87                 :            :     // <- SAFE
      88                 :            : 
      89         [ -  + ]:        254 :     if (!xNotifier.is())
      90                 :        254 :         return;
      91                 :            : 
      92         [ +  - ]:        254 :     css::uno::Reference< css::util::XChangesListener > xThis(static_cast< css::util::XChangesListener* >(this), css::uno::UNO_QUERY);
      93 [ +  - ][ +  - ]:        254 :     xNotifier->removeChangesListener(xThis);
         [ -  + ][ +  - ]
                 [ +  - ]
      94                 :            : }
      95                 :            : 
      96                 :            : 
      97                 :            : 
      98                 :          0 : void SAL_CALL  CacheUpdateListener::changesOccurred(const css::util::ChangesEvent& aEvent)
      99                 :            :     throw(css::uno::RuntimeException)
     100                 :            : {
     101                 :            :     // SAFE ->
     102         [ #  # ]:          0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     103                 :            : 
     104                 :            :     // disposed ?
     105         [ #  # ]:          0 :     if ( ! m_xConfig.is())
     106                 :          0 :         return;
     107                 :            : 
     108                 :          0 :     css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
     109                 :          0 :     FilterCache::EItemType                                 eType = m_eConfigType;
     110                 :            : 
     111         [ #  # ]:          0 :     aLock.clear();
     112                 :            :     // <- SAFE
     113                 :            : 
     114         [ #  # ]:          0 :     OUStringList lChangedItems;
     115                 :          0 :     sal_Int32    c = aEvent.Changes.getLength();
     116                 :          0 :     sal_Int32    i = 0;
     117                 :            : 
     118         [ #  # ]:          0 :     for (i=0; i<c; ++i)
     119                 :            :     {
     120                 :          0 :         const css::util::ElementChange& aChange = aEvent.Changes[i];
     121                 :            : 
     122                 :          0 :         ::rtl::OUString sOrgPath ;
     123                 :          0 :         ::rtl::OUString sTempPath;
     124                 :            : 
     125                 :          0 :         ::rtl::OUString sProperty;
     126                 :          0 :         ::rtl::OUString sNode    ;
     127                 :          0 :         ::rtl::OUString sLocale  ;
     128                 :            : 
     129                 :            :         /*  at least we must be able to retrieve 2 path elements
     130                 :            :             But sometimes the original path can contain 3 of them ... in case
     131                 :            :             a localized value was changed.
     132                 :            :             =>
     133                 :            :             1) Filters/Filter["filtername"]/Property
     134                 :            :             2) Filters/Filter["filtername"]/LocalizedProperty/Locale
     135                 :            :         */
     136                 :            : 
     137                 :          0 :         aChange.Accessor >>= sOrgPath;
     138 [ #  # ][ #  # ]:          0 :         if ( ! ::utl::splitLastFromConfigurationPath(sOrgPath, sTempPath, sLocale))
     139                 :          0 :             continue;
     140                 :          0 :         sOrgPath = sTempPath;
     141 [ #  # ][ #  # ]:          0 :         if ( ! ::utl::splitLastFromConfigurationPath(sOrgPath, sTempPath, sProperty))
     142                 :            :         {
     143                 :          0 :             sNode     = sLocale;
     144                 :          0 :             sProperty = ::rtl::OUString();
     145                 :          0 :             sLocale   = ::rtl::OUString();
     146                 :            :         }
     147                 :            :         else
     148                 :            :         {
     149                 :          0 :             sOrgPath = sTempPath;
     150 [ #  # ][ #  # ]:          0 :             if ( ! ::utl::splitLastFromConfigurationPath(sOrgPath, sTempPath, sNode))
     151                 :            :             {
     152                 :          0 :                 sNode     = sProperty;
     153                 :          0 :                 sProperty = sLocale;
     154                 :          0 :                 sLocale   = ::rtl::OUString();
     155                 :            :             }
     156                 :            :         }
     157                 :            : 
     158         [ #  # ]:          0 :         if ( sNode.isEmpty() )
     159                 :          0 :             continue;
     160                 :            : 
     161 [ #  # ][ #  # ]:          0 :         OUStringList::const_iterator pIt = ::std::find(lChangedItems.begin(), lChangedItems.end(), sNode);
     162 [ #  # ][ #  # ]:          0 :         if (pIt == lChangedItems.end())
     163         [ #  # ]:          0 :             lChangedItems.push_back(sNode);
     164 [ #  # ][ #  # ]:          0 :     }
         [ #  # ][ #  # ]
                 [ #  # ]
     165                 :            : 
     166                 :          0 :     sal_Bool                     bNotifyRefresh = sal_False;
     167                 :          0 :     OUStringList::const_iterator pIt;
     168 [ #  # ][ #  # ]:          0 :     for (  pIt  = lChangedItems.begin();
           [ #  #  #  # ]
     169                 :          0 :            pIt != lChangedItems.end()  ;
     170                 :            :          ++pIt                         )
     171                 :            :     {
     172                 :          0 :         const ::rtl::OUString& sItem = *pIt;
     173                 :            :         try
     174                 :            :         {
     175         [ #  # ]:          0 :             m_rCache.refreshItem(eType, sItem);
     176                 :            :         }
     177         [ #  # ]:          0 :         catch(const css::container::NoSuchElementException&)
     178                 :            :             {
     179                 :            :                 // can be ignored! Because we must be aware that
     180                 :            :                 // sItem was removed from the configuration and we forced an update of the cache.
     181                 :            :                 // But we know, that the cache is up-to-date know and has thrown this exception afterwards .-)
     182                 :            :             }
     183                 :            :         // NO FLUSH! Otherwise we start a never ending story here .-)
     184                 :          0 :         bNotifyRefresh = sal_True;
     185                 :            :     }
     186                 :            : 
     187                 :            :     // notify sfx cache about the changed filter cache .-)
     188         [ #  # ]:          0 :     if (bNotifyRefresh)
     189                 :            :     {
     190                 :            :         css::uno::Reference< css::util::XRefreshable > xRefreshBroadcaster(
     191         [ #  # ]:          0 :             xSMGR->createInstance(SERVICE_FILTERCONFIGREFRESH),
     192 [ #  # ][ #  # ]:          0 :             css::uno::UNO_QUERY);
                 [ #  # ]
     193         [ #  # ]:          0 :         if (xRefreshBroadcaster.is())
     194 [ #  # ][ #  # ]:          0 :             xRefreshBroadcaster->refresh();
     195 [ #  # ][ #  # ]:          0 :     }
     196                 :            : }
     197                 :            : 
     198                 :            : 
     199                 :            : 
     200                 :          0 : void SAL_CALL CacheUpdateListener::disposing(const css::lang::EventObject& aEvent)
     201                 :            :     throw(css::uno::RuntimeException)
     202                 :            : {
     203                 :            :     // SAFE ->
     204         [ #  # ]:          0 :     ::osl::ResettableMutexGuard aLock(m_aLock);
     205 [ #  # ][ #  # ]:          0 :     if (aEvent.Source == m_xConfig)
     206                 :          0 :         m_xConfig.clear();
     207 [ #  # ][ #  # ]:          0 :     aLock.clear();
     208                 :            :     // <- SAFE
     209                 :          0 : }
     210                 :            : 
     211                 :            :     } // namespace config
     212                 :            : } // namespace filter
     213                 :            : 
     214                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10