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