xref: /AOO41X/main/sd/source/ui/framework/configuration/ConfigurationController.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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 "framework/ConfigurationController.hxx"
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "framework/Configuration.hxx"
33*cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx"
34*cdf0e10cSrcweir #include "ConfigurationUpdater.hxx"
35*cdf0e10cSrcweir #include "ConfigurationControllerBroadcaster.hxx"
36*cdf0e10cSrcweir #include "ConfigurationTracer.hxx"
37*cdf0e10cSrcweir #include "GenericConfigurationChangeRequest.hxx"
38*cdf0e10cSrcweir #include "ResourceFactoryManager.hxx"
39*cdf0e10cSrcweir #include "UpdateRequest.hxx"
40*cdf0e10cSrcweir #include "ChangeRequestQueueProcessor.hxx"
41*cdf0e10cSrcweir #include "ConfigurationClassifier.hxx"
42*cdf0e10cSrcweir #include "ViewShellBase.hxx"
43*cdf0e10cSrcweir #include "UpdateLockManager.hxx"
44*cdf0e10cSrcweir #include "DrawController.hxx"
45*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp>
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
49*cdf0e10cSrcweir #include <vos/mutex.hxx>
50*cdf0e10cSrcweir #include <vcl/svapp.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir using namespace ::com::sun::star;
53*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
54*cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework;
55*cdf0e10cSrcweir using rtl::OUString;
56*cdf0e10cSrcweir using ::sd::framework::FrameworkHelper;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir #undef VERBOSE
59*cdf0e10cSrcweir //#define VERBOSE 3
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir namespace sd { namespace framework {
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir Reference<XInterface> SAL_CALL ConfigurationController_createInstance (
65*cdf0e10cSrcweir     const Reference<XComponentContext>& rxContext)
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir     (void)rxContext;
68*cdf0e10cSrcweir     return static_cast<XWeak*>(new ConfigurationController());
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir OUString ConfigurationController_getImplementationName (void) throw(RuntimeException)
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     return OUString(RTL_CONSTASCII_USTRINGPARAM(
77*cdf0e10cSrcweir         "com.sun.star.comp.Draw.framework.configuration.ConfigurationController"));
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir Sequence<rtl::OUString> SAL_CALL ConfigurationController_getSupportedServiceNames (void)
84*cdf0e10cSrcweir     throw (RuntimeException)
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir 	static const OUString sServiceName(OUString::createFromAscii(
87*cdf0e10cSrcweir         "com.sun.star.drawing.framework.ConfigurationController"));
88*cdf0e10cSrcweir 	return Sequence<rtl::OUString>(&sServiceName, 1);
89*cdf0e10cSrcweir }
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir //----- ConfigurationController::Implementation -------------------------------
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir class ConfigurationController::Implementation
97*cdf0e10cSrcweir {
98*cdf0e10cSrcweir public:
99*cdf0e10cSrcweir     Implementation (
100*cdf0e10cSrcweir         ConfigurationController& rController,
101*cdf0e10cSrcweir         const Reference<frame::XController>& rxController);
102*cdf0e10cSrcweir     ~Implementation (void);
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     Reference<XControllerManager> mxControllerManager;
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir     /** The Broadcaster class implements storing and calling of listeners.
107*cdf0e10cSrcweir     */
108*cdf0e10cSrcweir     ::boost::shared_ptr<ConfigurationControllerBroadcaster> mpBroadcaster;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir     /** The requested configuration which is modifed (asynchronously) by
111*cdf0e10cSrcweir         calls to requestResourceActivation() and
112*cdf0e10cSrcweir         requestResourceDeactivation().  The mpConfigurationUpdater makes the
113*cdf0e10cSrcweir         current configuration reflect the content of this one.
114*cdf0e10cSrcweir     */
115*cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
116*cdf0e10cSrcweir         ::com::sun::star::drawing::framework::XConfiguration> mxRequestedConfiguration;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     ViewShellBase* mpBase;
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir     ::boost::shared_ptr<ResourceFactoryManager> mpResourceFactoryContainer;
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     ::boost::shared_ptr<ConfigurationControllerResourceManager> mpResourceManager;
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir     ::boost::shared_ptr<ConfigurationUpdater> mpConfigurationUpdater;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir     /** The queue processor ownes the queue of configuration change request
127*cdf0e10cSrcweir         objects and processes the objects.
128*cdf0e10cSrcweir     */
129*cdf0e10cSrcweir     ::boost::scoped_ptr<ChangeRequestQueueProcessor> mpQueueProcessor;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     ::boost::shared_ptr<ConfigurationUpdaterLock> mpConfigurationUpdaterLock;
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir     sal_Int32 mnLockCount;
134*cdf0e10cSrcweir };
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir //===== ConfigurationController::Lock =========================================
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir ConfigurationController::Lock::Lock (const Reference<XConfigurationController>& rxController)
142*cdf0e10cSrcweir     : mxController(rxController)
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir     OSL_ASSERT(mxController.is());
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     if (mxController.is())
147*cdf0e10cSrcweir         mxController->lock();
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir ConfigurationController::Lock::~Lock (void)
154*cdf0e10cSrcweir {
155*cdf0e10cSrcweir     if (mxController.is())
156*cdf0e10cSrcweir         mxController->unlock();
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir //===== ConfigurationController ===============================================
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir ConfigurationController::ConfigurationController (void) throw()
165*cdf0e10cSrcweir     : ConfigurationControllerInterfaceBase(MutexOwner::maMutex),
166*cdf0e10cSrcweir       mpImplementation(),
167*cdf0e10cSrcweir       mbIsDisposed(false)
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir ConfigurationController::~ConfigurationController (void) throw()
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir void SAL_CALL ConfigurationController::disposing (void)
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir     if (mpImplementation.get() == NULL)
184*cdf0e10cSrcweir         return;
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=1
187*cdf0e10cSrcweir     OSL_TRACE("ConfigurationController::disposing\n");
188*cdf0e10cSrcweir     OSL_TRACE("    requesting empty configuration\n");
189*cdf0e10cSrcweir #endif
190*cdf0e10cSrcweir     // To destroy all resources an empty configuration is requested and then,
191*cdf0e10cSrcweir     // synchronously, all resulting requests are processed.
192*cdf0e10cSrcweir     mpImplementation->mpQueueProcessor->Clear();
193*cdf0e10cSrcweir     restoreConfiguration(new Configuration(this,false));
194*cdf0e10cSrcweir     mpImplementation->mpQueueProcessor->ProcessUntilEmpty();
195*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=1
196*cdf0e10cSrcweir     OSL_TRACE("    all requests processed\n");
197*cdf0e10cSrcweir #endif
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir     // Now that all resources have been deactivated, mark the controller as
200*cdf0e10cSrcweir     // disposed.
201*cdf0e10cSrcweir     mbIsDisposed = true;
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir     // Release the listeners.
204*cdf0e10cSrcweir 	lang::EventObject aEvent;
205*cdf0e10cSrcweir 	aEvent.Source = uno::Reference<uno::XInterface>((cppu::OWeakObject*)this);
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     {
208*cdf0e10cSrcweir         const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
209*cdf0e10cSrcweir         mpImplementation->mpBroadcaster->DisposeAndClear();
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     mpImplementation->mpQueueProcessor.reset();
213*cdf0e10cSrcweir     mpImplementation->mxRequestedConfiguration = NULL;
214*cdf0e10cSrcweir     mpImplementation.reset();
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir void ConfigurationController::ProcessEvent (void)
221*cdf0e10cSrcweir {
222*cdf0e10cSrcweir     if (mpImplementation.get() != NULL)
223*cdf0e10cSrcweir     {
224*cdf0e10cSrcweir         OSL_ASSERT(mpImplementation->mpQueueProcessor.get()!=NULL);
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir         mpImplementation->mpQueueProcessor->ProcessOneEvent();
227*cdf0e10cSrcweir     }
228*cdf0e10cSrcweir }
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir void ConfigurationController::RequestSynchronousUpdate (void)
234*cdf0e10cSrcweir {
235*cdf0e10cSrcweir     if (mpImplementation.get() == NULL)
236*cdf0e10cSrcweir         return;
237*cdf0e10cSrcweir     if (mpImplementation->mpQueueProcessor.get() == 0)
238*cdf0e10cSrcweir         return;
239*cdf0e10cSrcweir     mpImplementation->mpQueueProcessor->ProcessUntilEmpty();
240*cdf0e10cSrcweir }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir //----- XConfigurationControllerBroadcaster -----------------------------------
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir void SAL_CALL ConfigurationController::addConfigurationChangeListener (
248*cdf0e10cSrcweir     const Reference<XConfigurationChangeListener>& rxListener,
249*cdf0e10cSrcweir     const ::rtl::OUString& rsEventType,
250*cdf0e10cSrcweir     const Any& rUserData)
251*cdf0e10cSrcweir     throw (RuntimeException)
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 	ThrowIfDisposed();
256*cdf0e10cSrcweir     OSL_ASSERT(mpImplementation.get()!=NULL);
257*cdf0e10cSrcweir     mpImplementation->mpBroadcaster->AddListener(rxListener, rsEventType, rUserData);
258*cdf0e10cSrcweir }
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir void SAL_CALL ConfigurationController::removeConfigurationChangeListener (
264*cdf0e10cSrcweir     const Reference<XConfigurationChangeListener>& rxListener)
265*cdf0e10cSrcweir     throw (RuntimeException)
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir 	ThrowIfDisposed();
270*cdf0e10cSrcweir     mpImplementation->mpBroadcaster->RemoveListener(rxListener);
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir void SAL_CALL ConfigurationController::notifyEvent (
277*cdf0e10cSrcweir     const ConfigurationChangeEvent& rEvent)
278*cdf0e10cSrcweir     throw (RuntimeException)
279*cdf0e10cSrcweir {
280*cdf0e10cSrcweir 	ThrowIfDisposed();
281*cdf0e10cSrcweir     mpImplementation->mpBroadcaster->NotifyListeners(rEvent);
282*cdf0e10cSrcweir }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir //----- XConfigurationController ----------------------------------------------
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir void SAL_CALL ConfigurationController::lock (void)
291*cdf0e10cSrcweir     throw (RuntimeException)
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir     OSL_ASSERT(mpImplementation.get()!=NULL);
294*cdf0e10cSrcweir     OSL_ASSERT(mpImplementation->mpConfigurationUpdater.get()!=NULL);
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
297*cdf0e10cSrcweir     ThrowIfDisposed();
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     ++mpImplementation->mnLockCount;
301*cdf0e10cSrcweir     if (mpImplementation->mpConfigurationUpdaterLock.get()==NULL)
302*cdf0e10cSrcweir         mpImplementation->mpConfigurationUpdaterLock
303*cdf0e10cSrcweir             = mpImplementation->mpConfigurationUpdater->GetLock();
304*cdf0e10cSrcweir }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir void SAL_CALL ConfigurationController::unlock (void)
310*cdf0e10cSrcweir     throw (RuntimeException)
311*cdf0e10cSrcweir {
312*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir     // Allow unlocking while the ConfigurationController is being disposed
315*cdf0e10cSrcweir     // (but not when that is done and the controller is disposed.)
316*cdf0e10cSrcweir     if (rBHelper.bDisposed)
317*cdf0e10cSrcweir         ThrowIfDisposed();
318*cdf0e10cSrcweir 
319*cdf0e10cSrcweir     OSL_ASSERT(mpImplementation->mnLockCount>0);
320*cdf0e10cSrcweir     --mpImplementation->mnLockCount;
321*cdf0e10cSrcweir     if (mpImplementation->mnLockCount == 0)
322*cdf0e10cSrcweir         mpImplementation->mpConfigurationUpdaterLock.reset();
323*cdf0e10cSrcweir }
324*cdf0e10cSrcweir 
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir void SAL_CALL ConfigurationController::requestResourceActivation (
329*cdf0e10cSrcweir     const Reference<XResourceId>& rxResourceId,
330*cdf0e10cSrcweir     ResourceActivationMode eMode)
331*cdf0e10cSrcweir     throw (RuntimeException)
332*cdf0e10cSrcweir {
333*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
334*cdf0e10cSrcweir    	ThrowIfDisposed();
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     // Check whether we are being disposed.  This is handled differently
337*cdf0e10cSrcweir     // then being completely disposed because the first thing disposing()
338*cdf0e10cSrcweir     // does is to deactivate all remaining resources.  This is done via
339*cdf0e10cSrcweir     // regular methods which must not throw DisposedExceptions.  Therefore
340*cdf0e10cSrcweir     // we just return silently during that stage.
341*cdf0e10cSrcweir     if (rBHelper.bInDispose)
342*cdf0e10cSrcweir     {
343*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=1
344*cdf0e10cSrcweir         OSL_TRACE("ConfigurationController::requestResourceActivation(): ignoring %s\n",
345*cdf0e10cSrcweir             OUStringToOString(
346*cdf0e10cSrcweir                 FrameworkHelper::ResourceIdToString(rxResourceId), RTL_TEXTENCODING_UTF8).getStr());
347*cdf0e10cSrcweir #endif
348*cdf0e10cSrcweir         return;
349*cdf0e10cSrcweir     }
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=2
352*cdf0e10cSrcweir     OSL_TRACE("ConfigurationController::requestResourceActivation() %s\n",
353*cdf0e10cSrcweir         OUStringToOString(
354*cdf0e10cSrcweir             FrameworkHelper::ResourceIdToString(rxResourceId), RTL_TEXTENCODING_UTF8).getStr());
355*cdf0e10cSrcweir #endif
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir     if (rxResourceId.is())
358*cdf0e10cSrcweir     {
359*cdf0e10cSrcweir         if (eMode == ResourceActivationMode_REPLACE)
360*cdf0e10cSrcweir         {
361*cdf0e10cSrcweir             // Get a list of the matching resources and create deactivation
362*cdf0e10cSrcweir             // requests for them.
363*cdf0e10cSrcweir             Sequence<Reference<XResourceId> > aResourceList (
364*cdf0e10cSrcweir                 mpImplementation->mxRequestedConfiguration->getResources(
365*cdf0e10cSrcweir                     rxResourceId->getAnchor(),
366*cdf0e10cSrcweir                     rxResourceId->getResourceTypePrefix(),
367*cdf0e10cSrcweir                     AnchorBindingMode_DIRECT));
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir             for (sal_Int32 nIndex=0; nIndex<aResourceList.getLength(); ++nIndex)
370*cdf0e10cSrcweir             {
371*cdf0e10cSrcweir                 // Do not request the deactivation of the resource for which
372*cdf0e10cSrcweir                 // this method was called.  Doing it would not change the
373*cdf0e10cSrcweir                 // outcome but would result in unnecessary work.
374*cdf0e10cSrcweir                 if (rxResourceId->compareTo(aResourceList[nIndex]) == 0)
375*cdf0e10cSrcweir                     continue;
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir                 // Request the deactivation of a resource and all resources
378*cdf0e10cSrcweir                 // linked to it.
379*cdf0e10cSrcweir                 requestResourceDeactivation(aResourceList[nIndex]);
380*cdf0e10cSrcweir             }
381*cdf0e10cSrcweir         }
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir         Reference<XConfigurationChangeRequest> xRequest(
384*cdf0e10cSrcweir             new GenericConfigurationChangeRequest(
385*cdf0e10cSrcweir                 rxResourceId,
386*cdf0e10cSrcweir                 GenericConfigurationChangeRequest::Activation));
387*cdf0e10cSrcweir         postChangeRequest(xRequest);
388*cdf0e10cSrcweir     }
389*cdf0e10cSrcweir }
390*cdf0e10cSrcweir 
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir 
394*cdf0e10cSrcweir void SAL_CALL ConfigurationController::requestResourceDeactivation (
395*cdf0e10cSrcweir     const Reference<XResourceId>& rxResourceId)
396*cdf0e10cSrcweir     throw (RuntimeException)
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
399*cdf0e10cSrcweir     ThrowIfDisposed();
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=2
402*cdf0e10cSrcweir     OSL_TRACE("ConfigurationController::requestResourceDeactivation() %s\n",
403*cdf0e10cSrcweir             OUStringToOString(
404*cdf0e10cSrcweir                 FrameworkHelper::ResourceIdToString(rxResourceId), RTL_TEXTENCODING_UTF8).getStr());
405*cdf0e10cSrcweir #endif
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir     if (rxResourceId.is())
408*cdf0e10cSrcweir     {
409*cdf0e10cSrcweir         // Request deactivation of all resources linked to the specified one
410*cdf0e10cSrcweir         // as well.
411*cdf0e10cSrcweir         const Sequence<Reference<XResourceId> > aLinkedResources (
412*cdf0e10cSrcweir             mpImplementation->mxRequestedConfiguration->getResources(
413*cdf0e10cSrcweir                 rxResourceId,
414*cdf0e10cSrcweir                 OUString(),
415*cdf0e10cSrcweir                 AnchorBindingMode_DIRECT));
416*cdf0e10cSrcweir         const sal_Int32 nCount (aLinkedResources.getLength());
417*cdf0e10cSrcweir         for (sal_Int32 nIndex=0; nIndex<nCount; ++nIndex)
418*cdf0e10cSrcweir         {
419*cdf0e10cSrcweir             // We do not add deactivation requests directly but call this
420*cdf0e10cSrcweir             // method recursively, so that when one time there are resources
421*cdf0e10cSrcweir             // linked to linked resources, these are handled correctly, too.
422*cdf0e10cSrcweir             requestResourceDeactivation(aLinkedResources[nIndex]);
423*cdf0e10cSrcweir         }
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir         // Add a deactivation request for the specified resource.
426*cdf0e10cSrcweir         Reference<XConfigurationChangeRequest> xRequest(
427*cdf0e10cSrcweir             new GenericConfigurationChangeRequest(
428*cdf0e10cSrcweir                 rxResourceId,
429*cdf0e10cSrcweir                 GenericConfigurationChangeRequest::Deactivation));
430*cdf0e10cSrcweir         postChangeRequest(xRequest);
431*cdf0e10cSrcweir     }
432*cdf0e10cSrcweir }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir 
437*cdf0e10cSrcweir Reference<XResource> SAL_CALL ConfigurationController::getResource (
438*cdf0e10cSrcweir     const Reference<XResourceId>& rxResourceId)
439*cdf0e10cSrcweir     throw (RuntimeException)
440*cdf0e10cSrcweir {
441*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
442*cdf0e10cSrcweir     ThrowIfDisposed();
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir     ConfigurationControllerResourceManager::ResourceDescriptor aDescriptor (
445*cdf0e10cSrcweir         mpImplementation->mpResourceManager->GetResource(rxResourceId));
446*cdf0e10cSrcweir     return aDescriptor.mxResource;
447*cdf0e10cSrcweir }
448*cdf0e10cSrcweir 
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir 
451*cdf0e10cSrcweir 
452*cdf0e10cSrcweir void SAL_CALL ConfigurationController::update (void)
453*cdf0e10cSrcweir     throw (RuntimeException)
454*cdf0e10cSrcweir {
455*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
456*cdf0e10cSrcweir     ThrowIfDisposed();
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir     if (mpImplementation->mpQueueProcessor->IsEmpty())
459*cdf0e10cSrcweir     {
460*cdf0e10cSrcweir         // The queue is empty.  Add another request that does nothing but
461*cdf0e10cSrcweir         // asynchronously trigger a request for an update.
462*cdf0e10cSrcweir         mpImplementation->mpQueueProcessor->AddRequest(new UpdateRequest());
463*cdf0e10cSrcweir     }
464*cdf0e10cSrcweir     else
465*cdf0e10cSrcweir     {
466*cdf0e10cSrcweir         // The queue is not empty, so we rely on the queue processor to
467*cdf0e10cSrcweir         // request an update automatically when the queue becomes empty.
468*cdf0e10cSrcweir     }
469*cdf0e10cSrcweir }
470*cdf0e10cSrcweir 
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir sal_Bool SAL_CALL ConfigurationController::hasPendingRequests (void)
475*cdf0e10cSrcweir     throw (RuntimeException)
476*cdf0e10cSrcweir {
477*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
478*cdf0e10cSrcweir     ThrowIfDisposed();
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir     return ! mpImplementation->mpQueueProcessor->IsEmpty();
481*cdf0e10cSrcweir }
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir void SAL_CALL ConfigurationController::postChangeRequest (
488*cdf0e10cSrcweir     const Reference<XConfigurationChangeRequest>& rxRequest)
489*cdf0e10cSrcweir     throw (RuntimeException)
490*cdf0e10cSrcweir {
491*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
492*cdf0e10cSrcweir     ThrowIfDisposed();
493*cdf0e10cSrcweir 
494*cdf0e10cSrcweir     mpImplementation->mpQueueProcessor->AddRequest(rxRequest);
495*cdf0e10cSrcweir }
496*cdf0e10cSrcweir 
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir Reference<XConfiguration> SAL_CALL ConfigurationController::getRequestedConfiguration (void)
501*cdf0e10cSrcweir     throw (RuntimeException)
502*cdf0e10cSrcweir {
503*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
504*cdf0e10cSrcweir     ThrowIfDisposed();
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir     if (mpImplementation->mxRequestedConfiguration.is())
507*cdf0e10cSrcweir         return Reference<XConfiguration>(
508*cdf0e10cSrcweir             mpImplementation->mxRequestedConfiguration->createClone(), UNO_QUERY);
509*cdf0e10cSrcweir     else
510*cdf0e10cSrcweir         return Reference<XConfiguration>();
511*cdf0e10cSrcweir }
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir 
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir Reference<XConfiguration> SAL_CALL ConfigurationController::getCurrentConfiguration (void)
517*cdf0e10cSrcweir     throw (RuntimeException)
518*cdf0e10cSrcweir {
519*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
520*cdf0e10cSrcweir     ThrowIfDisposed();
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir     Reference<XConfiguration> xCurrentConfiguration(
523*cdf0e10cSrcweir         mpImplementation->mpConfigurationUpdater->GetCurrentConfiguration());
524*cdf0e10cSrcweir     if (xCurrentConfiguration.is())
525*cdf0e10cSrcweir         return Reference<XConfiguration>(xCurrentConfiguration->createClone(), UNO_QUERY);
526*cdf0e10cSrcweir     else
527*cdf0e10cSrcweir         return Reference<XConfiguration>();
528*cdf0e10cSrcweir }
529*cdf0e10cSrcweir 
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir /** The given configuration is restored by generating the appropriate set of
534*cdf0e10cSrcweir     activation and deactivation requests.
535*cdf0e10cSrcweir */
536*cdf0e10cSrcweir void SAL_CALL ConfigurationController::restoreConfiguration (
537*cdf0e10cSrcweir     const Reference<XConfiguration>& rxNewConfiguration)
538*cdf0e10cSrcweir     throw (RuntimeException)
539*cdf0e10cSrcweir {
540*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
541*cdf0e10cSrcweir     ThrowIfDisposed();
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir     // We will probably be making a couple of activation and deactivation
544*cdf0e10cSrcweir     // requests so lock the configuration controller and let it later update
545*cdf0e10cSrcweir     // all changes at once.
546*cdf0e10cSrcweir     ::boost::shared_ptr<ConfigurationUpdaterLock> pLock (
547*cdf0e10cSrcweir         mpImplementation->mpConfigurationUpdater->GetLock());
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir     // Get lists of resources that are to be activated or deactivated.
550*cdf0e10cSrcweir     Reference<XConfiguration> xCurrentConfiguration (mpImplementation->mxRequestedConfiguration);
551*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=1
552*cdf0e10cSrcweir     OSL_TRACE("ConfigurationController::restoreConfiguration(\n");
553*cdf0e10cSrcweir     ConfigurationTracer::TraceConfiguration(rxNewConfiguration, "requested configuration");
554*cdf0e10cSrcweir     ConfigurationTracer::TraceConfiguration(xCurrentConfiguration, "current configuration");
555*cdf0e10cSrcweir #endif
556*cdf0e10cSrcweir     ConfigurationClassifier aClassifier (rxNewConfiguration, xCurrentConfiguration);
557*cdf0e10cSrcweir     aClassifier.Partition();
558*cdf0e10cSrcweir #if defined VERBOSE && VERBOSE>=3
559*cdf0e10cSrcweir     aClassifier.TraceResourceIdVector(
560*cdf0e10cSrcweir         "requested but not current resources:\n", aClassifier.GetC1minusC2());
561*cdf0e10cSrcweir     aClassifier.TraceResourceIdVector(
562*cdf0e10cSrcweir         "current but not requested resources:\n", aClassifier.GetC2minusC1());
563*cdf0e10cSrcweir     aClassifier.TraceResourceIdVector(
564*cdf0e10cSrcweir         "requested and current resources:\n", aClassifier.GetC1andC2());
565*cdf0e10cSrcweir #endif
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir     ConfigurationClassifier::ResourceIdVector::const_iterator iResource;
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir     // Request the deactivation of resources that are not requested in the
570*cdf0e10cSrcweir     // new configuration.
571*cdf0e10cSrcweir     const ConfigurationClassifier::ResourceIdVector& rResourcesToDeactivate (
572*cdf0e10cSrcweir         aClassifier.GetC2minusC1());
573*cdf0e10cSrcweir     for (iResource=rResourcesToDeactivate.begin();
574*cdf0e10cSrcweir          iResource!=rResourcesToDeactivate.end();
575*cdf0e10cSrcweir          ++iResource)
576*cdf0e10cSrcweir     {
577*cdf0e10cSrcweir         requestResourceDeactivation(*iResource);
578*cdf0e10cSrcweir     }
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir     // Request the activation of resources that are requested in the
581*cdf0e10cSrcweir     // new configuration but are not part of the current configuration.
582*cdf0e10cSrcweir     const ConfigurationClassifier::ResourceIdVector& rResourcesToActivate (
583*cdf0e10cSrcweir         aClassifier.GetC1minusC2());
584*cdf0e10cSrcweir     for (iResource=rResourcesToActivate.begin();
585*cdf0e10cSrcweir          iResource!=rResourcesToActivate.end();
586*cdf0e10cSrcweir          ++iResource)
587*cdf0e10cSrcweir     {
588*cdf0e10cSrcweir         requestResourceActivation(*iResource, ResourceActivationMode_ADD);
589*cdf0e10cSrcweir     }
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir     pLock.reset();
592*cdf0e10cSrcweir }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir //----- XResourceFactoryManager -----------------------------------------------
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir void SAL_CALL ConfigurationController::addResourceFactory(
600*cdf0e10cSrcweir     const OUString& sResourceURL,
601*cdf0e10cSrcweir     const Reference<XResourceFactory>& rxResourceFactory)
602*cdf0e10cSrcweir     throw (RuntimeException)
603*cdf0e10cSrcweir {
604*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
605*cdf0e10cSrcweir     ThrowIfDisposed();
606*cdf0e10cSrcweir     mpImplementation->mpResourceFactoryContainer->AddFactory(sResourceURL, rxResourceFactory);
607*cdf0e10cSrcweir }
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir 
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir void SAL_CALL ConfigurationController::removeResourceFactoryForURL(
613*cdf0e10cSrcweir     const OUString& sResourceURL)
614*cdf0e10cSrcweir     throw (RuntimeException)
615*cdf0e10cSrcweir {
616*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
617*cdf0e10cSrcweir     ThrowIfDisposed();
618*cdf0e10cSrcweir     mpImplementation->mpResourceFactoryContainer->RemoveFactoryForURL(sResourceURL);
619*cdf0e10cSrcweir }
620*cdf0e10cSrcweir 
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir 
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir void SAL_CALL ConfigurationController::removeResourceFactoryForReference(
625*cdf0e10cSrcweir     const Reference<XResourceFactory>& rxResourceFactory)
626*cdf0e10cSrcweir     throw (RuntimeException)
627*cdf0e10cSrcweir {
628*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
629*cdf0e10cSrcweir     ThrowIfDisposed();
630*cdf0e10cSrcweir     mpImplementation->mpResourceFactoryContainer->RemoveFactoryForReference(rxResourceFactory);
631*cdf0e10cSrcweir }
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir 
636*cdf0e10cSrcweir Reference<XResourceFactory> SAL_CALL ConfigurationController::getResourceFactory (
637*cdf0e10cSrcweir     const OUString& sResourceURL)
638*cdf0e10cSrcweir     throw (RuntimeException)
639*cdf0e10cSrcweir {
640*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
641*cdf0e10cSrcweir     ThrowIfDisposed();
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir     return mpImplementation->mpResourceFactoryContainer->GetFactory(sResourceURL);
644*cdf0e10cSrcweir }
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir 
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir 
649*cdf0e10cSrcweir //----- XInitialization -------------------------------------------------------
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir void SAL_CALL ConfigurationController::initialize (const Sequence<Any>& aArguments)
652*cdf0e10cSrcweir     throw (Exception, RuntimeException)
653*cdf0e10cSrcweir {
654*cdf0e10cSrcweir     ::osl::MutexGuard aGuard (maMutex);
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir     if (aArguments.getLength() == 1)
657*cdf0e10cSrcweir     {
658*cdf0e10cSrcweir         const ::vos::OGuard aSolarGuard (Application::GetSolarMutex());
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir         mpImplementation.reset(new Implementation(
661*cdf0e10cSrcweir             *this,
662*cdf0e10cSrcweir             Reference<frame::XController>(aArguments[0], UNO_QUERY_THROW)));
663*cdf0e10cSrcweir     }
664*cdf0e10cSrcweir }
665*cdf0e10cSrcweir 
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir //-----------------------------------------------------------------------------
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir void ConfigurationController::ThrowIfDisposed (void) const
672*cdf0e10cSrcweir     throw (::com::sun::star::lang::DisposedException)
673*cdf0e10cSrcweir {
674*cdf0e10cSrcweir 	if (mbIsDisposed)
675*cdf0e10cSrcweir 	{
676*cdf0e10cSrcweir         throw lang::DisposedException (
677*cdf0e10cSrcweir             OUString(RTL_CONSTASCII_USTRINGPARAM(
678*cdf0e10cSrcweir                 "ConfigurationController object has already been disposed")),
679*cdf0e10cSrcweir             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
680*cdf0e10cSrcweir     }
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir     if (mpImplementation.get() == NULL)
683*cdf0e10cSrcweir     {
684*cdf0e10cSrcweir         OSL_ASSERT(mpImplementation.get() != NULL);
685*cdf0e10cSrcweir         throw RuntimeException(
686*cdf0e10cSrcweir             OUString(RTL_CONSTASCII_USTRINGPARAM(
687*cdf0e10cSrcweir                 "ConfigurationController not initialized")),
688*cdf0e10cSrcweir             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
689*cdf0e10cSrcweir     }
690*cdf0e10cSrcweir }
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir //===== ConfigurationController::Implementation ===============================
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir ConfigurationController::Implementation::Implementation (
698*cdf0e10cSrcweir     ConfigurationController& rController,
699*cdf0e10cSrcweir     const Reference<frame::XController>& rxController)
700*cdf0e10cSrcweir     : mxControllerManager(rxController, UNO_QUERY_THROW),
701*cdf0e10cSrcweir       mpBroadcaster(new ConfigurationControllerBroadcaster(&rController)),
702*cdf0e10cSrcweir       mxRequestedConfiguration(new Configuration(&rController, true)),
703*cdf0e10cSrcweir       mpBase(NULL),
704*cdf0e10cSrcweir       mpResourceFactoryContainer(new ResourceFactoryManager(mxControllerManager)),
705*cdf0e10cSrcweir       mpResourceManager(
706*cdf0e10cSrcweir           new ConfigurationControllerResourceManager(mpResourceFactoryContainer,mpBroadcaster)),
707*cdf0e10cSrcweir       mpConfigurationUpdater(
708*cdf0e10cSrcweir           new ConfigurationUpdater(mpBroadcaster, mpResourceManager,mxControllerManager)),
709*cdf0e10cSrcweir       mpQueueProcessor(new ChangeRequestQueueProcessor(&rController,mpConfigurationUpdater)),
710*cdf0e10cSrcweir       mpConfigurationUpdaterLock(),
711*cdf0e10cSrcweir       mnLockCount(0)
712*cdf0e10cSrcweir {
713*cdf0e10cSrcweir     mpQueueProcessor->SetConfiguration(mxRequestedConfiguration);
714*cdf0e10cSrcweir }
715*cdf0e10cSrcweir 
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir 
719*cdf0e10cSrcweir ConfigurationController::Implementation::~Implementation (void)
720*cdf0e10cSrcweir {
721*cdf0e10cSrcweir }
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir 
724*cdf0e10cSrcweir 
725*cdf0e10cSrcweir 
726*cdf0e10cSrcweir } } // end of namespace sd::framework
727