Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "ChangeRequestQueueProcessor.hxx"
31 : : #include "ConfigurationTracer.hxx"
32 : :
33 : : #include "framework/ConfigurationController.hxx"
34 : : #include "ConfigurationUpdater.hxx"
35 : :
36 : : #include <vcl/svapp.hxx>
37 : : #include <com/sun/star/container/XNamed.hpp>
38 : : #include <com/sun/star/drawing/framework/XConfiguration.hpp>
39 : : #include <com/sun/star/drawing/framework/ConfigurationChangeEvent.hpp>
40 : :
41 : : using namespace ::com::sun::star;
42 : : using namespace ::com::sun::star::uno;
43 : : using namespace ::com::sun::star::drawing::framework;
44 : :
45 : : namespace {
46 : :
47 : : #if OSL_DEBUG_LEVEL >= 2
48 : :
49 : : void TraceRequest (const Reference<XConfigurationChangeRequest>& rxRequest)
50 : : {
51 : : Reference<container::XNamed> xNamed (rxRequest, UNO_QUERY);
52 : : if (xNamed.is())
53 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": " <<
54 : : ::rtl::OUStringToOString(xNamed->getName(), RTL_TEXTENCODING_UTF8).getStr());
55 : : }
56 : :
57 : : #endif
58 : :
59 : : } // end of anonymous namespace
60 : :
61 : :
62 : : namespace sd { namespace framework {
63 : :
64 : 130 : ChangeRequestQueueProcessor::ChangeRequestQueueProcessor (
65 : : const ::rtl::Reference<ConfigurationController>& rpConfigurationController,
66 : : const ::boost::shared_ptr<ConfigurationUpdater>& rpConfigurationUpdater)
67 : : : maMutex(),
68 : : maQueue(),
69 : : mnUserEventId(0),
70 : : mxConfiguration(),
71 : : mpConfigurationController(rpConfigurationController),
72 [ + - ][ + - ]: 130 : mpConfigurationUpdater(rpConfigurationUpdater)
73 : : {
74 : 130 : }
75 : :
76 : :
77 : :
78 : :
79 [ + - ]: 130 : ChangeRequestQueueProcessor::~ChangeRequestQueueProcessor (void)
80 : : {
81 [ + - ]: 130 : if (mnUserEventId != 0)
82 [ + - ]: 130 : Application::RemoveUserEvent(mnUserEventId);
83 : 130 : }
84 : :
85 : :
86 : :
87 : :
88 : 130 : void ChangeRequestQueueProcessor::SetConfiguration (
89 : : const Reference<XConfiguration>& rxConfiguration)
90 : : {
91 [ + - ]: 130 : ::osl::MutexGuard aGuard (maMutex);
92 : :
93 [ + - ]: 130 : mxConfiguration = rxConfiguration;
94 [ + - ][ + - ]: 130 : StartProcessing();
95 : 130 : }
96 : :
97 : :
98 : :
99 : :
100 : 2165 : void ChangeRequestQueueProcessor::AddRequest (
101 : : const Reference<XConfigurationChangeRequest>& rxRequest)
102 : : {
103 [ + - ]: 2165 : ::osl::MutexGuard aGuard (maMutex);
104 : :
105 : : #if OSL_DEBUG_LEVEL >= 2
106 : : if (maQueue.empty())
107 : : {
108 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": Adding requests to empty queue");
109 : : ConfigurationTracer::TraceConfiguration(
110 : : mxConfiguration, "current configuration of queue processor");
111 : : }
112 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": Adding request");
113 : : TraceRequest(rxRequest);
114 : : #endif
115 : :
116 [ + - ]: 2165 : maQueue.push_back(rxRequest);
117 [ + - ][ + - ]: 2165 : StartProcessing();
118 : 2165 : }
119 : :
120 : :
121 : :
122 : :
123 : 2625 : void ChangeRequestQueueProcessor::StartProcessing (void)
124 : : {
125 [ + - ]: 2625 : ::osl::MutexGuard aGuard (maMutex);
126 : :
127 [ + + + - : 4059 : if (mnUserEventId == 0
+ + ][ + + ]
128 : 717 : && mxConfiguration.is()
129 : 717 : && ! maQueue.empty())
130 : : {
131 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ChangeRequestQueueProcessor scheduling processing");
132 : : mnUserEventId = Application::PostUserEvent(
133 [ + - ][ + - ]: 587 : LINK(this,ChangeRequestQueueProcessor,ProcessEvent));
134 [ + - ]: 2625 : }
135 : 2625 : }
136 : :
137 : :
138 : :
139 : :
140 : 457 : IMPL_LINK(ChangeRequestQueueProcessor, ProcessEvent, void*, pUnused)
141 : : {
142 : : (void)pUnused;
143 : :
144 [ + - ]: 457 : ::osl::MutexGuard aGuard (maMutex);
145 : :
146 : 457 : mnUserEventId = 0;
147 : :
148 [ + - ]: 457 : ProcessOneEvent();
149 : :
150 [ + + ]: 457 : if ( ! maQueue.empty())
151 : : {
152 : : // Schedule the processing of the next event.
153 [ + - ]: 330 : StartProcessing();
154 : : }
155 : :
156 [ + - ]: 457 : return 0;
157 : : }
158 : :
159 : :
160 : :
161 : :
162 : 2039 : void ChangeRequestQueueProcessor::ProcessOneEvent (void)
163 : : {
164 [ + - ]: 2039 : ::osl::MutexGuard aGuard (maMutex);
165 : :
166 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": ProcessOneEvent");
167 : :
168 [ + - + - ]: 4078 : if (mxConfiguration.is()
[ + - ]
169 : 2039 : && ! maQueue.empty())
170 : : {
171 : : // Get and remove the first entry from the queue.
172 [ + - ]: 2039 : Reference<XConfigurationChangeRequest> xRequest (maQueue.front());
173 [ + - ]: 2039 : maQueue.pop_front();
174 : :
175 : : // Execute the change request.
176 [ + - ]: 2039 : if (xRequest.is())
177 : : {
178 : : #if OSL_DEBUG_LEVEL >= 2
179 : : TraceRequest(xRequest);
180 : : #endif
181 [ + - ][ + - ]: 2039 : xRequest->execute(mxConfiguration);
182 : : }
183 : :
184 [ + + ]: 2039 : if (maQueue.empty())
185 : : {
186 : : SAL_INFO("sd.fwk", OSL_THIS_FUNC << ": All requests are processed");
187 : : // The queue is empty so tell the ConfigurationManager to update
188 : : // its state.
189 [ + - ]: 492 : if (mpConfigurationUpdater.get() != NULL)
190 : : {
191 : : #if OSL_DEBUG_LEVEL >= 2
192 : : ConfigurationTracer::TraceConfiguration (
193 : : mxConfiguration, "updating to configuration");
194 : : #endif
195 [ + - ]: 492 : mpConfigurationUpdater->RequestUpdate(mxConfiguration);
196 : : }
197 : 2039 : }
198 [ + - ]: 2039 : }
199 : 2039 : }
200 : :
201 : :
202 : :
203 : :
204 : 2154 : bool ChangeRequestQueueProcessor::IsEmpty (void) const
205 : : {
206 : 2154 : return maQueue.empty();
207 : : }
208 : :
209 : :
210 : :
211 : :
212 : 130 : void ChangeRequestQueueProcessor::ProcessUntilEmpty (void)
213 : : {
214 [ + + ]: 1114 : while ( ! IsEmpty())
215 : 984 : ProcessOneEvent();
216 : 130 : }
217 : :
218 : :
219 : :
220 : :
221 : 130 : void ChangeRequestQueueProcessor::Clear (void)
222 : : {
223 [ + - ]: 130 : ::osl::MutexGuard aGuard (maMutex);
224 [ + - ]: 130 : maQueue.clear();
225 : 130 : }
226 : :
227 : :
228 : : } } // end of namespace sd::framework::configuration
229 : :
230 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|