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 18 19class AttributeIndexer; 20class Package; 21class PackageDirectory; 22 23 24class PackageNode : public BReferenceable, public IndexedAttributeOwner, 25 public SinglyLinkedListLinkImpl<PackageNode> { 26public: 27 PackageNode(Package* package, mode_t mode); 28 virtual ~PackageNode(); 29 30 Package* GetPackage() const { return fPackage; } 31 PackageDirectory* Parent() const { return fParent; } 32 const char* Name() const { return fName; } 33 34 virtual status_t Init(PackageDirectory* parent, 35 const char* name); 36 37 virtual status_t VFSInit(dev_t deviceID, ino_t nodeID); 38 virtual void VFSUninit(); 39 40 mode_t Mode() const { return fMode; } 41 42 uid_t UserID() const { return fUserID; } 43 void SetUserID(uid_t id) { fUserID = id; } 44 45 gid_t GroupID() const { return fGroupID; } 46 void SetGroupID(gid_t id) { fGroupID = id; } 47 48 void SetModifiedTime(const timespec& time) 49 { fModifiedTime = time; } 50 const timespec& ModifiedTime() const 51 { return fModifiedTime; } 52 53 virtual off_t FileSize() const; 54 55 void AddAttribute(PackageNodeAttribute* attribute); 56 void RemoveAttribute( 57 PackageNodeAttribute* attribute); 58 59 const PackageNodeAttributeList& Attributes() const 60 { return fAttributes; } 61 62 PackageNodeAttribute* FindAttribute(const char* name) const; 63 64 virtual void UnsetIndexCookie(void* attributeCookie); 65 66 inline void* IndexCookieForAttribute(const char* name) const; 67 68protected: 69 Package* fPackage; 70 PackageDirectory* fParent; 71 char* fName; 72 mode_t fMode; 73 uid_t fUserID; 74 gid_t fGroupID; 75 timespec fModifiedTime; 76 PackageNodeAttributeList fAttributes; 77}; 78 79 80void* 81PackageNode::IndexCookieForAttribute(const char* name) const 82{ 83 PackageNodeAttribute* attribute = FindAttribute(name); 84 return attribute != NULL ? attribute->IndexCookie() : NULL; 85} 86 87 88typedef SinglyLinkedList<PackageNode> PackageNodeList; 89 90 91#endif // PACKAGE_NODE_H 92