1 /* 2 * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef PACKAGE_LINK_DIRECTORY_H 6 #define PACKAGE_LINK_DIRECTORY_H 7 8 9 #include "Directory.h" 10 #include "Package.h" 11 #include "PackageLinkSymlink.h" 12 13 14 class PackageLinksListener; 15 16 17 class PackageLinkDirectory : public Directory { 18 public: 19 PackageLinkDirectory(); 20 virtual ~PackageLinkDirectory(); 21 22 status_t Init(Package* package); 23 virtual status_t Init(const String& name); 24 25 virtual timespec ModifiedTime() const; 26 27 virtual status_t OpenAttributeDirectory( 28 AttributeDirectoryCookie*& _cookie); 29 virtual status_t OpenAttribute(const StringKey& name, 30 int openMode, AttributeCookie*& _cookie); 31 32 void AddPackage(Package* package, 33 PackageLinksListener* listener); 34 void RemovePackage(Package* package, 35 PackageLinksListener* listener); 36 void UpdatePackageDependencies(Package* package, 37 PackageLinksListener* listener); 38 39 bool IsEmpty() const 40 { return fPackages.IsEmpty(); } 41 42 private: 43 typedef PackageLinkSymlink Link; 44 45 struct DependencyLink : public PackageLinkSymlink { 46 DependencyLink(Package* package) 47 : 48 PackageLinkSymlink(package, TYPE_INSTALLATION_LOCATION) 49 { 50 } 51 52 DoublyLinkedListLink<DependencyLink> fPackageLinkDirectoryLink; 53 }; 54 55 typedef DoublyLinkedList<DependencyLink, 56 DoublyLinkedListMemberGetLink<DependencyLink, 57 &DependencyLink::fPackageLinkDirectoryLink> > 58 FamilyDependencyList; 59 60 private: 61 status_t _Update(PackageLinksListener* listener); 62 status_t _UpdateDependencies( 63 PackageLinksListener* listener); 64 65 status_t _CreateOrUpdateLink(Link*& link, 66 Package* package, Link::Type type, 67 const String& name, 68 PackageLinksListener* listener); 69 void _RemoveLink(Link* link, 70 PackageLinksListener* listener); 71 72 private: 73 timespec fModifiedTime; 74 PackageList fPackages; 75 Link* fSelfLink; 76 Link* fSettingsLink; 77 FamilyDependencyList fDependencyLinks; 78 }; 79 80 81 #endif // PACKAGE_LINK_DIRECTORY_H 82