25#include <vrs/ErrorCode.h>
26#include <vrs/FileDelegator.h>
27#include <vrs/FileSpec.h>
28#include <vrs/VrsExport.h>
29#include <vrs/helpers/EnumTemplates.hpp>
30#include <vrs/os/CompilerAttributes.h>
81 size_t blockReadCount;
82 size_t blockMissingCount;
83 size_t blockPendingCount;
87 using CacheStatsCallbackFunction = std::function<void(
const CacheStats& stats)>;
92 static unique_ptr<FileHandler> makeOpen(
const string& filePath);
93 static unique_ptr<FileHandler> makeOpen(
const FileSpec& fileSpec);
98 virtual unique_ptr<FileHandler>
makeNew()
const = 0;
99 virtual const string& getFileHandlerName()
const = 0;
100 virtual const string& getWriteFileHandlerName()
const;
105 virtual int open(
const string& filePath);
121 int delegateOpen(
const FileSpec& fileSpec, unique_ptr<FileHandler>& outNewDelegate)
override;
146 return !isRemoteFileSystem();
156 virtual int read(
void* buffer,
size_t length) = 0;
158 template <typename T, std::enable_if_t<std::is_trivially_copyable<T>::value,
int> = 0>
160 return read(&
object,
sizeof(
object));
163 template <typename T, std::enable_if_t<std::is_trivially_copyable<T>::value,
int> = 0>
165 return read(vec.data(), vec.size() *
sizeof(T));
173 virtual bool isReadOnly()
const;
197 virtual int getChunkRange(int64_t& outChunkOffset, int64_t& outChunkSize)
const = 0;
209 return CachingStrategy::Passive;
224 MAYBE_UNUSED
const vector<std::pair<size_t, size_t>>& sequence,
225 MAYBE_UNUSED
bool clearSequence =
true) {
229 virtual bool setStatsCallback(
const CacheStatsCallbackFunction& ) {
240 bool isFileHandlerMatch(
const FileSpec& fileSpec)
const;
248 return isRemoteFileSystem();
257 originalPtr_{handler_.get()},
258 originalStrategy_{handler->getCachingStrategy()} {
259 handler_->setCachingStrategy(temporaryStrategy);
263 if (originalPtr_ == handler_.get()) {
264 originalPtr_->setCachingStrategy(originalStrategy_);
269 unique_ptr<FileHandler>& handler_;
Class to abstract the delegate file open operation for VRS file.
Definition FileDelegator.h:32
Class to abstract VRS file system operations, to enable support for alternate storage methods,...
Definition FileHandler.h:75
virtual bool isAvailableOrPrefetch(MAYBE_UNUSED size_t length)
Definition FileHandler.h:145
virtual int read(void *buffer, size_t length)=0
virtual int64_t getPos() const =0
virtual int64_t getTotalSize() const =0
virtual int skipForward(int64_t offset)=0
virtual vector< std::pair< string, int64_t > > getFileChunks() const =0
virtual bool isRemoteFileSystem() const =0
virtual bool prefetchReadSequence(MAYBE_UNUSED const vector< std::pair< size_t, size_t > > &sequence, MAYBE_UNUSED bool clearSequence=true)
Definition FileHandler.h:223
int read(T &object)
Helper to read trivially copyable objects, in a chunk aware way.
Definition FileHandler.h:159
virtual bool isEof() const =0
virtual bool showProgress() const
Tell if the file handler is probably slow, and extra progress information might be useful.
Definition FileHandler.h:247
virtual unique_ptr< FileHandler > makeNew() const =0
virtual bool isOpened() const =0
virtual CachingStrategy getCachingStrategy() const
Definition FileHandler.h:208
int read(vector< T > &vec)
Helper to read a vector of trivially copyable objects, in a chunk aware way.
Definition FileHandler.h:164
virtual int setPos(int64_t offset)=0
virtual int64_t getChunkPos() const =0
virtual int openSpec(const FileSpec &fileSpec)=0
virtual void forgetFurtherChunks(int64_t maxSize)=0
Call this method to forget any chunk beyond this file size.
virtual size_t getLastRWSize() const =0
virtual int getChunkRange(int64_t &outChunkOffset, int64_t &outChunkSize) const =0
virtual bool purgeCache()
Definition FileHandler.h:236
virtual bool setCachingStrategy(CachingStrategy)
Definition FileHandler.h:203
virtual int getLastError() const =0
Helper class to temporarily modify a FileHandler's caching strategy.
Definition FileHandler.h:253
Definition Compressor.cpp:113
@ Undefined
when not set explicitly
constexpr const char * kPrefetchCache
To enable basic caching for network file handlers.
Definition FileHandler.h:52
CachingStrategy
Caching strategy requests.
Definition FileHandler.h:38
@ ReleaseAfterRead
Same as "Passive" but release used cache blocks immediately after read.
@ Streaming
Automatically download data "forward", using last read-request as a hint.
@ StreamingBackward
Automatically download data "backward", using last read-request as a hint.
@ Passive
(default) Read & cache on-demand (don't prefetch).
Stats for cache.
Definition FileHandler.h:78
Generalized file descriptor class, allowing the efficient representation of complex file objects,...
Definition FileSpec.h:42