bump product version to 4.1.6.2
[LibreOffice.git] / sd / source / ui / framework / configuration / ChangeRequestQueueProcessor.cxx
blob3b0182e4b9470af81695fdb69d1600ae98a9b076
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "ChangeRequestQueueProcessor.hxx"
22 #include "ConfigurationTracer.hxx"
24 #include "framework/ConfigurationController.hxx"
25 #include "ConfigurationUpdater.hxx"
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>
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::drawing::framework;
36 namespace {
38 #if OSL_DEBUG_LEVEL >= 2
40 void TraceRequest (const Reference<XConfigurationChangeRequest>& rxRequest)
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());
48 #endif
50 } // end of anonymous namespace
53 namespace sd { namespace framework {
55 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 mpConfigurationUpdater(rpConfigurationUpdater)
70 ChangeRequestQueueProcessor::~ChangeRequestQueueProcessor (void)
72 if (mnUserEventId != 0)
73 Application::RemoveUserEvent(mnUserEventId);
79 void ChangeRequestQueueProcessor::SetConfiguration (
80 const Reference<XConfiguration>& rxConfiguration)
82 ::osl::MutexGuard aGuard (maMutex);
84 mxConfiguration = rxConfiguration;
85 StartProcessing();
91 void ChangeRequestQueueProcessor::AddRequest (
92 const Reference<XConfigurationChangeRequest>& rxRequest)
94 ::osl::MutexGuard aGuard (maMutex);
96 #if OSL_DEBUG_LEVEL >= 2
97 if (maQueue.empty())
99 SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": Adding requests to empty queue");
100 ConfigurationTracer::TraceConfiguration(
101 mxConfiguration, "current configuration of queue processor");
103 SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": Adding request");
104 TraceRequest(rxRequest);
105 #endif
107 maQueue.push_back(rxRequest);
108 StartProcessing();
114 void ChangeRequestQueueProcessor::StartProcessing (void)
116 ::osl::MutexGuard aGuard (maMutex);
118 if (mnUserEventId == 0
119 && mxConfiguration.is()
120 && ! maQueue.empty())
122 SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ChangeRequestQueueProcessor scheduling processing");
123 mnUserEventId = Application::PostUserEvent(
124 LINK(this,ChangeRequestQueueProcessor,ProcessEvent));
131 IMPL_LINK(ChangeRequestQueueProcessor, ProcessEvent, void*, pUnused)
133 (void)pUnused;
135 ::osl::MutexGuard aGuard (maMutex);
137 mnUserEventId = 0;
139 ProcessOneEvent();
141 if ( ! maQueue.empty())
143 // Schedule the processing of the next event.
144 StartProcessing();
147 return 0;
153 void ChangeRequestQueueProcessor::ProcessOneEvent (void)
155 ::osl::MutexGuard aGuard (maMutex);
157 SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ProcessOneEvent");
159 if (mxConfiguration.is()
160 && ! maQueue.empty())
162 // Get and remove the first entry from the queue.
163 Reference<XConfigurationChangeRequest> xRequest (maQueue.front());
164 maQueue.pop_front();
166 // Execute the change request.
167 if (xRequest.is())
169 #if OSL_DEBUG_LEVEL >= 2
170 TraceRequest(xRequest);
171 #endif
172 xRequest->execute(mxConfiguration);
175 if (maQueue.empty())
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 if (mpConfigurationUpdater.get() != NULL)
182 #if OSL_DEBUG_LEVEL >= 2
183 ConfigurationTracer::TraceConfiguration (
184 mxConfiguration, "updating to configuration");
185 #endif
186 mpConfigurationUpdater->RequestUpdate(mxConfiguration);
195 bool ChangeRequestQueueProcessor::IsEmpty (void) const
197 return maQueue.empty();
203 void ChangeRequestQueueProcessor::ProcessUntilEmpty (void)
205 while ( ! IsEmpty())
206 ProcessOneEvent();
212 void ChangeRequestQueueProcessor::Clear (void)
214 ::osl::MutexGuard aGuard (maMutex);
215 maQueue.clear();
219 } } // end of namespace sd::framework::configuration
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */