1 /* 2 * Copyright 2013 Haiku, Inc. All rights reserved. 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 class Model; 26 27 28 class VirtualDirectoryManager { 29 public: 30 static VirtualDirectoryManager* Instance(); 31 Lock()32 bool Lock() { return fLock.Lock(); } Unlock()33 void Unlock() { fLock.Unlock(); } 34 35 status_t ResolveDirectoryPaths( 36 const node_ref& definitionFileNodeRef, 37 const entry_ref& definitionFileEntryRef, 38 BStringList& _directoryPaths, 39 node_ref* _definitionFileNodeRef = NULL, 40 entry_ref* _definitionFileEntryRef = NULL); 41 42 bool GetDefinitionFileChangeTime( 43 const node_ref& definitionFileRef, 44 bigtime_t& _time) const; 45 46 bool GetRootDefinitionFile( 47 const node_ref& definitionFileRef, 48 node_ref& _rootDefinitionFileRef); 49 bool GetSubDirectoryDefinitionFile( 50 const node_ref& baseDefinitionRef, 51 const char* subDirName, 52 entry_ref& _entryRef, node_ref& _nodeRef); 53 bool GetParentDirectoryDefinitionFile( 54 const node_ref& subDirDefinitionRef, 55 entry_ref& _entryRef, node_ref& _nodeRef); 56 57 status_t TranslateDirectoryEntry( 58 const node_ref& definitionFileRef, 59 dirent* buffer); 60 status_t TranslateDirectoryEntry( 61 const node_ref& definitionFileRef, 62 entry_ref& entryRef, node_ref& _nodeRef); 63 64 bool DefinitionFileChanged( 65 const node_ref& definitionFileRef); 66 // returns whether the directory still 67 // exists 68 status_t DirectoryRemoved( 69 const node_ref& definitionFileRef); 70 71 static bool GetEntry(const BStringList& directoryPaths, 72 const char* name, entry_ref* _ref, 73 struct stat* _st); 74 75 private: 76 class Info; 77 class RootInfo; 78 79 typedef std::map<node_ref, Info*> NodeRefInfoMap; 80 81 private: 82 VirtualDirectoryManager(); 83 84 Info* _InfoForNodeRef(const node_ref& nodeRef) const; 85 86 bool _AddInfo(Info* info); 87 void _RemoveInfo(Info* info); 88 89 void _UpdateTree(RootInfo* root); 90 void _UpdateTree(Info* info); 91 92 void _RemoveDirectory(Info* info); 93 94 status_t _ResolveUnknownDefinitionFile( 95 const node_ref& definitionFileNodeRef, 96 const entry_ref& definitionFileEntryRef, 97 Info*& _info); 98 status_t _CreateRootInfo( 99 const node_ref& definitionFileNodeRef, 100 const entry_ref& definitionFileEntryRef, 101 Info*& _info); 102 status_t _ReadSubDirectoryDefinitionFileInfo( 103 const entry_ref& entryRef, 104 entry_ref& _rootDefinitionFileEntryRef, 105 BString& _subDirPath); 106 107 private: 108 BLocker fLock; 109 NodeRefInfoMap fInfos; 110 }; 111 112 } // namespace BPrivate 113 114 115 #endif // _VIRTUAL_DIRECTORY_MANAGER_H 116