handles implementation

This commit is contained in:
georgemoralis 2023-11-04 23:43:12 +02:00
parent 997dbddfce
commit ca642a3a5f
2 changed files with 35 additions and 5 deletions

View File

@ -33,8 +33,34 @@ std::string MntPoints::getHostDirectory(const std::string& guest_directory) {
} }
return ""; return "";
} }
int HandleTable::createHandle() { return 0; } int HandleTable::createHandle() {
void HandleTable::deleteHandle(int d) {} std::unique_lock lock{m_mutex};
File* HandleTable::getFile(int d) { return nullptr; } auto* file = new File{};
File* HandleTable::getFile(const std::string& real_name) { return nullptr; } file->isDirectory = false;
file->isOpened = false;
int existingFilesNum = m_files.size();
// TODO when i close a file m_files probably have a open pos , so we can fill this
m_files.push_back(file);
return existingFilesNum - 1;
}
void HandleTable::deleteHandle(int d) {
std::unique_lock lock{m_mutex};
delete m_files.at(d);
m_files[d] = nullptr;
}
File* HandleTable::getFile(int d) {
std::unique_lock lock{m_mutex};
return m_files.at(d);
}
File* HandleTable::getFile(const std::string& real_name) {
std::unique_lock lock{m_mutex};
for (auto* file : m_files) {
if (file != nullptr && file->m_real_name == real_name) {
return file;
}
}
return nullptr;
}
} // namespace Core::FileSys } // namespace Core::FileSys

View File

@ -24,7 +24,11 @@ class MntPoints {
std::mutex m_mutex; std::mutex m_mutex;
}; };
struct File {}; struct File {
std::atomic_bool isOpened;
std::atomic_bool isDirectory;
std::string m_real_name;
};
class HandleTable { class HandleTable {
HandleTable() {} HandleTable() {}
virtual ~HandleTable() {} virtual ~HandleTable() {}