1*b1cdbd2cSJim Jagielski /************************************************************** 2*b1cdbd2cSJim Jagielski * 3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one 4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file 5*b1cdbd2cSJim Jagielski * distributed with this work for additional information 6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file 7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the 8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance 9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at 10*b1cdbd2cSJim Jagielski * 11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0 12*b1cdbd2cSJim Jagielski * 13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing, 14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an 15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the 17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations 18*b1cdbd2cSJim Jagielski * under the License. 19*b1cdbd2cSJim Jagielski * 20*b1cdbd2cSJim Jagielski *************************************************************/ 21*b1cdbd2cSJim Jagielski 22*b1cdbd2cSJim Jagielski #ifndef SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_QUEUE_HXX 23*b1cdbd2cSJim Jagielski #define SD_SIDEBAR_PANELS_MASTER_PAGE_CONTAINER_QUEUE_HXX 24*b1cdbd2cSJim Jagielski 25*b1cdbd2cSJim Jagielski #include "MasterPageContainer.hxx" 26*b1cdbd2cSJim Jagielski #include "MasterPageDescriptor.hxx" 27*b1cdbd2cSJim Jagielski 28*b1cdbd2cSJim Jagielski #include <boost/scoped_ptr.hpp> 29*b1cdbd2cSJim Jagielski #include <boost/weak_ptr.hpp> 30*b1cdbd2cSJim Jagielski 31*b1cdbd2cSJim Jagielski namespace sd { namespace sidebar { 32*b1cdbd2cSJim Jagielski 33*b1cdbd2cSJim Jagielski 34*b1cdbd2cSJim Jagielski /** The queue stores and processes all requests from a MasterPageContainer 35*b1cdbd2cSJim Jagielski for the creation of previews. 36*b1cdbd2cSJim Jagielski The order of request processing and its timing is controlled by a 37*b1cdbd2cSJim Jagielski heuristic that uses values given with each request and which is 38*b1cdbd2cSJim Jagielski controlled by various parameters that are described below. 39*b1cdbd2cSJim Jagielski */ 40*b1cdbd2cSJim Jagielski class MasterPageContainerQueue 41*b1cdbd2cSJim Jagielski { 42*b1cdbd2cSJim Jagielski public: 43*b1cdbd2cSJim Jagielski class ContainerAdapter { public: 44*b1cdbd2cSJim Jagielski virtual bool UpdateDescriptor ( 45*b1cdbd2cSJim Jagielski const SharedMasterPageDescriptor& rpDescriptor, 46*b1cdbd2cSJim Jagielski bool bForcePageObject, 47*b1cdbd2cSJim Jagielski bool bForcePreview, 48*b1cdbd2cSJim Jagielski bool bSendEvents) = 0; 49*b1cdbd2cSJim Jagielski }; 50*b1cdbd2cSJim Jagielski 51*b1cdbd2cSJim Jagielski static MasterPageContainerQueue* Create ( 52*b1cdbd2cSJim Jagielski const ::boost::weak_ptr<ContainerAdapter>& rpContainer); 53*b1cdbd2cSJim Jagielski virtual ~MasterPageContainerQueue (void); 54*b1cdbd2cSJim Jagielski 55*b1cdbd2cSJim Jagielski /** This method is typically called for entries in the container for 56*b1cdbd2cSJim Jagielski which GetPreviewState() returns OS_CREATABLE. The creation of the 57*b1cdbd2cSJim Jagielski preview is then scheduled to be executed asynchronously at a later 58*b1cdbd2cSJim Jagielski point in time. When the preview is available the change listeners 59*b1cdbd2cSJim Jagielski will be notified. 60*b1cdbd2cSJim Jagielski */ 61*b1cdbd2cSJim Jagielski bool RequestPreview (const SharedMasterPageDescriptor& rDescriptor); 62*b1cdbd2cSJim Jagielski 63*b1cdbd2cSJim Jagielski /** Return <TRUE/> when there is a request currently in the queue for 64*b1cdbd2cSJim Jagielski the given token. 65*b1cdbd2cSJim Jagielski */ 66*b1cdbd2cSJim Jagielski bool HasRequest (MasterPageContainer::Token aToken) const; 67*b1cdbd2cSJim Jagielski 68*b1cdbd2cSJim Jagielski /** Return <TRUE/> when there is at least one request in the queue. 69*b1cdbd2cSJim Jagielski */ 70*b1cdbd2cSJim Jagielski bool IsEmpty (void) const; 71*b1cdbd2cSJim Jagielski 72*b1cdbd2cSJim Jagielski /** After this call the queue does not wait anymore for requests with 73*b1cdbd2cSJim Jagielski higher priority when only a small number of requests with lower 74*b1cdbd2cSJim Jagielski priority are present. This method should be called when all 75*b1cdbd2cSJim Jagielski templates are inserted into the MasterPageContainer. 76*b1cdbd2cSJim Jagielski */ 77*b1cdbd2cSJim Jagielski void ProcessAllRequests (void); 78*b1cdbd2cSJim Jagielski 79*b1cdbd2cSJim Jagielski private: 80*b1cdbd2cSJim Jagielski ::boost::weak_ptr<ContainerAdapter> mpWeakContainer; 81*b1cdbd2cSJim Jagielski class PreviewCreationRequest; 82*b1cdbd2cSJim Jagielski class RequestQueue; 83*b1cdbd2cSJim Jagielski ::boost::scoped_ptr<RequestQueue> mpRequestQueue; 84*b1cdbd2cSJim Jagielski Timer maDelayedPreviewCreationTimer; 85*b1cdbd2cSJim Jagielski sal_uInt32 mnRequestsServedCount; 86*b1cdbd2cSJim Jagielski 87*b1cdbd2cSJim Jagielski // There are a couple of values that define various aspects of the 88*b1cdbd2cSJim Jagielski // heuristic that defines the order and timing in which requests for 89*b1cdbd2cSJim Jagielski // preview creation are processed. 90*b1cdbd2cSJim Jagielski 91*b1cdbd2cSJim Jagielski /** The time to wait (in milliseconds) between the creation of previews. 92*b1cdbd2cSJim Jagielski */ 93*b1cdbd2cSJim Jagielski static const sal_Int32 snDelayedCreationTimeout; 94*b1cdbd2cSJim Jagielski 95*b1cdbd2cSJim Jagielski /** The time to wait when the system is not idle. 96*b1cdbd2cSJim Jagielski */ 97*b1cdbd2cSJim Jagielski static const sal_Int32 snDelayedCreationTimeoutWhenNotIdle; 98*b1cdbd2cSJim Jagielski 99*b1cdbd2cSJim Jagielski /** Requests for previews of master pages in a document have their 100*b1cdbd2cSJim Jagielski priority increased by this value. 101*b1cdbd2cSJim Jagielski */ 102*b1cdbd2cSJim Jagielski static const sal_Int32 snMasterPagePriorityBoost; 103*b1cdbd2cSJim Jagielski 104*b1cdbd2cSJim Jagielski /** When only requests which a priority lower than this threshold exist 105*b1cdbd2cSJim Jagielski and not many requests have been made yet then wait with processing 106*b1cdbd2cSJim Jagielski them until more requests are present. 107*b1cdbd2cSJim Jagielski */ 108*b1cdbd2cSJim Jagielski static const sal_Int32 snWaitForMoreRequestsPriorityThreshold; 109*b1cdbd2cSJim Jagielski 110*b1cdbd2cSJim Jagielski /** When only requests which a priority lower than a threshold exist 111*b1cdbd2cSJim Jagielski and not more requests than this number have been made or already 112*b1cdbd2cSJim Jagielski processed then wait with processing them until more requests are 113*b1cdbd2cSJim Jagielski present. 114*b1cdbd2cSJim Jagielski */ 115*b1cdbd2cSJim Jagielski static sal_uInt32 snWaitForMoreRequestsCount; 116*b1cdbd2cSJim Jagielski 117*b1cdbd2cSJim Jagielski MasterPageContainerQueue (const ::boost::weak_ptr<ContainerAdapter>& rpContainer); 118*b1cdbd2cSJim Jagielski void LateInit (void); 119*b1cdbd2cSJim Jagielski 120*b1cdbd2cSJim Jagielski /** Calculate the priority that defines the order in which requests 121*b1cdbd2cSJim Jagielski are processed. 122*b1cdbd2cSJim Jagielski */ 123*b1cdbd2cSJim Jagielski sal_Int32 CalculatePriority (const SharedMasterPageDescriptor& rDescriptor) const; 124*b1cdbd2cSJim Jagielski 125*b1cdbd2cSJim Jagielski DECL_LINK(DelayedPreviewCreation, Timer *); 126*b1cdbd2cSJim Jagielski }; 127*b1cdbd2cSJim Jagielski 128*b1cdbd2cSJim Jagielski } } // end of namespace sd::sidebar 129*b1cdbd2cSJim Jagielski 130*b1cdbd2cSJim Jagielski #endif 131