RemoteDrawingEngine: Reduce RP_READ_BITMAP result timeout.
[haiku.git] / src / kits / tracker / EntryIterator.h
blob414e707723e8935d8c4196c5e902e70c1fbaddf6
1 /*
2 Open Tracker License
4 Terms and Conditions
6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
8 Permission is hereby granted, free of charge, to any person obtaining a copy of
9 this software and associated documentation files (the "Software"), to deal in
10 the Software without restriction, including without limitation the rights to
11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12 of the Software, and to permit persons to whom the Software is furnished to do
13 so, subject to the following conditions:
15 The above copyright notice and this permission notice applies to all licensees
16 and shall be included in all copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 Except as contained in this notice, the name of Be Incorporated shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings in
27 this Software without prior written authorization from Be Incorporated.
29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30 of Be Incorporated in the United States and other countries. Other brand product
31 names are registered trademarks or trademarks of their respective holders.
32 All rights reserved.
35 // A lot of the code in here wouldn't be needed if the destructor
36 // for BEntryList was virtual
38 // TODO: get rid of all BEntryList API's in here, replace them with
39 // EntryListBase ones
40 #ifndef _ENTRY_ITERATOR_H
41 #define _ENTRY_ITERATOR_H
44 #include <Directory.h>
45 #include <ObjectList.h>
47 #include "NodeWalker.h"
50 namespace BPrivate {
52 class EntryListBase : public BEntryList {
53 // this is what BEntryList should have been
54 public:
55 EntryListBase();
56 virtual ~EntryListBase() {}
58 virtual status_t InitCheck() const;
60 virtual status_t GetNextEntry(BEntry* entry, bool traverse = false) = 0;
61 virtual status_t GetNextRef(entry_ref* ref) = 0;
62 virtual int32 GetNextDirents(struct dirent* buffer, size_t length,
63 int32 count = INT_MAX) = 0;
65 virtual status_t Rewind() = 0;
66 virtual int32 CountEntries() = 0;
68 static dirent* Next(dirent*);
70 protected:
71 status_t fStatus;
75 class TWalkerWrapper : public EntryListBase {
76 // this is to be able to use TWalker polymorfically as BEntryListBase
77 public:
78 TWalkerWrapper(BTrackerPrivate::TWalker* walker);
79 virtual ~TWalkerWrapper();
81 virtual status_t InitCheck() const;
82 virtual status_t GetNextEntry(BEntry* entry, bool traverse = false);
83 virtual status_t GetNextRef(entry_ref* ref);
84 virtual int32 GetNextDirents(struct dirent* buffer, size_t length,
85 int32 count = INT_MAX);
86 virtual status_t Rewind();
87 virtual int32 CountEntries();
89 protected:
90 BTrackerPrivate::TWalker* fWalker;
91 status_t fStatus;
95 const int32 kDirentBufferSize = 10 * 1024;
98 class CachedEntryIterator : public EntryListBase {
99 public:
100 // takes any iterator and runs it through a cache of a specified size
101 // used to cluster entry_ref reads together, away from node accesses
103 // each chunk of iterators in the cache are then returned in an order,
104 // sorted by their i-node number -- this turns out to give quite a bit
105 // better performance over just using the order in which they show up
106 // using the default BEntryList iterator subclass
108 CachedEntryIterator(BEntryList* iterator, int32 numEntries,
109 bool sortInodes = false);
110 // CachedEntryIterator does not get to own the <iterator>
111 virtual ~CachedEntryIterator();
113 virtual status_t GetNextEntry(BEntry* entry, bool traverse = false);
114 virtual status_t GetNextRef(entry_ref* ref);
115 virtual int32 GetNextDirents(struct dirent* buffer, size_t length,
116 int32 count = INT_MAX);
118 virtual status_t Rewind();
119 virtual int32 CountEntries();
121 virtual void SetTo(BEntryList* iterator);
122 // CachedEntryIterator does not get to own the <iterator>
124 private:
125 static int _CompareInodes(const dirent* ent1, const dirent* ent2);
127 BEntryList* fIterator;
128 entry_ref* fEntryRefBuffer;
129 int32 fCacheSize;
130 int32 fNumEntries;
131 int32 fIndex;
133 dirent* fDirentBuffer;
134 dirent* fCurrentDirent;
135 bool fSortInodes;
136 BObjectList<dirent>* fSortedList;
138 BEntry* fEntryBuffer;
142 class DirectoryEntryList : public EntryListBase {
143 public:
144 DirectoryEntryList(const BDirectory &);
146 virtual status_t GetNextEntry(BEntry* entry, bool traverse = false);
147 virtual status_t GetNextRef(entry_ref* ref);
148 virtual int32 GetNextDirents(struct dirent* buffer, size_t length,
149 int32 count = INT_MAX);
151 virtual status_t Rewind();
152 virtual int32 CountEntries();
154 private:
155 BDirectory fDirectory;
159 class CachedDirectoryEntryList : public CachedEntryIterator {
160 // this class is to work around not being able to delete
161 // BEntryList polymorfically - need to have a special
162 // caching entry list iterator for directories
163 public:
164 CachedDirectoryEntryList(const BDirectory &);
165 virtual ~CachedDirectoryEntryList();
167 private:
168 BDirectory fDirectory;
172 class EntryIteratorList : public EntryListBase {
173 // This wraps up several BEntryList style iterators and
174 // iterates them all, going from one to the other as it finishes
175 // up each of them
176 public:
177 EntryIteratorList();
178 virtual ~EntryIteratorList();
180 void AddItem(BEntryList*);
181 // list gets to own walkers
183 virtual status_t GetNextEntry(BEntry* entry, bool traverse = false);
184 virtual status_t GetNextRef(entry_ref* ref);
185 virtual int32 GetNextDirents(struct dirent* buffer, size_t length,
186 int32 count = INT_MAX);
188 virtual status_t Rewind();
189 virtual int32 CountEntries();
191 protected:
192 BObjectList<BEntryList> fList;
193 int32 fCurrentIndex;
197 class CachedEntryIteratorList : public CachedEntryIterator {
198 public:
199 CachedEntryIteratorList(bool sortInodes = true);
200 void AddItem(BEntryList* list);
202 protected:
203 EntryIteratorList fIteratorList;
206 } // namespace BPrivate
208 using namespace BPrivate;
211 #endif // _ENTRY_ITERATOR_H