11c29b26eSIngo Weinhold/*
2d8d0539aSJohn Scipione * Copyright 2013 Haiku, Inc. All rights reserved.
31c29b26eSIngo Weinhold * Distributed under the terms of the MIT License.
41c29b26eSIngo Weinhold *
51c29b26eSIngo Weinhold * Authors:
61c29b26eSIngo Weinhold *		Ingo Weinhold, ingo_weinhold@gmx.de
71c29b26eSIngo Weinhold */
8d8d0539aSJohn Scipione#ifndef _VIRTUAL_DIRECTORY_MANAGER_H
9d8d0539aSJohn Scipione#define _VIRTUAL_DIRECTORY_MANAGER_H
101c29b26eSIngo Weinhold
111c29b26eSIngo Weinhold
121c29b26eSIngo Weinhold#include <dirent.h>
131c29b26eSIngo Weinhold
141c29b26eSIngo Weinhold#include <map>
151c29b26eSIngo Weinhold
161c29b26eSIngo Weinhold#include <Locker.h>
171c29b26eSIngo Weinhold#include <Node.h>
181c29b26eSIngo Weinhold
191c29b26eSIngo Weinhold
201c29b26eSIngo Weinholdclass BStringList;
211c29b26eSIngo Weinhold
221c29b26eSIngo Weinhold
231c29b26eSIngo Weinholdnamespace BPrivate {
241c29b26eSIngo Weinhold
251c29b26eSIngo Weinholdclass Model;
261c29b26eSIngo Weinhold
271c29b26eSIngo Weinhold
281c29b26eSIngo Weinholdclass VirtualDirectoryManager {
291c29b26eSIngo Weinholdpublic:
301c29b26eSIngo Weinhold	static	VirtualDirectoryManager* Instance();
311c29b26eSIngo Weinhold
321c29b26eSIngo Weinhold			bool				Lock()		{ return fLock.Lock(); }
331c29b26eSIngo Weinhold			void				Unlock()	{ fLock.Unlock(); }
341c29b26eSIngo Weinhold
351c29b26eSIngo Weinhold			status_t			ResolveDirectoryPaths(
361c29b26eSIngo Weinhold									const node_ref& definitionFileNodeRef,
371c29b26eSIngo Weinhold									const entry_ref& definitionFileEntryRef,
381c29b26eSIngo Weinhold									BStringList& _directoryPaths,
391c29b26eSIngo Weinhold									node_ref* _definitionFileNodeRef = NULL,
401c29b26eSIngo Weinhold									entry_ref* _definitionFileEntryRef = NULL);
411c29b26eSIngo Weinhold
421c29b26eSIngo Weinhold			bool				GetDefinitionFileChangeTime(
431c29b26eSIngo Weinhold									const node_ref& definitionFileRef,
441c29b26eSIngo Weinhold									bigtime_t& _time) const;
451c29b26eSIngo Weinhold
461c29b26eSIngo Weinhold			bool				GetRootDefinitionFile(
471c29b26eSIngo Weinhold									const node_ref& definitionFileRef,
481c29b26eSIngo Weinhold									node_ref& _rootDefinitionFileRef);
491c29b26eSIngo Weinhold			bool				GetSubDirectoryDefinitionFile(
501c29b26eSIngo Weinhold									const node_ref& baseDefinitionRef,
511c29b26eSIngo Weinhold									const char* subDirName,
521c29b26eSIngo Weinhold									entry_ref& _entryRef, node_ref& _nodeRef);
531c29b26eSIngo Weinhold			bool				GetParentDirectoryDefinitionFile(
541c29b26eSIngo Weinhold									const node_ref& subDirDefinitionRef,
551c29b26eSIngo Weinhold									entry_ref& _entryRef, node_ref& _nodeRef);
561c29b26eSIngo Weinhold
571c29b26eSIngo Weinhold			status_t			TranslateDirectoryEntry(
581c29b26eSIngo Weinhold									const node_ref& definitionFileRef,
591c29b26eSIngo Weinhold									dirent* buffer);
601c29b26eSIngo Weinhold			status_t			TranslateDirectoryEntry(
611c29b26eSIngo Weinhold									const node_ref& definitionFileRef,
621c29b26eSIngo Weinhold									entry_ref& entryRef, node_ref& _nodeRef);
631c29b26eSIngo Weinhold
641c29b26eSIngo Weinhold			bool				DefinitionFileChanged(
651c29b26eSIngo Weinhold									const node_ref& definitionFileRef);
661c29b26eSIngo Weinhold									// returns whether the directory still
671c29b26eSIngo Weinhold									// exists
681c29b26eSIngo Weinhold			status_t			DirectoryRemoved(
691c29b26eSIngo Weinhold									const node_ref& definitionFileRef);
701c29b26eSIngo Weinhold
711c29b26eSIngo Weinhold	static	bool				GetEntry(const BStringList& directoryPaths,
721c29b26eSIngo Weinhold									const char* name, entry_ref* _ref,
731c29b26eSIngo Weinhold						 			struct stat* _st);
741c29b26eSIngo Weinhold
751c29b26eSIngo Weinholdprivate:
761c29b26eSIngo Weinhold			class Info;
771c29b26eSIngo Weinhold			class RootInfo;
781c29b26eSIngo Weinhold
791c29b26eSIngo Weinhold			typedef std::map<node_ref, Info*> NodeRefInfoMap;
801c29b26eSIngo Weinhold
811c29b26eSIngo Weinholdprivate:
821c29b26eSIngo Weinhold								VirtualDirectoryManager();
831c29b26eSIngo Weinhold
841c29b26eSIngo Weinhold			Info*				_InfoForNodeRef(const node_ref& nodeRef) const;
851c29b26eSIngo Weinhold
861c29b26eSIngo Weinhold			bool				_AddInfo(Info* info);
871c29b26eSIngo Weinhold			void				_RemoveInfo(Info* info);
881c29b26eSIngo Weinhold
891c29b26eSIngo Weinhold			void				_UpdateTree(RootInfo* root);
901c29b26eSIngo Weinhold			void				_UpdateTree(Info* info);
911c29b26eSIngo Weinhold
921c29b26eSIngo Weinhold			void				_RemoveDirectory(Info* info);
931c29b26eSIngo Weinhold
941c29b26eSIngo Weinhold			status_t			_ResolveUnknownDefinitionFile(
951c29b26eSIngo Weinhold									const node_ref& definitionFileNodeRef,
961c29b26eSIngo Weinhold									const entry_ref& definitionFileEntryRef,
971c29b26eSIngo Weinhold									Info*& _info);
981c29b26eSIngo Weinhold			status_t			_CreateRootInfo(
991c29b26eSIngo Weinhold									const node_ref& definitionFileNodeRef,
1001c29b26eSIngo Weinhold									const entry_ref& definitionFileEntryRef,
1011c29b26eSIngo Weinhold									Info*& _info);
1021c29b26eSIngo Weinhold			status_t			_ReadSubDirectoryDefinitionFileInfo(
1031c29b26eSIngo Weinhold									const entry_ref& entryRef,
1041c29b26eSIngo Weinhold									entry_ref& _rootDefinitionFileEntryRef,
1051c29b26eSIngo Weinhold									BString& _subDirPath);
1061c29b26eSIngo Weinhold
1071c29b26eSIngo Weinholdprivate:
1081c29b26eSIngo Weinhold			BLocker				fLock;
1091c29b26eSIngo Weinhold			NodeRefInfoMap		fInfos;
1101c29b26eSIngo Weinhold};
1111c29b26eSIngo Weinhold
1121c29b26eSIngo Weinhold} // namespace BPrivate
1131c29b26eSIngo Weinhold
1141c29b26eSIngo Weinhold
115d8d0539aSJohn Scipione#endif	// _VIRTUAL_DIRECTORY_MANAGER_H
116