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 #ifndef INCLUDED_SD_SOURCE_UI_FRAMEWORK_CONFIGURATION_CHANGEREQUESTQUEUEPROCESSOR_HXX
21 #define INCLUDED_SD_SOURCE_UI_FRAMEWORK_CONFIGURATION_CHANGEREQUESTQUEUEPROCESSOR_HXX
22 
23 #include "ChangeRequestQueue.hxx"
24 #include <osl/mutex.hxx>
25 
26 #include <tools/link.hxx>
27 
28 #include <memory>
29 
30 namespace com { namespace sun { namespace star { namespace drawing { namespace framework { class XConfiguration; } } } } }
31 namespace com { namespace sun { namespace star { namespace drawing { namespace framework { class XConfigurationChangeRequest; } } } } }
32 
33 struct ImplSVEvent;
34 
35 namespace sd { namespace framework {
36 
37 class ConfigurationUpdater;
38 
39 /** The ChangeRequestQueueProcessor owns the ChangeRequestQueue and
40     processes the configuration change requests.
41 
42     When after processing one entry the queue is empty then the
43     XConfigurationController::update() method is called so that the changes
44     made to the local XConfiguration reference are reflected by the UI.
45 
46     Queue entries are processed asynchronously by calling PostUserEvent().
47 */
48 class ChangeRequestQueueProcessor
49 {
50 public:
51     /** The queue processor is created with a reference to an
52         ConfigurationController so that its UpdateConfiguration() method can
53         be called when the queue becomes empty.
54     */
55     explicit ChangeRequestQueueProcessor (
56         const std::shared_ptr<ConfigurationUpdater>& rpUpdater);
57     ~ChangeRequestQueueProcessor();
58 
59     /** Sets the configuration who will be changed by subsequent change
60         requests.  This method should be called only by the configuration
61         controller who owns the configuration.
62     */
63     void SetConfiguration (
64         const css::uno::Reference<css::drawing::framework::XConfiguration>& rxConfiguration);
65 
66     /** The given request is appended to the end of the queue and will
67         eventually be processed when all other entries in front of it have
68         been processed.
69     */
70     void AddRequest (const css::uno::Reference<css::drawing::framework::XConfigurationChangeRequest>& rxRequest);
71 
72     /** Returns </sal_True> when the queue is empty.
73     */
74     bool IsEmpty() const;
75 
76     /** Process all events in the queue synchronously.
77 
78         <p>This method is typically called when the framework is shut down
79         to establish an empty configuration.</p>
80     */
81     void ProcessUntilEmpty();
82 
83     /** Process the first event in queue.
84     */
85     void ProcessOneEvent();
86 
87     /** Remove all events from the queue.
88 
89         <p>This method is typically called when the framework is shut down
90         to avoid the processing of still pending activation requests.</p>
91     */
92     void Clear();
93 
94 private:
95     mutable ::osl::Mutex maMutex;
96 
97     ChangeRequestQueue maQueue;
98 
99     /** The id returned by the last PostUserEvent() call.  This id is stored
100         so that a pending user event can be removed when the queue processor
101         is destroyed.
102     */
103     ImplSVEvent * mnUserEventId;
104 
105     css::uno::Reference<css::drawing::framework::XConfiguration> mxConfiguration;
106 
107     std::shared_ptr<ConfigurationUpdater> mpConfigurationUpdater;
108 
109     /** Initiate the processing of the entries in the queue.  The actual
110         processing starts asynchronously.
111     */
112     void StartProcessing();
113 
114     /** Callback function for the PostUserEvent() call.
115     */
116     DECL_LINK(ProcessEvent, void*, void);
117 };
118 
119 } } // end of namespace sd::framework
120 
121 #endif
122 
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
124