Remoto - VFS: VFS Class Reference
Remoto - VFS

VFS is the root node for a Virtual Filesystem. More...

#include <VFS.h>

Inheritance diagram for VFS:
VFS_node

Signals

void codeDirectoryUpdated ()
 Emitted when VFS_creator has had its _plugins updated. This is for VFS_tcp_mount and VFS_tcp_export. More...
 
void initialized ()
 Emitted when the VFS_creator has completed its VFS_creator::build() call. More...
 
- 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...
 

Public Member Functions

 VFS (QString configFile, QStringList plugins=QStringList(), bool describe=false, bool printConfig=false)
 The VFS constructor will create a VFS based on an incoming config file and list of plugins. More...
 
 ~VFS ()
 Destroy the VFS node, which will remove references to logging nodes and return output to cp_init color scheme. More...
 
void getLogSettings (int &loglevel, int &logtime)
 Get the loglevel and logtime values for the logger. 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 bool isContainer ()
 A VFS_node may have children. More...
 
virtual VFS_nodemount ()
 Mount this node. More...
 
virtual QString reportDetails ()
 Additional details for a generated report. 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...
 

Static Public Member Functions

static void CRITICAL (QString message)
 Send a message to the VFS::_critical VFS_stream. More...
 
static void ERROR (QString message, int level=0, QString user="server")
 Send a message to the VFS::_errors VFS_stream. More...
 
static void LOG (QString message, int level=0, QString user="server")
 Send a message to the VFS::_messages VFS_stream. More...
 
static QJsonDocument parameters ()
 Fetch the parameters assigned to this VFS, as per the config file. More...
 
static VFSroot ()
 Return the root node of the VFS filesystem. More...
 
static qint64 starttime ()
 Get the epoch start time of this VFS instance, in milliseconds. More...
 
static qint64 uptime ()
 Get the uptime of this VFS instance, in milliseconds. More...
 
static QString uptimeString (bool ms=true)
 Get the uptime of this VFS instance as a string. More...
 
static void WARN (QString message, int level=0, QString user="server")
 Send a message to the VFS::_warnings VFS_stream. 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...
 

Protected Member Functions

virtual QByteArray icon ()
 Fetch the icon for this node. 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 metadata (VFS_request *r)
 Fetch the metadata of this node. More...
 
virtual void read (VFS_request *r)
 Return the data contents of this node, or if it's a container call ls() 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...
 

Static Protected Attributes

static QJsonObject _parameters
 VFS parameters, defined in a config file. More...
 
static VFS_vfs
 The global and single instance of VFS, returned by VFS::root() More...
 

Private Member Functions

void monitoredFilesCheck ()
 Iterate through all monitored files, and check their modification time. More...
 
void setAdminEmail (QString emails)
 Set the admin email addresses for CRITICAL messages. More...
 
void setLogSettings (int loglevel, int logtime)
 Set the loglevel and logtime values for the logger. More...
 
void timerEvent (QTimerEvent *event)
 Timer handler for VFS timer events. More...
 

Private Attributes

VFS_thread_logger
 The VFS_logger instance, which will always be on another thread. More...
 
int _logLevel
 Filter log entries by this value... lower entries are very important, higher ones are more fine-grained. More...
 
int _logTime
 Include log entry time in output, where 0 = none, 1 = locale time, 2 = locale time and date, 3 = UTC time date and offset. More...
 
int _monitorTimerID
 The timerID for monitoring config file changes. More...
 
QMutex _printLock
 A lock for ensuring that print messags don't get interleaved. More...
 
qint64 _start
 Set when the VFS instance begins. This is used to track uptime. More...
 
ColorPrint cp_bold
 Color settings for bold printing. More...
 
ColorPrint cp_error
 Color settings for error messages. More...
 
ColorPrint cp_init
 Color settings to print messages when other streams do not exist. More...
 
ColorPrint cp_warn
 Color settings for warning messages. More...
 

Static Private Attributes

static QMap< QString, QDateTime > _monitoredFiles
 A list of path:datetime entries that the VFS will monitor for changes. More...
 

Friends

class VFS_creator
 

Additional Inherited Members

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

Detailed Description

VFS is the root node for a Virtual Filesystem.

There should only be one VFS in a running executable, probably created in main(). The VFS root node is an access point for path requests, searches, logging, and stdout/stderr output.

Definition at line 14 of file VFS.h.

Constructor & Destructor Documentation

◆ VFS()

VFS::VFS ( QString  configFile,
QStringList  plugins = QStringList(),
bool  describe = false,
bool  printConfig = false 
)

The VFS constructor will create a VFS based on an incoming config file and list of plugins.

Parameters
configFileThe path to a config file
pluginsThe list of plugin paths to search
describeIf set to true, don't start the VFS but instead list information about the plugins that have been loaded.
printConfigA debug setting, used to make sure contexts are correct

A VFS_logger is created. VFS_creator::init() and VFS_creator::build() are called.

This method will block until all nodes are created, then the VFS::initialized() signal will be emitted, which will trigger other nodes to complete initialization. If a node has the potential to require the VFS to exist (like, for instance a listening server may require auth or other paths to exist), it should listen for the initialized() signal.

If any entries exist in VFS::_monitoredFiles, a monitor timer will be started.

See also
VFS_creator::init()
VFS_creator::build()
VFS_logger

Definition at line 50 of file VFS.cpp.

◆ ~VFS()

VFS::~VFS ( )

Destroy the VFS node, which will remove references to logging nodes and return output to cp_init color scheme.

Whenever a VFS_node is deleted, it will delete its children. Calling this will delete all nodes in the VFS, as it is the root.

When a VFS_httpd_browser receives a "/command/exit" request, QCoreApplication::exit(0) is called, which will exit the event loop and call this destructor.

Definition at line 132 of file VFS.cpp.

Member Function Documentation

◆ codeDirectoryUpdated

void VFS::codeDirectoryUpdated ( )
signal

Emitted when VFS_creator has had its _plugins updated. This is for VFS_tcp_mount and VFS_tcp_export.

◆ CRITICAL()

void VFS::CRITICAL ( QString  message)
static

Send a message to the VFS::_critical VFS_stream.

Parameters
messageThe message

This static global method will create a VFS_request and submit it to "logs/critical".

CRITICAL() messages will appear red in a terminal. An email to VFS::_adminAddress will also be sent, if possible.

This mechanism is for knowable failures, like a disk nearing full, remote credentials failing, credit card payents not completing, excessive access like DOS, etc. This is not for an imminent crash scenario, where little can be done.

Definition at line 357 of file VFS.cpp.

◆ ERROR()

void VFS::ERROR ( QString  message,
int  level = 0,
QString  user = "server" 
)
static

Send a message to the VFS::_errors VFS_stream.

Parameters
messageThe message
levelThe log level
userThe user submitting the message

This static global method will create a VFS_request and submit it to "logs/errors".

ERROR() messages will appear red in a terminal.

Definition at line 307 of file VFS.cpp.

◆ getLogSettings()

void VFS::getLogSettings ( int &  loglevel,
int &  logtime 
)

Get the loglevel and logtime values for the logger.

Parameters
loglevelThe log level setting, which will be written to
logtimeThe log time setting, which will be written to

Definition at line 182 of file VFS.cpp.

◆ icon()

QByteArray VFS::icon ( )
protectedvirtual

Fetch the icon for this node.

Returns
The VFS_icons "application" icon.

Reimplemented from VFS_node.

Definition at line 193 of file VFS.cpp.

◆ initialized

void VFS::initialized ( )
signal

Emitted when the VFS_creator has completed its VFS_creator::build() call.

See also
VFS::VFS()

◆ LOG()

void VFS::LOG ( QString  message,
int  level = 0,
QString  user = "server" 
)
static

Send a message to the VFS::_messages VFS_stream.

Parameters
messageThe message
levelThe log level
userThe user submitting the message

This static global method will create a VFS_request and submit it to "logs/messages".

LOG() messages will appear in the default terminal color scheme.

Definition at line 209 of file VFS.cpp.

◆ monitoredFilesCheck()

void VFS::monitoredFilesCheck ( )
private

Iterate through all monitored files, and check their modification time.

If a file is found to not exist, a warning will be generated. If a file is found to have a modification time later than the one recorded when the server started, the server will exit, and presumably a wrapper script or service monitor will restart it.

This check is performed every 30 seconds.

Definition at line 485 of file VFS.cpp.

◆ parameters()

QJsonDocument VFS::parameters ( )
static

Fetch the parameters assigned to this VFS, as per the config file.

Returns
The parameters assigned to this VFS, as per the config file.
See also
VFS_creator

Definition at line 412 of file VFS.cpp.

◆ root()

VFS * VFS::root ( )
static

Return the root node of the VFS filesystem.

Returns
Return the root node of the VFS filesystem.
Warning
There should only be one instance of VFS in a running application.

Definition at line 399 of file VFS.cpp.

◆ setAdminEmail()

void VFS::setAdminEmail ( QString  emails)
private

Set the admin email addresses for CRITICAL messages.

Parameters
emailsA space-separated list of admin email addresses

Definition at line 148 of file VFS.cpp.

◆ setLogSettings()

void VFS::setLogSettings ( int  loglevel,
int  logtime 
)
private

Set the loglevel and logtime values for the logger.

Parameters
loglevelThe log level setting
logtimeThe log time setting

Definition at line 163 of file VFS.cpp.

◆ starttime()

qint64 VFS::starttime ( )
static

Get the epoch start time of this VFS instance, in milliseconds.

Returns
The epoch time in milliseconds when this instance was started.

Definition at line 422 of file VFS.cpp.

◆ timerEvent()

void VFS::timerEvent ( QTimerEvent *  event)
private

Timer handler for VFS timer events.

Parameters
eventCurrently the only timer event would come from the config file monitor timer, and will call VFS::monitoredFilesCheck().

Definition at line 468 of file VFS.cpp.

◆ uptime()

qint64 VFS::uptime ( )
static

Get the uptime of this VFS instance, in milliseconds.

Returns
The number of milliseconds since this instance was started.

Definition at line 432 of file VFS.cpp.

◆ uptimeString()

QString VFS::uptimeString ( bool  ms = true)
static

Get the uptime of this VFS instance as a string.

Parameters
msInclude milliseconds?
Returns
A string representation of VFS::uptime()

Definition at line 443 of file VFS.cpp.

◆ WARN()

void VFS::WARN ( QString  message,
int  level = 0,
QString  user = "server" 
)
static

Send a message to the VFS::_warnings VFS_stream.

Parameters
messageThe message
levelThe log level
userThe user submitting the message

This static global method will create a VFS_request and submit it to "logs/warnings".

WARNING() messages will appear yellow in a terminal.

Definition at line 258 of file VFS.cpp.

Friends And Related Function Documentation

◆ VFS_creator

friend class VFS_creator
friend

Definition at line 18 of file VFS.h.

Member Data Documentation

◆ _logger

VFS_thread* VFS::_logger
private

The VFS_logger instance, which will always be on another thread.

Definition at line 53 of file VFS.h.

◆ _logLevel

int VFS::_logLevel
private

Filter log entries by this value... lower entries are very important, higher ones are more fine-grained.

Definition at line 51 of file VFS.h.

◆ _logTime

int VFS::_logTime
private

Include log entry time in output, where 0 = none, 1 = locale time, 2 = locale time and date, 3 = UTC time date and offset.

Definition at line 52 of file VFS.h.

◆ _monitoredFiles

QMap< QString, QDateTime > VFS::_monitoredFiles
staticprivate

A list of path:datetime entries that the VFS will monitor for changes.

If the modification time of any of these files is changed, the server will exit so it can restart.

Definition at line 57 of file VFS.h.

◆ _monitorTimerID

int VFS::_monitorTimerID
private

The timerID for monitoring config file changes.

Definition at line 58 of file VFS.h.

◆ _parameters

QJsonObject VFS::_parameters
staticprotected

VFS parameters, defined in a config file.

Definition at line 39 of file VFS.h.

◆ _printLock

QMutex VFS::_printLock
mutableprivate

A lock for ensuring that print messags don't get interleaved.

Definition at line 55 of file VFS.h.

◆ _start

qint64 VFS::_start
private

Set when the VFS instance begins. This is used to track uptime.

Definition at line 44 of file VFS.h.

◆ _vfs

VFS * VFS::_vfs
staticprotected

The global and single instance of VFS, returned by VFS::root()

Definition at line 38 of file VFS.h.

◆ cp_bold

ColorPrint VFS::cp_bold
private

Color settings for bold printing.

Definition at line 47 of file VFS.h.

◆ cp_error

ColorPrint VFS::cp_error
private

Color settings for error messages.

Definition at line 49 of file VFS.h.

◆ cp_init

ColorPrint VFS::cp_init
private

Color settings to print messages when other streams do not exist.

Definition at line 46 of file VFS.h.

◆ cp_warn

ColorPrint VFS::cp_warn
private

Color settings for warning messages.

Definition at line 48 of file VFS.h.


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