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 .
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
;
37 #if OSL_DEBUG_LEVEL >= 2
39 void TraceRequest (const Reference
<XConfigurationChangeRequest
>& rxRequest
)
41 Reference
<container::XNamed
> xNamed (rxRequest
, UNO_QUERY
);
43 SAL_INFO("sd.fwk", OSL_THIS_FUNC
<< ": " <<
44 OUStringToOString(xNamed
->getName(), RTL_TEXTENCODING_UTF8
).getStr());
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
)
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
;
80 void ChangeRequestQueueProcessor::AddRequest (
81 const Reference
<XConfigurationChangeRequest
>& rxRequest
)
83 ::osl::MutexGuard
aGuard (maMutex
);
85 #if OSL_DEBUG_LEVEL >= 2
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
);
96 maQueue
.push_back(rxRequest
);
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
);
122 if ( ! maQueue
.empty())
124 // Schedule the processing of the next event.
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());
144 // Execute the change request.
147 #if OSL_DEBUG_LEVEL >= 2
148 TraceRequest(xRequest
);
150 xRequest
->execute(mxConfiguration
);
155 SAL_INFO("sd.fwk", OSL_THIS_FUNC
<< ": All requests are processed");
156 // The queue is empty so tell the ConfigurationManager to update
158 if (mpConfigurationUpdater
.get() != NULL
)
160 #if OSL_DEBUG_LEVEL >= 2
161 ConfigurationTracer::TraceConfiguration (
162 mxConfiguration
, "updating to configuration");
164 mpConfigurationUpdater
->RequestUpdate(mxConfiguration
);
170 bool ChangeRequestQueueProcessor::IsEmpty() const
172 return maQueue
.empty();
175 void ChangeRequestQueueProcessor::ProcessUntilEmpty()
181 void ChangeRequestQueueProcessor::Clear()
183 ::osl::MutexGuard
aGuard (maMutex
);
187 } } // end of namespace sd::framework::configuration
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */