xref: /haiku/src/add-ons/kernel/file_systems/netfs/client/ShareNode.h (revision f2b4344867e97c3f4e742a1b4a15e6879644601a)
1 // Node.h
2 
3 #ifndef NET_FS_SHARE_NODE_H
4 #define NET_FS_SHARE_NODE_H
5 
6 #include <Referenceable.h>
7 #include <util/DoublyLinkedList.h>
8 
9 #include "HashString.h"
10 #include "Node.h"
11 #include "NodeInfo.h"
12 #include "SLList.h"
13 
14 class ShareAttrDir;
15 class ShareDir;
16 class ShareNode;
17 
18 static const int32 kRemoteShareDirIteratorCapacity = 32;
19 
20 // ShareDirEntry
21 class ShareDirEntry : public BReferenceable,
22 	public DoublyLinkedListLinkImpl<ShareDirEntry>,
23 	public SLListLinkImpl<ShareDirEntry> {
24 public:
25 								ShareDirEntry(ShareDir* directory,
26 									const char* name, ShareNode* node);
27 								~ShareDirEntry();
28 
29 			status_t			InitCheck() const;
30 
31 			ShareDir*			GetDirectory() const;
32 			const char*			GetName() const;
33 			ShareNode*			GetNode() const;
34 
35 			void				SetRevision(int64 revision);
36 			int64				GetRevision() const;
37 
38 			bool				IsActualEntry() const;
39 
40 private:
41 			ShareDir*			fDirectory;
42 			HashString			fName;
43 			ShareNode*			fNode;
44 			int64				fRevision;
45 };
46 
47 // ShareNode
48 class ShareNode : public Node {
49 public:
50 								ShareNode(Volume* volume, vnode_id id,
51 									const NodeInfo* nodeInfo);
52 	virtual						~ShareNode();
53 
54 			const NodeInfo&		GetNodeInfo() const;
55 
56 			NodeID				GetRemoteID() const;
57 
58 			void				Update(const NodeInfo& nodeInfo);
59 
60 			void				AddReferringEntry(ShareDirEntry* entry);
61 			void				RemoveReferringEntry(ShareDirEntry* entry);
62 			ShareDirEntry*		GetFirstReferringEntry() const;
63 			ShareDirEntry*		GetNextReferringEntry(
64 									ShareDirEntry* entry) const;
65 			ShareDirEntry*		GetActualReferringEntry() const;
66 
67 			void				SetAttrDir(ShareAttrDir* attrDir);
68 			ShareAttrDir*		GetAttrDir() const;
69 
70 private:
71 			NodeInfo			fInfo;
72 			SLList<ShareDirEntry> fReferringEntries;
73 			ShareAttrDir*		fAttrDir;
74 };
75 
76 // ShareDirIterator
77 class ShareDirIterator {
78 public:
79 								ShareDirIterator();
80 	virtual						~ShareDirIterator();
81 
82 	virtual	ShareDirEntry*		GetCurrentEntry() const = 0;
83 	virtual	void				NextEntry() = 0;
84 	virtual	void				Rewind() = 0;
85 	virtual	bool				IsDone() const = 0;
86 };
87 
88 // LocalShareDirIterator
89 class LocalShareDirIterator : public ShareDirIterator,
90 	public DoublyLinkedListLinkImpl<LocalShareDirIterator> {
91 public:
92 								LocalShareDirIterator();
93 								~LocalShareDirIterator();
94 
95 			void				SetDirectory(ShareDir* directory);
96 
97 	virtual	ShareDirEntry*		GetCurrentEntry() const;
98 	virtual	void				NextEntry();
99 	virtual	void				Rewind();
100 	virtual	bool				IsDone() const;
101 
102 private:
103 			ShareDir*			fDirectory;
104 			ShareDirEntry*		fCurrentEntry;
105 };
106 
107 // RemoteShareDirIterator
108 class RemoteShareDirIterator : public ShareDirIterator {
109 public:
110 								RemoteShareDirIterator();
111 								~RemoteShareDirIterator();
112 
113 	virtual	ShareDirEntry*		GetCurrentEntry() const;
114 	virtual	void				NextEntry();
115 	virtual	void				Rewind();
116 	virtual	bool				IsDone() const;
117 
118 			int32				GetCapacity() const;
119 
120 			void				SetCookie(int32 cookie);
121 			int32				GetCookie() const;
122 
123 			void				Clear();
124 			bool				AddEntry(ShareDirEntry* entry);
125 
126 			void				SetRevision(int64 revision);
127 			int64				GetRevision() const;
128 
129 			void				SetDone(bool done);
130 
131 			bool				GetRewind() const;
132 
133 private:
134 			int32				fCookie;
135 			ShareDirEntry*		fEntries[kRemoteShareDirIteratorCapacity];
136 			int32				fCapacity;
137 			int32				fCount;
138 			int32				fIndex;
139 			int64				fRevision;
140 			bool				fDone;
141 			bool				fRewind;
142 };
143 
144 // ShareDir
145 class ShareDir : public ShareNode {
146 public:
147 								ShareDir(Volume* volume, vnode_id id,
148 									const NodeInfo* nodeInfo);
149 	virtual						~ShareDir();
150 
151 			void				UpdateEntryCreatedEventRevision(int64 revision);
152 			int64				GetEntryCreatedEventRevision() const;
153 
154 			void				UpdateEntryRemovedEventRevision(int64 revision);
155 			int64				GetEntryRemovedEventRevision() const;
156 
157 			void				SetComplete(bool complete);
158 			bool				IsComplete() const;
159 
160 			void				AddEntry(ShareDirEntry* entry);
161 			void				RemoveEntry(ShareDirEntry* entry);
162 
163 			ShareDirEntry*		GetFirstEntry() const;
164 			ShareDirEntry*		GetNextEntry(ShareDirEntry* entry) const;
165 
166 			void				AddDirIterator(LocalShareDirIterator* iterator);
167 			void				RemoveDirIterator(
168 									LocalShareDirIterator* iterator);
169 
170 private:
171 			DoublyLinkedList<ShareDirEntry> fEntries;
172 			DoublyLinkedList<LocalShareDirIterator> fIterators;
173 			int64				fEntryCreatedEventRevision;
174 									// The revision of the latest "created" or
175 									// "moved" (destination entry) event for
176 									// which the entry could not be created
177 									// (for whatever reason -- missing entry
178 									// info in the event request most likely).
179 									// To be compared with remote dir iterator
180 									// revisions to set fIsComplete.
181 			int64				fEntryRemovedEventRevision;
182 									// The revision of the latest "removed" or
183 									// "moved" (source entry) event. To be
184 									// compared with entry info revisions
185 									// returned by client request replies.
186 									// Such an info is to be considered invalid,
187 									// if its revision is less than this
188 									// revision, and must be reloaded from the
189 									// server.
190 			bool				fIsComplete;
191 };
192 
193 #endif	// NET_FS_SHARE_NODE_H
194