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 "InlineReferenceable.h" 17 #include "PackageNodeAttribute.h" 18 #include "StringKey.h" 19 20 21 class AttributeIndexer; 22 class Package; 23 class PackageDirectory; 24 25 26 class PackageNode : public IndexedAttributeOwner, 27 public SinglyLinkedListLinkImpl<PackageNode> { 28 public: 29 PackageNode(Package* package, mode_t mode); 30 virtual ~PackageNode(); 31 32 void AcquireReference(); 33 void ReleaseReference(); 34 int32 CountReferences(); 35 36 BReference<Package> GetPackage() const; 37 // Since PackageNode does only hold a 38 // reference to the package between 39 // VFSInit() and VFSUninit(), the caller 40 // must otherwise make sure the package 41 // still exists. 42 PackageDirectory* Parent() const { return fParent; } 43 const String& Name() const { return fName; } 44 45 virtual status_t Init(PackageDirectory* parent, 46 const String& name); 47 48 virtual status_t VFSInit(dev_t deviceID, ino_t nodeID); 49 virtual void VFSUninit(); 50 // base class versions must be called 51 52 mode_t Mode() const { return fMode; } 53 uid_t UserID() const { return 0; } 54 gid_t GroupID() const { return 0; } 55 56 void SetModifiedTime(const timespec& time); 57 timespec ModifiedTime() const; 58 59 virtual off_t FileSize() const; 60 61 void AddAttribute(PackageNodeAttribute* attribute); 62 63 const PackageNodeAttributeList& Attributes() const 64 { return fAttributes; } 65 66 PackageNodeAttribute* FindAttribute(const StringKey& name) const; 67 68 virtual void UnsetIndexCookie(void* attributeCookie); 69 70 inline void* IndexCookieForAttribute(const StringKey& name) 71 const; 72 73 bool HasPrecedenceOver(const PackageNode* other) const; 74 75 // conceptually protected, but actually declaring it so causes 76 // compilation issues when used with MethodDeleter in subclasses 77 void NonVirtualVFSUninit() 78 { PackageNode::VFSUninit(); } 79 // service for derived classes, e.g. for use 80 // with MethodDeleter 81 82 protected: 83 mutable BWeakReference<Package> fPackage; 84 PackageDirectory* fParent; 85 String fName; 86 PackageNodeAttributeList fAttributes; 87 bigtime_t fModifiedTime; 88 mode_t fMode; 89 InlineReferenceable fReferenceable; 90 }; 91 92 93 void* 94 PackageNode::IndexCookieForAttribute(const StringKey& name) const 95 { 96 PackageNodeAttribute* attribute = FindAttribute(name); 97 return attribute != NULL ? attribute->IndexCookie() : NULL; 98 } 99 100 101 typedef SinglyLinkedList<PackageNode> PackageNodeList; 102 103 104 #endif // PACKAGE_NODE_H 105