xref: /haiku/src/add-ons/kernel/file_systems/netfs/server/NodeHandle.h (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 // NodeHandle.h
2 
3 #ifndef NET_FS_NODE_HANDLE_H
4 #define NET_FS_NODE_HANDLE_H
5 
6 #include <dirent.h>
7 
8 #include <Query.h>
9 #include <Referenceable.h>
10 #include <util/DoublyLinkedList.h>
11 
12 #include "Lockable.h"
13 #include "NodeRef.h"
14 
15 class Directory;
16 class Entry;
17 class Node;
18 
19 // NodeHandle
20 class NodeHandle : public BReferenceable, public Lockable {
21 public:
22 								NodeHandle();
23 	virtual						~NodeHandle();
24 
25 	virtual	status_t			GetStat(struct stat* st);
26 
27 			void				SetCookie(int32 cookie);
28 			int32				GetCookie() const;
29 
30 			const NodeRef&		GetNodeRef() const;
31 
32 protected:
33 	virtual	int					GetFD() const;
34 
35 protected:
36 			int32				fCookie;
37 			NodeRef				fNodeRef;
38 };
39 
40 // FileHandle
41 class FileHandle : public NodeHandle {
42 public:
43 								FileHandle();
44 	virtual						~FileHandle();
45 
46 			status_t			Open(Node* node, int openMode);
47 			status_t			Close();
48 
49 			status_t			Read(off_t pos, void* buffer, size_t size,
50 									size_t* bytesRead);
51 			status_t			Write(off_t pos, const void* buffer,
52 									size_t size, size_t* bytesWritten);
53 
54  			status_t			ReadAttr(const char* name, uint32 type,
55  									off_t pos, void* buffer, size_t size,
56  									size_t* bytesRead);
57  			status_t			WriteAttr(const char* name, uint32 type,
58  									off_t pos, const void* buffer, size_t size,
59  									size_t* bytesWritten);
60  			status_t			RemoveAttr(const char* name);
61 			status_t			StatAttr(const char* name, attr_info* info);
62 
63 protected:
64 	virtual	int					GetFD() const;
65 
66 private:
67 			int					fFD;
68 };
69 
70 // DirIterator
71 class DirIterator : public NodeHandle,
72 	public DoublyLinkedListLinkImpl<DirIterator> {
73 public:
74 								DirIterator();
75 	virtual						~DirIterator();
76 
77 			bool				IsValid() const;
78 
79 	virtual	Entry*				NextEntry() = 0;
80 	virtual	void				Rewind() = 0;
81 
82 
83 	// for Directory internal use only
84 	virtual	status_t			SetDirectory(Directory* directory) = 0;
85 
86 	virtual	Entry*				GetCurrentEntry() const = 0;
87 
88 protected:
89 			Directory*			fDirectory;
90 			bool				fValid;
91 };
92 
93 // AttrDirIterator
94 class AttrDirIterator : public NodeHandle {
95 public:
96 								AttrDirIterator();
97 	virtual						~AttrDirIterator();
98 
99 			status_t			Open(Node* node);
100 			status_t			Close();
101 
102 	virtual	status_t			ReadDir(dirent* entry, int32 bufferSize,
103 									int32 count, int32* countRead, bool *done);
104 	virtual	status_t			RewindDir();
105 
106 protected:
107 	virtual	int					GetFD() const;
108 
109 private:
110 			DIR*				fDir;
111 };
112 
113 // Query
114 class Query : public BQuery, public DoublyLinkedListLinkImpl<Query> {
115 public:
116 };
117 
118 class QueryHandle;
119 
120 // QueryListener
121 class QueryListener {
122 public:
123 								QueryListener();
124 	virtual						~QueryListener();
125 
126 	virtual	void				QueryHandleClosed(QueryHandle* handle) = 0;
127 };
128 
129 // QueryHandle
130 class QueryHandle : public NodeHandle {
131 public:
132 								QueryHandle(port_id remotePort,
133 									int32 remoteToken);
134 	virtual						~QueryHandle();
135 
136 			void				SetQueryListener(QueryListener* listener);
137 			QueryListener*		GetQueryListener() const;
138 
139 			void				AddQuery(Query* query);
140 			void				RemoveQuery(Query* query);
141 
142 			port_id				GetRemotePort() const;
143 			int32				GetRemoteToken() const;
144 
145 			status_t			Close();
146 
147 			status_t			ReadDir(dirent* entry, int32 count,
148 									int32* countRead);
149 private:
150 			port_id				fRemotePort;
151 			int32				fRemoteToken;
152 			DoublyLinkedList<Query> fQueries;
153 			Query*				fCurrentQuery;
154 			QueryListener*		fListener;
155 			bool				fClosed;
156 };
157 
158 #endif	// NET_FS_NODE_HANDLE_H
159