1 /* Copyright (C) 2003-2006 Jesper K. Pedersen <blackie@kde.org>
3 This program is free software; you can redistribute it and/or
4 modify it under the terms of the GNU General Public
5 License as published by the Free Software Foundation; either
6 version 2 of the License, or (at your option) any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; see the file COPYING. If not, write to
15 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16 Boston, MA 02110-1301, USA.
18 #ifndef REQUESTQUEUE_H
19 #define REQUESTQUEUE_H
23 #include "StopAction.h"
24 #include "ImageManager/ImageRequest.h"
26 namespace ImageManager
30 // RequestQueue for ImageRequests. Non-synchronized, locking has to be
31 // provided by the user.
32 class RequestQueue
:public QObject
39 // Add a new request to the input queue in the right priority level.
40 // @return 'true', if this is not a request already pending.
41 bool addRequest( ImageRequest
* request
);
43 // Return the next needed ImageRequest from the queue or NULL if there
44 // is none. The ownership is returned back to the caller so it has to
46 ImageRequest
* popNext();
48 // Remove all pending requests from the given client.
49 void cancelRequests( ImageClient
* client
, StopAction action
);
51 bool isRequestStillValid( ImageRequest
* request
);
52 void removeRequest( ImageRequest
* );
55 // A Reference to a ImageRequest withvalue semantic.
56 // This only stores the pointer to an ImageRequest object but behaves
57 // regarding the less-than and equals-operator like the object.
58 // This allows to store ImageRequests with value-semantic in a Set.
59 class ImageRequestReference
{
61 ImageRequestReference() : _ptr(0) {}
62 ImageRequestReference(const ImageRequestReference
& other
)
64 ImageRequestReference(const ImageRequest
* ptr
) : _ptr(ptr
) {}
66 bool operator<(const ImageRequestReference
&other
) const {
67 return *_ptr
< *other
._ptr
;
69 bool operator==(const ImageRequestReference
&other
) const {
70 return *_ptr
== *other
._ptr
;
72 operator const ImageRequest
&() const {
76 const ImageRequest
* _ptr
;
79 typedef QList
<QQueue
<ImageRequest
*> > QueueType
;
81 /** @short Priotized list of queues (= 1 priority queue) of image requests
82 * that are waiting for processing
87 * Set of unique requests currently pending; used to discard the exact
89 * TODO(hzeller): seems, that the unique-pending requests tried to be
90 * handled in different places in kpa but sometimes in a snakeoil
91 * way (it compares pointers instead of the content -> clean up that).
93 QSet
<ImageRequestReference
> _uniquePending
;
95 // All active requests that have a client
96 QSet
<ImageRequest
*> _activeRequests
;
101 #endif /* REQUESTQUEUE_H */