LCOV - code coverage report
Current view: top level - sd/source/ui/framework/configuration - ConfigurationControllerBroadcaster.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 64 73 87.7 %
Date: 2012-08-25 Functions: 7 7 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 76 167 45.5 %

           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 "ConfigurationControllerBroadcaster.hxx"
      31                 :            : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      32                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      33                 :            : #include <tools/debug.hxx>
      34                 :            : #include <tools/diagnose_ex.h>
      35                 :            : 
      36                 :            : using namespace ::com::sun::star;
      37                 :            : using namespace ::com::sun::star::uno;
      38                 :            : using namespace ::com::sun::star::drawing::framework;
      39                 :            : using rtl::OUString;
      40                 :            : 
      41                 :            : namespace sd { namespace framework {
      42                 :            : 
      43                 :        130 : ConfigurationControllerBroadcaster::ConfigurationControllerBroadcaster (
      44                 :            :     const Reference<XConfigurationController>& rxController)
      45                 :            :     : mxConfigurationController(rxController),
      46         [ +  - ]:        130 :     maListenerMap()
      47                 :            : {
      48                 :        130 : }
      49                 :            : 
      50                 :            : 
      51                 :            : 
      52                 :            : 
      53                 :       2054 : void ConfigurationControllerBroadcaster::AddListener(
      54                 :            :     const Reference<XConfigurationChangeListener>& rxListener,
      55                 :            :     const ::rtl::OUString& rsEventType,
      56                 :            :     const Any& rUserData)
      57                 :            : {
      58         [ -  + ]:       2054 :     if ( ! rxListener.is())
      59                 :            :         throw lang::IllegalArgumentException("invalid listener",
      60                 :            :             mxConfigurationController,
      61         [ #  # ]:          0 :             0);
      62                 :            : 
      63 [ +  - ][ +  - ]:       2054 :     if (maListenerMap.find(rsEventType) == maListenerMap.end())
                 [ +  + ]
      64 [ +  - ][ +  - ]:        806 :         maListenerMap[rsEventType] = ListenerList();
      65         [ +  - ]:       2054 :     ListenerDescriptor aDescriptor;
      66         [ +  - ]:       2054 :     aDescriptor.mxListener = rxListener;
      67                 :       2054 :     aDescriptor.maUserData = rUserData;
      68 [ +  - ][ +  - ]:       2054 :     maListenerMap[rsEventType].push_back(aDescriptor);
                 [ +  - ]
      69                 :       2054 : }
      70                 :            : 
      71                 :            : 
      72                 :            : 
      73                 :            : 
      74                 :       1066 : void ConfigurationControllerBroadcaster::RemoveListener(
      75                 :            :     const Reference<XConfigurationChangeListener>& rxListener)
      76                 :            : {
      77         [ -  + ]:       1066 :     if ( ! rxListener.is())
      78                 :            :         throw lang::IllegalArgumentException("invalid listener",
      79                 :            :             mxConfigurationController,
      80         [ #  # ]:          0 :             0);
      81                 :            : 
      82                 :       1066 :     ListenerMap::iterator iMap;
      83                 :       1066 :     ListenerList::iterator iList;
      84 [ +  - ][ +  + ]:       5824 :     for (iMap=maListenerMap.begin(); iMap!=maListenerMap.end(); ++iMap)
                 [ +  - ]
      85                 :            :     {
      86 [ +  - ][ +  - ]:      11752 :         for (iList=iMap->second.begin(); iList!=iMap->second.end(); ++iList)
         [ +  - ][ +  + ]
      87                 :            :         {
      88 [ +  - ][ +  + ]:       9048 :             if (iList->mxListener == rxListener)
      89                 :            :             {
      90 [ +  - ][ +  - ]:       2054 :                 iMap->second.erase(iList);
      91                 :       2054 :                 break;
      92                 :            :             }
      93                 :            :         }
      94                 :            :     }
      95                 :       1066 : }
      96                 :            : 
      97                 :            : 
      98                 :            : 
      99                 :            : 
     100                 :       4140 : void ConfigurationControllerBroadcaster::NotifyListeners (
     101                 :            :     const ListenerList& rList,
     102                 :            :     const ConfigurationChangeEvent& rEvent)
     103                 :            : {
     104                 :            :     // Create a local copy of the event in which the user data is modified
     105                 :            :     // for every listener.
     106         [ +  - ]:       4140 :     ConfigurationChangeEvent aEvent (rEvent);
     107                 :            : 
     108                 :       4140 :     ListenerList::const_iterator iListener;
     109 [ +  - ][ +  + ]:      13966 :     for (iListener=rList.begin(); iListener!=rList.end(); ++iListener)
     110                 :            :     {
     111                 :            :         try
     112                 :            :         {
     113                 :       9826 :             aEvent.UserData = iListener->maUserData;
     114 [ +  - ][ +  - ]:       9826 :             iListener->mxListener->notifyConfigurationChange(aEvent);
     115                 :            :         }
     116   [ #  #  #  #  :          0 :         catch (const lang::DisposedException& rException)
                      # ]
     117                 :            :         {
     118                 :            :             // When the exception comes from the listener itself then
     119                 :            :             // unregister it.
     120   [ #  #  #  # ]:          0 :             if (rException.Context == iListener->mxListener)
     121         [ #  # ]:          0 :                 RemoveListener(iListener->mxListener);
     122                 :            :         }
     123         [ #  # ]:          0 :         catch (const RuntimeException&)
     124                 :            :         {
     125                 :            :             DBG_UNHANDLED_EXCEPTION();
     126                 :            :         }
     127         [ +  - ]:       4140 :     }
     128                 :       4140 : }
     129                 :            : 
     130                 :            : 
     131                 :            : 
     132                 :            : 
     133                 :       3616 : void ConfigurationControllerBroadcaster::NotifyListeners (const ConfigurationChangeEvent& rEvent)
     134                 :            : {
     135                 :            :     // Notify the specialized listeners.
     136         [ +  - ]:       3616 :     ListenerMap::const_iterator iMap (maListenerMap.find(rEvent.Type));
     137 [ +  - ][ +  - ]:       3616 :     if (iMap != maListenerMap.end())
     138                 :            :     {
     139                 :            :         // Create a local list of the listeners to avoid problems with
     140                 :            :         // concurrent changes and to be able to remove disposed listeners.
     141 [ +  - ][ +  - ]:       3616 :         ListenerList aList (iMap->second.begin(), iMap->second.end());
                 [ +  - ]
     142         [ +  - ]:       3616 :         NotifyListeners(aList,rEvent);
     143                 :            :     }
     144                 :            : 
     145                 :            :     // Notify the universal listeners.
     146         [ +  - ]:       3616 :     iMap = maListenerMap.find(OUString());
     147 [ +  + ][ +  - ]:       3616 :     if (iMap != maListenerMap.end())
     148                 :            :     {
     149                 :            :         // Create a local list of the listeners to avoid problems with
     150                 :            :         // concurrent changes and to be able to remove disposed listeners.
     151 [ +  - ][ +  - ]:        524 :         ListenerList aList (iMap->second.begin(), iMap->second.end());
                 [ +  - ]
     152         [ +  - ]:        524 :         NotifyListeners(aList,rEvent);
     153                 :            :     }
     154                 :       3616 : }
     155                 :            : 
     156                 :            : 
     157                 :            : 
     158                 :            : 
     159                 :       1552 : void ConfigurationControllerBroadcaster::NotifyListeners (
     160                 :            :     const OUString& rsEventType,
     161                 :            :     const Reference<XResourceId>& rxResourceId,
     162                 :            :     const Reference<XResource>& rxResourceObject)
     163                 :            : {
     164         [ +  - ]:       1552 :     ConfigurationChangeEvent aEvent;
     165                 :       1552 :     aEvent.Type = rsEventType;
     166         [ +  - ]:       1552 :     aEvent.ResourceId = rxResourceId;
     167         [ +  - ]:       1552 :     aEvent.ResourceObject = rxResourceObject;
     168                 :            :     try
     169                 :            :     {
     170         [ +  - ]:       1552 :         NotifyListeners(aEvent);
     171                 :            :     }
     172         [ #  # ]:          0 :     catch (const lang::DisposedException&)
     173                 :            :     {
     174         [ +  - ]:       1552 :     }
     175         [ #  # ]:       1552 : }
     176                 :            : 
     177                 :            : 
     178                 :            : 
     179                 :            : 
     180                 :            : 
     181                 :        130 : void ConfigurationControllerBroadcaster::DisposeAndClear (void)
     182                 :            : {
     183         [ +  - ]:        130 :     lang::EventObject aEvent;
     184         [ +  - ]:        130 :     aEvent.Source = mxConfigurationController;
     185         [ +  + ]:       1950 :     while (!maListenerMap.empty())
     186                 :            :     {
     187         [ +  - ]:       1820 :         ListenerMap::iterator iMap (maListenerMap.begin());
     188 [ +  - ][ +  - ]:       1820 :         if (iMap == maListenerMap.end())
     189                 :            :             break;
     190                 :            : 
     191                 :            :         // When the first vector is empty then remove it from the map.
     192 [ +  - ][ +  + ]:       1820 :         if (iMap->second.empty())
     193                 :            :         {
     194   [ +  -  #  # ]:        806 :             maListenerMap.erase(iMap);
     195                 :        806 :             continue;
     196                 :            :         }
     197                 :            :         else
     198                 :            :         {
     199                 :            :             Reference<lang::XEventListener> xListener (
     200 [ +  - ][ +  - ]:       1014 :                 iMap->second.front().mxListener, UNO_QUERY);
                 [ +  - ]
     201         [ +  - ]:       1014 :             if (xListener.is())
     202                 :            :             {
     203                 :            :                 // Tell the listener that the configuration controller is
     204                 :            :                 // being disposed and remove the listener (for all event
     205                 :            :                 // types).
     206                 :            :                 try
     207                 :            :                 {
     208 [ +  - ][ +  - ]:       1014 :                     RemoveListener(iMap->second.front().mxListener);
                 [ +  - ]
     209 [ +  - ][ +  - ]:       1014 :                     xListener->disposing(aEvent);
     210                 :            :                 }
     211         [ #  # ]:          0 :                 catch (const RuntimeException&)
     212                 :            :                 {
     213                 :            :                     DBG_UNHANDLED_EXCEPTION();
     214                 :            :                 }
     215                 :            :             }
     216                 :            :             else
     217                 :            :             {
     218                 :            :                 // Remove just this reference to the listener.
     219 [ #  # ][ #  # ]:          0 :                 iMap->second.erase(iMap->second.begin());
                 [ #  # ]
     220                 :       1014 :             }
     221                 :            :         }
     222         [ +  - ]:        130 :     }
     223                 :        130 : }
     224                 :            : 
     225                 :            : 
     226                 :            : 
     227                 :            : 
     228                 :            : } } // end of namespace sd::framework
     229                 :            : 
     230                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10