Remoto - VFS: VFS_node_interface Class Reference
Remoto - VFS

The interface class for dynamically loaded plugins. More...

#include <VFS_node_interface.h>

Inheritance diagram for VFS_node_interface:
VFS_mongoPlugin VFS_stdlib VFS_tcp_mount_directory adminPlugin google_oauth2Plugin pamPlugin

Public Member Functions

virtual ~VFS_node_interface ()
 
virtual QString arguments (QString type)
 Describe the arguments needed to create a node. More...
 
virtual QString code (QString nodename, QString libname, QString &error)
 Request code or other resource from a plugin bundle. More...
 
virtual VFS_nodecreate (QString type, QVariantMap env, QDomElement child)
 Create a new node instance. More...
 
QString describe ()
 Describe all the nodes in a plugin. More...
 
virtual QString description (QString type)
 Descriptive text about an individual node. More...
 
virtual bool initialize ()
 The plugin initializer. More...
 
bool isRemote ()
 If a plugin represents a remote resource, this value will be true. More...
 
virtual bool licensed (QString type)
 A licensing mechanism for node creation. More...
 
virtual QStringList provides ()
 A string list of node names that this plugin is prepared to create. More...
 
VFS_noderemoteNode ()
 Return the node needed to satisfy a remote request. More...
 

Protected Member Functions

 VFS_node_interface (VFS_node *remoteNode=nullptr)
 VFS_node_interface::VFS_node_interface. More...
 
QString argumentString (QMetaObject s)
 Format a constructor string based on a node's metadata object. More...
 

Protected Attributes

bool _remote
 Does this plugin exist on another resource? More...
 
VFS_node_remoteNode
 The node responding to requests for remote resources. More...
 

Detailed Description

The interface class for dynamically loaded plugins.

VFS_node_interface is a pure virtual class used to bundle nodes for plugin distribution.

Plugins are loaded from the plugin folders provided on the command line. All identified plugins are loaded immediately, and their initialize() method is called.

Definition at line 9 of file VFS_node_interface.h.

Constructor & Destructor Documentation

◆ VFS_node_interface()

VFS_node_interface::VFS_node_interface ( VFS_node remoteNode = nullptr)
explicitprotected

VFS_node_interface::VFS_node_interface.

Parameters
remoteNodeIf this is a remote reference, this is a pointer to the node that will resolve a code request.

Definition at line 88 of file VFS_node_interface.cpp.

◆ ~VFS_node_interface()

VFS_node_interface::~VFS_node_interface ( )
virtual

Definition at line 94 of file VFS_node_interface.cpp.

Member Function Documentation

◆ arguments()

QString VFS_node_interface::arguments ( QString  type)
virtual

Describe the arguments needed to create a node.

Parameters
typeThe node name
Returns
The argument string.

The implementation of this pure method will look something like:

QString skeletonPlugin::arguments(QString type)
{
if (type == "skeleton")
return argumentString( skeleton::staticMetaObject );
}
QString argumentString(QMetaObject s)
Format a constructor string based on a node's metadata object.
virtual QString arguments(QString type)
Describe the arguments needed to create a node.
See also
The Skeleton Plugin

Reimplemented in adminPlugin, google_oauth2Plugin, VFS_mongoPlugin, pamPlugin, and VFS_stdlib.

Definition at line 146 of file VFS_node_interface.cpp.

◆ argumentString()

QString VFS_node_interface::argumentString ( QMetaObject  s)
protected

Format a constructor string based on a node's metadata object.

Parameters
sA node's metadata object
Returns
A string representing each of a node's constructors

A node must flag its constructor(s) using Q_INVOKABLE for the signature data to be available.

Definition at line 297 of file VFS_node_interface.cpp.

◆ code()

QString VFS_node_interface::code ( QString  nodename,
QString  libname,
QString &  error 
)
virtual

Request code or other resource from a plugin bundle.

Parameters
nodenameThe node providing the code
libnameThe library requested
errorA reference to an error string, for writing errors back to the caller
Returns
The raw source code or resource requested

This will generally result in javascript code for a user interface, but could return anything, including base64-encoded images, css, xml, json, etc.

When code is requested, the request is routed to a plugin by nodename. A plugin can service the request itself, or pass it on to a node's static code function. Larger plugins with many nodes will probably want to bundle all their resources together.

It is highly reccommended that if a library is not found, it will call VFS_node::code() for error handling.

See also
VFS_creator::code

Reimplemented in adminPlugin, VFS_mongoPlugin, and VFS_stdlib.

Definition at line 283 of file VFS_node_interface.cpp.

◆ create()

VFS_node * VFS_node_interface::create ( QString  type,
QVariantMap  env,
QDomElement  child 
)
virtual

Create a new node instance.

Base implementation that does nothing.

Returns
The new VFS_node, or 0 (null) if it was unable to create it.

Plugins bundle groups of node definitions together. This is the factory function for creating new nodes.

For example:

VFS_node *myFancyPlugin::create(QString type, QVariantMap env, QDomElement child)
{
if (type == "myFancyNode")
{
int a = VFS_creator::configAttribute(env,child,"alpha").toInt();
QString b = VFS_creator::configAttribute(env,child,"beta",false,"beta string");
return new myFancyNode(a,b);
}
if (type == "myMagicNode")
{
QString magicPath = VFS_creator::configPathAttribute(env,child,"magicPath");
return new myMagicNode(magicPath);
}
return 0;
}
static QString configAttribute(QVariantMap env, QDomElement e, QString attr, bool req=true, QString def="")
Fetch an XML node attribute value and resolve it against an environment.
static QString configPathAttribute(QVariantMap env, QDomElement e, QString attr, bool req=true, QString def="")
Fetch an XML node attribute value and resolve it against an environment, ensuring it is a cleaned pat...
VFS_node is the base class from which all other VFS_node classes derive.
Definition: VFS_node.h:143

Please note the entries for a config file:

<myFancyNode name='fancy1' alpha='10' beta='gamma' />
<myMagicNode name='magic_thing' magicPath='/mnt/magic' />

As a pure virtual function, this must be implemented in all plugins.

See also
The Skeleton Plugin
Parameters
typeThe node type, as listed in provides() and referenced in a config.xml
envThe constructor environment
childThe config DOM element
Returns
Always returns a nullptr

Subclasses must implement this for a plugin to be useful. This base implementation is present so that a minimal plugin can implement initialize() without providing any nodes.

Reimplemented in adminPlugin, google_oauth2Plugin, VFS_mongoPlugin, pamPlugin, VFS_stdlib, and VFS_tcp_mount_directory.

Definition at line 255 of file VFS_node_interface.cpp.

◆ describe()

QString VFS_node_interface::describe ( )

Describe all the nodes in a plugin.

Returns
A description string for each node in provides()

Definition at line 194 of file VFS_node_interface.cpp.

◆ description()

QString VFS_node_interface::description ( QString  type)
virtual

Descriptive text about an individual node.

Parameters
typeThe node name
Returns
The description string.

The implementation of this pure method will look something like:

QString skeletonPlugin::description(QString type)
{
if (type == "skeleton")
return "A node provided as an example for the documentation. It does nothing.";
}
virtual QString description(QString type)
Descriptive text about an individual node.
See also
The Skeleton Plugin

Reimplemented in adminPlugin, google_oauth2Plugin, VFS_mongoPlugin, pamPlugin, and VFS_stdlib.

Definition at line 120 of file VFS_node_interface.cpp.

◆ initialize()

bool VFS_node_interface::initialize ( )
virtual

The plugin initializer.

Returns
bool The initialization status.

This is an opportunity to register filetypes, log data, or perform any other prep work needed.

For instance:

bool myFancyPlugin::initialize()
{
if (!VFS_node_type::registerType("magic","myFancyPlugin:magicNode",true))
{ VFS::WARN( "Could not register type 'magic'... is it already registered by something else?" );
return false;
}
if (!connectToLicenseServer("myFancyPlugin"))
{ VFS::WARN( "Could not connect to license server for 'myFancyPlugin'. License was denied." );
return false;
}
return true;
}
static bool registerType(QString type, QString handler, bool json=true)
Add a type to the registry.
static void WARN(QString message, int level=0, QString user="server")
Send a message to the VFS::_warnings VFS_stream.
Definition: VFS.cpp:258

If a plugin fails to initialize, it can return false here and will not be added to the plugin registry.

This may also be used to create a (network or other) license check for this node group so future licensed() requests don't have to do network validation. In practice nodes should be licensed per use, not globally when the application starts, and should be checked at some interval for validity.

Reimplemented in adminPlugin, google_oauth2Plugin, pamPlugin, and VFS_stdlib.

Definition at line 184 of file VFS_node_interface.cpp.

◆ isRemote()

bool VFS_node_interface::isRemote ( )

If a plugin represents a remote resource, this value will be true.

Returns
the value of _remote

Definition at line 342 of file VFS_node_interface.cpp.

◆ licensed()

bool VFS_node_interface::licensed ( QString  type)
virtual

A licensing mechanism for node creation.

Parameters
typeThe node type being queried
Returns
boolean licensing state

By default, all nodes are licensed for use. A plugin can choose to license on a group level or individual node level. It can use network functions or read the filesystem or whatever it needs to do to determine state.

Reimplemented in VFS_stdlib.

Definition at line 224 of file VFS_node_interface.cpp.

◆ provides()

QStringList VFS_node_interface::provides ( )
virtual

A string list of node names that this plugin is prepared to create.

Base implementation that returns an empty list.

Returns
The list of nodes

Plugins bundle groups of node definitions together. This is the list of nodes.

For example:

QStringList myFancyPlugin::provides()
{
QStringList p;
p << "myFancyNode";
p << "myMagicNode";
return p;
}

As a pure virtual function, this must be implemented in all plugins.

See also
The Skeleton Plugin
Returns
An empty list

Subclasses must implement this for a plugin to be useful. This base implementation is present so that a minimal plugin can implement initialize() without providing any nodes.

Reimplemented in adminPlugin, google_oauth2Plugin, VFS_mongoPlugin, pamPlugin, VFS_stdlib, and VFS_tcp_mount_directory.

Definition at line 239 of file VFS_node_interface.cpp.

◆ remoteNode()

VFS_node * VFS_node_interface::remoteNode ( )

Return the node needed to satisfy a remote request.

Returns
VFS_node_interface::_remoteNode

By default, this is a nullptr.

Definition at line 354 of file VFS_node_interface.cpp.

Member Data Documentation

◆ _remote

bool VFS_node_interface::_remote
protected

Does this plugin exist on another resource?

Definition at line 50 of file VFS_node_interface.h.

◆ _remoteNode

VFS_node* VFS_node_interface::_remoteNode
protected

The node responding to requests for remote resources.

Definition at line 51 of file VFS_node_interface.h.


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