1/*
2Open Tracker License
3
4Terms and Conditions
5
6Copyright (c) 1991-2000, Be Incorporated. All rights reserved.
7
8Permission is hereby granted, free of charge, to any person obtaining a copy of
9this software and associated documentation files (the "Software"), to deal in
10the Software without restriction, including without limitation the rights to
11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12of the Software, and to permit persons to whom the Software is furnished to do
13so, subject to the following conditions:
14
15The above copyright notice and this permission notice applies to all licensees
16and shall be included in all copies or substantial portions of the Software.
17
18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY,
20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION
23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25Except as contained in this notice, the name of Be Incorporated shall not be
26used in advertising or otherwise to promote the sale, use or other dealings in
27this Software without prior written authorization from Be Incorporated.
28
29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks
30of Be Incorporated in the United States and other countries. Other brand product
31names are registered trademarks or trademarks of their respective holders.
32All rights reserved.
33*/
34#ifndef WALKER_H
35#define WALKER_H
36
37
38#ifndef _BE_BUILD_H
39#include <BeBuild.h>
40#endif
41#include <VolumeRoster.h>
42#include <Volume.h>
43#include <List.h>
44#include <EntryList.h>
45#include <Directory.h>
46#include <Entry.h>
47#include <Query.h>
48
49#include "ObjectList.h"
50
51
52namespace BTrackerPrivate {
53
54class TWalker : public BEntryList {
55	// adds a virtual destructor that is severely missing in BEntryList
56	// BEntryList should never be used polymorphically because of that
57
58public:
59	virtual ~TWalker();
60
61	virtual	status_t GetNextEntry(BEntry*, bool traverse = false) = 0;
62	virtual	status_t GetNextRef(entry_ref*) = 0;
63	virtual	int32 GetNextDirents(struct dirent*, size_t,
64		int32 count = INT_MAX) = 0;
65	virtual	status_t Rewind() = 0;
66	virtual	int32 CountEntries() = 0;
67};
68
69
70class TNodeWalker : public TWalker {
71// TNodeWalker supports iterating a single volume, starting from a specified
72// entry; if passed a non-directory entry it returns just that one entry
73public:
74	TNodeWalker(bool includeTopDirectory);
75	TNodeWalker(const char* path, bool includeTopDirectory);
76	TNodeWalker(const entry_ref* ref, bool includeTopDirectory);
77	TNodeWalker(const BDirectory* dir, bool includeTopDirectory);
78	virtual ~TNodeWalker();
79
80	// Backwards compatibility with Tracker compiled for R5 (remove when this
81	// gets integrated into the official release).
82	TNodeWalker();
83	TNodeWalker(const char* path);
84	TNodeWalker(const entry_ref* ref);
85	TNodeWalker(const BDirectory* dir);
86
87	virtual	status_t GetNextEntry(BEntry*, bool traverse = false);
88	virtual	status_t GetNextRef(entry_ref*);
89	virtual	int32 GetNextDirents(struct dirent*, size_t,
90		int32 count = INT_MAX);
91	virtual	status_t Rewind();
92
93protected:
94	status_t PopDirCommon();
95	void PushDirCommon(const entry_ref*);
96
97private:
98	virtual	int32 CountEntries();
99		// don't know how to do that, have just a fake stub here
100
101protected:
102	BObjectList<BDirectory> fDirs;
103	int32 fTopIndex;
104	BDirectory* fTopDir;
105	bool fIncludeTopDir;
106	bool fOriginalIncludeTopDir;
107
108private:
109	BEntry* fJustFile;
110	BDirectory fOriginalDirCopy;
111	BEntry* fOriginalJustFile;
112		// keep around to support Rewind
113};
114
115
116class TVolWalker : public TNodeWalker {
117// TNodeWalker supports iterating over all the mounted volumes;
118// non-attribute and read-only volumes may optionaly be filtered out
119public:
120	TVolWalker(bool knows_attr = true, bool writable = true,
121		bool includeTopDirectory = true);
122	virtual ~TVolWalker();
123
124	virtual status_t GetNextEntry(BEntry*, bool traverse = false);
125	virtual status_t GetNextRef(entry_ref*);
126	virtual int32 GetNextDirents(struct dirent*, size_t,
127		int32 count = INT_MAX);
128	virtual status_t Rewind();
129
130	virtual status_t NextVolume();
131		// skips to the next volume
132		// Note: it would be cool to return const BVolume*
133		// that way a subclass could implement a volume filter -
134		// it would just override, call inherited for as long as there
135		// are volumes and it does not like them
136		// we would have to give up the status_t then, which might be
137		// ok
138
139private:
140	BVolumeRoster fVolRoster;
141	BVolume fVol;
142	bool fKnowsAttr;
143	bool fWritable;
144
145	typedef	TNodeWalker _inherited;
146};
147
148
149class TQueryWalker : public TWalker {
150public:
151	TQueryWalker(const char* predicate);
152	virtual ~TQueryWalker();
153
154	// Does an in-fix walk of all entries
155	virtual status_t GetNextEntry(BEntry*, bool traverse = false);
156	virtual status_t GetNextRef(entry_ref*);
157	virtual int32 GetNextDirents(struct dirent*, size_t,
158		int32 count = INT_MAX);
159
160	virtual	status_t NextVolume();
161	// skips to the next volume
162	virtual	status_t Rewind();
163
164private:
165	virtual int32 CountEntries();
166	// can't count
167
168	BQuery fQuery;
169	BVolumeRoster fVolRoster;
170	BVolume fVol;
171	bigtime_t fTime;
172	const char* fPredicate;
173
174	typedef TQueryWalker _inherited;
175};
176
177}	// namespace BTrackerPrivate
178
179using namespace BTrackerPrivate;
180
181#endif	// WALKER_H
182