4 #include <QCoreApplication>
41 , _thread(this, nodeConfig, env, printConfig)
49 VFS::LOG( QString(
" -Creating thread #%1 '%2:%3'").arg(
_threadcount).arg(nodeConfig.tagName()).arg(nodeConfig.attribute(
"name")), 9 );
52 _thread.setObjectName( nodeConfig.tagName()+
":"+nodeConfig.attribute(
"name") );
73 if (config.setContent( configString, &error ))
75 QDomElement child = config.firstChildElement();
79 VFS::ERROR( QString(
"Could not create thread with config: %1\nerror: %2\n").arg(configString).arg(error));
100 VFS::LOG( QString(
" -Destroying thread %1").arg(
_thread.objectName()), 9 );
150 {
VFS::ERROR(
"Node already set on thread. Aborting this command.");
182 Q_UNUSED(containerCheck);
185 VFS::ERROR(
"Adding children to a VFS_thread is unsupported... pass a config instead" );
233 QMutexLocker l(&
_lock);
235 if (!
_node)
return false;
250 return (
_node !=
nullptr);
324 VFS::ERROR( QString(
"No node set for this thread: %1\n%2\n").arg((quintptr)thread()).arg(QString(t->
toJson(0,
true))), 0, t->
_user );
346 , _nodeConfig(nodeConfig)
348 , _printConfig(printConfig)
392 QString currentConfigFile =
_env[
"file"].toString();
395 VFS::ERROR( QString(
"Failed to load config '%1' on tag '%2'.").arg(currentConfigFile).arg(tag), 0,
"VFS_threadthread" );
402 {
VFS::ERROR( QString(
"Thread %1 unable to create '%2'").arg(objectName()).arg(
_nodeConfig.tagName()) );
#define VFS_CREATOR_MAX_OUTSTANDING
static VFS_node * constructNode(QDomElement child, QVariantMap &env, bool printConfig=false)
VFS_creator::constructNode.
static QSemaphore _outstanding
A semaphore used to sync creation during startup.
VFS_node is the base class from which all other VFS_node classes derive.
virtual VFS_node * unmount()
Unmount this node.
virtual void issueRequest(VFS_request *t)
A convenience function.
void mounted()
Emitted when a node is mount()ed.
void unmounted(VFS_node *self)
Emitted when a node is unmount()ed.
virtual bool isContainer()
A VFS_node may have children.
QMutex _lock
A recursive mutex that is local to this node.
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 VFS_node * mount()
Mount this node.
The base class for all requests between nodes.
QString _user
who initiated this request, mostly for logging
virtual QByteArray toJson(postID id=0, bool ignoreSuccess=false, bool includeInitialPath=false)
Serialize this request.
A thread interface for creating multithreaded applications.
virtual void subtreeRequest(VFS_request *t)
Subclass implementation of VFS_node::subtreeRequest()
static int _threadcount
The internal thread count, useful for debug and logging messages.
virtual void executeRequest(VFS_request *t)
Execute the VFS_request.
void defunct()
When a thread is complete, it will emit finished(), which will trigger this slot.
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.
VFS_node * _node
The root VFS_node running in the new thread.
static VFS_thread * fromConfig(QString configString, QVariantMap env=QVariantMap(), bool printConfig=false)
A convenience method for creating threads.
virtual VFS_node * unmount()
Unmount the node and the thread node if it exists.
static int threadcount()
Return the current thread count, mostly only useful for logging output.
VFS_threadthread _thread
The subclassed QThread, which will provide the event loop and actually run the thread.
bool hasNode()
When a thread is created, it must construct its root node to become operational.
virtual ~VFS_thread()
VFS_thread destructor.
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.
void setNode(VFS_node *node)
Once the node is created in the new thread, this VFS_thread will keep a reference to it.
virtual VFS_node * find(VFS_request *r)
Subclass implementation of VFS_node::find(), which is the path lookup mechanism.
void run()
Run the QThread event loop.
void nodeCreated(VFS_node *node)
Once the _node has been created, this signals back to the owning VFS_thread of its existence.
VFS_node * _node
The root VFS_node running in the new thread.
QVariantMap _env
The environment.
VFS_threadthread(VFS_node *p, QDomElement nodeConfig, QVariantMap env, bool printConfig)
QDomElement _nodeConfig
XML config node.
void creationFailed()
If _node creation was not possible, this signal is emitted.
bool _printConfig
A debug setting, used to make sure contexts are correct.
static void LOG(QString message, int level=0, QString user="server")
Send a message to the VFS::_messages VFS_stream.
static void ERROR(QString message, int level=0, QString user="server")
Send a message to the VFS::_errors VFS_stream.
setter name
a setter DOCME
QStringList exec(QString command, bool *ok=nullptr)
execute a command in a shell, and return the resulting output as a QStringList