Remoto - VFS
|
VFS_curl reads data from a url when read() is called. More...
#include <VFS_curl.h>
Public Slots | |
void | replyFinished (QNetworkReply *reply) |
A network request has completed. More... | |
virtual void | sslErrors (QNetworkReply *, const QList< QSslError > &errors) |
One or more ssl errors have occurred. More... | |
![]() | |
virtual void | applyDiff (VFS_request *r) |
Apply a diff received via subscription. More... | |
virtual void | executeRequest (VFS_request *t) |
Based on the VFS_request::requestType, execute the function associated with an operation. More... | |
void | notifySubscribers (VFS_node *origin, VFS_request *t) |
Propagate a diff to subscribers. More... | |
virtual void | receiveResponse (VFS_request *t) |
Once a VFS_request has been completed, a response will be issued back to its _origin. More... | |
void | remove (bool andDelete) |
Remove a child node. More... | |
virtual void | remove (VFS_node *node=nullptr, QString *name=nullptr, QString user="server") |
Remove a child node from this node. More... | |
virtual void | subtreeRequest (VFS_request *t) |
find() the target of a VFS_request, and execute the request More... | |
virtual void | unsubscribeAll (VFS_node *n) |
Remove all references to a subscriber from this node. More... | |
Public Member Functions | |
Q_INVOKABLE | VFS_curl (QString url, bool json=false, bool poll=false, int expire=10000, int timeout=60000) |
virtual | ~VFS_curl () |
virtual bool | isContainer () |
A VFS_curl node cannot contain children. More... | |
virtual void | metadata (VFS_request *r) |
Fetch the metadata for this node. More... | |
virtual void | read (VFS_request *r) |
Request the _url. More... | |
virtual QString | reportDetails () |
Report the url. More... | |
![]() | |
Q_INVOKABLE | VFS_node () |
The VFS_node constructor will add its instance to the VFS_node::__allNodes global node registry, observing thread safety rules. More... | |
virtual | ~VFS_node () |
VFS_node destructor. More... | |
virtual VFS_node * | append (QString name, VFS_node *node, bool containerCheck=true, QString user="server") |
Append a VFS_node as a child of this node. More... | |
QString | className () |
Return the class name of a node. More... | |
virtual VFS_request * | createRequest (VFS_request::requestType type, QString path, QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false) |
Create a new VFS_request with this object as _origin. More... | |
VFS_node * | find (QString path) |
Find a node by string path. More... | |
virtual VFS_node * | find (VFS_request *r) |
Find a node using a VFS_request. More... | |
VFS_node * | findChildWithName (QString name) |
Check if a child with a given name exists. More... | |
virtual VFS_node * | mount () |
Mount this node. More... | |
QString | uniqueChildName (QString name) |
Generate a unique child name. More... | |
virtual VFS_node * | unmount () |
Unmount this node. More... | |
virtual bool | validChildName (QString name) |
Check if a node name is valid. More... | |
Protected Slots | |
virtual void | expire () |
Set the _stale value to true, and if _poll , request an update. More... | |
virtual void | networkTimeout () |
A request was initiated, but timed out. More... | |
Protected Member Functions | |
virtual void | get (VFS_request *r) |
VFS_curl::get. More... | |
virtual QByteArray | icon () |
The "stream" icon found in the VFS_icons library. More... | |
virtual QJsonObject | parse (QJsonObject data, QJsonObject &diffout) |
Parse the incoming data into useful format. More... | |
![]() | |
virtual void | aclDefaults (VFS_request *r) |
Return default values and features associated wth this node. More... | |
void | addACLDefault (QJsonObject &acl, bool value, QString description="") |
Add a default value to the acl object. More... | |
void | addACLFeature (QJsonObject &acl, QString feature, bool value, QString description="") |
Add a feature to the acl object. More... | |
void | addACLFeatureGroup (QJsonObject &acl, QString feature, QString group, bool value) |
Add a feature group to the acl object. More... | |
void | addACLFeatureUser (QJsonObject &acl, QString feature, QString user, bool value) |
Add a feature user to the acl object. More... | |
void | addACLGroup (QJsonObject &acl, QString group, bool value) |
Add a group to the acl object. More... | |
void | addACLUser (QJsonObject &acl, QString user, bool value) |
Add a user to the acl object. More... | |
virtual void | issueRequest (VFS_node *target, VFS_request *t) |
Issue a VFS_request to its target. More... | |
virtual void | issueRequest (VFS_request *t) |
A convenience function. More... | |
virtual void | issueResponse (VFS_request *t) |
Once a request has been completed, issue a response. More... | |
virtual void | ls (VFS_request *r) |
List the contents of this node. More... | |
virtual void | releaseLock (VFS_request *r) |
Release a lock on this node. More... | |
virtual void | report (VFS_request *r) |
Report debugging information about the current state of this node. More... | |
virtual void | requestLock (VFS_request *r) |
Request a lock on this node. More... | |
virtual void | rm (VFS_request *r) |
Remove a child entry from a node, or the node itself. More... | |
virtual void | submit (VFS_request *r) |
Submit a diff to a node. More... | |
virtual void | subscribe (VFS_request *r) |
Add an entry to this node's _subscription list. More... | |
virtual void | unsubscribe (VFS_request *r) |
Remove an entry from this node's _subscription list. More... | |
virtual void | unsubscribePath (QString path) |
Unsubscribe all references to a subpath. More... | |
virtual void | write (VFS_request *r) |
Write data to this node. More... | |
Protected Attributes | |
QJsonObject | _data |
The data retrieved from a http get request after it has been sent to parse(). More... | |
int | _expire |
Time in milliseconds to consider the retrieved data stale. More... | |
bool | _json |
Interpret fetched data as json. More... | |
QNetworkAccessManager | _manager |
The http request manager. More... | |
QJsonObject | _metadata |
Certain headers returned from a successful http get request. More... | |
bool | _poll |
If data is considered expired, re-request it. More... | |
QList< VFS_request * > | _requests |
A list of outstanding VFS_request objects to satisfy once an http request is complete. More... | |
QUrl | _url |
The url to request. More... | |
![]() | |
VFS_children | _children |
This node's children. More... | |
QMutex | _lock |
A recursive mutex that is local to this node. More... | |
VFS_subscriptionType | _subscribers |
This node's subscribers. These subscribers will receive diff notifications. More... | |
Private Member Functions | |
QJsonObject | getHeaders (QNetworkReply *reply) |
Create a QJsonObject based on a QNetworkReply. More... | |
Private Attributes | |
bool | _getting |
If an outstanding request exists. More... | |
QString | _reason |
If an http request was invalid, this will contain the error string. More... | |
QNetworkReply * | _request |
The outstanding request, if any. More... | |
bool | _stale |
If the retrieved content is stale. Initialized as true. More... | |
int | _timeout |
The time to wait for a response before timing out. Defaults to 60000 ms = 1 minute. More... | |
QTimer | _timer |
For detecting timeouts on network requests. The QNetworkAccessManager doesn't do this on its own. More... | |
bool | _valid |
If the http request was valid. More... | |
Additional Inherited Members | |
![]() | |
void | diff (VFS_node *origin, VFS_request *t) |
Emit a diff, which will trigger notifySubscribers() for a mounted node. More... | |
void | finished (bool andDelete=false) |
Emitted if a thread fails to create its node, or a node is rm()'d, or any other reason a node has completed its lifecycle. It is deleted if andDelete==true . More... | |
void | mounted () |
Emitted when a node is mount()ed. More... | |
void | unmounted (VFS_node *self) |
Emitted when a node is unmount()ed. More... | |
![]() | |
static bool | __isNode (VFS_node *) |
Check to see if a node is in the global registry. More... | |
static QString | code (QString nodename, QString libname, QString &error) |
Fetch code or any other resource from a node. More... | |
VFS_curl reads data from a url when read() is called.
This will use a QNetworkAccessManager to supply asynchronous http reqests to a _url.
Needs to be subclassed to support write() or submit(), or possibly even subscribe()
Data will be returned in the "data" field of the VFS_request object if _json
is not set, otherwise json data will be decoded into the VFS_request object.
All http headers will be reported by metadata() in the http
field.
Definition at line 12 of file VFS_curl.h.
|
explicit |
url | The url to load when requested |
json | Interpret incoming data as JSON |
poll | Re-pull data if it is considered to be expired |
expire | Time in milliseconds to consider retrieved data _stale, which defaults to 10000 ms = 10 seconds |
timeout | Time in milliseconds to consider a request timed out, which defaults to 60000 ms = 1 minute |
The constructor connects to signals on the QNetworkManager.
Definition at line 33 of file VFS_curl.cpp.
|
virtual |
Definition at line 69 of file VFS_curl.cpp.
|
protectedvirtualslot |
Set the _stale
value to true, and if _poll
, request an update.
Definition at line 316 of file VFS_curl.cpp.
|
protectedvirtual |
r | The VFS_request object to enqueue |
Definition at line 180 of file VFS_curl.cpp.
|
private |
Create a QJsonObject based on a QNetworkReply.
reply | The QNetworkReply object to be used |
Definition at line 335 of file VFS_curl.cpp.
|
protectedvirtual |
The "stream" icon found in the VFS_icons library.
Reimplemented from VFS_node.
Definition at line 80 of file VFS_curl.cpp.
|
virtual |
A VFS_curl node cannot contain children.
Reimplemented from VFS_node.
Definition at line 100 of file VFS_curl.cpp.
|
virtual |
Fetch the metadata for this node.
r | The VFS_request object |
VFS_curl will return a metadata type of "urlData", plus some additional http header fields from the url request.
The captured headers will be those enumerated in QNetworkRequest::KnownHeaders.
Reimplemented from VFS_node.
Definition at line 114 of file VFS_curl.cpp.
|
protectedvirtualslot |
A request was initiated, but timed out.
The timeout should be longer than _expire, so that we don't compound requests indefinitely for a slow or failing network request.
Definition at line 302 of file VFS_curl.cpp.
|
protectedvirtual |
Parse the incoming data into useful format.
This is useful for subclasses.
data | The data to parse |
diffout | The diff object to write to |
_data
This method has the opportunity to parse incoming data, update the current data model, and write a diff if the incoming data is different. The default implementation replaces current data with all new data, and sets the data as the diff. Subclasses will want to override this to create more meaningful diffs.
Definition at line 400 of file VFS_curl.cpp.
|
virtual |
Request the _url.
r | The VFS_request object |
Dispatch a QNetworkAccessManager get request on the url, and when the request is complete, return the resulting data.
Some additional http data will be provided in the "http" field of the resulting metadata of the VFS_request object.
If _json
is true, the response will be parsed as json and stored to _data
on the VFS_request.
If _json
is false, a "data" field will be populated with the result of the curl request.
Reimplemented from VFS_node.
Definition at line 153 of file VFS_curl.cpp.
|
slot |
A network request has completed.
reply | The reply from a network request |
This method will call issueResponse() on the VFS_request or generate an error.
Definition at line 217 of file VFS_curl.cpp.
|
virtual |
Report the url.
Reimplemented from VFS_node.
Definition at line 90 of file VFS_curl.cpp.
|
virtualslot |
One or more ssl errors have occurred.
Log them as errors and call replyFinished()
reply | The QNetworkReply that had errors |
errors | The list of QSslErrors to log |
Definition at line 378 of file VFS_curl.cpp.
|
protected |
The data retrieved from a http get request after it has been sent to parse().
Definition at line 38 of file VFS_curl.h.
|
protected |
Time in milliseconds to consider the retrieved data stale.
Definition at line 33 of file VFS_curl.h.
|
private |
If an outstanding request exists.
Definition at line 48 of file VFS_curl.h.
|
protected |
Interpret fetched data as json.
Definition at line 31 of file VFS_curl.h.
|
protected |
The http request manager.
Definition at line 34 of file VFS_curl.h.
|
protected |
Certain headers returned from a successful http get request.
Definition at line 37 of file VFS_curl.h.
|
protected |
If data is considered expired, re-request it.
Definition at line 32 of file VFS_curl.h.
|
private |
If an http request was invalid, this will contain the error string.
Definition at line 49 of file VFS_curl.h.
|
private |
The outstanding request, if any.
Definition at line 53 of file VFS_curl.h.
|
protected |
A list of outstanding VFS_request objects to satisfy once an http request is complete.
Definition at line 35 of file VFS_curl.h.
|
private |
If the retrieved content is stale. Initialized as true.
Definition at line 46 of file VFS_curl.h.
|
private |
The time to wait for a response before timing out. Defaults to 60000 ms = 1 minute.
Definition at line 52 of file VFS_curl.h.
|
private |
For detecting timeouts on network requests. The QNetworkAccessManager doesn't do this on its own.
Definition at line 51 of file VFS_curl.h.
|
protected |
The url to request.
Definition at line 30 of file VFS_curl.h.
|
private |
If the http request was valid.
Definition at line 47 of file VFS_curl.h.