1*c45d927aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c45d927aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c45d927aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c45d927aSAndrew Rist * distributed with this work for additional information 6*c45d927aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c45d927aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c45d927aSAndrew Rist * "License"); you may not use this file except in compliance 9*c45d927aSAndrew Rist * with the License. You may obtain a copy of the License at 10*c45d927aSAndrew Rist * 11*c45d927aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*c45d927aSAndrew Rist * 13*c45d927aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c45d927aSAndrew Rist * software distributed under the License is distributed on an 15*c45d927aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c45d927aSAndrew Rist * KIND, either express or implied. See the License for the 17*c45d927aSAndrew Rist * specific language governing permissions and limitations 18*c45d927aSAndrew Rist * under the License. 19*c45d927aSAndrew Rist * 20*c45d927aSAndrew Rist *************************************************************/ 21*c45d927aSAndrew Rist 22*c45d927aSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SD_FRAMEWORK_CHANGE_REQUEST_QUEUE_PROCESSOR_HXX 25cdf0e10cSrcweir #define SD_FRAMEWORK_CHANGE_REQUEST_QUEUE_PROCESSOR_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "ChangeRequestQueue.hxx" 28cdf0e10cSrcweir #include <osl/mutex.hxx> 29cdf0e10cSrcweir #include <rtl/ref.hxx> 30cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationChangeRequest.hpp> 31cdf0e10cSrcweir #include <com/sun/star/drawing/framework/ConfigurationChangeEvent.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 34cdf0e10cSrcweir #include <tools/link.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace sd { namespace framework { 39cdf0e10cSrcweir 40cdf0e10cSrcweir class ConfigurationController; 41cdf0e10cSrcweir class ConfigurationUpdater; 42cdf0e10cSrcweir 43cdf0e10cSrcweir /** The ChangeRequestQueueProcessor ownes the ChangeRequestQueue and 44cdf0e10cSrcweir processes the configuration change requests. 45cdf0e10cSrcweir 46cdf0e10cSrcweir When after processing one entry the queue is empty then the 47cdf0e10cSrcweir XConfigurationController::update() method is called so that the changes 48cdf0e10cSrcweir made to the local XConfiguration reference are reflected by the UI. 49cdf0e10cSrcweir 50cdf0e10cSrcweir Queue entries are processed asynchronously by calling PostUserEvent(). 51cdf0e10cSrcweir */ 52cdf0e10cSrcweir class ChangeRequestQueueProcessor 53cdf0e10cSrcweir { 54cdf0e10cSrcweir public: 55cdf0e10cSrcweir /** The queue processor is created with a reference to an 56cdf0e10cSrcweir ConfigurationController so that its UpdateConfiguration() method can 57cdf0e10cSrcweir be called when the queue becomes empty. 58cdf0e10cSrcweir */ 59cdf0e10cSrcweir ChangeRequestQueueProcessor ( 60cdf0e10cSrcweir const ::rtl::Reference<ConfigurationController>& rxController, 61cdf0e10cSrcweir const ::boost::shared_ptr<ConfigurationUpdater>& rpUpdater); 62cdf0e10cSrcweir ~ChangeRequestQueueProcessor (void); 63cdf0e10cSrcweir 64cdf0e10cSrcweir /** Sets the configuration who will be changed by subsequent change 65cdf0e10cSrcweir requests. This method should be called only by the configuration 66cdf0e10cSrcweir controller who owns the configuration. 67cdf0e10cSrcweir */ 68cdf0e10cSrcweir void SetConfiguration ( 69cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 70cdf0e10cSrcweir ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration); 71cdf0e10cSrcweir 72cdf0e10cSrcweir /** The given request is appended to the end of the queue and will 73cdf0e10cSrcweir eventually be processed when all other entries in front of it have 74cdf0e10cSrcweir been processed. 75cdf0e10cSrcweir */ 76cdf0e10cSrcweir void AddRequest (const ::com::sun::star::uno::Reference< 77cdf0e10cSrcweir ::com::sun::star::drawing::framework::XConfigurationChangeRequest>& rxRequest); 78cdf0e10cSrcweir 79cdf0e10cSrcweir /** Returns </sal_True> when the queue is empty. 80cdf0e10cSrcweir */ 81cdf0e10cSrcweir bool IsEmpty (void) const; 82cdf0e10cSrcweir 83cdf0e10cSrcweir /** Process all events in the queue synchronously. 84cdf0e10cSrcweir 85cdf0e10cSrcweir <p>This method is typically called when the framework is shut down 86cdf0e10cSrcweir to establish an empty configuration.</p> 87cdf0e10cSrcweir */ 88cdf0e10cSrcweir void ProcessUntilEmpty (void); 89cdf0e10cSrcweir 90cdf0e10cSrcweir /** Process the first event in queue. 91cdf0e10cSrcweir */ 92cdf0e10cSrcweir void ProcessOneEvent (void); 93cdf0e10cSrcweir 94cdf0e10cSrcweir /** Remove all events from the queue. 95cdf0e10cSrcweir 96cdf0e10cSrcweir <p>This method is typically called when the framework is shut down 97cdf0e10cSrcweir to avoid the processing of still pending activation requests.</p> 98cdf0e10cSrcweir */ 99cdf0e10cSrcweir void Clear (void); 100cdf0e10cSrcweir 101cdf0e10cSrcweir private: 102cdf0e10cSrcweir mutable ::osl::Mutex maMutex; 103cdf0e10cSrcweir 104cdf0e10cSrcweir ChangeRequestQueue maQueue; 105cdf0e10cSrcweir 106cdf0e10cSrcweir /** The id returned by the last PostUserEvent() call. This id is stored 107cdf0e10cSrcweir so that a pending user event can be removed whent he queue processor 108cdf0e10cSrcweir is destroyed. 109cdf0e10cSrcweir */ 110cdf0e10cSrcweir sal_uIntPtr mnUserEventId; 111cdf0e10cSrcweir 112cdf0e10cSrcweir ::com::sun::star::uno::Reference< 113cdf0e10cSrcweir ::com::sun::star::drawing::framework::XConfiguration> mxConfiguration; 114cdf0e10cSrcweir 115cdf0e10cSrcweir ::rtl::Reference<ConfigurationController> mpConfigurationController; 116cdf0e10cSrcweir 117cdf0e10cSrcweir ::boost::shared_ptr<ConfigurationUpdater> mpConfigurationUpdater; 118cdf0e10cSrcweir 119cdf0e10cSrcweir /** Initiate the processing of the entries in the queue. The actual 120cdf0e10cSrcweir processing starts asynchronously. 121cdf0e10cSrcweir */ 122cdf0e10cSrcweir void StartProcessing (void); 123cdf0e10cSrcweir 124cdf0e10cSrcweir /** Callback function for the PostUserEvent() call. 125cdf0e10cSrcweir */ 126cdf0e10cSrcweir DECL_LINK(ProcessEvent,void*); 127cdf0e10cSrcweir }; 128cdf0e10cSrcweir 129cdf0e10cSrcweir 130cdf0e10cSrcweir } } // end of namespace sd::framework 131cdf0e10cSrcweir 132cdf0e10cSrcweir #endif 133