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