Remoto - VFS: VFS_curl Class Reference
Remoto - VFS

VFS_curl reads data from a url when read() is called. More...

#include <VFS_curl.h>

Inheritance diagram for VFS_curl:
VFS_node

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...
 
- Public Slots inherited from VFS_node
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...
 
- Public Member Functions inherited from VFS_node
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_nodeappend (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_requestcreateRequest (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_nodefind (QString path)
 Find a node by string path. More...
 
virtual VFS_nodefind (VFS_request *r)
 Find a node using a VFS_request. More...
 
VFS_nodefindChildWithName (QString name)
 Check if a child with a given name exists. More...
 
virtual VFS_nodemount ()
 Mount this node. More...
 
QString uniqueChildName (QString name)
 Generate a unique child name. More...
 
virtual VFS_nodeunmount ()
 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...
 
- Protected Member Functions inherited from VFS_node
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...
 
- Protected Attributes inherited from VFS_node
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

- Signals inherited from VFS_node
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 Public Member Functions inherited from VFS_node
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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ VFS_curl()

VFS_curl::VFS_curl ( QString  url,
bool  json = false,
bool  poll = false,
int  expire = 10000,
int  timeout = 60000 
)
explicit
Parameters
urlThe url to load when requested
jsonInterpret incoming data as JSON
pollRe-pull data if it is considered to be expired
expireTime in milliseconds to consider retrieved data _stale, which defaults to 10000 ms = 10 seconds
timeoutTime 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.

◆ ~VFS_curl()

VFS_curl::~VFS_curl ( )
virtual

Definition at line 69 of file VFS_curl.cpp.

Member Function Documentation

◆ expire

void VFS_curl::expire ( )
protectedvirtualslot

Set the _stale value to true, and if _poll, request an update.

Definition at line 316 of file VFS_curl.cpp.

◆ get()

void VFS_curl::get ( VFS_request r)
protectedvirtual

VFS_curl::get.

Parameters
rThe VFS_request object to enqueue

Definition at line 180 of file VFS_curl.cpp.

◆ getHeaders()

QJsonObject VFS_curl::getHeaders ( QNetworkReply *  reply)
private

Create a QJsonObject based on a QNetworkReply.

Parameters
replyThe QNetworkReply object to be used
Returns
The resulting header QJsonObject

Definition at line 335 of file VFS_curl.cpp.

◆ icon()

QByteArray VFS_curl::icon ( )
protectedvirtual

The "stream" icon found in the VFS_icons library.

Returns
The "stream" icon
See also
VFS_node::icon()

Reimplemented from VFS_node.

Definition at line 80 of file VFS_curl.cpp.

◆ isContainer()

bool VFS_curl::isContainer ( )
virtual

A VFS_curl node cannot contain children.

Returns
false

Reimplemented from VFS_node.

Definition at line 100 of file VFS_curl.cpp.

◆ metadata()

void VFS_curl::metadata ( VFS_request r)
virtual

Fetch the metadata for this node.

Parameters
rThe 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.

◆ networkTimeout

void VFS_curl::networkTimeout ( )
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.

◆ parse()

QJsonObject VFS_curl::parse ( QJsonObject  data,
QJsonObject &  diffout 
)
protectedvirtual

Parse the incoming data into useful format.

This is useful for subclasses.

Parameters
dataThe data to parse
diffoutThe diff object to write to
Returns
The parsed data as a QJSonObject, which will be stored in _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.

◆ read()

void VFS_curl::read ( VFS_request r)
virtual

Request the _url.

Parameters
rThe 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.

◆ replyFinished

void VFS_curl::replyFinished ( QNetworkReply *  reply)
slot

A network request has completed.

Parameters
replyThe 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.

◆ reportDetails()

QString VFS_curl::reportDetails ( )
virtual

Report the url.

Returns
The url as a fully decoded url string.

Reimplemented from VFS_node.

Definition at line 90 of file VFS_curl.cpp.

◆ sslErrors

void VFS_curl::sslErrors ( QNetworkReply *  reply,
const QList< QSslError > &  errors 
)
virtualslot

One or more ssl errors have occurred.

Log them as errors and call replyFinished()

Parameters
replyThe QNetworkReply that had errors
errorsThe list of QSslErrors to log

Definition at line 378 of file VFS_curl.cpp.

Member Data Documentation

◆ _data

QJsonObject VFS_curl::_data
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.

◆ _expire

int VFS_curl::_expire
protected

Time in milliseconds to consider the retrieved data stale.

Definition at line 33 of file VFS_curl.h.

◆ _getting

bool VFS_curl::_getting
private

If an outstanding request exists.

Definition at line 48 of file VFS_curl.h.

◆ _json

bool VFS_curl::_json
protected

Interpret fetched data as json.

Definition at line 31 of file VFS_curl.h.

◆ _manager

QNetworkAccessManager VFS_curl::_manager
protected

The http request manager.

Definition at line 34 of file VFS_curl.h.

◆ _metadata

QJsonObject VFS_curl::_metadata
protected

Certain headers returned from a successful http get request.

Definition at line 37 of file VFS_curl.h.

◆ _poll

bool VFS_curl::_poll
protected

If data is considered expired, re-request it.

Definition at line 32 of file VFS_curl.h.

◆ _reason

QString VFS_curl::_reason
private

If an http request was invalid, this will contain the error string.

Definition at line 49 of file VFS_curl.h.

◆ _request

QNetworkReply* VFS_curl::_request
private

The outstanding request, if any.

Definition at line 53 of file VFS_curl.h.

◆ _requests

QList< VFS_request *> VFS_curl::_requests
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.

◆ _stale

bool VFS_curl::_stale
private

If the retrieved content is stale. Initialized as true.

Definition at line 46 of file VFS_curl.h.

◆ _timeout

int VFS_curl::_timeout
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.

◆ _timer

QTimer VFS_curl::_timer
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.

◆ _url

QUrl VFS_curl::_url
protected

The url to request.

Definition at line 30 of file VFS_curl.h.

◆ _valid

bool VFS_curl::_valid
private

If the http request was valid.

Definition at line 47 of file VFS_curl.h.


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