bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / framework / configuration / ChangeRequestQueueProcessor.cxx
blob0a0014a9b701b20fdee70f41af92750c53336337
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 .
20 #include "ChangeRequestQueueProcessor.hxx"
21 #include "ConfigurationTracer.hxx"
23 #include "framework/ConfigurationController.hxx"
24 #include "ConfigurationUpdater.hxx"
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>
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::drawing::framework;
35 namespace {
37 #if OSL_DEBUG_LEVEL >= 2
39 void TraceRequest (const Reference<XConfigurationChangeRequest>& rxRequest)
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());
47 #endif
49 } // end of anonymous namespace
51 namespace sd { namespace framework {
53 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 mpConfigurationUpdater(rpConfigurationUpdater)
65 ChangeRequestQueueProcessor::~ChangeRequestQueueProcessor()
67 if (mnUserEventId != 0)
68 Application::RemoveUserEvent(mnUserEventId);
71 void ChangeRequestQueueProcessor::SetConfiguration (
72 const Reference<XConfiguration>& rxConfiguration)
74 ::osl::MutexGuard aGuard (maMutex);
76 mxConfiguration = rxConfiguration;
77 StartProcessing();
80 void ChangeRequestQueueProcessor::AddRequest (
81 const Reference<XConfigurationChangeRequest>& rxRequest)
83 ::osl::MutexGuard aGuard (maMutex);
85 #if OSL_DEBUG_LEVEL >= 2
86 if (maQueue.empty())
88 SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": Adding requests to empty queue");
89 ConfigurationTracer::TraceConfiguration(
90 mxConfiguration, "current configuration of queue processor");
92 SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": Adding request");
93 TraceRequest(rxRequest);
94 #endif
96 maQueue.push_back(rxRequest);
97 StartProcessing();
100 void ChangeRequestQueueProcessor::StartProcessing()
102 ::osl::MutexGuard aGuard (maMutex);
104 if (mnUserEventId == 0
105 && mxConfiguration.is()
106 && ! maQueue.empty())
108 SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ChangeRequestQueueProcessor scheduling processing");
109 mnUserEventId = Application::PostUserEvent(
110 LINK(this,ChangeRequestQueueProcessor,ProcessEvent));
114 IMPL_LINK_NOARG(ChangeRequestQueueProcessor, ProcessEvent)
116 ::osl::MutexGuard aGuard (maMutex);
118 mnUserEventId = 0;
120 ProcessOneEvent();
122 if ( ! maQueue.empty())
124 // Schedule the processing of the next event.
125 StartProcessing();
128 return 0;
131 void ChangeRequestQueueProcessor::ProcessOneEvent()
133 ::osl::MutexGuard aGuard (maMutex);
135 SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ProcessOneEvent");
137 if (mxConfiguration.is()
138 && ! maQueue.empty())
140 // Get and remove the first entry from the queue.
141 Reference<XConfigurationChangeRequest> xRequest (maQueue.front());
142 maQueue.pop_front();
144 // Execute the change request.
145 if (xRequest.is())
147 #if OSL_DEBUG_LEVEL >= 2
148 TraceRequest(xRequest);
149 #endif
150 xRequest->execute(mxConfiguration);
153 if (maQueue.empty())
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 if (mpConfigurationUpdater.get() != NULL)
160 #if OSL_DEBUG_LEVEL >= 2
161 ConfigurationTracer::TraceConfiguration (
162 mxConfiguration, "updating to configuration");
163 #endif
164 mpConfigurationUpdater->RequestUpdate(mxConfiguration);
170 bool ChangeRequestQueueProcessor::IsEmpty() const
172 return maQueue.empty();
175 void ChangeRequestQueueProcessor::ProcessUntilEmpty()
177 while ( ! IsEmpty())
178 ProcessOneEvent();
181 void ChangeRequestQueueProcessor::Clear()
183 ::osl::MutexGuard aGuard (maMutex);
184 maQueue.clear();
187 } } // end of namespace sd::framework::configuration
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */