Remoto - VFS: VFS_HD_cache_entry Class Reference
Remoto - VFS

A subclass of VFS_datastore_cache_entry, used for disk access. More...

#include <VFS_hd.h>

Inheritance diagram for VFS_HD_cache_entry:
VFS_datastore_cache_entry

Public Member Functions

 VFS_HD_cache_entry (QString path, bool debug, int flushInterval, int expireInterval, bool create=false, bool container=false, bool raw=false, bool watch=false)
 
virtual ~VFS_HD_cache_entry ()
 VFS_HD_cache_entry destructor. More...
 
virtual bool valid (QString &reason)
 If the file or directory does not exist or is not readable, _valid is set to false. More...
 
- Public Member Functions inherited from VFS_datastore_cache_entry
 VFS_datastore_cache_entry (bool debug, int flushInterval, int expireInterval, bool raw=false)
 Construct the cache entry. More...
 
virtual ~VFS_datastore_cache_entry ()
 Destroy the cache entry. More...
 
virtual QJsonDocument getData ()
 Return the data from an entry. More...
 
virtual QByteArray getRawData ()
 Return the data from an entry. More...
 
virtual void setData (QByteArray data)
 Write raw data to the entry. More...
 
virtual void setData (QJsonObject json)
 Write data to the entry. More...
 
quint64 size ()
 

Protected Member Functions

virtual void flush ()
 Actually write the file to disk. More...
 
- Protected Member Functions inherited from VFS_datastore_cache_entry
virtual void touch ()
 Reset the expiration timer. More...
 

Protected Attributes

QFileInfo _info
 An info object, useful for type and metadata information. More...
 
QString _path
 The actual file path. More...
 
QFileSystemWatcher _watcher
 Watches for changes to the file or directory, and expires the entry on change. More...
 
- Protected Attributes inherited from VFS_datastore_cache_entry
QJsonDocument _data
 The actual cache data. More...
 
bool _debug
 Debug flag, for verbose output. More...
 
bool _dirty
 Changes have occurred but they are not commited to storage yet. More...
 
int _expireID
 Timer ID for expire events. More...
 
int _expireInterval
 Expire interval, in milliseconds. More...
 
QBasicTimer _expireTimer
 The expiration timer. More...
 
int _flushID
 Timer ID for flush events. More...
 
int _flushInterval
 Flush interval, in milliseconds. More...
 
bool _raw
 A convenience flag used in subclasses. Not used by this class. More...
 
QByteArray _rawData
 Raw binary data. Used if _raw=true. More...
 
QString _reason
 The reason this may be invalid. Set by a subclass. More...
 
quint64 _size
 The size of the data. Always initialized to zero. Must be set in a subclass. More...
 
bool _valid
 Defaults to false. A subclass will determine if _valid is true, like for instance if an underlying file doesn't exist. More...
 

Private Slots

void modified (const QString &path)
 A slot for when the _watcher detects that there has been a change. More...
 

Friends

class VFS_HD
 

Additional Inherited Members

- Public Slots inherited from VFS_datastore_cache_entry
virtual void timerEvent (QTimerEvent *e)
 Either a flush or expire has happened. More...
 
- Signals inherited from VFS_datastore_cache_entry
void expired (VFS_datastore_cache_entry *)
 Signal emitted when a cache entry has expired and is no longer in use. More...
 
void touched ()
 Signal emitted when a cache entry has made a change and should climb the cache queue. More...
 
- Public Attributes inherited from VFS_datastore_cache_entry
QString _key
 The cache entry key. More...
 

Detailed Description

A subclass of VFS_datastore_cache_entry, used for disk access.

See also
VFS_datastore_cache_entry

Definition at line 14 of file VFS_hd.h.

Constructor & Destructor Documentation

◆ VFS_HD_cache_entry()

VFS_HD_cache_entry::VFS_HD_cache_entry ( QString  path,
bool  debug,
int  flushInterval,
int  expireInterval,
bool  create = false,
bool  container = false,
bool  raw = false,
bool  watch = false 
)
explicit
Parameters
pathThe filesystem path of the file resource, which may be relative to the VFS executable or absolute
debugVerbose debug mode
flushIntervalInterval to flush to disk, in milliseconds.
expireIntervalInterval to expire the cache entry, in milliseconds.
createIf the filesystem path doesn't exist and it's not a container, create an empty json object: {}.
containerWhen true, and create is true, create an empty directory instead
rawSet the raw flag on this entry.
watchSet the watch flag on this entry, which will expire an entry if a change happens outside of the VFS
Warning
DOCME: describe the logic here more thoroughly

Definition at line 112 of file VFS_hd.cpp.

◆ ~VFS_HD_cache_entry()

VFS_HD_cache_entry::~VFS_HD_cache_entry ( )
virtual

VFS_HD_cache_entry destructor.

Will call flush() if _dirty and _valid are true.

See also
VFS_datastore_cache_entry::~VFS_datastore_cache_entry()

Definition at line 288 of file VFS_hd.cpp.

Member Function Documentation

◆ flush()

void VFS_HD_cache_entry::flush ( )
protectedvirtual

Actually write the file to disk.

If the entry is not _dirty, this immediately returns. If data cannot be written to disk, the entry is left _dirty and a _reason is recorded.

If a partial file is written, a VFS::CRITICAL() message is sent, on suspicion that the disk is full.

On write success, _dirty is set to false, and the _size of the entry is updated.

Note
FIXME: The data size consumed in the cache should also be updated, but this is currently unimplemented.

Implements VFS_datastore_cache_entry.

Definition at line 354 of file VFS_hd.cpp.

◆ modified

void VFS_HD_cache_entry::modified ( const QString &  path)
privateslot

A slot for when the _watcher detects that there has been a change.

Parameters
pathThe changed path, which should be this path

This will emit expired() to remove this entry, as it needs to be re-cached.

Note
On a watched cache entry, flush() will cause the _watcher to see a change and will un-cache the entry. Have to think of a solution for this.

Definition at line 307 of file VFS_hd.cpp.

◆ valid()

bool VFS_HD_cache_entry::valid ( QString &  reason)
virtual

If the file or directory does not exist or is not readable, _valid is set to false.

Parameters
reasonIf invalid, the reason will be written to this string.
Returns
The _valid flag value

This uses values in VFS_HD_cache_entry::_info. An attempt is made to not continuously hit the disk by checking if _valid is already true, however in a production environment this optimization may be invalid.

Reimplemented from VFS_datastore_cache_entry.

Definition at line 326 of file VFS_hd.cpp.

Friends And Related Function Documentation

◆ VFS_HD

friend class VFS_HD
friend

Definition at line 18 of file VFS_hd.h.

Member Data Documentation

◆ _info

QFileInfo VFS_HD_cache_entry::_info
protected

An info object, useful for type and metadata information.

Definition at line 28 of file VFS_hd.h.

◆ _path

QString VFS_HD_cache_entry::_path
protected

The actual file path.

Definition at line 27 of file VFS_hd.h.

◆ _watcher

QFileSystemWatcher VFS_HD_cache_entry::_watcher
protected

Watches for changes to the file or directory, and expires the entry on change.

Definition at line 29 of file VFS_hd.h.


The documentation for this class was generated from the following files: