LCOV - code coverage report
Current view: top level - sd/source/ui/framework/configuration - ChangeRequestQueueProcessor.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 56 56 100.0 %
Date: 2014-04-11 Functions: 11 11 100.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          73 : 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          73 :       mpConfigurationUpdater(rpConfigurationUpdater)
      64             : {
      65          73 : }
      66             : 
      67             : 
      68             : 
      69             : 
      70         146 : ChangeRequestQueueProcessor::~ChangeRequestQueueProcessor (void)
      71             : {
      72          73 :     if (mnUserEventId != 0)
      73          73 :         Application::RemoveUserEvent(mnUserEventId);
      74          73 : }
      75             : 
      76             : 
      77             : 
      78             : 
      79          73 : void ChangeRequestQueueProcessor::SetConfiguration (
      80             :     const Reference<XConfiguration>& rxConfiguration)
      81             : {
      82          73 :     ::osl::MutexGuard aGuard (maMutex);
      83             : 
      84          73 :     mxConfiguration = rxConfiguration;
      85          73 :     StartProcessing();
      86          73 : }
      87             : 
      88             : 
      89             : 
      90             : 
      91        1082 : void ChangeRequestQueueProcessor::AddRequest (
      92             :     const Reference<XConfigurationChangeRequest>& rxRequest)
      93             : {
      94        1082 :     ::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        1082 :     maQueue.push_back(rxRequest);
     108        1082 :     StartProcessing();
     109        1082 : }
     110             : 
     111             : 
     112             : 
     113             : 
     114        1228 : void ChangeRequestQueueProcessor::StartProcessing (void)
     115             : {
     116        1228 :     ::osl::MutexGuard aGuard (maMutex);
     117             : 
     118        2456 :     if (mnUserEventId == 0
     119         285 :         && mxConfiguration.is()
     120        1513 :         && ! maQueue.empty())
     121             :     {
     122             :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ChangeRequestQueueProcessor scheduling processing");
     123             :         mnUserEventId = Application::PostUserEvent(
     124         212 :             LINK(this,ChangeRequestQueueProcessor,ProcessEvent));
     125        1228 :     }
     126        1228 : }
     127             : 
     128             : 
     129             : 
     130             : 
     131         278 : IMPL_LINK(ChangeRequestQueueProcessor, ProcessEvent, void*, pUnused)
     132             : {
     133             :     (void)pUnused;
     134             : 
     135         139 :     ::osl::MutexGuard aGuard (maMutex);
     136             : 
     137         139 :     mnUserEventId = 0;
     138             : 
     139         139 :     ProcessOneEvent();
     140             : 
     141         139 :     if ( ! maQueue.empty())
     142             :     {
     143             :         // Schedule the processing of the next event.
     144          73 :         StartProcessing();
     145             :     }
     146             : 
     147         139 :     return 0;
     148             : }
     149             : 
     150             : 
     151             : 
     152             : 
     153        1058 : void ChangeRequestQueueProcessor::ProcessOneEvent (void)
     154             : {
     155        1058 :     ::osl::MutexGuard aGuard (maMutex);
     156             : 
     157             :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ProcessOneEvent");
     158             : 
     159        2116 :     if (mxConfiguration.is()
     160        1058 :         && ! maQueue.empty())
     161             :     {
     162             :         // Get and remove the first entry from the queue.
     163        1058 :         Reference<XConfigurationChangeRequest> xRequest (maQueue.front());
     164        1058 :         maQueue.pop_front();
     165             : 
     166             :         // Execute the change request.
     167        1058 :         if (xRequest.is())
     168             :         {
     169             : #if OSL_DEBUG_LEVEL >= 2
     170             :             TraceRequest(xRequest);
     171             : #endif
     172        1058 :             xRequest->execute(mxConfiguration);
     173             :         }
     174             : 
     175        1058 :         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         262 :             if (mpConfigurationUpdater.get() != NULL)
     181             :             {
     182             : #if OSL_DEBUG_LEVEL >= 2
     183             :                 ConfigurationTracer::TraceConfiguration (
     184             :                     mxConfiguration, "updating to configuration");
     185             : #endif
     186         262 :                 mpConfigurationUpdater->RequestUpdate(mxConfiguration);
     187             :             }
     188        1058 :         }
     189        1058 :     }
     190        1058 : }
     191             : 
     192             : 
     193             : 
     194             : 
     195        1195 : bool ChangeRequestQueueProcessor::IsEmpty (void) const
     196             : {
     197        1195 :     return maQueue.empty();
     198             : }
     199             : 
     200             : 
     201             : 
     202             : 
     203          73 : void ChangeRequestQueueProcessor::ProcessUntilEmpty (void)
     204             : {
     205         710 :     while ( ! IsEmpty())
     206         564 :         ProcessOneEvent();
     207          73 : }
     208             : 
     209             : 
     210             : 
     211             : 
     212          73 : void ChangeRequestQueueProcessor::Clear (void)
     213             : {
     214          73 :     ::osl::MutexGuard aGuard (maMutex);
     215          73 :     maQueue.clear();
     216          73 : }
     217             : 
     218             : 
     219             : } } // end of namespace sd::framework::configuration
     220             : 
     221             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10