Remoto - VFS: VFS_hd.h Source File
Remoto - VFS
VFS_hd.h
Go to the documentation of this file.
1 #ifndef VFS_HD_H
2 #define VFS_HD_H
3 
4 #include <QJsonDocument>
5 #include <QJsonObject>
6 #include <QJsonArray>
7 
8 #include <QMimeDatabase>
9 #include <QFileInfo>
10 #include <QFileSystemWatcher>
11 
13 
15 {
16  Q_OBJECT
17 
18  friend class VFS_HD;
19 
20  public:
21  explicit VFS_HD_cache_entry(QString path, bool debug, int flushInterval, int expireInterval, bool create=false, bool container=false, bool raw=false, bool watch=false);
22  virtual ~VFS_HD_cache_entry();
23 
24  virtual bool valid(QString &reason);
25 
26  protected:
27  QString _path;
28  QFileInfo _info;
29  QFileSystemWatcher _watcher;
30 
31  virtual void flush();
32 
33  public slots:
34 
35  private slots:
36  void modified(const QString &path);
37 };
38 
39 /*
40 class VFS_HD_cache : public VFS_datastore_cache
41 {
42  Q_OBJECT
43 
44  public:
45  explicit VFS_HD_cache(int size);
46  virtual ~VFS_HD_cache();
47 
48  virtual VFS_datastore_cache_entry *createEntry(QString p);
49 };
50 */
51 
52 class VFS_HD : public VFS_datastore
53 {
54  Q_OBJECT
55 
56  public:
57  Q_INVOKABLE explicit VFS_HD( QString p, quint64 size=VFS_datastore_cache::DEFAULT_DATACACHE_SIZE, bool create=false, bool debug=false, int flushInterval=5000, int expireInterval=60000, bool raw=false, bool watch=false );
58  virtual ~VFS_HD();
59 
60  //virtual VFS_node *find(VFS_request *r);
61 
62  virtual QString reportDetails();
63 
64  const QString path();
65 
66  protected:
67  QString _path;
70  bool _raw;
71  bool _watch;
72 
73  static QMimeDatabase _mimeDatabase;
74 
75  virtual QByteArray icon();
76 
77  virtual void ls(VFS_request *r);
78  virtual void read(VFS_request *r);
79  virtual void write(VFS_request *r);
80  virtual void metadata(VFS_request *r);
81  //virtual void report(VFS_request *r);
82  virtual void submit(VFS_request *r);
83  virtual void rm(VFS_request *r);
84  virtual void subscribe(VFS_request *r);
85 
86  virtual void fetchRange(VFS_request *r);
87 
88  private:
89 
90  public slots:
91  virtual void applyDiff(VFS_request *r);
92 };
93 
94 #endif // VFS_HD_H
A subclass of VFS_datastore_cache_entry, used for disk access.
Definition: VFS_hd.h:15
virtual void flush()
Actually write the file to disk.
Definition: VFS_hd.cpp:354
QString _path
The actual file path.
Definition: VFS_hd.h:27
QFileSystemWatcher _watcher
Watches for changes to the file or directory, and expires the entry on change.
Definition: VFS_hd.h:29
QFileInfo _info
An info object, useful for type and metadata information.
Definition: VFS_hd.h:28
virtual ~VFS_HD_cache_entry()
VFS_HD_cache_entry destructor.
Definition: VFS_hd.cpp:288
VFS_HD_cache_entry(QString path, bool debug, int flushInterval, int expireInterval, bool create=false, bool container=false, bool raw=false, bool watch=false)
Definition: VFS_hd.cpp:112
void modified(const QString &path)
A slot for when the _watcher detects that there has been a change.
Definition: VFS_hd.cpp:307
virtual bool valid(QString &reason)
If the file or directory does not exist or is not readable, _valid is set to false.
Definition: VFS_hd.cpp:326
A VFS_datastore subclass for storing data on a locally attached hard drive or NFS share.
Definition: VFS_hd.h:53
const QString path()
Return the _path of this node.
Definition: VFS_hd.cpp:507
bool _raw
Whether to default to JSON mode or RAW mode, which can be overridden with metadata.
Definition: VFS_hd.h:70
virtual QByteArray icon()
The "disk" icon found in the VFS_icons library.
Definition: VFS_hd.cpp:481
virtual void applyDiff(VFS_request *r)
Apply a diff to a file.
Definition: VFS_hd.cpp:1209
virtual QString reportDetails()
Report the current cache usage.
Definition: VFS_hd.cpp:492
virtual void rm(VFS_request *r)
Attempt to delete a file.
Definition: VFS_hd.cpp:1099
virtual void read(VFS_request *r)
Read the contents of a directory or file.
Definition: VFS_hd.cpp:716
virtual void fetchRange(VFS_request *r)
Fetch a byte range within a file.
Definition: VFS_hd.cpp:1252
Q_INVOKABLE VFS_HD(QString p, quint64 size=VFS_datastore_cache::DEFAULT_DATACACHE_SIZE, bool create=false, bool debug=false, int flushInterval=5000, int expireInterval=60000, bool raw=false, bool watch=false)
Create a VFS_HD node, with an optional create flag.
Definition: VFS_hd.cpp:441
int _expireInterval
Interval for cache entries to expire, in milliseconds.
Definition: VFS_hd.h:69
virtual void write(VFS_request *r)
Write data to a file.
Definition: VFS_hd.cpp:809
static QMimeDatabase _mimeDatabase
The mime database, used for metadata.
Definition: VFS_hd.h:73
bool _watch
Whether to set the watch flag on cache entries.
Definition: VFS_hd.h:71
virtual void submit(VFS_request *r)
Submit data to a file, applying the data as a diff.
Definition: VFS_hd.cpp:994
QString _path
The base prefix path for this VFS_HD node.
Definition: VFS_hd.h:67
virtual void ls(VFS_request *r)
List the contents of a filesystem directory.
Definition: VFS_hd.cpp:548
virtual void subscribe(VFS_request *r)
Subscribe to changes on a file or directory.
Definition: VFS_hd.cpp:1168
int _flushInterval
Interval for cache entries to flush, in milliseconds.
Definition: VFS_hd.h:68
virtual void metadata(VFS_request *r)
Fetch the metadata for a file or directory.
Definition: VFS_hd.cpp:896
virtual ~VFS_HD()
Definition: VFS_hd.cpp:469
A pure virtual class which must be subclassed for data storage.
Definition: VFS_datastore.h:13
static const quint64 DEFAULT_DATACACHE_SIZE
The default size to create a cache. Defaults to 100mb.
Definition: VFS_datastore.h:74
A base class for creating storage nodes in VFS.
Definition: VFS_datastore.h:84
The base class for all requests between nodes.
Definition: VFS_node.h:54