Remoto - VFS
|
A pure virtual class which must be subclassed for data storage. More...
#include <VFS_datastore.h>
Public Slots | |
virtual void | timerEvent (QTimerEvent *e) |
Either a flush or expire has happened. More... | |
Signals | |
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 Member Functions | |
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 () |
virtual bool | valid (QString &reason) |
Public Attributes | |
QString | _key |
The cache entry key. More... | |
Protected Member Functions | |
virtual void | flush ()=0 |
A pure virtual function that must be overridden in subclasses. This is the function that actually commits data to a storage medium. More... | |
virtual void | touch () |
Reset the expiration timer. More... | |
Protected Attributes | |
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... | |
A pure virtual class which must be subclassed for data storage.
This class will provide basic functionality for caching data before flushing to a storage medium. It is designed to act as an entry in a VFS_datastore_cache.
Cache entries will flush at some interval if _dirty, regardless of expire status. touch() will restart the expire timer, pushing expiration into the future.
Definition at line 12 of file VFS_datastore.h.
|
explicit |
Construct the cache entry.
debug | Verbose debug output |
flushInterval | Interval to flush to storage medium, provided by a storage VFS_node like VFS_HD, but could be set uniquely per cache entry. In milliseconds. |
expireInterval | Interval to expire a cache entry, which will cause it to be removed from the cache. In milliseconds. |
raw | Whether or not to treat this data as JSON or raw data. Useful for subclasses as a flag, but unused in this class. |
On creation, the cache entry will start the flush timer and call touch().
Definition at line 31 of file VFS_datastore.cpp.
|
virtual |
Destroy the cache entry.
If it is _dirty or not _valid, a warning will be issued, but a flush() is not called. Subclasses may choose to flush().
Definition at line 57 of file VFS_datastore.cpp.
|
signal |
Signal emitted when a cache entry has expired and is no longer in use.
|
protectedpure virtual |
A pure virtual function that must be overridden in subclasses. This is the function that actually commits data to a storage medium.
Implemented in VFS_mongo_cache_entry, and VFS_HD_cache_entry.
|
virtual |
Return the data from an entry.
Also touch() the cache entry, because this means it is in use and can expire later.
Definition at line 156 of file VFS_datastore.cpp.
|
virtual |
Return the data from an entry.
Also touch() the cache entry, because this means it is in use and can expire later.
Definition at line 187 of file VFS_datastore.cpp.
|
virtual |
Write raw data to the entry.
data | The data |
The _dirty flag will be set, because the data has not been flush()ed yet.
Definition at line 170 of file VFS_datastore.cpp.
|
virtual |
Write data to the entry.
json | The data |
If a subclass chooses to use the raw flag, it will want to use setData(QByteArray).
The _dirty flag will be set, because the data has not been flush()ed yet.
Definition at line 135 of file VFS_datastore.cpp.
quint64 VFS_datastore_cache_entry::size | ( | ) |
Definition at line 121 of file VFS_datastore.cpp.
|
virtualslot |
Either a flush or expire has happened.
event | The timer event |
In either case, call flush() to commit data to a storage medium, or report an error if flush() was not possible.
If expired and flush was not possible, the expired() signal will not be emitted. This is a tricky case to deal with, because it implies that some other problem, like a full disk, is the culprit. At least the data here is not lost yet.
Definition at line 75 of file VFS_datastore.cpp.
|
protectedvirtual |
Reset the expiration timer.
This will cause expiration to happen in the future. Another touch() will extend this.
Definition at line 215 of file VFS_datastore.cpp.
|
signal |
Signal emitted when a cache entry has made a change and should climb the cache queue.
|
virtual |
reason | If invalid, the reason will be written to this string. |
A subclass must set an entry as _valid, based on whatever criteria it wants. By default all entries are _valid==false
.
Reimplemented in VFS_mongo_cache_entry, and VFS_HD_cache_entry.
Definition at line 201 of file VFS_datastore.cpp.
|
protected |
The actual cache data.
Definition at line 32 of file VFS_datastore.h.
|
protected |
Debug flag, for verbose output.
Definition at line 39 of file VFS_datastore.h.
|
protected |
Changes have occurred but they are not commited to storage yet.
Definition at line 36 of file VFS_datastore.h.
|
protected |
Timer ID for expire events.
Definition at line 43 of file VFS_datastore.h.
|
protected |
Expire interval, in milliseconds.
Definition at line 44 of file VFS_datastore.h.
|
protected |
The expiration timer.
Definition at line 45 of file VFS_datastore.h.
|
protected |
Timer ID for flush events.
Definition at line 41 of file VFS_datastore.h.
|
protected |
Flush interval, in milliseconds.
Definition at line 42 of file VFS_datastore.h.
QString VFS_datastore_cache_entry::_key |
The cache entry key.
Definition at line 26 of file VFS_datastore.h.
|
protected |
A convenience flag used in subclasses. Not used by this class.
Definition at line 35 of file VFS_datastore.h.
|
protected |
Raw binary data. Used if _raw=true.
Definition at line 33 of file VFS_datastore.h.
|
protected |
The reason this may be invalid. Set by a subclass.
Definition at line 38 of file VFS_datastore.h.
|
protected |
The size of the data. Always initialized to zero. Must be set in a subclass.
Definition at line 34 of file VFS_datastore.h.
|
protected |
Defaults to false. A subclass will determine if _valid is true, like for instance if an underlying file doesn't exist.
Definition at line 37 of file VFS_datastore.h.