1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "precompiled_sd.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include "ConfigurationUpdater.hxx"
31*cdf0e10cSrcweir #include "ConfigurationTracer.hxx"
32*cdf0e10cSrcweir #include "ConfigurationClassifier.hxx"
33*cdf0e10cSrcweir #include "ConfigurationControllerBroadcaster.hxx"
34*cdf0e10cSrcweir #include "framework/Configuration.hxx"
35*cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <comphelper/scopeguard.hxx>
38*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <boost/bind.hpp>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir using namespace ::com::sun::star;
43*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
44*cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework;
45*cdf0e10cSrcweir using ::sd::framework::FrameworkHelper;
46*cdf0e10cSrcweir using ::rtl::OUString;
47*cdf0e10cSrcweir using ::std::vector;
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #undef VERBOSE
50*cdf0e10cSrcweir //#define VERBOSE 2
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir namespace {
53*cdf0e10cSrcweir static const sal_Int32 snShortTimeout (100);
54*cdf0e10cSrcweir static const sal_Int32 snNormalTimeout (1000);
55*cdf0e10cSrcweir static const sal_Int32 snLongTimeout (10000);
56*cdf0e10cSrcweir static const sal_Int32 snShortTimeoutCountThreshold (1);
57*cdf0e10cSrcweir static const sal_Int32 snNormalTimeoutCountThreshold (5);
58*cdf0e10cSrcweir }
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir namespace sd { namespace framework {
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir //===== ConfigurationUpdaterLock ==============================================
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir class ConfigurationUpdaterLock
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir public:
68*cdf0e10cSrcweir     ConfigurationUpdaterLock (ConfigurationUpdater& rUpdater)
69*cdf0e10cSrcweir         : mrUpdater(rUpdater) { mrUpdater.LockUpdates(); }
70*cdf0e10cSrcweir     ~ConfigurationUpdaterLock(void) { mrUpdater.UnlockUpdates(); }
71*cdf0e10cSrcweir private:
72*cdf0e10cSrcweir     ConfigurationUpdater& mrUpdater;
73*cdf0e10cSrcweir };
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir //===== ConfigurationUpdater ==================================================
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir ConfigurationUpdater::ConfigurationUpdater (
81*cdf0e10cSrcweir     const ::boost::shared_ptr<ConfigurationControllerBroadcaster>& rpBroadcaster,
82*cdf0e10cSrcweir     const ::boost::shared_ptr<ConfigurationControllerResourceManager>& rpResourceManager,
83*cdf0e10cSrcweir     const Reference<XControllerManager>& rxControllerManager)
84*cdf0e10cSrcweir     : mxControllerManager(),
85*cdf0e10cSrcweir       mpBroadcaster(rpBroadcaster),
86*cdf0e10cSrcweir       mxCurrentConfiguration(Reference<XConfiguration>(new Configuration(NULL, false))),
87*cdf0e10cSrcweir       mxRequestedConfiguration(),
88*cdf0e10cSrcweir       mbUpdatePending(false),
89*cdf0e10cSrcweir       mbUpdateBeingProcessed(false),
90*cdf0e10cSrcweir       mnLockCount(0),
91*cdf0e10cSrcweir       maUpdateTimer(),
92*cdf0e10cSrcweir       mnFailedUpdateCount(0),
93*cdf0e10cSrcweir       mpResourceManager(rpResourceManager)
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir     // Prepare the timer that is started when after an update the current
96*cdf0e10cSrcweir     // and the requested configuration differ.  With the timer we try
97*cdf0e10cSrcweir     // updates until the two configurations are the same.
98*cdf0e10cSrcweir     maUpdateTimer.SetTimeout(snNormalTimeout);
99*cdf0e10cSrcweir     maUpdateTimer.SetTimeoutHdl(LINK(this,ConfigurationUpdater,TimeoutHandler));
100*cdf0e10cSrcweir     SetControllerManager(rxControllerManager);
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir ConfigurationUpdater::~ConfigurationUpdater (void)
107*cdf0e10cSrcweir {
108*cdf0e10cSrcweir     maUpdateTimer.Stop();
109*cdf0e10cSrcweir }
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir void ConfigurationUpdater::SetControllerManager(
115*cdf0e10cSrcweir     const Reference<XControllerManager>& rxControllerManager)
116*cdf0e10cSrcweir {
117*cdf0e10cSrcweir     mxControllerManager = rxControllerManager;
118*cdf0e10cSrcweir }
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir void ConfigurationUpdater::RequestUpdate (
124*cdf0e10cSrcweir     const Reference<XConfiguration>& rxRequestedConfiguration)
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     mxRequestedConfiguration = rxRequestedConfiguration;
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     // Find out whether we really can update the configuration.
129*cdf0e10cSrcweir     if (IsUpdatePossible())
130*cdf0e10cSrcweir     {
131*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=1
132*cdf0e10cSrcweir         OSL_TRACE("UpdateConfiguration start");
133*cdf0e10cSrcweir #endif
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir         // Call UpdateConfiguration while that is possible and while someone
136*cdf0e10cSrcweir         // set mbUpdatePending to true in the middle of it.
137*cdf0e10cSrcweir         do
138*cdf0e10cSrcweir         {
139*cdf0e10cSrcweir             UpdateConfiguration();
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir             if (mbUpdatePending && IsUpdatePossible())
142*cdf0e10cSrcweir                 continue;
143*cdf0e10cSrcweir         }
144*cdf0e10cSrcweir         while (false);
145*cdf0e10cSrcweir     }
146*cdf0e10cSrcweir     else
147*cdf0e10cSrcweir     {
148*cdf0e10cSrcweir         mbUpdatePending = true;
149*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=1
150*cdf0e10cSrcweir         OSL_TRACE("scheduling update for later");
151*cdf0e10cSrcweir #endif
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir Reference<XConfiguration> ConfigurationUpdater::GetCurrentConfiguration (void) const
159*cdf0e10cSrcweir {
160*cdf0e10cSrcweir     return mxCurrentConfiguration;
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir bool ConfigurationUpdater::IsUpdatePossible (void)
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir     return ! mbUpdateBeingProcessed
169*cdf0e10cSrcweir         && mxControllerManager.is()
170*cdf0e10cSrcweir         && mnLockCount==0
171*cdf0e10cSrcweir         && mxRequestedConfiguration.is()
172*cdf0e10cSrcweir         && mxCurrentConfiguration.is();
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir void ConfigurationUpdater::UpdateConfiguration (void)
179*cdf0e10cSrcweir {
180*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=1
181*cdf0e10cSrcweir         OSL_TRACE("UpdateConfiguration update");
182*cdf0e10cSrcweir #endif
183*cdf0e10cSrcweir     SetUpdateBeingProcessed(true);
184*cdf0e10cSrcweir     comphelper::ScopeGuard aScopeGuard (
185*cdf0e10cSrcweir         ::boost::bind(&ConfigurationUpdater::SetUpdateBeingProcessed, this, false));
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     try
188*cdf0e10cSrcweir     {
189*cdf0e10cSrcweir         mbUpdatePending = false;
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir         CleanRequestedConfiguration();
192*cdf0e10cSrcweir         ConfigurationClassifier aClassifier(mxRequestedConfiguration, mxCurrentConfiguration);
193*cdf0e10cSrcweir         if (aClassifier.Partition())
194*cdf0e10cSrcweir         {
195*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=2
196*cdf0e10cSrcweir             OSL_TRACE("ConfigurationUpdater::UpdateConfiguration(");
197*cdf0e10cSrcweir             ConfigurationTracer::TraceConfiguration(
198*cdf0e10cSrcweir                 mxRequestedConfiguration, "requested configuration");
199*cdf0e10cSrcweir             ConfigurationTracer::TraceConfiguration(
200*cdf0e10cSrcweir                 mxCurrentConfiguration, "current configuration");
201*cdf0e10cSrcweir #endif
202*cdf0e10cSrcweir             // Notify the begining of the update.
203*cdf0e10cSrcweir             ConfigurationChangeEvent aEvent;
204*cdf0e10cSrcweir             aEvent.Type = FrameworkHelper::msConfigurationUpdateStartEvent;
205*cdf0e10cSrcweir             aEvent.Configuration = mxRequestedConfiguration;
206*cdf0e10cSrcweir             mpBroadcaster->NotifyListeners(aEvent);
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir             // Do the actual update.  All exceptions are caught and ignored,
209*cdf0e10cSrcweir             // so that the the end of the update is notified always.
210*cdf0e10cSrcweir             try
211*cdf0e10cSrcweir             {
212*cdf0e10cSrcweir                 if (mnLockCount == 0)
213*cdf0e10cSrcweir                     UpdateCore(aClassifier);
214*cdf0e10cSrcweir             }
215*cdf0e10cSrcweir             catch(RuntimeException)
216*cdf0e10cSrcweir             {
217*cdf0e10cSrcweir             }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir             // Notify the end of the update.
220*cdf0e10cSrcweir             aEvent.Type = FrameworkHelper::msConfigurationUpdateEndEvent;
221*cdf0e10cSrcweir             mpBroadcaster->NotifyListeners(aEvent);
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir             CheckUpdateSuccess();
224*cdf0e10cSrcweir         }
225*cdf0e10cSrcweir         else
226*cdf0e10cSrcweir         {
227*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>0
228*cdf0e10cSrcweir             OSL_TRACE("nothing to do");
229*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=2
230*cdf0e10cSrcweir             ConfigurationTracer::TraceConfiguration(
231*cdf0e10cSrcweir                 mxRequestedConfiguration, "requested configuration");
232*cdf0e10cSrcweir             ConfigurationTracer::TraceConfiguration(
233*cdf0e10cSrcweir                 mxCurrentConfiguration, "current configuration");
234*cdf0e10cSrcweir #endif
235*cdf0e10cSrcweir #endif
236*cdf0e10cSrcweir         }
237*cdf0e10cSrcweir     }
238*cdf0e10cSrcweir     catch (RuntimeException e)
239*cdf0e10cSrcweir     {
240*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
241*cdf0e10cSrcweir     }
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>0
244*cdf0e10cSrcweir     OSL_TRACE("ConfigurationUpdater::UpdateConfiguration)");
245*cdf0e10cSrcweir     OSL_TRACE("UpdateConfiguration end");
246*cdf0e10cSrcweir #endif
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir void ConfigurationUpdater::CleanRequestedConfiguration (void)
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir     if (mxControllerManager.is())
255*cdf0e10cSrcweir     {
256*cdf0e10cSrcweir         // Request the deactivation of pure anchors that have no child.
257*cdf0e10cSrcweir         vector<Reference<XResourceId> > aResourcesToDeactivate;
258*cdf0e10cSrcweir         CheckPureAnchors(mxRequestedConfiguration, aResourcesToDeactivate);
259*cdf0e10cSrcweir         if (!aResourcesToDeactivate.empty() )
260*cdf0e10cSrcweir         {
261*cdf0e10cSrcweir             Reference<XConfigurationController> xCC (
262*cdf0e10cSrcweir                 mxControllerManager->getConfigurationController());
263*cdf0e10cSrcweir             vector<Reference<XResourceId> >::iterator iId;
264*cdf0e10cSrcweir             for (iId=aResourcesToDeactivate.begin(); iId!=aResourcesToDeactivate.end(); ++iId)
265*cdf0e10cSrcweir                 if (iId->is())
266*cdf0e10cSrcweir                     xCC->requestResourceDeactivation(*iId);
267*cdf0e10cSrcweir         }
268*cdf0e10cSrcweir     }
269*cdf0e10cSrcweir }
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir void ConfigurationUpdater::CheckUpdateSuccess (void)
275*cdf0e10cSrcweir {
276*cdf0e10cSrcweir     // When the two configurations differ then start the timer to call
277*cdf0e10cSrcweir     // another update later.
278*cdf0e10cSrcweir     if ( ! AreConfigurationsEquivalent(mxCurrentConfiguration, mxRequestedConfiguration))
279*cdf0e10cSrcweir     {
280*cdf0e10cSrcweir         if (mnFailedUpdateCount <= snShortTimeoutCountThreshold)
281*cdf0e10cSrcweir             maUpdateTimer.SetTimeout(snShortTimeout);
282*cdf0e10cSrcweir         else if (mnFailedUpdateCount < snNormalTimeoutCountThreshold)
283*cdf0e10cSrcweir             maUpdateTimer.SetTimeout(snNormalTimeout);
284*cdf0e10cSrcweir         else
285*cdf0e10cSrcweir             maUpdateTimer.SetTimeout(snLongTimeout);
286*cdf0e10cSrcweir         ++mnFailedUpdateCount;
287*cdf0e10cSrcweir         maUpdateTimer.Start();
288*cdf0e10cSrcweir     }
289*cdf0e10cSrcweir     else
290*cdf0e10cSrcweir     {
291*cdf0e10cSrcweir         // Update was successfull.  Reset the failed update count.
292*cdf0e10cSrcweir         mnFailedUpdateCount = 0;
293*cdf0e10cSrcweir     }
294*cdf0e10cSrcweir }
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir void ConfigurationUpdater::UpdateCore (const ConfigurationClassifier& rClassifier)
300*cdf0e10cSrcweir {
301*cdf0e10cSrcweir     try
302*cdf0e10cSrcweir     {
303*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=2
304*cdf0e10cSrcweir         rClassifier.TraceResourceIdVector(
305*cdf0e10cSrcweir             "requested but not current resources:", rClassifier.GetC1minusC2());
306*cdf0e10cSrcweir         rClassifier.TraceResourceIdVector(
307*cdf0e10cSrcweir             "current but not requested resources:", rClassifier.GetC2minusC1());
308*cdf0e10cSrcweir         rClassifier.TraceResourceIdVector(
309*cdf0e10cSrcweir             "requested and current resources:", rClassifier.GetC1andC2());
310*cdf0e10cSrcweir #endif
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir         // Updating of the sub controllers is done in two steps.  In the
313*cdf0e10cSrcweir         // first the sub controllers typically shut down resources that are
314*cdf0e10cSrcweir         // not requested anymore.  In the second the sub controllers
315*cdf0e10cSrcweir         // typically set up resources that have been newly requested.
316*cdf0e10cSrcweir         mpResourceManager->DeactivateResources(rClassifier.GetC2minusC1(), mxCurrentConfiguration);
317*cdf0e10cSrcweir         mpResourceManager->ActivateResources(rClassifier.GetC1minusC2(), mxCurrentConfiguration);
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=2
320*cdf0e10cSrcweir         OSL_TRACE("ConfigurationController::UpdateConfiguration)");
321*cdf0e10cSrcweir         ConfigurationTracer::TraceConfiguration(
322*cdf0e10cSrcweir             mxRequestedConfiguration, "requested configuration");
323*cdf0e10cSrcweir         ConfigurationTracer::TraceConfiguration(
324*cdf0e10cSrcweir             mxCurrentConfiguration, "current configuration");
325*cdf0e10cSrcweir #endif
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir         // Deactivate pure anchors that have no child.
328*cdf0e10cSrcweir         vector<Reference<XResourceId> > aResourcesToDeactivate;
329*cdf0e10cSrcweir         CheckPureAnchors(mxCurrentConfiguration, aResourcesToDeactivate);
330*cdf0e10cSrcweir         if (!aResourcesToDeactivate.empty() )
331*cdf0e10cSrcweir             mpResourceManager->DeactivateResources(aResourcesToDeactivate, mxCurrentConfiguration);
332*cdf0e10cSrcweir     }
333*cdf0e10cSrcweir     catch(RuntimeException)
334*cdf0e10cSrcweir     {
335*cdf0e10cSrcweir         DBG_UNHANDLED_EXCEPTION();
336*cdf0e10cSrcweir     }
337*cdf0e10cSrcweir }
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir void ConfigurationUpdater::CheckPureAnchors (
343*cdf0e10cSrcweir     const Reference<XConfiguration>& rxConfiguration,
344*cdf0e10cSrcweir     vector<Reference<XResourceId> >& rResourcesToDeactivate)
345*cdf0e10cSrcweir {
346*cdf0e10cSrcweir     if ( ! rxConfiguration.is())
347*cdf0e10cSrcweir         return;
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir     // Get a list of all resources in the configuration.
350*cdf0e10cSrcweir     Sequence<Reference<XResourceId> > aResources(
351*cdf0e10cSrcweir         rxConfiguration->getResources(
352*cdf0e10cSrcweir             NULL, OUString(), AnchorBindingMode_INDIRECT));
353*cdf0e10cSrcweir     sal_Int32 nCount (aResources.getLength());
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir     // Prepare the list of pure anchors that have to be deactivated.
356*cdf0e10cSrcweir     rResourcesToDeactivate.clear();
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir     // Iterate over the list in reverse order because when there is a chain
359*cdf0e10cSrcweir     // of pure anchors with only the last one having no child then the whole
360*cdf0e10cSrcweir     // list has to be deactivated.
361*cdf0e10cSrcweir     sal_Int32 nIndex (nCount-1);
362*cdf0e10cSrcweir     while (nIndex >= 0)
363*cdf0e10cSrcweir     {
364*cdf0e10cSrcweir         const Reference<XResourceId> xResourceId (aResources[nIndex]);
365*cdf0e10cSrcweir         const Reference<XResource> xResource (
366*cdf0e10cSrcweir             mpResourceManager->GetResource(xResourceId).mxResource);
367*cdf0e10cSrcweir         bool bDeactiveCurrentResource (false);
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir         // Skip all resources that are no pure anchors.
370*cdf0e10cSrcweir         if (xResource.is() && xResource->isAnchorOnly())
371*cdf0e10cSrcweir         {
372*cdf0e10cSrcweir             // When xResource is not an anchor of the the next resource in
373*cdf0e10cSrcweir             // the list then it is the anchor of no resource at all.
374*cdf0e10cSrcweir             if (nIndex == nCount-1)
375*cdf0e10cSrcweir             {
376*cdf0e10cSrcweir                 // No following anchors, deactivate this one, then remove it
377*cdf0e10cSrcweir                 // from the list.
378*cdf0e10cSrcweir                 bDeactiveCurrentResource = true;
379*cdf0e10cSrcweir             }
380*cdf0e10cSrcweir             else
381*cdf0e10cSrcweir             {
382*cdf0e10cSrcweir                 const Reference<XResourceId> xPrevResourceId (aResources[nIndex+1]);
383*cdf0e10cSrcweir                 if ( ! xPrevResourceId.is()
384*cdf0e10cSrcweir                     || ! xPrevResourceId->isBoundTo(xResourceId, AnchorBindingMode_DIRECT))
385*cdf0e10cSrcweir                 {
386*cdf0e10cSrcweir                     // The previous resource (id) does not exist or is not bound to
387*cdf0e10cSrcweir                     // the current anchor.
388*cdf0e10cSrcweir                     bDeactiveCurrentResource = true;
389*cdf0e10cSrcweir                 }
390*cdf0e10cSrcweir             }
391*cdf0e10cSrcweir         }
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir         if (bDeactiveCurrentResource)
394*cdf0e10cSrcweir         {
395*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=2
396*cdf0e10cSrcweir             OSL_TRACE("deactiving pure anchor %s because it has no children",
397*cdf0e10cSrcweir                 OUStringToOString(
398*cdf0e10cSrcweir                     FrameworkHelper::ResourceIdToString(xResourceId),
399*cdf0e10cSrcweir                     RTL_TEXTENCODING_UTF8).getStr());
400*cdf0e10cSrcweir #endif
401*cdf0e10cSrcweir             // Erase element from current configuration.
402*cdf0e10cSrcweir             for (sal_Int32 nI=nIndex; nI<nCount-2; ++nI)
403*cdf0e10cSrcweir                 aResources[nI] = aResources[nI+1];
404*cdf0e10cSrcweir             nCount -= 1;
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir             rResourcesToDeactivate.push_back(xResourceId);
407*cdf0e10cSrcweir         }
408*cdf0e10cSrcweir         nIndex -= 1;
409*cdf0e10cSrcweir     }
410*cdf0e10cSrcweir }
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir 
414*cdf0e10cSrcweir 
415*cdf0e10cSrcweir void ConfigurationUpdater::LockUpdates (void)
416*cdf0e10cSrcweir {
417*cdf0e10cSrcweir     ++mnLockCount;
418*cdf0e10cSrcweir }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir void ConfigurationUpdater::UnlockUpdates (void)
424*cdf0e10cSrcweir {
425*cdf0e10cSrcweir     --mnLockCount;
426*cdf0e10cSrcweir     if (mnLockCount == 0 && mbUpdatePending)
427*cdf0e10cSrcweir     {
428*cdf0e10cSrcweir         RequestUpdate(mxRequestedConfiguration);
429*cdf0e10cSrcweir     }
430*cdf0e10cSrcweir }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir ::boost::shared_ptr<ConfigurationUpdaterLock> ConfigurationUpdater::GetLock (void)
436*cdf0e10cSrcweir {
437*cdf0e10cSrcweir     return ::boost::shared_ptr<ConfigurationUpdaterLock>(new ConfigurationUpdaterLock(*this));
438*cdf0e10cSrcweir }
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir void ConfigurationUpdater::SetUpdateBeingProcessed (bool bValue)
444*cdf0e10cSrcweir {
445*cdf0e10cSrcweir     mbUpdateBeingProcessed = bValue;
446*cdf0e10cSrcweir }
447*cdf0e10cSrcweir 
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir IMPL_LINK(ConfigurationUpdater, TimeoutHandler, Timer*, EMPTYARG)
452*cdf0e10cSrcweir {
453*cdf0e10cSrcweir     OSL_TRACE("configuration update timer");
454*cdf0e10cSrcweir     if ( ! mbUpdateBeingProcessed
455*cdf0e10cSrcweir         && mxCurrentConfiguration.is()
456*cdf0e10cSrcweir         && mxRequestedConfiguration.is())
457*cdf0e10cSrcweir     {
458*cdf0e10cSrcweir         if ( ! AreConfigurationsEquivalent(mxCurrentConfiguration, mxRequestedConfiguration))
459*cdf0e10cSrcweir         {
460*cdf0e10cSrcweir             OSL_TRACE("configurations differ, requesting update");
461*cdf0e10cSrcweir             RequestUpdate(mxRequestedConfiguration);
462*cdf0e10cSrcweir         }
463*cdf0e10cSrcweir     }
464*cdf0e10cSrcweir     return 0;
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir } } // end of namespace sd::framework
469