Alexandria
2.19
Please provide a description of the project.
|
#include <FileManager.h>
Public Types | |
using | FileId = FileMetadata * |
Opaque FileId, its concrete type should only be assumed to be copyable and hashable. More... | |
Public Member Functions | |
FileManager () | |
Constructor. More... | |
virtual | ~FileManager () |
Destructor. More... | |
std::shared_ptr< FileHandler > | getFileHandler (const boost::filesystem::path &path) |
template<typename TFD > | |
std::pair< FileId, TFD > | open (const boost::filesystem::path &path, bool write, std::function< bool(FileId)> request_close) |
template<typename TFD > | |
void | close (FileId id, TFD &fd) |
void | closeAll () |
virtual void | notifyUsed (FileId id) |
bool | hasHandler (const boost::filesystem::path &path) const |
![]() | |
T | enable_shared_from_this (T... args) |
T | operator= (T... args) |
T | shared_from_this (T... args) |
T | ~enable_shared_from_this (T... args) |
Static Public Member Functions | |
static std::shared_ptr< FileManager > | getDefault () |
Protected Types | |
using | Clock = std::chrono::steady_clock |
using | Timestamp = Clock::time_point |
Protected Member Functions | |
virtual void | notifyIntentToOpen (bool write)=0 |
virtual void | notifyOpenedFile (FileId)=0 |
virtual void | notifyClosedFile (FileId)=0 |
Protected Attributes | |
std::mutex | m_mutex |
std::map< boost::filesystem::path, std::weak_ptr< FileHandler > > | m_handlers |
std::map< FileId, std::unique_ptr< FileMetadata > > | m_files |
Provide an open/close interface to FileHandler. Concrete policies must inherit this interface and implement the notify* methods.
Definition at line 56 of file FileManager.h.
|
protected |
Definition at line 155 of file FileManager.h.
using Euclid::FilePool::FileManager::FileId = FileMetadata* |
Opaque FileId, its concrete type should only be assumed to be copyable and hashable.
Definition at line 62 of file FileManager.h.
|
protected |
Definition at line 156 of file FileManager.h.
Euclid::FilePool::FileManager::FileManager | ( | ) |
Constructor.
Definition at line 64 of file FileManager.cpp.
|
virtual |
Destructor.
Definition at line 66 of file FileManager.cpp.
void Euclid::FilePool::FileManager::close | ( | FileId | id, |
TFD & | fd | ||
) |
Close a file
id | The id returned by open |
Referenced by Euclid::FilePool::FileHandler::TypedFdWrapper< TFD >::close().
void Euclid::FilePool::FileManager::closeAll | ( | ) |
Close all closeable file descriptors
Definition at line 75 of file FileManager.cpp.
References std::back_inserter(), std::map< K, T >::begin(), std::map< K, T >::end(), m_files, m_mutex, and std::transform().
Referenced by Euclid::FilePool::LRUFileManager::~LRUFileManager().
|
static |
Definition at line 59 of file FileManager.cpp.
std::shared_ptr< FileHandler > Euclid::FilePool::FileManager::getFileHandler | ( | const boost::filesystem::path & | path | ) |
Get a file handler
TFD | File descriptor type |
path | File path |
Elements::Exception | If there is already a FileHandler with a different file descriptor type. |
Definition at line 91 of file FileManager.cpp.
References std::weak_ptr< T >::lock(), m_handlers, m_mutex, std::enable_shared_from_this< FileManager >::shared_from_this(), and weakly_canonical().
bool Euclid::FilePool::FileManager::hasHandler | ( | const boost::filesystem::path & | path | ) | const |
Definition at line 119 of file FileManager.cpp.
References m_handlers, m_mutex, and weakly_canonical().
|
protectedpure virtual |
Implemented in Euclid::FilePool::LRUFileManager.
|
protectedpure virtual |
Implemented in Euclid::FilePool::LRUFileManager.
|
protectedpure virtual |
Implemented in Euclid::FilePool::LRUFileManager.
|
virtual |
Notify that the given file has been/is going to be used. This will update the book-keeping data used to decide what to close when.
Reimplemented in Euclid::FilePool::LRUFileManager.
Definition at line 69 of file FileManager.cpp.
References std::chrono::steady_clock::now().
std::pair<FileId, TFD> Euclid::FilePool::FileManager::open | ( | const boost::filesystem::path & | path, |
bool | write, | ||
std::function< bool(FileId)> | request_close | ||
) |
Open a file
TFD | File descriptor type. |
path | File path |
write | True if the file is to be opened in write mode |
request_close | The manager will call this function when it needs to close the file descriptor, so whoever called open can put everything in order. The callback can return "false" if the given FileId can not be closed (i.e. it is still in use). The callback is responsible for calling close. |
|
protected |
Map a file id to its metadata
Definition at line 172 of file FileManager.h.
Referenced by closeAll(), and Euclid::FilePool::LRUFileManager::notifyIntentToOpen().
|
protected |
Map path / handler The value is a std::weak_ptr because we are not really interested on keeping a handler alive if no one is using it. However, if someone has a handler pointing to a file alive, and someone else wants a handler to the same file, it should get the same handler.
Definition at line 167 of file FileManager.h.
Referenced by getFileHandler(), and hasHandler().
|
mutableprotected |
Definition at line 158 of file FileManager.h.
Referenced by closeAll(), getFileHandler(), hasHandler(), Euclid::FilePool::LRUFileManager::notifyClosedFile(), Euclid::FilePool::LRUFileManager::notifyIntentToOpen(), Euclid::FilePool::LRUFileManager::notifyOpenedFile(), and Euclid::FilePool::LRUFileManager::notifyUsed().