LCOV - code coverage report
Current view: top level - sd/source/ui/framework/configuration - ChangeRequestQueueProcessor.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 56 0.0 %
Date: 2014-04-14 Functions: 0 11 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 "ChangeRequestQueueProcessor.hxx"
      22             : #include "ConfigurationTracer.hxx"
      23             : 
      24             : #include "framework/ConfigurationController.hxx"
      25             : #include "ConfigurationUpdater.hxx"
      26             : 
      27             : #include <vcl/svapp.hxx>
      28             : #include <com/sun/star/container/XNamed.hpp>
      29             : #include <com/sun/star/drawing/framework/XConfiguration.hpp>
      30             : #include <com/sun/star/drawing/framework/ConfigurationChangeEvent.hpp>
      31             : 
      32             : using namespace ::com::sun::star;
      33             : using namespace ::com::sun::star::uno;
      34             : using namespace ::com::sun::star::drawing::framework;
      35             : 
      36             : namespace {
      37             : 
      38             : #if OSL_DEBUG_LEVEL >= 2
      39             : 
      40             : void TraceRequest (const Reference<XConfigurationChangeRequest>& rxRequest)
      41             : {
      42             :     Reference<container::XNamed> xNamed (rxRequest, UNO_QUERY);
      43             :     if (xNamed.is())
      44             :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ":    " <<
      45             :             OUStringToOString(xNamed->getName(), RTL_TEXTENCODING_UTF8).getStr());
      46             : }
      47             : 
      48             : #endif
      49             : 
      50             : } // end of anonymous namespace
      51             : 
      52             : 
      53             : namespace sd { namespace framework {
      54             : 
      55           0 : ChangeRequestQueueProcessor::ChangeRequestQueueProcessor (
      56             :     const ::rtl::Reference<ConfigurationController>& rpConfigurationController,
      57             :     const ::boost::shared_ptr<ConfigurationUpdater>& rpConfigurationUpdater)
      58             :     : maMutex(),
      59             :       maQueue(),
      60             :       mnUserEventId(0),
      61             :       mxConfiguration(),
      62             :       mpConfigurationController(rpConfigurationController),
      63           0 :       mpConfigurationUpdater(rpConfigurationUpdater)
      64             : {
      65           0 : }
      66             : 
      67             : 
      68             : 
      69             : 
      70           0 : ChangeRequestQueueProcessor::~ChangeRequestQueueProcessor (void)
      71             : {
      72           0 :     if (mnUserEventId != 0)
      73           0 :         Application::RemoveUserEvent(mnUserEventId);
      74           0 : }
      75             : 
      76             : 
      77             : 
      78             : 
      79           0 : void ChangeRequestQueueProcessor::SetConfiguration (
      80             :     const Reference<XConfiguration>& rxConfiguration)
      81             : {
      82           0 :     ::osl::MutexGuard aGuard (maMutex);
      83             : 
      84           0 :     mxConfiguration = rxConfiguration;
      85           0 :     StartProcessing();
      86           0 : }
      87             : 
      88             : 
      89             : 
      90             : 
      91           0 : void ChangeRequestQueueProcessor::AddRequest (
      92             :     const Reference<XConfigurationChangeRequest>& rxRequest)
      93             : {
      94           0 :     ::osl::MutexGuard aGuard (maMutex);
      95             : 
      96             : #if OSL_DEBUG_LEVEL >= 2
      97             :     if (maQueue.empty())
      98             :     {
      99             :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": Adding requests to empty queue");
     100             :         ConfigurationTracer::TraceConfiguration(
     101             :             mxConfiguration, "current configuration of queue processor");
     102             :     }
     103             :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": Adding request");
     104             :     TraceRequest(rxRequest);
     105             : #endif
     106             : 
     107           0 :     maQueue.push_back(rxRequest);
     108           0 :     StartProcessing();
     109           0 : }
     110             : 
     111             : 
     112             : 
     113             : 
     114           0 : void ChangeRequestQueueProcessor::StartProcessing (void)
     115             : {
     116           0 :     ::osl::MutexGuard aGuard (maMutex);
     117             : 
     118           0 :     if (mnUserEventId == 0
     119           0 :         && mxConfiguration.is()
     120           0 :         && ! maQueue.empty())
     121             :     {
     122             :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ChangeRequestQueueProcessor scheduling processing");
     123             :         mnUserEventId = Application::PostUserEvent(
     124           0 :             LINK(this,ChangeRequestQueueProcessor,ProcessEvent));
     125           0 :     }
     126           0 : }
     127             : 
     128             : 
     129             : 
     130             : 
     131           0 : IMPL_LINK(ChangeRequestQueueProcessor, ProcessEvent, void*, pUnused)
     132             : {
     133             :     (void)pUnused;
     134             : 
     135           0 :     ::osl::MutexGuard aGuard (maMutex);
     136             : 
     137           0 :     mnUserEventId = 0;
     138             : 
     139           0 :     ProcessOneEvent();
     140             : 
     141           0 :     if ( ! maQueue.empty())
     142             :     {
     143             :         // Schedule the processing of the next event.
     144           0 :         StartProcessing();
     145             :     }
     146             : 
     147           0 :     return 0;
     148             : }
     149             : 
     150             : 
     151             : 
     152             : 
     153           0 : void ChangeRequestQueueProcessor::ProcessOneEvent (void)
     154             : {
     155           0 :     ::osl::MutexGuard aGuard (maMutex);
     156             : 
     157             :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ProcessOneEvent");
     158             : 
     159           0 :     if (mxConfiguration.is()
     160           0 :         && ! maQueue.empty())
     161             :     {
     162             :         // Get and remove the first entry from the queue.
     163           0 :         Reference<XConfigurationChangeRequest> xRequest (maQueue.front());
     164           0 :         maQueue.pop_front();
     165             : 
     166             :         // Execute the change request.
     167           0 :         if (xRequest.is())
     168             :         {
     169             : #if OSL_DEBUG_LEVEL >= 2
     170             :             TraceRequest(xRequest);
     171             : #endif
     172           0 :             xRequest->execute(mxConfiguration);
     173             :         }
     174             : 
     175           0 :         if (maQueue.empty())
     176             :         {
     177             :             SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": All requests are processed");
     178             :             // The queue is empty so tell the ConfigurationManager to update
     179             :             // its state.
     180           0 :             if (mpConfigurationUpdater.get() != NULL)
     181             :             {
     182             : #if OSL_DEBUG_LEVEL >= 2
     183             :                 ConfigurationTracer::TraceConfiguration (
     184             :                     mxConfiguration, "updating to configuration");
     185             : #endif
     186           0 :                 mpConfigurationUpdater->RequestUpdate(mxConfiguration);
     187             :             }
     188           0 :         }
     189           0 :     }
     190           0 : }
     191             : 
     192             : 
     193             : 
     194             : 
     195           0 : bool ChangeRequestQueueProcessor::IsEmpty (void) const
     196             : {
     197           0 :     return maQueue.empty();
     198             : }
     199             : 
     200             : 
     201             : 
     202             : 
     203           0 : void ChangeRequestQueueProcessor::ProcessUntilEmpty (void)
     204             : {
     205           0 :     while ( ! IsEmpty())
     206           0 :         ProcessOneEvent();
     207           0 : }
     208             : 
     209             : 
     210             : 
     211             : 
     212           0 : void ChangeRequestQueueProcessor::Clear (void)
     213             : {
     214           0 :     ::osl::MutexGuard aGuard (maMutex);
     215           0 :     maQueue.clear();
     216           0 : }
     217             : 
     218             : 
     219             : } } // end of namespace sd::framework::configuration
     220             : 
     221             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10