mirror of
https://github.com/arcan1s/queued.git
synced 2025-06-30 15:35:54 +00:00
implement work with plugins
This commit is contained in:
@ -54,6 +54,14 @@ public:
|
|||||||
* @remark plugin settings will be stored as "plugin.name.Key"
|
* @remark plugin settings will be stored as "plugin.name.Key"
|
||||||
*/
|
*/
|
||||||
virtual void init(const QVariantHash &_settings) = 0;
|
virtual void init(const QVariantHash &_settings) = 0;
|
||||||
|
/**
|
||||||
|
* @brief set plugin token
|
||||||
|
* @remark this method may be safety ignored if plugin does not use methods
|
||||||
|
* require auth
|
||||||
|
* @param _token
|
||||||
|
* new token ID
|
||||||
|
*/
|
||||||
|
virtual void setToken(const QString &_token) = 0;
|
||||||
/**
|
/**
|
||||||
* @brief method which will be called on option update
|
* @brief method which will be called on option update
|
||||||
* @param _key
|
* @param _key
|
||||||
@ -61,7 +69,8 @@ public:
|
|||||||
* @param _value
|
* @param _value
|
||||||
* option value
|
* option value
|
||||||
*/
|
*/
|
||||||
virtual void updateSettings(const QString &_key, const QVariant &_value);
|
virtual void updateSettings(const QString &_key, const QVariant &_value)
|
||||||
|
= 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_INTERFACE(QueuedPluginInterface, PLUGIN_INTERFACE_NAME)
|
Q_DECLARE_INTERFACE(QueuedPluginInterface, PLUGIN_INTERFACE_NAME)
|
||||||
|
@ -50,8 +50,10 @@ public:
|
|||||||
* @brief QueuedPluginManager class constructor
|
* @brief QueuedPluginManager class constructor
|
||||||
* @param parent
|
* @param parent
|
||||||
* pointer to parent item
|
* pointer to parent item
|
||||||
|
* @param token
|
||||||
|
* plugin auth token
|
||||||
*/
|
*/
|
||||||
explicit QueuedPluginManager(QObject *parent);
|
explicit QueuedPluginManager(QObject *parent, const QString &token);
|
||||||
/**
|
/**
|
||||||
* @brief QueuedPluginManager class destructor
|
* @brief QueuedPluginManager class destructor
|
||||||
*/
|
*/
|
||||||
@ -101,14 +103,18 @@ public slots:
|
|||||||
void optionChanged(const QString &_key, const QVariant &_value);
|
void optionChanged(const QString &_key, const QVariant &_value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/**
|
||||||
|
* @brief pointer to database object
|
||||||
|
*/
|
||||||
|
QueuedPluginManagerInterface *m_interface = nullptr;
|
||||||
/**
|
/**
|
||||||
* @brief loaded plugins
|
* @brief loaded plugins
|
||||||
*/
|
*/
|
||||||
QueuedPluginMap m_plugins;
|
QueuedPluginMap m_plugins;
|
||||||
/**
|
/**
|
||||||
* @brief pointer to database object
|
* @brief plugin auth token
|
||||||
*/
|
*/
|
||||||
QueuedPluginManagerInterface *m_interface = nullptr;
|
QString m_token;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +46,72 @@ public:
|
|||||||
virtual ~QueuedPluginManagerInterface(){};
|
virtual ~QueuedPluginManagerInterface(){};
|
||||||
|
|
||||||
signals:
|
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"
|
#include "QueuedProcess.h"
|
||||||
|
|
||||||
|
|
||||||
|
class QueuedPluginManagerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief implementation over QProcess to run processes
|
* @brief implementation over QProcess to run processes
|
||||||
*/
|
*/
|
||||||
|
@ -72,6 +72,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
QueuedUser *add(const QueuedUser::QueuedUserDefinitions &_definitions,
|
QueuedUser *add(const QueuedUser::QueuedUserDefinitions &_definitions,
|
||||||
const long long _id);
|
const long long _id);
|
||||||
|
/**
|
||||||
|
* @brief authorize user manually
|
||||||
|
* @remark it ignores password input and creates unlimited token
|
||||||
|
* @param _user
|
||||||
|
* user name
|
||||||
|
* @return generated token
|
||||||
|
*/
|
||||||
|
QString authorize(const QString &_user);
|
||||||
/**
|
/**
|
||||||
* @brief authorize user
|
* @brief authorize user
|
||||||
* @param _user
|
* @param _user
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include <QDBusMessage>
|
#include <QDBusMessage>
|
||||||
|
|
||||||
#include <queued/QueuedDatabaseSchema.h>
|
#include <queued/QueuedDatabaseSchema.h>
|
||||||
|
#include <queued/QueuedStaticConfig.h>
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -683,10 +684,14 @@ void QueuedCore::updateTaskTime(const long long _id,
|
|||||||
<< _endTime;
|
<< _endTime;
|
||||||
|
|
||||||
QVariantHash record;
|
QVariantHash record;
|
||||||
if (_startTime.isValid())
|
if (_startTime.isValid()) {
|
||||||
record[QString("startTime")] = _startTime.toString(Qt::ISODateWithMs);
|
record[QString("startTime")] = _startTime.toString(Qt::ISODateWithMs);
|
||||||
if (_endTime.isValid())
|
emit(m_plugins->interface()->onStartTask(_id));
|
||||||
|
}
|
||||||
|
if (_endTime.isValid()) {
|
||||||
record[QString("endTime")] = _endTime.toString(Qt::ISODateWithMs);
|
record[QString("endTime")] = _endTime.toString(Qt::ISODateWithMs);
|
||||||
|
emit(m_plugins->interface()->onStopTask(_id));
|
||||||
|
}
|
||||||
|
|
||||||
bool status = m_database->modify(QueuedDB::TASKS_TABLE, _id, record);
|
bool status = m_database->modify(QueuedDB::TASKS_TABLE, _id, record);
|
||||||
if (!status)
|
if (!status)
|
||||||
@ -780,8 +785,9 @@ void QueuedCore::initPlugins()
|
|||||||
= m_advancedSettings->get(QueuedConfig::QueuedSettings::Plugins)
|
= m_advancedSettings->get(QueuedConfig::QueuedSettings::Plugins)
|
||||||
.toString()
|
.toString()
|
||||||
.split('\n');
|
.split('\n');
|
||||||
|
QString token = m_users->authorize(m_settings->admin().name);
|
||||||
|
|
||||||
m_plugins = new QueuedPluginManager(this);
|
m_plugins = new QueuedPluginManager(this, token);
|
||||||
for (auto &plugin : pluginList)
|
for (auto &plugin : pluginList)
|
||||||
m_plugins->loadPlugin(plugin, pluginSettings(plugin));
|
m_plugins->loadPlugin(plugin, pluginSettings(plugin));
|
||||||
}
|
}
|
||||||
@ -925,6 +931,9 @@ long long QueuedCore::addTaskPrivate(const QString &_command,
|
|||||||
|
|
||||||
// add to child object
|
// add to child object
|
||||||
m_processes->add(properties, id);
|
m_processes->add(properties, id);
|
||||||
|
// notify plugins
|
||||||
|
emit(m_plugins->interface()->onAddTask(id));
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -955,6 +964,9 @@ long long QueuedCore::addUserPrivate(const QString &_name,
|
|||||||
|
|
||||||
// add to child object
|
// add to child object
|
||||||
m_users->add(properties, id);
|
m_users->add(properties, id);
|
||||||
|
// notify plugins
|
||||||
|
emit(m_plugins->interface()->onAddUser(id));
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -984,8 +996,15 @@ bool QueuedCore::editOptionPrivate(const QString &_key, const QVariant &_value)
|
|||||||
// add to child object
|
// add to child object
|
||||||
if (status) {
|
if (status) {
|
||||||
m_advancedSettings->set(_key, _value);
|
m_advancedSettings->set(_key, _value);
|
||||||
// notify plugin if required
|
// notify plugins if required
|
||||||
|
auto tryPluginOption = m_plugins->convertOptionName(_key);
|
||||||
|
if ((!tryPluginOption.first.isEmpty())
|
||||||
|
&& (!tryPluginOption.second.isEmpty()))
|
||||||
|
m_plugins->optionChanged(_key, _value);
|
||||||
|
// notify plugins
|
||||||
|
emit(m_plugins->interface()->onEditOption(_key, _value));
|
||||||
}
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1003,13 +1022,27 @@ bool QueuedCore::editPluginPrivate(const QString &_plugin, const bool _add)
|
|||||||
.split('\n');
|
.split('\n');
|
||||||
|
|
||||||
bool status = false;
|
bool status = false;
|
||||||
if (_add && !pluginList.contains(_plugin))
|
if (_add && !pluginList.contains(_plugin)) {
|
||||||
status = m_plugins->loadPlugin(_plugin, pluginSettings(_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);
|
status = m_plugins->unloadPlugin(_plugin);
|
||||||
else
|
pluginList.removeAll(_plugin);
|
||||||
|
} else {
|
||||||
qCDebug(LOG_LIB) << "Plugin" << _plugin
|
qCDebug(LOG_LIB) << "Plugin" << _plugin
|
||||||
<< "not loaded or already loaded";
|
<< "not loaded or already loaded";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status) {
|
||||||
|
editOptionPrivate(m_advancedSettings->internalId(
|
||||||
|
QueuedConfig::QueuedSettings::Plugins),
|
||||||
|
pluginList.join('\n'));
|
||||||
|
// notify plugins
|
||||||
|
if (_add)
|
||||||
|
emit(m_plugins->interface()->onAddPlugin(_plugin));
|
||||||
|
else
|
||||||
|
emit(m_plugins->interface()->onRemovePlugin(_plugin));
|
||||||
|
}
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -1040,6 +1073,8 @@ bool QueuedCore::editTaskPrivate(const long long _id,
|
|||||||
// modify values stored in memory
|
// modify values stored in memory
|
||||||
for (auto &property : _taskData.keys())
|
for (auto &property : _taskData.keys())
|
||||||
task->setProperty(qPrintable(property), _taskData[property]);
|
task->setProperty(qPrintable(property), _taskData[property]);
|
||||||
|
// notify plugins
|
||||||
|
emit(m_plugins->interface()->onEditTask(_id, _taskData));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -1070,6 +1105,8 @@ bool QueuedCore::editUserPrivate(const long long _id,
|
|||||||
// modify values stored in memory
|
// modify values stored in memory
|
||||||
for (auto &property : _userData.keys())
|
for (auto &property : _userData.keys())
|
||||||
userObj->setProperty(qPrintable(property), _userData[property]);
|
userObj->setProperty(qPrintable(property), _userData[property]);
|
||||||
|
// notify plugins
|
||||||
|
emit(m_plugins->interface()->onEditUser(_id, _userData));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -34,8 +34,9 @@
|
|||||||
/**
|
/**
|
||||||
* @fn QueuedPluginManager
|
* @fn QueuedPluginManager
|
||||||
*/
|
*/
|
||||||
QueuedPluginManager::QueuedPluginManager(QObject *parent)
|
QueuedPluginManager::QueuedPluginManager(QObject *parent, const QString &token)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
|
, m_token(token)
|
||||||
{
|
{
|
||||||
qCDebug(LOG_PL) << __PRETTY_FUNCTION__;
|
qCDebug(LOG_PL) << __PRETTY_FUNCTION__;
|
||||||
|
|
||||||
@ -121,6 +122,7 @@ bool QueuedPluginManager::loadPlugin(const QString &_name,
|
|||||||
if (item) {
|
if (item) {
|
||||||
m_plugins[_name] = item;
|
m_plugins[_name] = item;
|
||||||
item->init(pluginSettings);
|
item->init(pluginSettings);
|
||||||
|
item->setToken(m_token);
|
||||||
item->connect(interface());
|
item->connect(interface());
|
||||||
} else {
|
} else {
|
||||||
qCCritical(LOG_PL) << "Could not cast plugin" << _name;
|
qCCritical(LOG_PL) << "Could not cast plugin" << _name;
|
||||||
|
@ -93,6 +93,20 @@ QueuedUserManager::add(const QueuedUser::QueuedUserDefinitions &_definitions,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @fn authorize
|
||||||
|
*/
|
||||||
|
QString QueuedUserManager::authorize(const QString &_user)
|
||||||
|
{
|
||||||
|
qCDebug(LOG_LIB) << "Authorize user manually" << _user;
|
||||||
|
|
||||||
|
auto time = QDateTime::currentDateTimeUtc();
|
||||||
|
time = time.addDays(9999);
|
||||||
|
|
||||||
|
return m_tokens->registerToken(_user, time);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fn authorize
|
* @fn authorize
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user