1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
;
38 #if OSL_DEBUG_LEVEL >= 2
40 void TraceRequest (const Reference
<XConfigurationChangeRequest
>& rxRequest
)
42 Reference
<container::XNamed
> xNamed (rxRequest
, UNO_QUERY
);
44 SAL_INFO("sd.fwk", OSL_THIS_FUNC
<< ": " <<
45 OUStringToOString(xNamed
->getName(), RTL_TEXTENCODING_UTF8
).getStr());
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
)
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
;
91 void ChangeRequestQueueProcessor::AddRequest (
92 const Reference
<XConfigurationChangeRequest
>& rxRequest
)
94 ::osl::MutexGuard
aGuard (maMutex
);
96 #if OSL_DEBUG_LEVEL >= 2
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
);
107 maQueue
.push_back(rxRequest
);
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
)
135 ::osl::MutexGuard
aGuard (maMutex
);
141 if ( ! maQueue
.empty())
143 // Schedule the processing of the next event.
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());
166 // Execute the change request.
169 #if OSL_DEBUG_LEVEL >= 2
170 TraceRequest(xRequest
);
172 xRequest
->execute(mxConfiguration
);
177 SAL_INFO("sd.fwk", OSL_THIS_FUNC
<< ": All requests are processed");
178 // The queue is empty so tell the ConfigurationManager to update
180 if (mpConfigurationUpdater
.get() != NULL
)
182 #if OSL_DEBUG_LEVEL >= 2
183 ConfigurationTracer::TraceConfiguration (
184 mxConfiguration
, "updating to configuration");
186 mpConfigurationUpdater
->RequestUpdate(mxConfiguration
);
195 bool ChangeRequestQueueProcessor::IsEmpty (void) const
197 return maQueue
.empty();
203 void ChangeRequestQueueProcessor::ProcessUntilEmpty (void)
212 void ChangeRequestQueueProcessor::Clear (void)
214 ::osl::MutexGuard
aGuard (maMutex
);
219 } } // end of namespace sd::framework::configuration
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */