LCOV - code coverage report
Current view: top level - sd/source/ui/framework/configuration - ChangeRequestQueueProcessor.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 57 57 100.0 %
Date: 2014-11-03 Functions: 13 13 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         212 : 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         212 :       mpConfigurationUpdater(rpConfigurationUpdater)
      62             : {
      63         212 : }
      64             : 
      65         424 : ChangeRequestQueueProcessor::~ChangeRequestQueueProcessor (void)
      66             : {
      67         212 :     if (mnUserEventId != 0)
      68         212 :         Application::RemoveUserEvent(mnUserEventId);
      69         212 : }
      70             : 
      71         212 : void ChangeRequestQueueProcessor::SetConfiguration (
      72             :     const Reference<XConfiguration>& rxConfiguration)
      73             : {
      74         212 :     ::osl::MutexGuard aGuard (maMutex);
      75             : 
      76         212 :     mxConfiguration = rxConfiguration;
      77         212 :     StartProcessing();
      78         212 : }
      79             : 
      80        3050 : void ChangeRequestQueueProcessor::AddRequest (
      81             :     const Reference<XConfigurationChangeRequest>& rxRequest)
      82             : {
      83        3050 :     ::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        3050 :     maQueue.push_back(rxRequest);
      97        3050 :     StartProcessing();
      98        3050 : }
      99             : 
     100        3424 : void ChangeRequestQueueProcessor::StartProcessing (void)
     101             : {
     102        3424 :     ::osl::MutexGuard aGuard (maMutex);
     103             : 
     104        6848 :     if (mnUserEventId == 0
     105         736 :         && mxConfiguration.is()
     106        4160 :         && ! maQueue.empty())
     107             :     {
     108             :         SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ChangeRequestQueueProcessor scheduling processing");
     109             :         mnUserEventId = Application::PostUserEvent(
     110         524 :             LINK(this,ChangeRequestQueueProcessor,ProcessEvent));
     111        3424 :     }
     112        3424 : }
     113             : 
     114         624 : IMPL_LINK(ChangeRequestQueueProcessor, ProcessEvent, void*, pUnused)
     115             : {
     116             :     (void)pUnused;
     117             : 
     118         312 :     ::osl::MutexGuard aGuard (maMutex);
     119             : 
     120         312 :     mnUserEventId = 0;
     121             : 
     122         312 :     ProcessOneEvent();
     123             : 
     124         312 :     if ( ! maQueue.empty())
     125             :     {
     126             :         // Schedule the processing of the next event.
     127         162 :         StartProcessing();
     128             :     }
     129             : 
     130         312 :     return 0;
     131             : }
     132             : 
     133        2900 : void ChangeRequestQueueProcessor::ProcessOneEvent (void)
     134             : {
     135        2900 :     ::osl::MutexGuard aGuard (maMutex);
     136             : 
     137             :     SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ProcessOneEvent");
     138             : 
     139        5800 :     if (mxConfiguration.is()
     140        2900 :         && ! maQueue.empty())
     141             :     {
     142             :         // Get and remove the first entry from the queue.
     143        2900 :         Reference<XConfigurationChangeRequest> xRequest (maQueue.front());
     144        2900 :         maQueue.pop_front();
     145             : 
     146             :         // Execute the change request.
     147        2900 :         if (xRequest.is())
     148             :         {
     149             : #if OSL_DEBUG_LEVEL >= 2
     150             :             TraceRequest(xRequest);
     151             : #endif
     152        2900 :             xRequest->execute(mxConfiguration);
     153             :         }
     154             : 
     155        2900 :         if (maQueue.empty())
     156             :         {
     157             :             SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": All requests are processed");
     158             :             // The queue is empty so tell the ConfigurationManager to update
     159             :             // its state.
     160         688 :             if (mpConfigurationUpdater.get() != NULL)
     161             :             {
     162             : #if OSL_DEBUG_LEVEL >= 2
     163             :                 ConfigurationTracer::TraceConfiguration (
     164             :                     mxConfiguration, "updating to configuration");
     165             : #endif
     166         688 :                 mpConfigurationUpdater->RequestUpdate(mxConfiguration);
     167             :             }
     168        2900 :         }
     169        2900 :     }
     170        2900 : }
     171             : 
     172        3264 : bool ChangeRequestQueueProcessor::IsEmpty (void) const
     173             : {
     174        3264 :     return maQueue.empty();
     175             : }
     176             : 
     177         212 : void ChangeRequestQueueProcessor::ProcessUntilEmpty (void)
     178             : {
     179        2008 :     while ( ! IsEmpty())
     180        1584 :         ProcessOneEvent();
     181         212 : }
     182             : 
     183         212 : void ChangeRequestQueueProcessor::Clear (void)
     184             : {
     185         212 :     ::osl::MutexGuard aGuard (maMutex);
     186         212 :     maQueue.clear();
     187         212 : }
     188             : 
     189         114 : } } // end of namespace sd::framework::configuration
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10