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 <Referenceable.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 Package* GetPackage() const { return fPackage; } 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 // conceptually protected, but actually declaring it so causes 77 // compilation issues when used with MethodDeleter in subclasses 78 void NonVirtualVFSUninit() 79 { PackageNode::VFSUninit(); } 80 // service for derived classes, e.g. for use 81 // with MethodDeleter 82 83 protected: 84 Package* fPackage; 85 PackageDirectory* fParent; 86 String fName; 87 mode_t fMode; 88 uid_t fUserID; 89 gid_t fGroupID; 90 timespec fModifiedTime; 91 PackageNodeAttributeList fAttributes; 92 }; 93 94 95 void* 96 PackageNode::IndexCookieForAttribute(const StringKey& name) const 97 { 98 PackageNodeAttribute* attribute = FindAttribute(name); 99 return attribute != NULL ? attribute->IndexCookie() : NULL; 100 } 101 102 103 typedef SinglyLinkedList<PackageNode> PackageNodeList; 104 105 106 #endif // PACKAGE_NODE_H 107