5 #include <QMutexLocker>
7 #include <QCoreApplication>
50 VFS::VFS(QString configFile, QStringList plugins,
bool describe,
bool printConfig)
52 , _start(QDateTime::currentMSecsSinceEpoch())
54 , cp_bold(UNDEF, BOLD)
55 , cp_warn(YELLOW, BOLD)
62 throw "Only one instance of the VFS is allowed.";
67 if (configFile.isEmpty())
72 VFS::LOG(
"Initializing VFS on thread #0 'VFS'", 0);
75 thread()->setObjectName(
"VFS");
83 VFS::LOG( QString(
"Plugins loaded."), 0);
92 qApp->processEvents();
96 VFS::LOG(
"----------------------------------" );
97 VFS::LOG( QString(
"VFS %1").arg(VFS_GIT_VERSION),0);
98 VFS::LOG( QString(
"Logger started: %1 %2").arg(QDateTime::currentDateTime().toString()).arg(QDateTime::currentDateTime().toString(
"t")), 0);
99 VFS::LOG(
"----------------------------------" );
106 LOG(
"----------------------------------" );
108 QMap<QString, QDateTime>::iterator i;
111 LOG(
"----------------------------------" );
117 LOG(
"----------------------------------" );
137 WARN(
"Exiting VFS...");
151 o[
"adminemail"] = emails;
169 o[
"loglevel"] = loglevel;
170 o[
"logtime"] = logtime;
211 level = qBound(0,level,9);
216 QDateTime now = QDateTime::currentDateTime();
221 QString s = QString(
"%1,LOG,%2,%3,%4%5").arg(QString::number(now.toMSecsSinceEpoch()),user,QString::number(level),message,message.right(1)==
"\n" ?
"" :
"\n");
224 { printf(
"%s",qUtf8Printable(s));
242 _vfs->
cp_init.cprintf(
"[ INIT %d ] %s ",level,qUtf8Printable(user));
243 printf(
"%s%s",qUtf8Printable(message), (message.right(1)==
"\n" ?
"" :
"\n"));
260 level = qBound(0,level,9);
265 QDateTime now = QDateTime::currentDateTime();
270 QString s = QString(
"%1,WARN,%2,%3,%4%5").arg(QString::number(now.toMSecsSinceEpoch()),user,QString::number(level),message,message.right(1)==
"\n" ?
"" :
"\n");
273 { printf(
"%s",qUtf8Printable(s));
291 _vfs->
cp_warn.cprintf(
"[ WARN %d ] %s %s",level,qUtf8Printable(user),qUtf8Printable(message));
292 printf(
"%s",(message.right(1)==
"\n" ?
"" :
"\n"));
309 level = qBound(0,level,9);
314 QDateTime now = QDateTime::currentDateTime();
319 QString s = QString(
"%1,ERROR,%2,%3,%4%5").arg(QString::number(now.toMSecsSinceEpoch()),user,QString::number(level),message,message.right(1)==
"\n" ?
"" :
"\n");
322 { printf(
"%s",qUtf8Printable(s));
340 _vfs->
cp_error.cprintferr(
"[ ERROR %d ] %s %s",level,qUtf8Printable(user),qUtf8Printable(message));
341 printf(
"%s",(message.right(1)==
"\n" ?
"" :
"\n"));
361 QDateTime now = QDateTime::currentDateTime();
366 QString s = QString(
"%1,CRITICAL,%2,%3,%4%5").arg(QString::number(now.toMSecsSinceEpoch()),
"CRITICAL",QString::number(level),message,message.right(1)==
"\n" ?
"" :
"\n");
369 { printf(
"%s\n",qUtf8Printable(s));
384 _vfs->
cp_error.cprintferr(
"[ CRITICAL ] %s",qUtf8Printable(message));
385 printf(
"%s",(message.right(1)==
"\n" ?
"" :
"\n"));
434 return (QDateTime::currentMSecsSinceEpoch() -
_vfs->
_start);
447 return QString(
"%1:%2:%3:%4.%5")
448 .arg(u / (1000*60*60*24))
449 .arg((
int)floor((u % (1000*60*60*24))/(1000*60*60)),2,(
int)10,QChar(
'0'))
450 .arg((
int)floor((u % (1000*60*60))/(1000*60)),2,(
int)10,QChar(
'0'))
451 .arg((
int)floor((u % (1000*60))/(1000)),2,(
int)10,QChar(
'0'))
452 .arg((
int)(u % 1000),3,(
int)10,QChar(
'0'));
454 return QString(
"%1:%2:%3:%4")
455 .arg(u / (1000*60*60*24))
456 .arg((
int)floor((u % (1000*60*60*24))/(1000*60*60)),2,(
int)10,QChar(
'0'))
457 .arg((
int)floor((u % (1000*60*60))/(1000*60)),2,(
int)10,QChar(
'0'))
458 .arg((
int)floor((u % (1000*60))/(1000)),2,(
int)10,QChar(
'0'));
489 QMap<QString, QDateTime>::iterator i;
492 LOG( QString(
"Checking modification time on '%1'...").arg(i.key()), 9 );
495 f.setFile( i.key() );
498 WARN( QString(
"Monitored file '%1' doesn't exist.").arg(i.key()), 8 );
500 {
if ( f.lastModified() > t )
504 QString message = QString(
"Monitored file '%1' has changed!").arg(i.key());
506 cp_warn.cprintf(
"[ WARN %d ] %s %s\n",0,
"server",qUtf8Printable(message));
508 QCoreApplication::exit(0);
#define VFS_CREATOR_MAX_OUTSTANDING
static void build(QString configFile, VFS_node *root, bool printConfig=false)
Build an environment for creating nodes.
static void init(QStringList plugins=QStringList(), bool describe=false)
Initialize plugins recursively.
static QSemaphore _outstanding
A semaphore used to sync creation during startup.
static char * get(QString which="")
Fetch an icon from the library.
VFS_node is the base class from which all other VFS_node classes derive.
virtual VFS_node * append(QString name, VFS_node *node, bool containerCheck=true, QString user="server")
Append a VFS_node as a child of this node.
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.
virtual void issueRequest(VFS_request *t)
A convenience function.
The base class for all requests between nodes.
static VFS_thread * fromConfig(QString configString, QVariantMap env=QVariantMap(), bool printConfig=false)
A convenience method for creating threads.
static int threadcount()
Return the current thread count, mostly only useful for logging output.
bool hasNode()
When a thread is created, it must construct its root node to become operational.
VFS is the root node for a Virtual Filesystem.
static QJsonObject _parameters
VFS parameters, defined in a config file.
void timerEvent(QTimerEvent *event)
Timer handler for VFS timer events.
static QMap< QString, QDateTime > _monitoredFiles
A list of path:datetime entries that the VFS will monitor for changes.
static VFS * root()
Return the root node of the VFS filesystem.
int _logLevel
Filter log entries by this value... lower entries are very important, higher ones are more fine-grain...
void setLogSettings(int loglevel, int logtime)
Set the loglevel and logtime values for the logger.
static void LOG(QString message, int level=0, QString user="server")
Send a message to the VFS::_messages VFS_stream.
void setAdminEmail(QString emails)
Set the admin email addresses for CRITICAL messages.
static void ERROR(QString message, int level=0, QString user="server")
Send a message to the VFS::_errors VFS_stream.
static void CRITICAL(QString message)
Send a message to the VFS::_critical VFS_stream.
int _logTime
Include log entry time in output, where 0 = none, 1 = locale time, 2 = locale time and date,...
void initialized()
Emitted when the VFS_creator has completed its VFS_creator::build() call.
static QString uptimeString(bool ms=true)
Get the uptime of this VFS instance as a string.
int _monitorTimerID
The timerID for monitoring config file changes.
ColorPrint cp_init
Color settings to print messages when other streams do not exist.
static void WARN(QString message, int level=0, QString user="server")
Send a message to the VFS::_warnings VFS_stream.
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.
void getLogSettings(int &loglevel, int &logtime)
Get the loglevel and logtime values for the logger.
void monitoredFilesCheck()
Iterate through all monitored files, and check their modification time.
qint64 _start
Set when the VFS instance begins. This is used to track uptime.
static qint64 starttime()
Get the epoch start time of this VFS instance, in milliseconds.
static qint64 uptime()
Get the uptime of this VFS instance, in milliseconds.
virtual QByteArray icon()
Fetch the icon for this node.
ColorPrint cp_error
Color settings for error messages.
static QJsonDocument parameters()
Fetch the parameters assigned to this VFS, as per the config file.
ColorPrint cp_warn
Color settings for warning messages.
VFS_thread * _logger
The VFS_logger instance, which will always be on another thread.
~VFS()
Destroy the VFS node, which will remove references to logging nodes and return output to cp_init colo...
QMutex _printLock
A lock for ensuring that print messags don't get interleaved.
static VFS * _vfs
The global and single instance of VFS, returned by VFS::root()
message(m)
Change the message of an existing arrowMessage.