xref: /haiku/src/add-ons/kernel/file_systems/packagefs/package/PackageNode.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef PACKAGE_NODE_H
6 #define PACKAGE_NODE_H
7 
8 
9 #include <sys/stat.h>
10 
11 #include <WeakReferenceable.h>
12 
13 #include <util/SinglyLinkedList.h>
14 
15 #include "IndexedAttributeOwner.h"
16 #include "PackageNodeAttribute.h"
17 #include "StringKey.h"
18 
19 
20 class AttributeIndexer;
21 class Package;
22 class PackageDirectory;
23 
24 
25 class PackageNode : public BReferenceable, public IndexedAttributeOwner,
26 	public SinglyLinkedListLinkImpl<PackageNode> {
27 public:
28 								PackageNode(Package* package, mode_t mode);
29 	virtual						~PackageNode();
30 
31 			BReference<Package>		GetPackage() const;
32 									// Since PackageNode does only hold a
33 									// reference to the package between
34 									// VFSInit() and VFSUninit(), the caller
35 									// must otherwise make sure the package
36 									// still exists.
37 			PackageDirectory*	Parent() const		{ return fParent; }
38 			const String&		Name() const		{ return fName; }
39 
40 	virtual	status_t			Init(PackageDirectory* parent,
41 									const String& name);
42 
43 	virtual	status_t			VFSInit(dev_t deviceID, ino_t nodeID);
44 	virtual	void				VFSUninit();
45 									// base class versions must be called
46 
47 			mode_t				Mode() const			{ return fMode; }
48 
49 			uid_t				UserID() const			{ return fUserID; }
50 			void				SetUserID(uid_t id)		{ fUserID = id; }
51 
52 			gid_t				GroupID() const			{ return fGroupID; }
53 			void				SetGroupID(gid_t id)	{ fGroupID = id; }
54 
55 			void				SetModifiedTime(const timespec& time)
56 									{ fModifiedTime = time; }
57 			const timespec&		ModifiedTime() const
58 									{ return fModifiedTime; }
59 
60 	virtual	off_t				FileSize() const;
61 
62 			void				AddAttribute(PackageNodeAttribute* attribute);
63 			void				RemoveAttribute(
64 									PackageNodeAttribute* attribute);
65 
66 			const PackageNodeAttributeList& Attributes() const
67 									{ return fAttributes; }
68 
69 			PackageNodeAttribute* FindAttribute(const StringKey& name) const;
70 
71 	virtual	void				UnsetIndexCookie(void* attributeCookie);
72 
73 	inline	void*				IndexCookieForAttribute(const StringKey& name)
74 									const;
75 
76 			bool				HasPrecedenceOver(const PackageNode* other) const;
77 
78 			// conceptually protected, but actually declaring it so causes
79 			// compilation issues when used with MethodDeleter in subclasses
80 			void				NonVirtualVFSUninit()
81 									{ PackageNode::VFSUninit(); }
82 									// service for derived classes, e.g. for use
83 									// with MethodDeleter
84 
85 protected:
86 	mutable BWeakReference<Package> fPackage;
87 			PackageDirectory*	fParent;
88 			String				fName;
89 			mode_t				fMode;
90 			uid_t				fUserID;
91 			gid_t				fGroupID;
92 			timespec			fModifiedTime;
93 			PackageNodeAttributeList fAttributes;
94 };
95 
96 
97 void*
98 PackageNode::IndexCookieForAttribute(const StringKey& name) const
99 {
100 	PackageNodeAttribute* attribute = FindAttribute(name);
101 	return attribute != NULL ? attribute->IndexCookie() : NULL;
102 }
103 
104 
105 typedef SinglyLinkedList<PackageNode> PackageNodeList;
106 
107 
108 #endif	// PACKAGE_NODE_H
109