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

Generated by: LCOV version 1.11