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 #ifndef INCLUDED_SD_SOURCE_UI_FRAMEWORK_CONFIGURATION_CONFIGURATIONUPDATER_HXX
21 #define INCLUDED_SD_SOURCE_UI_FRAMEWORK_CONFIGURATION_CONFIGURATIONUPDATER_HXX
23 #include "ConfigurationControllerResourceManager.hxx"
24 #include <com/sun/star/drawing/framework/XResourceId.hpp>
25 #include <com/sun/star/drawing/framework/XConfiguration.hpp>
26 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
27 #include <vcl/timer.hxx>
29 #include <boost/shared_ptr.hpp>
31 namespace sd
{ namespace framework
{
33 class ConfigurationClassifier
;
34 class ConfigurationUpdaterLock
;
36 /** This is a helper class for the ConfigurationController. It handles the
37 update of the current configuration so that it looks like a requested
38 configuration. An update is made by activating or deactivating drawing
41 When an update is not successful, i.e. after the update the current
42 configuration is not equivalent to the requested configuration, then a
43 timer is started to repeat the update after a short time.
45 class ConfigurationUpdater
48 /** Create a new ConfigurationUpdater object that notifies configuration
49 changes and the start and end of updates via the given broadcaster.
51 ConfigurationUpdater (
52 const ::boost::shared_ptr
<ConfigurationControllerBroadcaster
>& rpBroadcaster
,
53 const ::boost::shared_ptr
<ConfigurationControllerResourceManager
>& rpResourceManager
,
54 const css::uno::Reference
<
55 css::drawing::framework::XControllerManager
>& rxControllerManager
);
56 ~ConfigurationUpdater();
58 /** This method is typically called once, when the controller manager is
59 accessible to the caller.
61 void SetControllerManager(
62 const css::uno::Reference
<
63 css::drawing::framework::XControllerManager
>& rxControllerManager
);
65 /** Request an update of the current configuration so that it looks like
66 the given requested configuration. It checks whether an update of
67 the current configuration can be done. Calls UpdateConfiguration()
68 if that is the case. Otherwise it schedules a later call to
69 UpdateConfiguration().
71 void RequestUpdate (const css::uno::Reference
<
72 css::drawing::framework::XConfiguration
>& rxRequestedConfiguration
);
75 css::drawing::framework::XConfiguration
> GetCurrentConfiguration() const { return mxCurrentConfiguration
;}
77 friend class ConfigurationUpdaterLock
;
78 /** Return a lock of the called ConfigurationUpdater. While the
79 returned object exists no update of the current configuration is
82 ::boost::shared_ptr
<ConfigurationUpdaterLock
> GetLock();
85 /** A reference to the XControllerManager is kept so that
86 UpdateConfiguration() has access to the other sub controllers.
89 css::drawing::framework::XControllerManager
> mxControllerManager
;
91 ::boost::shared_ptr
<ConfigurationControllerBroadcaster
> mpBroadcaster
;
93 /** The current configuration holds the resources that are currently
94 active. It is modified during an update.
97 css::drawing::framework::XConfiguration
> mxCurrentConfiguration
;
99 /** The requested configuration holds the resources that have been
100 requested to activate or to deactivate since the last update. It is
101 (usually) not modified during an update. This configuration is
102 maintained by the ConfigurationController and given to the
103 ConfigurationUpdater in the RequestUpdate() method.
106 css::drawing::framework::XConfiguration
> mxRequestedConfiguration
;
108 /** This flag is set to </sal_True> when an update of the current
109 configurtion was requested (because the last request in the queue
110 was processed) but could not be exected because the
111 ConfigurationController was locked. A call to UpdateConfiguration()
112 resets the flag to </sal_False>.
114 bool mbUpdatePending
;
116 /** This flag is set to </sal_True> while the UpdateConfiguration() method
117 is running. It is used to prevent reentrance problems with this
120 bool mbUpdateBeingProcessed
;
122 /** The ConfigurationController is locked when this count has a value
123 larger then zero. If the controller is locked then updates of the
124 current configuration are not made.
126 sal_Int32 mnLockCount
;
128 /** This timer is used to check from time to time whether the requested
129 configuration and the current configuration are identical and request
130 an update when they are not.
131 This is used to overcome problems with resources that become
132 available asynchronously.
136 /** The number of failed updates (those after which the current
137 configuration is not equivalent to the requested configuration) is
138 used to determine how long to wait before another update is made.
140 sal_Int32 mnFailedUpdateCount
;
142 ::boost::shared_ptr
<ConfigurationControllerResourceManager
> mpResourceManager
;
144 /** This method does the main work of an update. It calls the sub
145 controllers that are responsible for the various types of resources
146 and tells them to update their active resources. It notifies
147 listeners about the start and end of the configuration update.
149 void UpdateConfiguration();
151 /** Basically calls UpdaterStart() andUpdateEnd() and makes some debug
154 void UpdateCore (const ConfigurationClassifier
& rClassifier
);
156 /** Check for all pure anchors if they have at least one child.
157 Childless pure anchors are deactivated.
158 This affects only the current configuration.
160 void CheckPureAnchors (
161 const css::uno::Reference
<css::drawing::framework::XConfiguration
>& rxConfiguration
,
162 ::std::vector
<css::uno::Reference
<css::drawing::framework::XResourceId
> >&
163 rResourcesToDeactivate
);
165 /** Remove from the requested configuration all pure anchors that have no
166 child. Requested but not yet activated anchors can not be removed
167 because without the actual resource the 'pureness' of an anchor can
170 void CleanRequestedConfiguration();
172 /** Check the success of a recently executed configuration update.
173 When the update failed then start the timer.
175 void CheckUpdateSuccess();
177 /** This method sets the mbUpdateBeingProcessed member that is used to
178 prevent reentrance problems. This method allows function objects
179 easily and safely to modify the variable.
181 void SetUpdateBeingProcessed (bool bValue
);
183 /** Return whether it is possible to do an update of the configuration.
184 This takes into account whether another update is currently being
185 executed, the lock count, and whether the configuration controller
188 bool IsUpdatePossible();
190 /** Lock updates of the current configuration. For intermediate requests
191 for updates mbUpdatePending is set to <TRUE/>.
195 /** When an update was requested since the last LockUpdates() call then
196 RequestUpdate() is called.
198 void UnlockUpdates();
200 DECL_LINK_TYPED(TimeoutHandler
, Timer
*, void);
203 } } // end of namespace sd::framework
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */