10 #include <QVariantMap>
12 #include <QJsonDocument>
13 #include <QJsonObject>
16 #define POST_ID_NONE 0
17 #define POST_ID_PING 1
18 #define POST_ID_SESSION_DATA 2
19 #define POST_ID_DIFF 7
20 #define POST_ID_CODE_DIRECTORY 16
21 #define POST_ID_START 256
22 #define POST_ID_MAX 65000
47 #ifdef DEBUG_DANGLING_REQUESTS
119 virtual QByteArray
toJson(
postID id=0,
bool ignoreSuccess=
false,
bool includeInitialPath=
false);
120 virtual void fromJsonObject(QJsonObject json,
bool includeInitialPath=
false);
129 #ifdef DEBUG_DANGLING_REQUESTS
132 virtual void timerEvent(QTimerEvent *e=
nullptr);
158 static QString
code(QString nodename, QString libname, QString &error);
182 virtual QByteArray
icon();
209 void addACLUser( QJsonObject &
acl, QString user,
bool value );
210 void addACLFeature( QJsonObject &
acl, QString feature,
bool value, QString description=
"" );
228 void remove(
bool andDelete);
229 virtual void remove(
VFS_node *
node=
nullptr, QString *name=
nullptr, QString user=
"server");
QMap< QString, VFS_subscriptionOrigin > VFS_subscriptionType
QPair< VFS_node *, QString > notifyException
QMap< QString, VFS_node * > VFS_children
QMap< QString, VFS_node * >::const_iterator VFS_childrenConstIterator
QMap< VFS_node *, qint32 > VFS_subscriptionCounter
QMap< QString, VFS_node * >::iterator VFS_childrenIterator
QMap< QString, VFS_subscriptionCounter > VFS_subscriptionOrigin
VFS_node is the base class from which all other VFS_node classes derive.
virtual bool validChildName(QString name)
Check if a node name is valid.
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.
VFS_children _children
This node's children.
virtual void issueResponse(VFS_request *t)
Once a request has been completed, issue a response.
void addACLGroup(QJsonObject &acl, QString group, bool value)
Add a group to the acl object.
static bool __removeNode(VFS_node *)
Remove a node from the global registry.
virtual void requestLock(VFS_request *r)
Request a lock on this node.
QString uniqueChildName(QString name)
Generate a unique child name.
virtual void unsubscribeAll(VFS_node *n)
Remove all references to a subscriber from this node.
virtual void issueRequest(VFS_request *t)
A convenience function.
static bool __isNode(VFS_node *)
Check to see if a node is in the global registry.
void addACLFeatureUser(QJsonObject &acl, QString feature, QString user, bool value)
Add a feature user to the acl object.
void addACLFeature(QJsonObject &acl, QString feature, bool value, QString description="")
Add a feature to the acl object.
VFS_node * findChildWithName(QString name)
Check if a child with a given name exists.
virtual void releaseLock(VFS_request *r)
Release a lock on this node.
virtual QByteArray icon()
Fetch the icon for a node.
void mounted()
Emitted when a node is mount()ed.
void unmounted(VFS_node *self)
Emitted when a node is unmount()ed.
void diff(VFS_node *origin, VFS_request *t)
Emit a diff, which will trigger notifySubscribers() for a mounted node.
QString className()
Return the class name of a node.
VFS_subscriptionType _subscribers
This node's subscribers. These subscribers will receive diff notifications.
void remove(bool andDelete)
Remove a child node.
void addACLFeatureGroup(QJsonObject &acl, QString feature, QString group, bool value)
Add a feature group to the acl object.
void addACLUser(QJsonObject &acl, QString user, bool value)
Add a user to the acl object.
virtual ~VFS_node()
VFS_node destructor.
void addACLDefault(QJsonObject &acl, bool value, QString description="")
Add a default value to the acl object.
virtual void unsubscribePath(QString path)
Unsubscribe all references to a subpath.
QMutex _lock
A recursive mutex that is local to this node.
void notifySubscribers(VFS_node *origin, VFS_request *t)
Propagate a diff to subscribers.
static void __addNode(VFS_node *)
Add a node to the global registry.
static QSet< VFS_node * > __allNodes
The static global registry for all exiting nodes, used for thread safety checks.
virtual void applyDiff(VFS_request *r)
Apply a diff received via subscription.
virtual void aclDefaults(VFS_request *r)
Return default values and features associated wth this node.
virtual QString reportDetails()
Additional details for a generated report.
static QMutex __allNodesMutex
The global registry mutex, which will lock when node creation or deletion is being performed.
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 com...
virtual void receiveResponse(VFS_request *t)
Once a VFS_request has been completed, a response will be issued back to its _origin.
The base class for all requests between nodes.
static const char * requestTypeStrings[]
A printable string for each request type.
requestType
Requests perform one of these actions.
@ read
read full contents (4)
@ report
provide node report, for debugging (12)
@ requestlock
request a lock (13)
@ unsubscribe
unsubscribe from a path (10)
@ ls
list children of a node (1)
@ acl
return the ACL defaults for this node (11)
@ metadata
read metadata (6)
@ create
create a new file/path (2)
@ write
write full contents (5)
@ code
request code from a node (15)
@ codeDirectory
request a listing of code served by a node (16)
@ releaselock
release a lock (14)
@ subscribe
subscribe to a path (9)
@ rm
delete an existing file/path (3)
virtual ~VFS_request()
VFS_request destructor.
VFS_node * _responder
the receiver of the request
static QMutex _sampleLock
A mutex to protect thread safety of samples.
VFS_node * _origin
the origin of the request
virtual void setCallback(VFS_request *c)
Chain a callback onto this request.
QByteArray _rawData
the request payload, but raw data
bool hasCallback()
Check if this request has a callback set.
VFS_request(requestType type=VFS_request::none, VFS_node *origin=nullptr, QString path="", QString user="unknown", QJsonDocument data=QJsonDocument(), QJsonObject metadata=QJsonObject(), bool dontDelete=false)
VFS_request constructor.
requestType _requestType
the action this request is performing or requesting
static quint32 getSample()
Get the current sample count and clear the counter.
static quint32 _sampleCount
A count of the number of VFS_requests since the last sample was taken.
QString _initialPath
the target path when the request was made (relative to the responder)
QStringList _prefixPath
the prefix elements found while searching for the target
bool _dontDelete
A rarely used flag that will cause VFS_node::receiveResponse to not delete the node,...
QString _user
who initiated this request, mostly for logging
virtual void copyCallback(VFS_request *d)
Copy the data from a callback to this VFS_request.
virtual void fromJsonObject(QJsonObject json, bool includeInitialPath=false)
Deserialize a JSON string into a VFS_request.
virtual void execute()
after a request has completed, a request may have a special execute function.
VFS_session * _session
The session associated with this request. This is an optional value, and care should be taken to chec...
QString _reason
if something (probably bad) happened, this is the reason
QString _path
the target path remnant... the remaining path element once the request has found its target
bool _isCallback
whether or not to issue a response (IE, another request is chained to this request,...
virtual VFS_request * createDiff(VFS_node *origin, QString originPath)
VFS_request::createDiff.
QString _originPath
the subpath of the origin node
QList< notifyException > _notifyExceptions
a list of nodes not to send responses to for this transaction. For instance if a node submits to a no...
bool _success
if the request was successfully completed
QJsonDocument _data
the request payload
virtual VFS_request * getCallback(VFS_node *receiver)
Create and chain a VFS_request for a receiver.
VFS_request * _callback
request to execute once this request completes
virtual QByteArray toJson(postID id=0, bool ignoreSuccess=false, bool includeInitialPath=false)
Serialize this request.
virtual void timerEvent(QTimerEvent *e=nullptr)
The callback for when a request times out.
static long _refcount
A reference counter for VFS_request instances, used for debugging to ensure all instances are properl...
QJsonObject _metadata
the request payload
The VFS_session object represents a single session.
A thread interface for creating multithreaded applications.
virtual void subtreeRequest(VFS_request *t)
Subclass implementation of VFS_node::subtreeRequest()
virtual void executeRequest(VFS_request *t)
Execute the VFS_request.
virtual bool isContainer()
The container-ness of the thread node.
virtual VFS_node * mount()
Mount the node, and mount the thread node if it exists.
virtual VFS_node * unmount()
Unmount the node and the thread node if it exists.
virtual VFS_node * append(QString name, VFS_node *node, bool containerCheck=true, QString user="unknown")
A dummy entry used to warn a developer of illegal use.
virtual VFS_node * find(VFS_request *r)
Subclass implementation of VFS_node::find(), which is the path lookup mechanism.