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