1 /* 2 * Copyright 2013, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Ingo Weinhold, ingo_weinhold@gmx.de 7 */ 8 #ifndef VIRTUAL_DIRECTORY_MANAGER_H 9 #define VIRTUAL_DIRECTORY_MANAGER_H 10 11 12 #include <dirent.h> 13 14 #include <map> 15 16 #include <Locker.h> 17 #include <Node.h> 18 19 20 class BStringList; 21 22 23 namespace BPrivate { 24 25 26 class Model; 27 28 29 class VirtualDirectoryManager { 30 public: 31 static VirtualDirectoryManager* Instance(); 32 33 bool Lock() { return fLock.Lock(); } 34 void Unlock() { fLock.Unlock(); } 35 36 status_t ResolveDirectoryPaths( 37 const node_ref& definitionFileNodeRef, 38 const entry_ref& definitionFileEntryRef, 39 BStringList& _directoryPaths, 40 node_ref* _definitionFileNodeRef = NULL, 41 entry_ref* _definitionFileEntryRef = NULL); 42 43 bool GetDefinitionFileChangeTime( 44 const node_ref& definitionFileRef, 45 bigtime_t& _time) const; 46 47 bool GetRootDefinitionFile( 48 const node_ref& definitionFileRef, 49 node_ref& _rootDefinitionFileRef); 50 bool GetSubDirectoryDefinitionFile( 51 const node_ref& baseDefinitionRef, 52 const char* subDirName, 53 entry_ref& _entryRef, node_ref& _nodeRef); 54 bool GetParentDirectoryDefinitionFile( 55 const node_ref& subDirDefinitionRef, 56 entry_ref& _entryRef, node_ref& _nodeRef); 57 58 status_t TranslateDirectoryEntry( 59 const node_ref& definitionFileRef, 60 dirent* buffer); 61 status_t TranslateDirectoryEntry( 62 const node_ref& definitionFileRef, 63 entry_ref& entryRef, node_ref& _nodeRef); 64 65 bool DefinitionFileChanged( 66 const node_ref& definitionFileRef); 67 // returns whether the directory still 68 // exists 69 status_t DirectoryRemoved( 70 const node_ref& definitionFileRef); 71 72 static bool GetEntry(const BStringList& directoryPaths, 73 const char* name, entry_ref* _ref, 74 struct stat* _st); 75 76 private: 77 class Info; 78 class RootInfo; 79 80 typedef std::map<node_ref, Info*> NodeRefInfoMap; 81 82 private: 83 VirtualDirectoryManager(); 84 85 Info* _InfoForNodeRef(const node_ref& nodeRef) const; 86 87 bool _AddInfo(Info* info); 88 void _RemoveInfo(Info* info); 89 90 void _UpdateTree(RootInfo* root); 91 void _UpdateTree(Info* info); 92 93 void _RemoveDirectory(Info* info); 94 95 status_t _ResolveUnknownDefinitionFile( 96 const node_ref& definitionFileNodeRef, 97 const entry_ref& definitionFileEntryRef, 98 Info*& _info); 99 status_t _CreateRootInfo( 100 const node_ref& definitionFileNodeRef, 101 const entry_ref& definitionFileEntryRef, 102 Info*& _info); 103 status_t _ReadSubDirectoryDefinitionFileInfo( 104 const entry_ref& entryRef, 105 entry_ref& _rootDefinitionFileEntryRef, 106 BString& _subDirPath); 107 108 private: 109 BLocker fLock; 110 NodeRefInfoMap fInfos; 111 }; 112 113 114 } // namespace BPrivate 115 116 117 #endif // VIRTUAL_DIRECTORY_MANAGER_H 118