LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/cache - SlsCacheConfiguration.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 50 0.0 %
Date: 2014-04-14 Functions: 0 7 0.0 %
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 "SlsCacheConfiguration.hxx"
      22             : #include <osl/mutex.hxx>
      23             : #include <rtl/instance.hxx>
      24             : #include <vcl/svapp.hxx>
      25             : 
      26             : #include <comphelper/processfactory.hxx>
      27             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      28             : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
      29             : #include <com/sun/star/configuration/theDefaultProvider.hpp>
      30             : #include <com/sun/star/beans/PropertyValue.hpp>
      31             : 
      32             : using namespace ::com::sun::star;
      33             : using namespace ::com::sun::star::uno;
      34             : 
      35             : namespace sd { namespace slidesorter { namespace cache {
      36             : 
      37             : namespace
      38             : {
      39             :     typedef ::boost::shared_ptr<CacheConfiguration> CacheConfigSharedPtr;
      40             :     class theInstance :
      41             :         public rtl::Static<CacheConfigSharedPtr, theInstance> {};
      42             : }
      43             : 
      44           0 : ::boost::weak_ptr<CacheConfiguration> CacheConfiguration::mpWeakInstance;
      45           0 : Timer CacheConfiguration::maReleaseTimer;
      46             : 
      47           0 : ::boost::shared_ptr<CacheConfiguration> CacheConfiguration::Instance (void)
      48             : {
      49           0 :     SolarMutexGuard aSolarGuard;
      50           0 :     CacheConfigSharedPtr &rInstancePtr = theInstance::get();
      51           0 :     if (rInstancePtr.get() == NULL)
      52             :     {
      53             :         // Maybe somebody else kept a previously created instance alive.
      54           0 :         if ( ! mpWeakInstance.expired())
      55           0 :             rInstancePtr = ::boost::shared_ptr<CacheConfiguration>(mpWeakInstance);
      56           0 :         if (rInstancePtr.get() == NULL)
      57             :         {
      58             :             // We have to create a new instance.
      59           0 :             rInstancePtr.reset(new CacheConfiguration());
      60           0 :             mpWeakInstance = rInstancePtr;
      61             :             // Prepare to release this instance in the near future.
      62             :             maReleaseTimer.SetTimeoutHdl(
      63           0 :                 LINK(rInstancePtr.get(),CacheConfiguration,TimerCallback));
      64           0 :             maReleaseTimer.SetTimeout(5000 /* 5s */);
      65           0 :             maReleaseTimer.Start();
      66             :         }
      67             :     }
      68           0 :     return rInstancePtr;
      69             : }
      70             : 
      71             : 
      72             : 
      73             : 
      74           0 : CacheConfiguration::CacheConfiguration (void)
      75             : {
      76             :     // Get the cache size from configuration.
      77           0 :     const OUString sPathToImpressConfigurationRoot("/org.openoffice.Office.Impress/");
      78           0 :     const OUString sPathToNode("MultiPaneGUI/SlideSorter/PreviewCache");
      79             : 
      80             :     try
      81             :     {
      82             :         // Obtain access to the configuration.
      83             :         Reference<lang::XMultiServiceFactory> xProvider =
      84           0 :             configuration::theDefaultProvider::get( ::comphelper::getProcessComponentContext() );
      85             : 
      86             :         // Obtain access to Impress configuration.
      87           0 :         Sequence<Any> aCreationArguments(3);
      88           0 :         aCreationArguments[0] = makeAny(beans::PropertyValue(
      89             :             "nodepath",
      90             :             0,
      91             :             makeAny(sPathToImpressConfigurationRoot),
      92           0 :             beans::PropertyState_DIRECT_VALUE));
      93           0 :         aCreationArguments[1] = makeAny(beans::PropertyValue(
      94             :             "depth",
      95             :             0,
      96             :             makeAny((sal_Int32)-1),
      97           0 :             beans::PropertyState_DIRECT_VALUE));
      98           0 :         aCreationArguments[2] = makeAny(beans::PropertyValue(
      99             :             "lazywrite",
     100             :             0,
     101             :             makeAny(true),
     102           0 :             beans::PropertyState_DIRECT_VALUE));
     103             : 
     104           0 :         Reference<XInterface> xRoot (xProvider->createInstanceWithArguments(
     105             :             "com.sun.star.configuration.ConfigurationAccess",
     106           0 :             aCreationArguments));
     107           0 :         if ( ! xRoot.is())
     108           0 :             return;
     109           0 :         Reference<container::XHierarchicalNameAccess> xHierarchy (xRoot, UNO_QUERY);
     110           0 :         if ( ! xHierarchy.is())
     111           0 :             return;
     112             : 
     113             :         // Get the node for the slide sorter preview cache.
     114           0 :         mxCacheNode = Reference<container::XNameAccess>(
     115           0 :             xHierarchy->getByHierarchicalName(sPathToNode),
     116           0 :             UNO_QUERY);
     117             :     }
     118           0 :     catch (RuntimeException &)
     119             :     {
     120             :     }
     121           0 :     catch (Exception &)
     122             :     {
     123           0 :     }
     124             : }
     125             : 
     126             : 
     127             : 
     128             : 
     129           0 : Any CacheConfiguration::GetValue (const OUString& rName)
     130             : {
     131           0 :     Any aResult;
     132             : 
     133           0 :     if (mxCacheNode != NULL)
     134             :     {
     135             :         try
     136             :         {
     137           0 :             aResult = mxCacheNode->getByName(rName);
     138             :         }
     139           0 :         catch (Exception &)
     140             :         {
     141             :         }
     142             :     }
     143             : 
     144           0 :     return aResult;
     145             : }
     146             : 
     147             : 
     148             : 
     149             : 
     150           0 : IMPL_LINK_NOARG(CacheConfiguration, TimerCallback)
     151             : {
     152           0 :     CacheConfigSharedPtr &rInstancePtr = theInstance::get();
     153             :     // Release out reference to the instance.
     154           0 :     rInstancePtr.reset();
     155           0 :     return 0;
     156             : }
     157             : 
     158             : 
     159           0 : } } } // end of namespace ::sd::slidesorter::cache
     160             : 
     161             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10