merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / framework / configuration / ChangeRequestQueueProcessor.cxx
blob4190a343b497493beff4f6fb28f31620ff7fbaf1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChangeRequestQueueProcessor.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "ChangeRequestQueueProcessor.hxx"
34 #include "ConfigurationTracer.hxx"
36 #include "framework/ConfigurationController.hxx"
37 #include "ConfigurationUpdater.hxx"
39 #include <vcl/svapp.hxx>
40 #include <com/sun/star/container/XNamed.hpp>
41 #include <com/sun/star/drawing/framework/XConfiguration.hpp>
42 #include <com/sun/star/drawing/framework/ConfigurationChangeEvent.hpp>
44 using namespace ::com::sun::star;
45 using namespace ::com::sun::star::uno;
46 using namespace ::com::sun::star::drawing::framework;
48 #undef VERBOSE
49 //#define VERBOSE 1
51 namespace {
53 #ifdef VERBOSE
55 void TraceRequest (const Reference<XConfigurationChangeRequest>& rxRequest)
57 Reference<container::XNamed> xNamed (rxRequest, UNO_QUERY);
58 if (xNamed.is())
59 OSL_TRACE(" %s\n",
60 ::rtl::OUStringToOString(xNamed->getName(), RTL_TEXTENCODING_UTF8).getStr());
63 #endif
65 } // end of anonymous namespace
68 namespace sd { namespace framework {
70 ChangeRequestQueueProcessor::ChangeRequestQueueProcessor (
71 const ::rtl::Reference<ConfigurationController>& rpConfigurationController,
72 const ::boost::shared_ptr<ConfigurationUpdater>& rpConfigurationUpdater)
73 : maMutex(),
74 maQueue(),
75 mnUserEventId(0),
76 mxConfiguration(),
77 mpConfigurationController(rpConfigurationController),
78 mpConfigurationUpdater(rpConfigurationUpdater)
85 ChangeRequestQueueProcessor::~ChangeRequestQueueProcessor (void)
87 if (mnUserEventId != 0)
88 Application::RemoveUserEvent(mnUserEventId);
94 void ChangeRequestQueueProcessor::SetConfiguration (
95 const Reference<XConfiguration>& rxConfiguration)
97 ::osl::MutexGuard aGuard (maMutex);
99 mxConfiguration = rxConfiguration;
100 StartProcessing();
106 void ChangeRequestQueueProcessor::AddRequest (
107 const Reference<XConfigurationChangeRequest>& rxRequest)
109 ::osl::MutexGuard aGuard (maMutex);
111 #ifdef VERBOSE
112 if (maQueue.empty())
114 OSL_TRACE("Adding requests to empty queue\n");
115 ConfigurationTracer::TraceConfiguration(
116 mxConfiguration, "current configuration of queue processor");
118 OSL_TRACE("Adding request\n");
119 TraceRequest(rxRequest);
120 #endif
122 maQueue.push_back(rxRequest);
123 StartProcessing();
129 void ChangeRequestQueueProcessor::StartProcessing (void)
131 ::osl::MutexGuard aGuard (maMutex);
133 if (mnUserEventId == 0
134 && mxConfiguration.is()
135 && ! maQueue.empty())
137 #ifdef VERBOSE
138 OSL_TRACE("ChangeRequestQueueProcessor scheduling processing\n");
139 #endif
140 mnUserEventId = Application::PostUserEvent(
141 LINK(this,ChangeRequestQueueProcessor,ProcessEvent));
148 IMPL_LINK(ChangeRequestQueueProcessor, ProcessEvent, void*, pUnused)
150 (void)pUnused;
152 ::osl::MutexGuard aGuard (maMutex);
154 mnUserEventId = 0;
156 ProcessOneEvent();
158 if ( ! maQueue.empty())
160 // Schedule the processing of the next event.
161 StartProcessing();
164 return 0;
170 void ChangeRequestQueueProcessor::ProcessOneEvent (void)
172 ::osl::MutexGuard aGuard (maMutex);
174 #ifdef VERBOSE
175 OSL_TRACE("ProcessOneEvent\n");
176 #endif
178 if (mxConfiguration.is()
179 && ! maQueue.empty())
181 // Get and remove the first entry from the queue.
182 Reference<XConfigurationChangeRequest> xRequest (maQueue.front());
183 maQueue.pop_front();
185 // Execute the change request.
186 if (xRequest.is())
188 #ifdef VERBOSE
189 TraceRequest(xRequest);
190 #endif
191 xRequest->execute(mxConfiguration);
194 if (maQueue.empty())
196 #ifdef VERBOSE
197 OSL_TRACE("All requests are processed\n");
198 #endif
199 // The queue is empty so tell the ConfigurationManager to update
200 // its state.
201 if (mpConfigurationUpdater.get() != NULL)
203 ConfigurationTracer::TraceConfiguration (
204 mxConfiguration, "updating to configuration");
206 mpConfigurationUpdater->RequestUpdate(mxConfiguration);
215 bool ChangeRequestQueueProcessor::IsEmpty (void) const
217 return maQueue.empty();
223 void ChangeRequestQueueProcessor::ProcessUntilEmpty (void)
225 while ( ! IsEmpty())
226 ProcessOneEvent();
232 void ChangeRequestQueueProcessor::Clear (void)
234 ::osl::MutexGuard aGuard (maMutex);
235 maQueue.clear();
239 } } // end of namespace sd::framework::configuration