1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SD_FRAMEWORK_CHANGE_REQUEST_QUEUE_PROCESSOR_HXX 29 #define SD_FRAMEWORK_CHANGE_REQUEST_QUEUE_PROCESSOR_HXX 30 31 #include "ChangeRequestQueue.hxx" 32 #include <osl/mutex.hxx> 33 #include <rtl/ref.hxx> 34 #include <com/sun/star/drawing/framework/XConfigurationChangeRequest.hpp> 35 #include <com/sun/star/drawing/framework/ConfigurationChangeEvent.hpp> 36 37 #include <cppuhelper/interfacecontainer.hxx> 38 #include <tools/link.hxx> 39 40 #include <boost/shared_ptr.hpp> 41 42 namespace sd { namespace framework { 43 44 class ConfigurationController; 45 class ConfigurationUpdater; 46 47 /** The ChangeRequestQueueProcessor ownes the ChangeRequestQueue and 48 processes the configuration change requests. 49 50 When after processing one entry the queue is empty then the 51 XConfigurationController::update() method is called so that the changes 52 made to the local XConfiguration reference are reflected by the UI. 53 54 Queue entries are processed asynchronously by calling PostUserEvent(). 55 */ 56 class ChangeRequestQueueProcessor 57 { 58 public: 59 /** The queue processor is created with a reference to an 60 ConfigurationController so that its UpdateConfiguration() method can 61 be called when the queue becomes empty. 62 */ 63 ChangeRequestQueueProcessor ( 64 const ::rtl::Reference<ConfigurationController>& rxController, 65 const ::boost::shared_ptr<ConfigurationUpdater>& rpUpdater); 66 ~ChangeRequestQueueProcessor (void); 67 68 /** Sets the configuration who will be changed by subsequent change 69 requests. This method should be called only by the configuration 70 controller who owns the configuration. 71 */ 72 void SetConfiguration ( 73 const ::com::sun::star::uno::Reference< 74 ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration); 75 76 /** The given request is appended to the end of the queue and will 77 eventually be processed when all other entries in front of it have 78 been processed. 79 */ 80 void AddRequest (const ::com::sun::star::uno::Reference< 81 ::com::sun::star::drawing::framework::XConfigurationChangeRequest>& rxRequest); 82 83 /** Returns </sal_True> when the queue is empty. 84 */ 85 bool IsEmpty (void) const; 86 87 /** Process all events in the queue synchronously. 88 89 <p>This method is typically called when the framework is shut down 90 to establish an empty configuration.</p> 91 */ 92 void ProcessUntilEmpty (void); 93 94 /** Process the first event in queue. 95 */ 96 void ProcessOneEvent (void); 97 98 /** Remove all events from the queue. 99 100 <p>This method is typically called when the framework is shut down 101 to avoid the processing of still pending activation requests.</p> 102 */ 103 void Clear (void); 104 105 private: 106 mutable ::osl::Mutex maMutex; 107 108 ChangeRequestQueue maQueue; 109 110 /** The id returned by the last PostUserEvent() call. This id is stored 111 so that a pending user event can be removed whent he queue processor 112 is destroyed. 113 */ 114 sal_uIntPtr mnUserEventId; 115 116 ::com::sun::star::uno::Reference< 117 ::com::sun::star::drawing::framework::XConfiguration> mxConfiguration; 118 119 ::rtl::Reference<ConfigurationController> mpConfigurationController; 120 121 ::boost::shared_ptr<ConfigurationUpdater> mpConfigurationUpdater; 122 123 /** Initiate the processing of the entries in the queue. The actual 124 processing starts asynchronously. 125 */ 126 void StartProcessing (void); 127 128 /** Callback function for the PostUserEvent() call. 129 */ 130 DECL_LINK(ProcessEvent,void*); 131 }; 132 133 134 } } // end of namespace sd::framework 135 136 #endif 137