Remoto - VFS: VFS_datastore.h Source File
Remoto - VFS
VFS_datastore.h
Go to the documentation of this file.
1 #ifndef VFS_DATASTORE_H
2 #define VFS_DATASTORE_H
3 
4 #include <QCache>
5 #include <QBasicTimer>
6 #include <QJsonDocument>
7 #include <QJsonObject>
8 #include <QJsonArray>
9 
10 #include "VFS_base/VFS_node.h"
11 
12 class VFS_datastore_cache_entry : public QObject
13 {
14  Q_OBJECT
15 
16  public:
17  explicit VFS_datastore_cache_entry(bool debug, int flushInterval, int expireInterval, bool raw=false);
19 
20  virtual void setData(QJsonObject json);
21  virtual QJsonDocument getData();
22 
23  virtual void setData(QByteArray data);
24  virtual QByteArray getRawData();
25 
26  QString _key;
27 
28  quint64 size();
29  virtual bool valid(QString &reason);
30 
31  protected:
32  QJsonDocument _data;
33  QByteArray _rawData;
34  quint64 _size;
35  bool _raw;
36  bool _dirty;
37  bool _valid;
38  QString _reason;
39  bool _debug;
40 
41  int _flushID;
43  int _expireID;
45  QBasicTimer _expireTimer;
46 
47  //pure virtual
48  virtual void flush() = 0;
49  virtual void touch();
50 
51  public slots:
52  virtual void timerEvent(QTimerEvent *e);
53 
54  signals:
56  void touched();
57 };
58 
59 //FIXME: multiple inheritance is bad! should be a HasA instead of IsA
60 class VFS_datastore_cache : public QObject, public QCache<QString, VFS_datastore_cache_entry>
61 {
62  Q_OBJECT
63 
64  public:
65  explicit VFS_datastore_cache(quint64 size);
66  virtual ~VFS_datastore_cache();
67 
68  //virtual VFS_datastore_cache_entry *createEntry(QString p);
69  //VFS_datastore_cache_entry *operator [](QString p);
70 
71  bool insert(const QString &key, VFS_datastore_cache_entry *object);
72 
73  //static const quint64 DEFAULT_DATACACHE_SIZE = 8000000; //!< The default size to create a cache. Defaults to ~8mb.
74  static const quint64 DEFAULT_DATACACHE_SIZE = 104857600;
75  //static const int DATACACHE_PRUNE_INTERVAL = 60000; //1 minute
76 
77  private slots:
79  void touched();
80 };
81 
82 
83 class VFS_datastore : public VFS_node
84 {
85  Q_OBJECT
86 
87  public:
88  explicit VFS_datastore(quint64 size, bool debug=false);
89  virtual ~VFS_datastore();
90 
91  virtual VFS_node *find(VFS_request *r);
92  virtual bool isContainer();
93 
94  virtual QString reportDetails();
95 
96  static QJsonObject applyJsonDiff(QJsonObject obj, QJsonObject diff, QString trace="", QString user="server");
97  static QString applyDeltaDiff(QString data, QJsonObject delta, QString trace="", QString user="server");
98 
99  protected:
101  bool _debug;
102 
103  //virtual void ls(VFS_request *r);
104  //virtual void read(VFS_request *r);
105  //virtual void write(VFS_request *r);
106  //virtual void metadata(VFS_request *r);
107  //virtual void report(VFS_request *r);
108  //virtual void submit(VFS_request *r);
109  //virtual void rm(VFS_request *r);
110  //virtual void requestLock(VFS_request *r);
111  //virtual void releaseLock(VFS_request *r);
112  //virtual void aclDefaults(VFS_request *r);
113 
114  private:
115 
116  signals:
117 
118  public slots:
119 };
120 
121 #endif // VFS_DATASTORE_H
A pure virtual class which must be subclassed for data storage.
Definition: VFS_datastore.h:13
quint64 size()
quint64 _size
The size of the data. Always initialized to zero. Must be set in a subclass.
Definition: VFS_datastore.h:34
virtual bool valid(QString &reason)
virtual void setData(QJsonObject json)
Write data to the entry.
virtual ~VFS_datastore_cache_entry()
Destroy the cache entry.
void touched()
Signal emitted when a cache entry has made a change and should climb the cache queue.
virtual QByteArray getRawData()
Return the data from an entry.
QString _reason
The reason this may be invalid. Set by a subclass.
Definition: VFS_datastore.h:38
bool _debug
Debug flag, for verbose output.
Definition: VFS_datastore.h:39
void expired(VFS_datastore_cache_entry *)
Signal emitted when a cache entry has expired and is no longer in use.
int _expireInterval
Expire interval, in milliseconds.
Definition: VFS_datastore.h:44
QByteArray _rawData
Raw binary data. Used if _raw=true.
Definition: VFS_datastore.h:33
virtual QJsonDocument getData()
Return the data from an entry.
bool _valid
Defaults to false. A subclass will determine if _valid is true, like for instance if an underlying fi...
Definition: VFS_datastore.h:37
bool _dirty
Changes have occurred but they are not commited to storage yet.
Definition: VFS_datastore.h:36
QBasicTimer _expireTimer
The expiration timer.
Definition: VFS_datastore.h:45
QString _key
The cache entry key.
Definition: VFS_datastore.h:26
virtual void touch()
Reset the expiration timer.
QJsonDocument _data
The actual cache data.
Definition: VFS_datastore.h:32
int _flushID
Timer ID for flush events.
Definition: VFS_datastore.h:41
virtual void timerEvent(QTimerEvent *e)
Either a flush or expire has happened.
bool _raw
A convenience flag used in subclasses. Not used by this class.
Definition: VFS_datastore.h:35
int _expireID
Timer ID for expire events.
Definition: VFS_datastore.h:43
int _flushInterval
Flush interval, in milliseconds.
Definition: VFS_datastore.h:42
virtual void flush()=0
A pure virtual function that must be overridden in subclasses. This is the function that actually com...
VFS_datastore_cache_entry(bool debug, int flushInterval, int expireInterval, bool raw=false)
Construct the cache entry.
A subclass of QCache and QObject.
Definition: VFS_datastore.h:61
void expired(VFS_datastore_cache_entry *)
A cache entry has exipred.
bool insert(const QString &key, VFS_datastore_cache_entry *object)
Insert a new entry.
virtual ~VFS_datastore_cache()
static const quint64 DEFAULT_DATACACHE_SIZE
The default size to create a cache. Defaults to 100mb.
Definition: VFS_datastore.h:74
VFS_datastore_cache(quint64 size)
void touched()
A cache entry has been touched.
A base class for creating storage nodes in VFS.
Definition: VFS_datastore.h:84
VFS_datastore_cache _cache
The data cache.
bool _debug
Debug mode.
virtual bool isContainer()
All datastore subclasses are containers.
static QString applyDeltaDiff(QString data, QJsonObject delta, QString trace="", QString user="server")
Apply a delta diff to a json object.
VFS_datastore(quint64 size, bool debug=false)
static QJsonObject applyJsonDiff(QJsonObject obj, QJsonObject diff, QString trace="", QString user="server")
Apply a json diff to a json object.
virtual QString reportDetails()
Report the current cache usage.
virtual ~VFS_datastore()
virtual VFS_node * find(VFS_request *r)
VFS_node is the base class from which all other VFS_node classes derive.
Definition: VFS_node.h:143
void diff(VFS_node *origin, VFS_request *t)
Emit a diff, which will trigger notifySubscribers() for a mounted node.
The base class for all requests between nodes.
Definition: VFS_node.h:54