LCOV - code coverage report
Current view: top level - sd/source/ui/framework/configuration - ConfigurationControllerResourceManager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 60 71 84.5 %
Date: 2012-08-25 Functions: 12 12 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 72 171 42.1 %

           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 "ConfigurationControllerResourceManager.hxx"
      31                 :            : #include "ConfigurationControllerBroadcaster.hxx"
      32                 :            : #include "ResourceFactoryManager.hxx"
      33                 :            : #include "framework/FrameworkHelper.hxx"
      34                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      35                 :            : #include <tools/diagnose_ex.h>
      36                 :            : #include <algorithm>
      37                 :            : #include <boost/bind.hpp>
      38                 :            : 
      39                 :            : using namespace ::com::sun::star;
      40                 :            : using namespace ::com::sun::star::uno;
      41                 :            : using namespace ::com::sun::star::drawing::framework;
      42                 :            : using ::rtl::OUString;
      43                 :            : 
      44                 :            : namespace sd { namespace framework {
      45                 :            : 
      46                 :            : //===== ConfigurationControllerResourceManager ================================
      47                 :            : 
      48                 :        130 : ConfigurationControllerResourceManager::ConfigurationControllerResourceManager (
      49                 :            :     const ::boost::shared_ptr<ResourceFactoryManager>& rpResourceFactoryContainer,
      50                 :            :     const ::boost::shared_ptr<ConfigurationControllerBroadcaster>& rpBroadcaster)
      51                 :            :     : maResourceMap(ResourceComparator()),
      52                 :            :       mpResourceFactoryContainer(rpResourceFactoryContainer),
      53 [ +  - ][ +  - ]:        130 :       mpBroadcaster(rpBroadcaster)
         [ +  - ][ +  - ]
      54                 :            : {
      55                 :        130 : }
      56                 :            : 
      57                 :            : 
      58                 :            : 
      59                 :            : 
      60 [ +  - ][ +  - ]:        130 : ConfigurationControllerResourceManager::~ConfigurationControllerResourceManager (void)
                 [ +  - ]
      61                 :            : {
      62                 :        130 : }
      63                 :            : 
      64                 :            : 
      65                 :            : 
      66                 :            : 
      67                 :            : ConfigurationControllerResourceManager::ResourceDescriptor
      68                 :      11788 :     ConfigurationControllerResourceManager::GetResource (
      69                 :            :         const Reference<XResourceId>& rxResourceId)
      70                 :            : {
      71         [ +  - ]:      11788 :     ::osl::MutexGuard aGuard (maMutex);
      72         [ +  - ]:      11788 :     ResourceMap::const_iterator iResource (maResourceMap.find(rxResourceId));
      73         [ +  + ]:      11788 :     if (iResource != maResourceMap.end())
      74         [ +  - ]:       9842 :         return iResource->second;
      75                 :            :     else
      76 [ +  - ][ +  - ]:      11788 :         return ResourceDescriptor();
      77                 :            : }
      78                 :            : 
      79                 :            : 
      80                 :            : 
      81                 :            : 
      82                 :        412 : void ConfigurationControllerResourceManager::ActivateResources (
      83                 :            :     const ::std::vector<Reference<XResourceId> >& rResources,
      84                 :            :     const Reference<XConfiguration>& rxConfiguration)
      85                 :            : {
      86         [ +  - ]:        412 :     ::osl::MutexGuard aGuard (maMutex);
      87                 :            :     // Iterate in normal order over the resources that are to be
      88                 :            :     // activated so that resources on which others depend are activated
      89                 :            :     // beforet the depending resources are activated.
      90                 :            :     ::std::for_each(
      91                 :            :         rResources.begin(),
      92                 :            :         rResources.end(),
      93                 :            :         ::boost::bind(&ConfigurationControllerResourceManager::ActivateResource,
      94 [ +  - ][ +  - ]:        412 :             this, _1, rxConfiguration));
         [ +  - ][ +  - ]
                 [ +  - ]
      95                 :        412 : }
      96                 :            : 
      97                 :            : 
      98                 :            : 
      99                 :            : 
     100                 :        542 : void ConfigurationControllerResourceManager::DeactivateResources (
     101                 :            :     const ::std::vector<Reference<XResourceId> >& rResources,
     102                 :            :     const Reference<XConfiguration>& rxConfiguration)
     103                 :            : {
     104         [ +  - ]:        542 :     ::osl::MutexGuard aGuard (maMutex);
     105                 :            :     // Iterate in reverese order over the resources that are to be
     106                 :            :     // deactivated so that resources on which others depend are deactivated
     107                 :            :     // only when the depending resources have already been deactivated.
     108                 :            :     ::std::for_each(
     109                 :            :         rResources.rbegin(),
     110                 :            :         rResources.rend(),
     111                 :            :         ::boost::bind(&ConfigurationControllerResourceManager::DeactivateResource,
     112 [ +  - ][ +  - ]:        542 :             this, _1, rxConfiguration));
         [ +  - ][ +  - ]
                 [ +  - ]
     113                 :        542 : }
     114                 :            : 
     115                 :            : 
     116                 :            : 
     117                 :            : 
     118                 :            : /* In this method we do following steps.
     119                 :            :     1. Get the factory with which the resource will be created.
     120                 :            :     2. Create the resource.
     121                 :            :     3. Add the resource to the URL->Object map of the configuration
     122                 :            :     controller.
     123                 :            :     4. Add the resource id to the current configuration.
     124                 :            :     5. Notify listeners.
     125                 :            : */
     126                 :        932 : void ConfigurationControllerResourceManager::ActivateResource (
     127                 :            :     const Reference<XResourceId>& rxResourceId,
     128                 :            :     const Reference<XConfiguration>& rxConfiguration)
     129                 :            : {
     130         [ +  - ]:        932 :    if ( ! rxResourceId.is())
     131                 :            :    {
     132                 :            :        OSL_ASSERT(rxResourceId.is());
     133                 :            :        return;
     134                 :            :    }
     135                 :            : 
     136                 :            :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": activating resource " << OUStringToOString(
     137                 :            :         FrameworkHelper::ResourceIdToString(rxResourceId), RTL_TEXTENCODING_UTF8).getStr());
     138                 :            : 
     139                 :            :     // 1. Get the factory.
     140 [ +  - ][ +  - ]:        932 :     const OUString sResourceURL (rxResourceId->getResourceURL());
     141         [ +  - ]:        932 :     Reference<XResourceFactory> xFactory (mpResourceFactoryContainer->GetFactory(sResourceURL));
     142         [ -  + ]:        932 :     if ( ! xFactory.is())
     143                 :            :     {
     144                 :            :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ":    no factory found for " <<
     145                 :            :             OUStringToOString(sResourceURL, RTL_TEXTENCODING_UTF8).getStr());
     146                 :            :         return;
     147                 :            :     }
     148                 :            : 
     149                 :            :     try
     150                 :            :     {
     151                 :            :         // 2. Create the resource.
     152                 :        932 :         Reference<XResource> xResource;
     153                 :            :         try
     154                 :            :         {
     155 [ +  - ][ +  - ]:        932 :             xResource = xFactory->createResource(rxResourceId);
                 [ +  - ]
     156                 :            :         }
     157   [ #  #  #  #  :          0 :         catch (lang::DisposedException&)
                      # ]
     158                 :            :         {
     159                 :            :             // The factory is disposed and can be removed from the list
     160                 :            :             // of registered factories.
     161         [ #  # ]:          0 :             mpResourceFactoryContainer->RemoveFactoryForReference(xFactory);
     162                 :            :         }
     163         [ #  # ]:          0 :         catch(Exception&)
     164                 :            :         {
     165                 :            :             DBG_UNHANDLED_EXCEPTION();
     166                 :            :         }
     167                 :            : 
     168         [ +  + ]:        932 :         if (xResource.is())
     169                 :            :         {
     170                 :            :             SAL_INFO("sd.fwk", OSL_THIS_FUNC << ":    successfully created");
     171                 :            :             // 3. Add resource to URL->Object map.
     172         [ +  - ]:        776 :             AddResource(xResource, xFactory);
     173                 :            : 
     174                 :            :             // 4. Add resource id to current configuration.
     175 [ +  - ][ +  - ]:        776 :             rxConfiguration->addResource(rxResourceId);
     176                 :            : 
     177                 :            :             // 5. Notify the new resource to listeners of the ConfigurationController.
     178                 :            :             mpBroadcaster->NotifyListeners(
     179                 :            :                 FrameworkHelper::msResourceActivationEvent,
     180                 :            :                 rxResourceId,
     181         [ +  - ]:        776 :                 xResource);
     182                 :            :         }
     183                 :            :         else
     184                 :            :         {
     185                 :            :             SAL_INFO("sd.fwk", OSL_THIS_FUNC << ":    resource creation failed");
     186         [ #  # ]:        932 :         }
     187                 :            :     }
     188         [ #  # ]:          0 :     catch (RuntimeException&)
     189                 :            :     {
     190                 :            :         DBG_UNHANDLED_EXCEPTION();
     191 [ -  + ][ +  - ]:        932 :     }
     192                 :            : }
     193                 :            : 
     194                 :            : 
     195                 :            : 
     196                 :            : 
     197                 :            : /* In this method we do following steps.
     198                 :            :     1. Remove the resource from the URL->Object map of the configuration
     199                 :            :     controller.
     200                 :            :     2. Notify listeners.
     201                 :            :     3. Remove the resource id from the current configuration.
     202                 :            :     4. Release the resource.
     203                 :            : */
     204                 :        776 : void ConfigurationControllerResourceManager::DeactivateResource (
     205                 :            :     const Reference<XResourceId>& rxResourceId,
     206                 :            :     const Reference<XConfiguration>& rxConfiguration)
     207                 :            : {
     208         [ -  + ]:        776 :     if ( ! rxResourceId.is())
     209                 :        776 :         return;
     210                 :            : 
     211                 :            : #if OSL_DEBUG_LEVEL >= 1
     212                 :            :     bool bSuccess (false);
     213                 :            : #endif
     214                 :            :     try
     215                 :            :     {
     216                 :            :         // 1. Remove resource from URL->Object map.
     217         [ +  - ]:        776 :         ResourceDescriptor aDescriptor (RemoveResource(rxResourceId));
     218                 :            : 
     219 [ +  - ][ +  - ]:        776 :         if (aDescriptor.mxResource.is() && aDescriptor.mxResourceFactory.is())
                 [ +  - ]
     220                 :            :         {
     221                 :            :             // 2.  Notifiy listeners that the resource is being deactivated.
     222                 :            :             mpBroadcaster->NotifyListeners(
     223                 :            :                 FrameworkHelper::msResourceDeactivationEvent,
     224                 :            :                 rxResourceId,
     225         [ +  - ]:        776 :                 aDescriptor.mxResource);
     226                 :            : 
     227                 :            :             // 3. Remove resource id from current configuration.
     228 [ +  - ][ +  - ]:        776 :             rxConfiguration->removeResource(rxResourceId);
     229                 :            : 
     230                 :            :             // 4. Release the resource.
     231                 :            :             try
     232                 :            :             {
     233 [ +  - ][ +  - ]:        776 :                 aDescriptor.mxResourceFactory->releaseResource(aDescriptor.mxResource);
     234                 :            :             }
     235   [ #  #  #  # ]:          0 :             catch (const lang::DisposedException& rException)
     236                 :            :             {
     237   [ #  #  #  #  :          0 :                 if ( ! rException.Context.is()
                   #  # ]
     238         [ #  # ]:          0 :                     || rException.Context == aDescriptor.mxResourceFactory)
     239                 :            :                 {
     240                 :            :                     // The factory is disposed and can be removed from the
     241                 :            :                     // list of registered factories.
     242                 :            :                     mpResourceFactoryContainer->RemoveFactoryForReference(
     243         [ #  # ]:          0 :                         aDescriptor.mxResourceFactory);
     244                 :            :                 }
     245                 :            :             }
     246                 :            : 
     247                 :            : #if OSL_DEBUG_LEVEL >= 1
     248                 :            :             bSuccess = true;
     249                 :            : #endif
     250 [ +  - ][ #  # ]:        776 :         }
     251                 :            :     }
     252                 :          0 :     catch (RuntimeException&)
     253                 :            :     {
     254                 :            :         DBG_UNHANDLED_EXCEPTION();
     255                 :            :     }
     256                 :            : 
     257                 :            : #if OSL_DEBUG_LEVEL >= 1
     258                 :            :     if (bSuccess)
     259                 :            :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": successfully deactivated " << OUStringToOString(
     260                 :            :             FrameworkHelper::ResourceIdToString(rxResourceId), RTL_TEXTENCODING_UTF8).getStr());
     261                 :            :     else
     262                 :            :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": activating resource " << OUStringToOString(
     263                 :            :             FrameworkHelper::ResourceIdToString(rxResourceId), RTL_TEXTENCODING_UTF8).getStr()
     264                 :            :             << " failed");
     265                 :            : #endif
     266                 :            : }
     267                 :            : 
     268                 :            : 
     269                 :            : 
     270                 :            : 
     271                 :        776 : void ConfigurationControllerResourceManager::AddResource (
     272                 :            :     const Reference<XResource>& rxResource,
     273                 :            :     const Reference<XResourceFactory>& rxFactory)
     274                 :            : {
     275         [ +  - ]:        776 :     if ( ! rxResource.is())
     276                 :            :     {
     277                 :            :         OSL_ASSERT(rxResource.is());
     278                 :        776 :         return;
     279                 :            :     }
     280                 :            : 
     281                 :            :     // Add the resource to the resource container.
     282         [ +  - ]:        776 :     ResourceDescriptor aDescriptor;
     283         [ +  - ]:        776 :     aDescriptor.mxResource = rxResource;
     284         [ +  - ]:        776 :     aDescriptor.mxResourceFactory = rxFactory;
     285 [ +  - ][ +  - ]:        776 :     maResourceMap[rxResource->getResourceId()] = aDescriptor;
         [ +  - ][ +  - ]
                 [ +  - ]
     286                 :            : 
     287                 :            : #if OSL_DEBUG_LEVEL >= 2
     288                 :            :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ConfigurationControllerResourceManager::AddResource(): added " <<
     289                 :            :         OUStringToOString(
     290                 :            :             FrameworkHelper::ResourceIdToString(rxResource->getResourceId()),
     291                 :            :             RTL_TEXTENCODING_UTF8).getStr() << " -> " << rxResource.get());
     292                 :            : #endif
     293                 :            : }
     294                 :            : 
     295                 :            : 
     296                 :            : 
     297                 :            : 
     298                 :            : ConfigurationControllerResourceManager::ResourceDescriptor
     299                 :        776 :     ConfigurationControllerResourceManager::RemoveResource (
     300                 :            :         const Reference<XResourceId>& rxResourceId)
     301                 :            : {
     302         [ +  - ]:        776 :     ResourceDescriptor aDescriptor;
     303                 :            : 
     304         [ +  - ]:        776 :     ResourceMap::iterator iResource (maResourceMap.find(rxResourceId));
     305         [ +  - ]:        776 :     if (iResource != maResourceMap.end())
     306                 :            :     {
     307                 :            : #if OSL_DEBUG_LEVEL >= 2
     308                 :            :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ConfigurationControllerResourceManager::RemoveResource(): removing " <<
     309                 :            :             OUStringToOString(
     310                 :            :                 FrameworkHelper::ResourceIdToString(rxResourceId),
     311                 :            :                 RTL_TEXTENCODING_UTF8).getStr() <<
     312                 :            :                 " -> " << &iResource);
     313                 :            : #endif
     314                 :            : 
     315         [ +  - ]:        776 :         aDescriptor = iResource->second;
     316         [ +  - ]:        776 :         maResourceMap.erase(rxResourceId);
     317                 :            :     }
     318                 :            : 
     319                 :        776 :     return aDescriptor;
     320                 :            : }
     321                 :            : 
     322                 :            : 
     323                 :            : 
     324                 :            : 
     325                 :            : //===== ConfigurationControllerResourceManager::ResourceComparator ============
     326                 :            : 
     327                 :      41302 : bool ConfigurationControllerResourceManager::ResourceComparator::operator() (
     328                 :            :     const Reference<XResourceId>& rxId1,
     329                 :            :     const Reference<XResourceId>& rxId2) const
     330                 :            : {
     331 [ +  - ][ +  - ]:      41302 :     if (rxId1.is() && rxId2.is())
                 [ +  - ]
     332                 :      41302 :         return rxId1->compareTo(rxId2)<0;
     333         [ #  # ]:          0 :     else if (rxId1.is())
     334                 :          0 :         return true;
     335                 :            :     else
     336                 :      41302 :         return false;
     337                 :            : }
     338                 :            : 
     339                 :            : 
     340                 :            : 
     341                 :            : 
     342 [ +  - ][ +  - ]:         75 : } } // end of namespace sd::framework
     343                 :            : 
     344                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10