LibreOffice Module sd (master) 1
ChangeRequestQueueProcessor.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "debugtrace.hxx"
23
25
26#include <utility>
27#include <vcl/svapp.hxx>
28#include <sal/log.hxx>
29#include <com/sun/star/container/XNamed.hpp>
30#include <com/sun/star/drawing/framework/XConfigurationChangeRequest.hpp>
31
32using namespace ::com::sun::star;
33using namespace ::com::sun::star::uno;
35
36namespace {
37
38#if DEBUG_SD_CONFIGURATION_TRACE
39
40void TraceRequest (const Reference<XConfigurationChangeRequest>& rxRequest)
41{
42 Reference<container::XNamed> xNamed (rxRequest, UNO_QUERY);
43 if (xNamed.is())
44 SAL_INFO("sd.fwk", __func__ << ": " << xNamed->getName());
45}
46
47#endif
48
49} // end of anonymous namespace
50
51namespace sd::framework {
52
54 std::shared_ptr<ConfigurationUpdater> pConfigurationUpdater)
55 : mnUserEventId(nullptr),
56 mpConfigurationUpdater(std::move(pConfigurationUpdater))
57{
58}
59
61{
62 if (mnUserEventId != nullptr)
64}
65
67 const Reference<XConfiguration>& rxConfiguration)
68{
69 ::osl::MutexGuard aGuard (maMutex);
70
71 mxConfiguration = rxConfiguration;
73}
74
76 const Reference<XConfigurationChangeRequest>& rxRequest)
77{
78 ::osl::MutexGuard aGuard (maMutex);
79
80#if DEBUG_SD_CONFIGURATION_TRACE
81 if (maQueue.empty())
82 {
83 SAL_INFO("sd.fwk", __func__ << ": Adding requests to empty queue");
85 mxConfiguration, "current configuration of queue processor");
86 }
87 SAL_INFO("sd.fwk", __func__ << ": Adding request");
88 TraceRequest(rxRequest);
89#endif
90
91 maQueue.push(rxRequest);
93}
94
96{
97 ::osl::MutexGuard aGuard (maMutex);
98
99 if (mnUserEventId == nullptr
100 && mxConfiguration.is()
101 && ! maQueue.empty())
102 {
103 SAL_INFO("sd.fwk", __func__ << ": ChangeRequestQueueProcessor scheduling processing");
105 LINK(this,ChangeRequestQueueProcessor,ProcessEvent));
106 }
107}
108
110{
111 ::osl::MutexGuard aGuard (maMutex);
112
113 mnUserEventId = nullptr;
114
115 ProcessOneEvent();
116
117 if ( ! maQueue.empty())
118 {
119 // Schedule the processing of the next event.
120 StartProcessing();
121 }
122}
123
125{
126 ::osl::MutexGuard aGuard (maMutex);
127
128 SAL_INFO("sd.fwk", __func__ << ": ProcessOneEvent");
129
130 if (!mxConfiguration.is() || maQueue.empty())
131 return;
132
133 // Get and remove the first entry from the queue.
134 Reference<XConfigurationChangeRequest> xRequest (maQueue.front());
135 maQueue.pop();
136
137 // Execute the change request.
138 if (xRequest.is())
139 {
140#if DEBUG_SD_CONFIGURATION_TRACE
141 TraceRequest(xRequest);
142#endif
143 xRequest->execute(mxConfiguration);
144 }
145
146 if (!maQueue.empty())
147 return;
148
149 SAL_INFO("sd.fwk", __func__ << ": All requests are processed");
150 // The queue is empty so tell the ConfigurationManager to update
151 // its state.
152 if (mpConfigurationUpdater != nullptr)
153 {
154#if DEBUG_SD_CONFIGURATION_TRACE
156 mxConfiguration, "updating to configuration");
157#endif
159 }
160}
161
163{
164 return maQueue.empty();
165}
166
168{
169 while ( ! IsEmpty())
171}
172
174{
175 ::osl::MutexGuard aGuard (maMutex);
177}
178
179} // end of namespace sd::framework
180
181/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::mutex maMutex
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
The ChangeRequestQueueProcessor owns the ChangeRequestQueue and processes the configuration change re...
void AddRequest(const css::uno::Reference< css::drawing::framework::XConfigurationChangeRequest > &rxRequest)
The given request is appended to the end of the queue and will eventually be processed when all other...
ChangeRequestQueueProcessor(std::shared_ptr< ConfigurationUpdater > pUpdater)
The queue processor is created with a reference to an ConfigurationController so that its UpdateConfi...
ImplSVEvent * mnUserEventId
The id returned by the last PostUserEvent() call.
void StartProcessing()
Initiate the processing of the entries in the queue.
void ProcessUntilEmpty()
Process all events in the queue synchronously.
void ProcessOneEvent()
Process the first event in queue.
void SetConfiguration(const css::uno::Reference< css::drawing::framework::XConfiguration > &rxConfiguration)
Sets the configuration who will be changed by subsequent change requests.
void Clear()
Remove all events from the queue.
bool IsEmpty() const
Returns </sal_True> when the queue is empty.
std::shared_ptr< ConfigurationUpdater > mpConfigurationUpdater
css::uno::Reference< css::drawing::framework::XConfiguration > mxConfiguration
The ChangeRequestQueue stores the pending requests for changes to the requested configuration.
static void TraceConfiguration(const css::uno::Reference< css::drawing::framework::XConfiguration > &rxConfiguration, const char *pMessage)
#define SAL_INFO(area, stream)
IMPL_LINK_NOARG(ChangeRequestQueueProcessor, ProcessEvent, void *, void)