xref: /haiku/src/add-ons/kernel/file_systems/netfs/client/ShareAttrDir.h (revision 5a1d355fdf2747f80f8c46e2539f844a0b813346)
1 // ShareAttrDir.h
2 
3 #ifndef NET_FS_SHARE_ATTR_DIR_H
4 #define NET_FS_SHARE_ATTR_DIR_H
5 
6 #include <fs_attr.h>
7 
8 #include "ShareAttrDirIterator.h"
9 #include "SLList.h"
10 
11 class AttrDirInfo;
12 class AttributeInfo;
13 class BNode;
14 
15 // Attribute
16 class Attribute : public SLListLinkImpl<Attribute> {
17 								Attribute(const char* name,
18 									const attr_info& info, const void* data);
19 								~Attribute();
20 public:
21 	static	status_t			CreateAttribute(const char* name,
22 									const attr_info& info, const void* data,
23 									Attribute** attribute);
24 	static	void				DeleteAttribute(Attribute* attribute);
25 
26 			const char*			GetName() const;
27 			void				GetInfo(attr_info* info) const;
28 			uint32				GetType() const;
29 			off_t				GetSize() const;
30 			const void*			GetData() const;
31 
32 private:
33 			attr_info			fInfo;
34 			char				fDataAndName[1];
35 };
36 
37 // ShareAttrDir
38 class ShareAttrDir {
39 public:
40 								ShareAttrDir();
41 								~ShareAttrDir();
42 
43 			status_t			Init(const AttrDirInfo& dirInfo);
44 			status_t			Update(const AttrDirInfo& dirInfo,
45 									DoublyLinkedList<ShareAttrDirIterator>*
46 										iterators);
47 
48 			void				SetRevision(int64 revision);
49 			int64				GetRevision() const;
50 
51 			void				SetUpToDate(bool upToDate);
52 			bool				IsUpToDate() const;
53 
54 			// These modifying methods are currently used internally only.
55 			// Init()/Update() should be sufficient.
56 			void				ClearAttrDir();
57 
58 			status_t			AddAttribute(const char* name,
59 									const attr_info& info, const void* data);
60 			bool				RemoveAttribute(const char* name);
61 			void				RemoveAttribute(Attribute* attribute);
62 
63 			Attribute*			GetAttribute(const char* name) const;
64 			Attribute*			GetFirstAttribute() const;
65 			Attribute*			GetNextAttribute(Attribute* attribute) const;
66 
67 private:
68 			status_t			_GetAttributes(const AttrDirInfo& dirInfo,
69 									Attribute**& attributes, int32& count);
70 
71 private:
72 			SLList<Attribute>	fAttributes;
73 // TODO: Rethink whether we rather want an array.
74 			int64				fRevision;
75 			bool				fUpToDate;	// to enforce reloading even if
76 											// a revision is cached
77 };
78 
79 #endif	// NET_FS_SHARE_ATTR_DIR_H
80