14031a32aSIngo Weinhold/*
24031a32aSIngo Weinhold * Copyright 2011, Ingo Weinhold, ingo_weinhold@gmx.de.
34031a32aSIngo Weinhold * Distributed under the terms of the MIT License.
44031a32aSIngo Weinhold */
54031a32aSIngo Weinhold#ifndef PACKAGE_LINK_DIRECTORY_H
64031a32aSIngo Weinhold#define PACKAGE_LINK_DIRECTORY_H
74031a32aSIngo Weinhold
84031a32aSIngo Weinhold
94031a32aSIngo Weinhold#include "Directory.h"
104031a32aSIngo Weinhold#include "Package.h"
11a39e95cdSIngo Weinhold#include "PackageLinkSymlink.h"
124031a32aSIngo Weinhold
134031a32aSIngo Weinhold
143e7333b7SIngo Weinholdclass PackageLinksListener;
153e7333b7SIngo Weinhold
163e7333b7SIngo Weinhold
174031a32aSIngo Weinholdclass PackageLinkDirectory : public Directory {
184031a32aSIngo Weinholdpublic:
194031a32aSIngo Weinhold								PackageLinkDirectory();
204031a32aSIngo Weinhold	virtual						~PackageLinkDirectory();
214031a32aSIngo Weinhold
224031a32aSIngo Weinhold			status_t			Init(Directory* parent, Package* package);
23d07c930cSIngo Weinhold	virtual	status_t			Init(Directory* parent, const String& name);
244031a32aSIngo Weinhold
254031a32aSIngo Weinhold	virtual	timespec			ModifiedTime() const;
264031a32aSIngo Weinhold
27d0126238SIngo Weinhold	virtual	status_t			OpenAttributeDirectory(
28d0126238SIngo Weinhold									AttributeDirectoryCookie*& _cookie);
29d0126238SIngo Weinhold	virtual	status_t			OpenAttribute(const StringKey& name,
30d0126238SIngo Weinhold									int openMode, AttributeCookie*& _cookie);
31d0126238SIngo Weinhold
323e7333b7SIngo Weinhold			void				AddPackage(Package* package,
333e7333b7SIngo Weinhold									PackageLinksListener* listener);
343e7333b7SIngo Weinhold			void				RemovePackage(Package* package,
353e7333b7SIngo Weinhold									PackageLinksListener* listener);
36bd66b7e6SIngo Weinhold			void				UpdatePackageDependencies(Package* package,
37bd66b7e6SIngo Weinhold									PackageLinksListener* listener);
384031a32aSIngo Weinhold
394031a32aSIngo Weinhold			bool				IsEmpty() const
404031a32aSIngo Weinhold									{ return fPackages.IsEmpty(); }
414031a32aSIngo Weinhold
421d8edd93SIngo Weinholdprivate:
43a39e95cdSIngo Weinhold			typedef PackageLinkSymlink Link;
441d8edd93SIngo Weinhold
45dd9554aeSIngo Weinhold			struct DependencyLink : public PackageLinkSymlink {
46dd9554aeSIngo Weinhold				DependencyLink(Package* package)
47dd9554aeSIngo Weinhold					:
4858081381SIngo Weinhold					PackageLinkSymlink(package, TYPE_INSTALLATION_LOCATION)
49dd9554aeSIngo Weinhold				{
50dd9554aeSIngo Weinhold				}
51dd9554aeSIngo Weinhold
52dd9554aeSIngo Weinhold				DoublyLinkedListLink<DependencyLink> fPackageLinkDirectoryLink;
53dd9554aeSIngo Weinhold			};
54dd9554aeSIngo Weinhold
55dd9554aeSIngo Weinhold			typedef DoublyLinkedList<DependencyLink,
56dd9554aeSIngo Weinhold				DoublyLinkedListMemberGetLink<DependencyLink,
57dd9554aeSIngo Weinhold					&DependencyLink::fPackageLinkDirectoryLink> >
58dd9554aeSIngo Weinhold				FamilyDependencyList;
59dd9554aeSIngo Weinhold
60cd81fea0SIngo Weinholdprivate:
61cd81fea0SIngo Weinhold			status_t			_Update(PackageLinksListener* listener);
62dd9554aeSIngo Weinhold			status_t			_UpdateDependencies(
63dd9554aeSIngo Weinhold									PackageLinksListener* listener);
64cd81fea0SIngo Weinhold
6558081381SIngo Weinhold			status_t			_CreateOrUpdateLink(Link*& link,
6658081381SIngo Weinhold									Package* package, Link::Type type,
67d07c930cSIngo Weinhold									const String& name,
6858081381SIngo Weinhold									PackageLinksListener* listener);
6958081381SIngo Weinhold			void				_RemoveLink(Link* link,
7058081381SIngo Weinhold									PackageLinksListener* listener);
7158081381SIngo Weinhold
724031a32aSIngo Weinholdprivate:
734031a32aSIngo Weinhold			timespec			fModifiedTime;
744031a32aSIngo Weinhold			PackageList			fPackages;
75a39e95cdSIngo Weinhold			Link*				fSelfLink;
7658081381SIngo Weinhold			Link*				fSettingsLink;
77dd9554aeSIngo Weinhold			FamilyDependencyList fDependencyLinks;
784031a32aSIngo Weinhold};
794031a32aSIngo Weinhold
804031a32aSIngo Weinhold
814031a32aSIngo Weinhold#endif	// PACKAGE_LINK_DIRECTORY_H
82