1/*
2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef FILE_MANAGER_H
6#define FILE_MANAGER_H
7
8#include <Locker.h>
9#include <String.h>
10
11#include <util/DoublyLinkedList.h>
12#include <util/OpenHashTable.h>
13
14
15class LocatableEntry;
16class LocatableFile;
17class SourceFile;
18
19
20class FileManager {
21public:
22								FileManager();
23								~FileManager();
24
25			status_t			Init(bool targetIsLocal);
26
27			bool				Lock()		{ return fLock.Lock(); }
28			void				Unlock()	{ fLock.Unlock(); }
29
30			LocatableFile*		GetTargetFile(const BString& directory,
31									const BString& relativePath);
32										// returns a reference
33			LocatableFile*		GetTargetFile(const BString& path);
34										// returns a reference
35			void				TargetEntryLocated(const BString& path,
36									const BString& locatedPath);
37
38			LocatableFile*		GetSourceFile(const BString& directory,
39									const BString& relativePath);
40										// returns a reference
41			LocatableFile*		GetSourceFile(const BString& path);
42										// returns a reference
43			void				SourceEntryLocated(const BString& path,
44									const BString& locatedPath);
45
46			status_t			LoadSourceFile(LocatableFile* file,
47									SourceFile*& _sourceFile);
48										// returns a reference
49
50private:
51			struct EntryPath;
52			struct EntryHashDefinition;
53			class Domain;
54			struct SourceFileEntry;
55			struct SourceFileHashDefinition;
56
57			typedef BOpenHashTable<EntryHashDefinition> LocatableEntryTable;
58			typedef DoublyLinkedList<LocatableEntry> DeadEntryList;
59			typedef BOpenHashTable<SourceFileHashDefinition> SourceFileTable;
60
61			friend struct SourceFileEntry;
62				// for gcc 2
63
64private:
65			SourceFileEntry*	_LookupSourceFile(const BString& path);
66			void				_SourceFileUnused(SourceFileEntry* entry);
67
68private:
69			BLocker				fLock;
70			Domain*				fTargetDomain;
71			Domain*				fSourceDomain;
72			SourceFileTable*	fSourceFiles;
73};
74
75
76
77#endif	// FILE_MANAGER_H
78