Alexandria 2.31.0
SDC-CH common library for the Euclid project
|
#include <FileHandler.h>
Classes | |
struct | FdWrapper |
struct | TypedFdWrapper |
Public Types | |
enum | Mode { kRead = 0 , kWrite = 1 , kTry = 2 , kTryRead = kTry , kTryWrite = kTry | kWrite } |
Open modes. More... | |
Public Member Functions | |
virtual | ~FileHandler () |
Destructor. | |
template<typename TFD > | |
std::unique_ptr< FileAccessor< TFD > > | getAccessor (Mode mode=kRead) |
bool | isReadOnly () const |
Private Types | |
using | SharedMutex = typename FileAccessorBase::SharedMutex |
using | SharedLock = typename FileAccessorBase::SharedLock |
using | UniqueLock = typename FileAccessorBase::UniqueLock |
Private Member Functions | |
FileHandler (const boost::filesystem::path &path, std::weak_ptr< FileManager > file_manager) | |
bool | close (FileManager::FileId id) |
template<typename TFD > | |
std::unique_ptr< FileAccessor< TFD > > | getWriteAccessor (bool try_lock) |
template<typename TFD > | |
std::unique_ptr< FileAccessor< TFD > > | getReadAccessor (bool try_lock) |
Private Attributes | |
std::mutex | m_handler_mutex |
boost::filesystem::path | m_path |
std::weak_ptr< FileManager > | m_file_manager |
SharedMutex | m_file_mutex |
std::map< FileManager::FileId, std::unique_ptr< FdWrapper > > | m_available_fd |
bool | m_is_readonly |
Friends | |
class | FileManager |
Wraps a set of file descriptors. It should rely on a FileManager implementation to do the opening/closing and policy handling of lifetimes. This is, the FileManager implementation decides the policy on when to close a given file descriptor if the maximum is reached. However, it will play "nice" and just ask the handler to please close it. The handler must not close a file being accessed, so it should just refuse to do so and let the FileManager figure it out.
Definition at line 39 of file FileHandler.h.
|
private |
Definition at line 66 of file FileHandler.h.
|
private |
Definition at line 65 of file FileHandler.h.
|
private |
Definition at line 67 of file FileHandler.h.
Open modes.
Enumerator | |
---|---|
kRead | |
kWrite | |
kTry | |
kTryRead | |
kTryWrite |
Definition at line 42 of file FileHandler.h.
|
virtual |
|
private |
Constructor
path | File path |
file_manager | FileManager implementation responsible for opening/closing and keeping track of number of opened files. A FileHandler could survive the manager as long as no new accessors are needed. |
Definition at line 24 of file FileHandler.cpp.
|
private |
This is to be used by the FileManager to request the closing of a file descriptor
id | ID of the file to close |
Definition at line 37 of file FileHandler.cpp.
References m_available_fd, m_handler_mutex, and std::move().
std::unique_ptr< FileAccessor< TFD > > Euclid::FilePool::FileHandler::getAccessor | ( | Mode | mode = kRead | ) |
Get a new FileAccessor
mode | The accessor mode. TryRead and TryWrite can be used if the caller does not want to block. |
If | opening the file fails |
|
private |
|
private |
bool Euclid::FilePool::FileHandler::isReadOnly | ( | ) | const |
Definition at line 33 of file FileHandler.cpp.
References m_is_readonly.
|
friend |
Definition at line 63 of file FileHandler.h.
|
private |
Definition at line 93 of file FileHandler.h.
Referenced by close(), and ~FileHandler().
|
private |
Definition at line 91 of file FileHandler.h.
|
private |
Definition at line 92 of file FileHandler.h.
|
private |
Definition at line 89 of file FileHandler.h.
Referenced by close().
|
private |
Definition at line 94 of file FileHandler.h.
Referenced by isReadOnly().
|
private |
Definition at line 90 of file FileHandler.h.