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