1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChangeRequestQueueProcessor.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "ChangeRequestQueueProcessor.hxx"
34 #include "ConfigurationTracer.hxx"
36 #include "framework/ConfigurationController.hxx"
37 #include "ConfigurationUpdater.hxx"
39 #include <vcl/svapp.hxx>
40 #include <com/sun/star/container/XNamed.hpp>
41 #include <com/sun/star/drawing/framework/XConfiguration.hpp>
42 #include <com/sun/star/drawing/framework/ConfigurationChangeEvent.hpp>
44 using namespace ::com::sun::star
;
45 using namespace ::com::sun::star::uno
;
46 using namespace ::com::sun::star::drawing::framework
;
55 void TraceRequest (const Reference
<XConfigurationChangeRequest
>& rxRequest
)
57 Reference
<container::XNamed
> xNamed (rxRequest
, UNO_QUERY
);
60 ::rtl::OUStringToOString(xNamed
->getName(), RTL_TEXTENCODING_UTF8
).getStr());
65 } // end of anonymous namespace
68 namespace sd
{ namespace framework
{
70 ChangeRequestQueueProcessor::ChangeRequestQueueProcessor (
71 const ::rtl::Reference
<ConfigurationController
>& rpConfigurationController
,
72 const ::boost::shared_ptr
<ConfigurationUpdater
>& rpConfigurationUpdater
)
77 mpConfigurationController(rpConfigurationController
),
78 mpConfigurationUpdater(rpConfigurationUpdater
)
85 ChangeRequestQueueProcessor::~ChangeRequestQueueProcessor (void)
87 if (mnUserEventId
!= 0)
88 Application::RemoveUserEvent(mnUserEventId
);
94 void ChangeRequestQueueProcessor::SetConfiguration (
95 const Reference
<XConfiguration
>& rxConfiguration
)
97 ::osl::MutexGuard
aGuard (maMutex
);
99 mxConfiguration
= rxConfiguration
;
106 void ChangeRequestQueueProcessor::AddRequest (
107 const Reference
<XConfigurationChangeRequest
>& rxRequest
)
109 ::osl::MutexGuard
aGuard (maMutex
);
114 OSL_TRACE("Adding requests to empty queue\n");
115 ConfigurationTracer::TraceConfiguration(
116 mxConfiguration
, "current configuration of queue processor");
118 OSL_TRACE("Adding request\n");
119 TraceRequest(rxRequest
);
122 maQueue
.push_back(rxRequest
);
129 void ChangeRequestQueueProcessor::StartProcessing (void)
131 ::osl::MutexGuard
aGuard (maMutex
);
133 if (mnUserEventId
== 0
134 && mxConfiguration
.is()
135 && ! maQueue
.empty())
138 OSL_TRACE("ChangeRequestQueueProcessor scheduling processing\n");
140 mnUserEventId
= Application::PostUserEvent(
141 LINK(this,ChangeRequestQueueProcessor
,ProcessEvent
));
148 IMPL_LINK(ChangeRequestQueueProcessor
, ProcessEvent
, void*, pUnused
)
152 ::osl::MutexGuard
aGuard (maMutex
);
158 if ( ! maQueue
.empty())
160 // Schedule the processing of the next event.
170 void ChangeRequestQueueProcessor::ProcessOneEvent (void)
172 ::osl::MutexGuard
aGuard (maMutex
);
175 OSL_TRACE("ProcessOneEvent\n");
178 if (mxConfiguration
.is()
179 && ! maQueue
.empty())
181 // Get and remove the first entry from the queue.
182 Reference
<XConfigurationChangeRequest
> xRequest (maQueue
.front());
185 // Execute the change request.
189 TraceRequest(xRequest
);
191 xRequest
->execute(mxConfiguration
);
197 OSL_TRACE("All requests are processed\n");
199 // The queue is empty so tell the ConfigurationManager to update
201 if (mpConfigurationUpdater
.get() != NULL
)
203 ConfigurationTracer::TraceConfiguration (
204 mxConfiguration
, "updating to configuration");
206 mpConfigurationUpdater
->RequestUpdate(mxConfiguration
);
215 bool ChangeRequestQueueProcessor::IsEmpty (void) const
217 return maQueue
.empty();
223 void ChangeRequestQueueProcessor::ProcessUntilEmpty (void)
232 void ChangeRequestQueueProcessor::Clear (void)
234 ::osl::MutexGuard
aGuard (maMutex
);
239 } } // end of namespace sd::framework::configuration