mirror of
https://github.com/arcan1s/queued.git
synced 2025-04-24 15:37:19 +00:00
add plugin interaction
This commit is contained in:
parent
3ed3973f4d
commit
793d833d55
@ -46,6 +46,72 @@ public:
|
||||
virtual ~QueuedPluginManagerInterface(){};
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief signal which emits on plugin addition
|
||||
* @param _plugin
|
||||
* plugin name
|
||||
*/
|
||||
void onAddPlugin(const QString &_plugin);
|
||||
/**
|
||||
* @brief signal which emits on task addition
|
||||
* @param _id
|
||||
* generated task ID
|
||||
*/
|
||||
void onAddTask(const long long _id);
|
||||
/**
|
||||
* @brief signal which emits on user addition
|
||||
* @param _id
|
||||
* generated user ID
|
||||
*/
|
||||
void onAddUser(const long long _id);
|
||||
/**
|
||||
* @brief signal which emits on user authorization
|
||||
* @param _user
|
||||
* user name
|
||||
*/
|
||||
void onAuthorization(const QString &_user);
|
||||
/**
|
||||
* @brief signal which emits on option edition
|
||||
* @param _option
|
||||
* option name
|
||||
* @param _value
|
||||
* option value
|
||||
*/
|
||||
void onEditOption(const QString &_option, const QVariant &_value);
|
||||
/**
|
||||
* @brief signal which emits on task edition
|
||||
* @param _id
|
||||
* task ID
|
||||
* @param _taskData
|
||||
* new task data
|
||||
*/
|
||||
void onEditTask(const long long _id, const QVariantHash &_taskData);
|
||||
/**
|
||||
* @brief signal which emits on user edition
|
||||
* @param _id
|
||||
* user ID
|
||||
* @param _userData
|
||||
* new user data
|
||||
*/
|
||||
void onEditUser(const long long _id, const QVariantHash &_userData);
|
||||
/**
|
||||
* @brief signal which emits on plugin removal
|
||||
* @param _plugin
|
||||
* plugin name
|
||||
*/
|
||||
void onRemovePlugin(const QString &_plugin);
|
||||
/**
|
||||
* @brief signal which emits on task starting
|
||||
* @param _id
|
||||
* started task ID
|
||||
*/
|
||||
void onStartTask(const long long _id);
|
||||
/**
|
||||
* @brief signal which emits on task stoping
|
||||
* @param _id
|
||||
* stopped task ID
|
||||
*/
|
||||
void onStopTask(const long long _id);
|
||||
};
|
||||
|
||||
|
||||
|
@ -32,6 +32,8 @@
|
||||
#include "QueuedProcess.h"
|
||||
|
||||
|
||||
class QueuedPluginManagerInterface;
|
||||
|
||||
/**
|
||||
* @brief implementation over QProcess to run processes
|
||||
*/
|
||||
|
@ -683,10 +683,16 @@ void QueuedCore::updateTaskTime(const long long _id,
|
||||
<< _endTime;
|
||||
|
||||
QVariantHash record;
|
||||
if (_startTime.isValid())
|
||||
if (_startTime.isValid()) {
|
||||
record[QString("startTime")] = _startTime.toString(Qt::ISODateWithMs);
|
||||
if (_endTime.isValid())
|
||||
if (m_plugins)
|
||||
emit(m_plugins->interface()->onStartTask(_id));
|
||||
}
|
||||
if (_endTime.isValid()) {
|
||||
record[QString("endTime")] = _endTime.toString(Qt::ISODateWithMs);
|
||||
if (m_plugins)
|
||||
emit(m_plugins->interface()->onStopTask(_id));
|
||||
}
|
||||
|
||||
bool status = m_database->modify(QueuedDB::TASKS_TABLE, _id, record);
|
||||
if (!status)
|
||||
@ -925,6 +931,10 @@ long long QueuedCore::addTaskPrivate(const QString &_command,
|
||||
|
||||
// add to child object
|
||||
m_processes->add(properties, id);
|
||||
// notify plugins
|
||||
if (m_plugins)
|
||||
emit(m_plugins->interface()->onAddTask(id));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -955,6 +965,10 @@ long long QueuedCore::addUserPrivate(const QString &_name,
|
||||
|
||||
// add to child object
|
||||
m_users->add(properties, id);
|
||||
// notify plugins
|
||||
if (m_plugins)
|
||||
emit(m_plugins->interface()->onAddUser(id));
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -984,8 +998,12 @@ bool QueuedCore::editOptionPrivate(const QString &_key, const QVariant &_value)
|
||||
// add to child object
|
||||
if (status) {
|
||||
m_advancedSettings->set(_key, _value);
|
||||
// notify plugin if required
|
||||
// TODO notify plugin if required
|
||||
// notify plugins
|
||||
if (m_plugins)
|
||||
emit(m_plugins->interface()->onEditOption(_key, _value));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -1003,13 +1021,28 @@ bool QueuedCore::editPluginPrivate(const QString &_plugin, const bool _add)
|
||||
.split('\n');
|
||||
|
||||
bool status = false;
|
||||
if (_add && !pluginList.contains(_plugin))
|
||||
if (_add && !pluginList.contains(_plugin)) {
|
||||
status = m_plugins->loadPlugin(_plugin, pluginSettings(_plugin));
|
||||
else if (!_add && pluginList.contains(_plugin))
|
||||
pluginList.append(_plugin);
|
||||
} else if (!_add && pluginList.contains(_plugin)) {
|
||||
status = m_plugins->unloadPlugin(_plugin);
|
||||
else
|
||||
pluginList.removeAll(_plugin);
|
||||
} else {
|
||||
qCDebug(LOG_LIB) << "Plugin" << _plugin
|
||||
<< "not loaded or already loaded";
|
||||
}
|
||||
|
||||
if (status) {
|
||||
editOptionPrivate(m_advancedSettings->internalId(
|
||||
QueuedConfig::QueuedSettings::Plugins),
|
||||
pluginList.join('\n'));
|
||||
// notify plugins
|
||||
if (_add)
|
||||
if (m_plugins)
|
||||
emit(m_plugins->interface()->onAddPlugin(_plugin));
|
||||
else if (m_plugins)
|
||||
emit(m_plugins->interface()->onRemovePlugin(_plugin));
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
@ -1040,6 +1073,9 @@ bool QueuedCore::editTaskPrivate(const long long _id,
|
||||
// modify values stored in memory
|
||||
for (auto &property : _taskData.keys())
|
||||
task->setProperty(qPrintable(property), _taskData[property]);
|
||||
// notify plugins
|
||||
if (m_plugins)
|
||||
emit(m_plugins->interface()->onEditTask(_id, _taskData));
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1070,6 +1106,9 @@ bool QueuedCore::editUserPrivate(const long long _id,
|
||||
// modify values stored in memory
|
||||
for (auto &property : _userData.keys())
|
||||
userObj->setProperty(qPrintable(property), _userData[property]);
|
||||
// notify plugins
|
||||
if (m_plugins)
|
||||
emit(m_plugins->interface()->onEditUser(_id, _userData));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -58,7 +58,8 @@ QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
||||
= _parser.value("task-user").isEmpty()
|
||||
? 0
|
||||
: QueuedctlUser::getUserId(_parser.value("task-user"));
|
||||
definitions.workingDirectory = _parser.value("directory");
|
||||
definitions.workingDirectory
|
||||
= QFileInfo(_parser.value("directory")).absoluteFilePath();
|
||||
// limits now
|
||||
QueuedLimits::Limits limits(
|
||||
_parser.value("limit-cpu").toLongLong(),
|
||||
@ -70,7 +71,8 @@ QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
||||
|
||||
// all options
|
||||
if (_expandAll) {
|
||||
definitions.command = _parser.value("program");
|
||||
definitions.command
|
||||
= QFileInfo(_parser.value("program")).absoluteFilePath();
|
||||
definitions.endTime
|
||||
= QDateTime::fromString(_parser.value("stop"), Qt::ISODateWithMs);
|
||||
definitions.gid = _parser.value("gid").toUInt();
|
||||
@ -79,7 +81,8 @@ QueuedctlTask::getDefinitions(const QCommandLineParser &_parser,
|
||||
definitions.uid = _parser.value("uid").toUInt();
|
||||
} else {
|
||||
// queuedctl -- task-add /path/to/application
|
||||
definitions.command = _parser.positionalArguments().at(1);
|
||||
definitions.command
|
||||
= QFileInfo(_parser.positionalArguments().at(1)).absoluteFilePath();
|
||||
}
|
||||
|
||||
return definitions;
|
||||
|
Loading…
Reference in New Issue
Block a user