1*c45d927aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c45d927aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c45d927aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c45d927aSAndrew Rist * distributed with this work for additional information 6*c45d927aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c45d927aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c45d927aSAndrew Rist * "License"); you may not use this file except in compliance 9*c45d927aSAndrew Rist * with the License. You may obtain a copy of the License at 10*c45d927aSAndrew Rist * 11*c45d927aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*c45d927aSAndrew Rist * 13*c45d927aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c45d927aSAndrew Rist * software distributed under the License is distributed on an 15*c45d927aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c45d927aSAndrew Rist * KIND, either express or implied. See the License for the 17*c45d927aSAndrew Rist * specific language governing permissions and limitations 18*c45d927aSAndrew Rist * under the License. 19*c45d927aSAndrew Rist * 20*c45d927aSAndrew Rist *************************************************************/ 21*c45d927aSAndrew Rist 22*c45d927aSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SD_SLIDESORTER_REQUEST_QUEUE_HXX 25cdf0e10cSrcweir #define SD_SLIDESORTER_REQUEST_QUEUE_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "SlsRequestPriorityClass.hxx" 28cdf0e10cSrcweir #include "cache/SlsCacheContext.hxx" 29cdf0e10cSrcweir #include "taskpane/SlideSorterCacheDisplay.hxx" 30cdf0e10cSrcweir #include <drawdoc.hxx> 31cdf0e10cSrcweir #include "osl/mutex.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir 34cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace cache { 35cdf0e10cSrcweir 36cdf0e10cSrcweir class RequestData; 37cdf0e10cSrcweir 38cdf0e10cSrcweir /** The request queue stores requests that are described by the RequestData 39cdf0e10cSrcweir sorted according to priority class and then priority. 40cdf0e10cSrcweir */ 41cdf0e10cSrcweir class RequestQueue 42cdf0e10cSrcweir { 43cdf0e10cSrcweir public: 44cdf0e10cSrcweir RequestQueue (const SharedCacheContext& rpCacheContext); 45cdf0e10cSrcweir ~RequestQueue (void); 46cdf0e10cSrcweir 47cdf0e10cSrcweir /** Insert a request with highest or lowest priority in its priority 48cdf0e10cSrcweir class. When the request is already present then it is first 49cdf0e10cSrcweir removed. This effect is then a re-prioritization. 50cdf0e10cSrcweir @param rRequestData 51cdf0e10cSrcweir The request. 52cdf0e10cSrcweir @param eRequestClass 53cdf0e10cSrcweir The priority class in which to insert the request with highest 54cdf0e10cSrcweir or lowest priority. 55cdf0e10cSrcweir @param bInsertWithHighestPriority 56cdf0e10cSrcweir When this flag is <TRUE/> the request is inserted with highes 57cdf0e10cSrcweir priority in its class. When <FALSE/> the request is inserted 58cdf0e10cSrcweir with lowest priority. 59cdf0e10cSrcweir */ 60cdf0e10cSrcweir void AddRequest ( 61cdf0e10cSrcweir CacheKey aKey, 62cdf0e10cSrcweir RequestPriorityClass eRequestClass, 63cdf0e10cSrcweir bool bInsertWithHighestPriority = false); 64cdf0e10cSrcweir 65cdf0e10cSrcweir /** Remove the specified request from the queue. 66cdf0e10cSrcweir @param rRequestData 67cdf0e10cSrcweir It is OK when the specified request is not a member of the 68cdf0e10cSrcweir queue. 69cdf0e10cSrcweir @return 70cdf0e10cSrcweir Returns <TRUE/> when the request has been successfully been 71cdf0e10cSrcweir removed from the queue. Otherwise, e.g. because the request was 72cdf0e10cSrcweir not a member of the queue, <FALSE/> is returned. 73cdf0e10cSrcweir */ 74cdf0e10cSrcweir bool RemoveRequest (CacheKey aKey); 75cdf0e10cSrcweir 76cdf0e10cSrcweir /** Change the priority class of the specified request. 77cdf0e10cSrcweir */ 78cdf0e10cSrcweir void ChangeClass ( 79cdf0e10cSrcweir CacheKey aKey, 80cdf0e10cSrcweir RequestPriorityClass eNewRequestClass); 81cdf0e10cSrcweir 82cdf0e10cSrcweir /** Get the request with the highest priority int the highest priority class. 83cdf0e10cSrcweir */ 84cdf0e10cSrcweir CacheKey GetFront (void); 85cdf0e10cSrcweir 86cdf0e10cSrcweir // For debugging. 87cdf0e10cSrcweir RequestPriorityClass GetFrontPriorityClass (void); 88cdf0e10cSrcweir 89cdf0e10cSrcweir /** Really a synonym for RemoveRequest(GetFront()); 90cdf0e10cSrcweir */ 91cdf0e10cSrcweir void PopFront (void); 92cdf0e10cSrcweir 93cdf0e10cSrcweir /** Returns <TRUE/> when there is no element in the queue. 94cdf0e10cSrcweir */ 95cdf0e10cSrcweir bool IsEmpty (void); 96cdf0e10cSrcweir 97cdf0e10cSrcweir /** Remove all requests from the queue. This resets the minimum and 98cdf0e10cSrcweir maximum priorities to their default values. 99cdf0e10cSrcweir */ 100cdf0e10cSrcweir void Clear (void); 101cdf0e10cSrcweir 102cdf0e10cSrcweir /** Return the mutex that guards the access to the priority queue. 103cdf0e10cSrcweir */ 104cdf0e10cSrcweir ::osl::Mutex& GetMutex (void); 105cdf0e10cSrcweir 106cdf0e10cSrcweir private: 107cdf0e10cSrcweir ::osl::Mutex maMutex; 108cdf0e10cSrcweir class Container; 109cdf0e10cSrcweir ::boost::scoped_ptr<Container> mpRequestQueue; 110cdf0e10cSrcweir SharedCacheContext mpCacheContext; 111cdf0e10cSrcweir 112cdf0e10cSrcweir /** A lower bound of the lowest priority of all elements in the queues. 113cdf0e10cSrcweir The start value is 0. It is assigned and then decreased every time 114cdf0e10cSrcweir when an element is inserted or marked as the request with lowest 115cdf0e10cSrcweir priority. 116cdf0e10cSrcweir */ 117cdf0e10cSrcweir int mnMinimumPriority; 118cdf0e10cSrcweir /** An upper bound of the highest priority of all elements in the queues. 119cdf0e10cSrcweir The start value is 1. It is assigned and then increased every time 120cdf0e10cSrcweir when an element is inserted or marked as the request with highest 121cdf0e10cSrcweir priority. 122cdf0e10cSrcweir */ 123cdf0e10cSrcweir int mnMaximumPriority; 124cdf0e10cSrcweir }; 125cdf0e10cSrcweir 126cdf0e10cSrcweir 127cdf0e10cSrcweir } } } // end of namespace ::sd::slidesorter::cache 128cdf0e10cSrcweir 129cdf0e10cSrcweir #endif 130