xref: /AOO41X/main/sd/source/ui/slidesorter/cache/SlsRequestQueue.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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_SLIDESORTER_REQUEST_QUEUE_HXX
29 #define SD_SLIDESORTER_REQUEST_QUEUE_HXX
30 
31 #include "SlsRequestPriorityClass.hxx"
32 #include "cache/SlsCacheContext.hxx"
33 #include "taskpane/SlideSorterCacheDisplay.hxx"
34 #include <drawdoc.hxx>
35 #include "osl/mutex.hxx"
36 
37 
38 namespace sd { namespace slidesorter { namespace cache {
39 
40 class RequestData;
41 
42 /** The request queue stores requests that are described by the RequestData
43     sorted according to priority class and then priority.
44 */
45 class RequestQueue
46 {
47 public:
48     RequestQueue (const SharedCacheContext& rpCacheContext);
49     ~RequestQueue (void);
50 
51     /** Insert a request with highest or lowest priority in its priority
52         class.  When the request is already present then it is first
53         removed.  This effect is then a re-prioritization.
54         @param rRequestData
55             The request.
56         @param eRequestClass
57             The priority class in which to insert the request with highest
58             or lowest priority.
59         @param bInsertWithHighestPriority
60             When this flag is <TRUE/> the request is inserted with highes
61             priority in its class.  When <FALSE/> the request is inserted
62             with lowest priority.
63     */
64     void AddRequest (
65         CacheKey aKey,
66         RequestPriorityClass eRequestClass,
67         bool bInsertWithHighestPriority = false);
68 
69     /** Remove the specified request from the queue.
70         @param rRequestData
71             It is OK when the specified request is not a member of the
72             queue.
73         @return
74             Returns <TRUE/> when the request has been successfully been
75             removed from the queue.  Otherwise, e.g. because the request was
76             not a member of the queue, <FALSE/> is returned.
77     */
78     bool RemoveRequest (CacheKey aKey);
79 
80     /** Change the priority class of the specified request.
81     */
82     void ChangeClass (
83         CacheKey aKey,
84         RequestPriorityClass eNewRequestClass);
85 
86     /** Get the request with the highest priority int the highest priority class.
87     */
88     CacheKey GetFront (void);
89 
90     // For debugging.
91     RequestPriorityClass GetFrontPriorityClass (void);
92 
93     /** Really a synonym for RemoveRequest(GetFront());
94     */
95     void PopFront (void);
96 
97     /** Returns <TRUE/> when there is no element in the queue.
98     */
99     bool IsEmpty (void);
100 
101     /** Remove all requests from the queue.  This resets the minimum and
102         maximum priorities to their default values.
103     */
104     void Clear (void);
105 
106     /** Return the mutex that guards the access to the priority queue.
107     */
108     ::osl::Mutex& GetMutex (void);
109 
110 private:
111     ::osl::Mutex maMutex;
112     class Container;
113     ::boost::scoped_ptr<Container> mpRequestQueue;
114     SharedCacheContext mpCacheContext;
115 
116     /** A lower bound of the lowest priority of all elements in the queues.
117         The start value is 0.  It is assigned and then decreased every time
118         when an element is inserted or marked as the request with lowest
119         priority.
120     */
121     int mnMinimumPriority;
122     /** An upper bound of the highest priority of all elements in the queues.
123         The start value is 1.  It is assigned and then increased every time
124         when an element is inserted or marked as the request with highest
125         priority.
126     */
127     int mnMaximumPriority;
128 };
129 
130 
131 } } } // end of namespace ::sd::slidesorter::cache
132 
133 #endif
134