xref: /haiku/src/add-ons/kernel/file_systems/netfs/client/VirtualDir.h (revision 5a1d355fdf2747f80f8c46e2539f844a0b813346)
1 // VirtualDir.h
2 
3 #ifndef NET_FS_VIRTUAL_DIR_H
4 #define NET_FS_VIRTUAL_DIR_H
5 
6 #include <HashMap.h>
7 #include <HashString.h>
8 #include <util/DoublyLinkedList.h>
9 
10 #include "Node.h"
11 
12 class VirtualDir;
13 class VirtualDirEntry;
14 
15 // VirtualDirIterator
16 class VirtualDirIterator : public DoublyLinkedListLinkImpl<VirtualDirIterator> {
17 public:
18 								VirtualDirIterator();
19 								~VirtualDirIterator();
20 
21 			void				SetDirectory(VirtualDir* directory,
22 									bool onlyChildren = false);
23 
24 			bool				GetCurrentEntry(const char** name, Node** node);
25 			VirtualDirEntry*	GetCurrentEntry() const;
26 									// for use by VirtualDir only
27 			void				NextEntry();
28 			void				Rewind();
29 
30 private:
31 			enum {
32 				STATE_DOT		= 0,
33 				STATE_DOT_DOT	= 1,
34 				STATE_OTHERS	= 2,
35 			};
36 
37 			VirtualDir*			fDirectory;
38 			VirtualDirEntry*	fCurrentEntry;
39 			int					fState;
40 };
41 
42 // VirtualDirEntry
43 class VirtualDirEntry : public DoublyLinkedListLinkImpl<VirtualDirEntry> {
44 public:
45 								VirtualDirEntry();
46 								~VirtualDirEntry();
47 
48 			status_t			SetTo(const char* name, Node* node);
49 
50 			const char*			GetName() const;
51 			Node*				GetNode() const;
52 
53 private:
54 			HashString			fName;
55 			Node*				fNode;
56 };
57 
58 // VirtualDir
59 class VirtualDir : public Node, public DoublyLinkedListLinkImpl<VirtualDir> {
60 public:
61 								VirtualDir(Volume* volume, vnode_id nodeID);
62 	virtual						~VirtualDir();
63 
64 			status_t			InitCheck() const;
65 
66 			void				SetParent(VirtualDir* parent);
67 			VirtualDir*			GetParent() const;
68 				// TODO: Remove? We don't need it, do we?
69 
70 			time_t				GetCreationTime() const;
71 
72 			status_t			AddEntry(const char* name, Node* child);
73 			Node*				RemoveEntry(const char* name);
74 			VirtualDirEntry*	GetEntry(const char* name) const;
75 			Node*				GetChildNode(const char* name) const;
76 			VirtualDirEntry*	GetFirstEntry() const;
77 			VirtualDirEntry*	GetNextEntry(VirtualDirEntry* entry) const;
78 
79 			void				AddDirIterator(VirtualDirIterator* iterator);
80 			void				RemoveDirIterator(VirtualDirIterator* iterator);
81 
82 private:
83 			typedef HashMap<HashString, VirtualDirEntry*> EntryMap;
84 
85 			VirtualDir*			fParent;
86 			time_t				fCreationTime;
87 			EntryMap			fEntries;
88 			DoublyLinkedList<VirtualDirEntry> fEntryList;
89 			DoublyLinkedList<VirtualDirIterator> fIterators;
90 };
91 
92 #endif	// NET_FS_VIRTUAL_DIR_H
93