add ability to reload without reinitialization

This commit is contained in:
Evgenii Alekseev 2017-10-13 23:13:00 +03:00
parent 0d5e9a328e
commit de0653f038
12 changed files with 72 additions and 53 deletions

View File

@ -53,9 +53,10 @@ class QueuedCore : public QObject
public:
/**
* @brief QueuedCore class constructor
* @param parent pointer to parent item
* @param _parent
* pointer to parent item
*/
explicit QueuedCore(QObject *parent);
explicit QueuedCore(QObject *_parent);
/**
* @brief QueuedCore class destructor
*/
@ -382,6 +383,21 @@ private:
* @throw QueuedDBusException
*/
void initDBus();
/**
* @brief method allows to init class if it was not created
* @tparam T
* class name
* @tparam Args
* class constructor arguments
* @param _dest
* pointer to destination
* @param _args
* class constructor arguments
*/
template<class T, typename... Args> T *initObject(T *_dest, Args... _args)
{
return _dest ? _dest : new T(this, _args...);
};
/**
* @brief init plugins
*/

View File

@ -57,6 +57,10 @@ public:
* @brief check and create database
*/
void checkDatabase();
/**
* @brief close database connection
*/
void close();
/**
* @brief check and create queued administrator if missing
* @param _user

View File

@ -83,7 +83,7 @@ public:
* @brief path to plugin location
* @return full path to plugin location
*/
QStringList pluginLocations() const;
static QStringList pluginLocations();
/**
* @brief unload plugin
* @param _name

View File

@ -58,15 +58,10 @@ public:
/**
* @brief QueuedProcessManager class constructor
* @param parent
* @param _parent
* pointer to parent item
* @param processLine
* command line pattern
* @param onExit
* default action on exit
*/
explicit QueuedProcessManager(QObject *parent, const QString &processLine,
const QueuedEnums::ExitAction onExit);
explicit QueuedProcessManager(QObject *_parent);
/**
* @brief QueuedProcessManager class destructor
*/

View File

@ -42,12 +42,12 @@ class QueuedSettings : public QObject
public:
/**
* @brief QueuedSettings class constructor
* @param parent
* @param _parent
* pointer to parent item
* @param path
* @param _path
* path to configuration file
*/
explicit QueuedSettings(QObject *parent, const QString path);
explicit QueuedSettings(QObject *_parent, const QString _path);
/**
* @brief QueuedSettings class destructor
*/

View File

@ -66,7 +66,7 @@ public:
* @brief check if token is valid
* @param _token
* token ID
* @return token user if token is valid otherwise return false
* @return token user if token is valid otherwise return empty string
*/
QString isTokenValid(const QString &_token) const;
/**

View File

@ -35,8 +35,8 @@
/**
* @fn QueuedCore
*/
QueuedCore::QueuedCore(QObject *parent)
: QObject(parent)
QueuedCore::QueuedCore(QObject *_parent)
: QObject(_parent)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
}
@ -565,23 +565,13 @@ void QueuedCore::deinit()
m_connections.clear();
// dbus cleanup
QDBusConnection::sessionBus().unregisterObject(
QDBusConnection::systemBus().unregisterObject(
QueuedConfig::DBUS_OBJECT_PATH);
QDBusConnection::sessionBus().unregisterObject(
QDBusConnection::systemBus().unregisterObject(
QueuedConfig::DBUS_PROPERTY_PATH);
QDBusConnection::sessionBus().unregisterObject(
QDBusConnection::systemBus().unregisterObject(
QueuedConfig::DBUS_REPORTS_PATH);
QDBusConnection::sessionBus().unregisterService(QueuedConfig::DBUS_SERVICE);
// delete objects now
delete m_databaseManager;
delete m_reports;
delete m_plugins;
delete m_processes;
delete m_users;
delete m_database;
delete m_settings;
delete m_advancedSettings;
QDBusConnection::systemBus().unregisterService(QueuedConfig::DBUS_SERVICE);
}
@ -787,7 +777,7 @@ void QueuedCore::initPlugins()
.split('\n');
QString token = m_users->authorize(m_settings->admin().name);
m_plugins = new QueuedPluginManager(this, token);
m_plugins = initObject(m_plugins, token);
for (auto &plugin : pluginList)
m_plugins->loadPlugin(plugin, pluginSettings(plugin));
}
@ -807,7 +797,9 @@ void QueuedCore::initProcesses()
->get(QueuedConfig::QueuedSettings::ProcessCommandLine)
.toString();
m_processes = new QueuedProcessManager(this, processLine, onExitAction);
m_processes = initObject(m_processes);
m_processes->setProcessLine(processLine);
m_processes->setExitAction(onExitAction);
auto dbProcesses
= m_database->get(QueuedDB::TASKS_TABLE, "WHERE endTime IS NULL");
m_processes->loadProcesses(dbProcesses);
@ -831,10 +823,12 @@ void QueuedCore::initProcesses()
void QueuedCore::initSettings(const QString &_configuration)
{
// read configuration first
m_settings = new QueuedSettings(this, _configuration);
m_settings = initObject(m_settings, _configuration);
m_settings->readConfiguration();
// init database now
auto dbSetup = m_settings->db();
m_database = new QueuedDatabase(this, dbSetup.path, dbSetup.driver);
m_database = initObject(m_database, dbSetup.path, dbSetup.driver);
m_database->close();
bool status = m_database->open(dbSetup.hostname, dbSetup.port,
dbSetup.username, dbSetup.password);
if (!status) {
@ -848,7 +842,7 @@ void QueuedCore::initSettings(const QString &_configuration)
m_database->createAdministrator(dbAdmin.name, dbAdmin.password);
// and load advanced settings
m_advancedSettings = new QueuedAdvancedSettings(this);
m_advancedSettings = initObject(m_advancedSettings);
m_advancedSettings->set(m_database->get(QueuedDB::SETTINGS_TABLE));
if (!m_advancedSettings->checkDatabaseVersion()) {
qCInfo(LOG_LIB) << "Bump database version to"
@ -859,9 +853,9 @@ void QueuedCore::initSettings(const QString &_configuration)
}
// report manager
m_reports = new QueuedReportManager(this, m_database);
m_reports = initObject(m_reports, m_database);
// database manager
m_databaseManager = new QueuedDatabaseManager(this, m_database);
m_databaseManager = initObject(m_databaseManager, m_database);
}
@ -875,7 +869,7 @@ void QueuedCore::initUsers()
= m_advancedSettings->get(QueuedConfig::QueuedSettings::TokenExpiration)
.toLongLong();
m_users = new QueuedUserManager(this);
m_users = initObject(m_users);
m_users->setTokenExpiration(expiry);
QString now = QDateTime::currentDateTimeUtc().toString(Qt::ISODateWithMs);
auto dbTokens = m_database->get(

View File

@ -52,7 +52,7 @@ QueuedDatabase::~QueuedDatabase()
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
m_database.close();
close();
}
@ -73,6 +73,15 @@ void QueuedDatabase::checkDatabase()
}
/**
* @fn close
*/
void QueuedDatabase::close()
{
m_database.close();
}
/**
* @fn createAdministrator
*/

View File

@ -99,6 +99,14 @@ bool QueuedPluginManager::loadPlugin(const QString &_name,
{
qCDebug(LOG_PL) << "Load plugin" << _name << "with settings" << _settings;
// check if it was loaded already then call QueuedPluginInterface::init()
if (m_plugins.contains(_name)) {
m_plugins[_name]->init(_settings);
m_plugins[_name]->setToken(m_token);
return true;
}
// normal load
QString libraryName = QString("lib%2.so").arg(_name);
// init plugin settings with valid keys
QVariantHash pluginSettings;
@ -138,7 +146,7 @@ bool QueuedPluginManager::loadPlugin(const QString &_name,
/**
* @fn pluginLocations
*/
QStringList QueuedPluginManager::pluginLocations() const
QStringList QueuedPluginManager::pluginLocations()
{
QStringList locations = QStandardPaths::standardLocations(
QStandardPaths::GenericDataLocation);

View File

@ -31,17 +31,12 @@ extern "C" {
/**
* @fn QueuedProcessManager
*/
QueuedProcessManager::QueuedProcessManager(QObject *parent,
const QString &processLine,
const QueuedEnums::ExitAction onExit)
: QObject(parent)
QueuedProcessManager::QueuedProcessManager(QObject *_parent)
: QObject(_parent)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
qRegisterMetaType<QueuedEnums::ExitAction>("QueuedEnums::ExitAction");
setExitAction(onExit);
setProcessLine(processLine);
}

View File

@ -33,9 +33,9 @@
/**
* @fn QueuedSettings
*/
QueuedSettings::QueuedSettings(QObject *parent, const QString path)
: QObject(parent)
, m_path(path)
QueuedSettings::QueuedSettings(QObject *_parent, const QString _path)
: QObject(_parent)
, m_path(_path)
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
@ -43,8 +43,6 @@ QueuedSettings::QueuedSettings(QObject *parent, const QString path)
"QueuedConfig::QueuedAdminSetup");
qRegisterMetaType<QueuedConfig::QueuedDBSetup>(
"QueuedConfig::QueuedDBSetup");
readConfiguration();
}

View File

@ -109,7 +109,7 @@ QString QueuedTokenManager::registerToken(const QString &_user,
const QDateTime &_validUntil)
{
// generate from uuid
QString &token = QUuid::createUuid().toString().remove('{').remove('}');
QString token = QUuid::createUuid().toString().remove('{').remove('}');
qCInfo(LOG_LIB) << "Registered token" << token << "valid until"
<< _validUntil;