From 881abd4c51f9ac9e2e16071e82be6df0c9a6168a Mon Sep 17 00:00:00 2001 From: Evgeniy Alekseev Date: Fri, 17 Nov 2017 00:28:15 +0300 Subject: [PATCH] some improvements * add plugin tree * add emailnotify plugin template --- sources/CMakeLists.txt | 4 + sources/plugins/CMakeLists.txt | 9 + sources/plugins/QueuedConfig.cmake | 13 + .../plugins/emailnotify/QueuedEmailNotify.cpp | 74 ++++++ .../plugins/emailnotify/QueuedEmailNotify.h | 44 ++++ .../emailnotify/QueuedEmailNotifyHelper.cpp | 249 ++++++++++++++++++ .../emailnotify/QueuedEmailNotifyHelper.h | 78 ++++++ sources/queued-daemon/src/CMakeLists.txt | 8 +- sources/queued-server/src/CMakeLists.txt | 8 +- sources/queued/QueuedConfig.h.in | 2 +- sources/queued/QueuedLibraries.cmake | 4 +- sources/queued/QueuedMacros.cmake | 21 +- .../queued/include/queued/QueuedCoreAdaptor.h | 15 +- .../include/queued/QueuedPluginInterface.h | 14 +- sources/queued/src/CMakeLists.txt | 12 +- sources/queued/src/QueuedCorePrivate.cpp | 6 +- sources/queued/src/QueuedPluginManager.cpp | 2 +- sources/queuedctl/src/CMakeLists.txt | 8 +- 18 files changed, 516 insertions(+), 55 deletions(-) create mode 100644 sources/plugins/CMakeLists.txt create mode 100644 sources/plugins/QueuedConfig.cmake create mode 100644 sources/plugins/emailnotify/QueuedEmailNotify.cpp create mode 100644 sources/plugins/emailnotify/QueuedEmailNotify.h create mode 100644 sources/plugins/emailnotify/QueuedEmailNotifyHelper.cpp create mode 100644 sources/plugins/emailnotify/QueuedEmailNotifyHelper.h diff --git a/sources/CMakeLists.txt b/sources/CMakeLists.txt index 14ef30d..a8f77f3 100644 --- a/sources/CMakeLists.txt +++ b/sources/CMakeLists.txt @@ -27,6 +27,7 @@ message(STATUS "Version: ${PROJECT_VERSION}") message(STATUS "Build date: ${CURRENT_DATE}") # components +option(BUILD_PLUGINS "Build plugins" ON) option(BUILD_DEB_PACKAGE "Build deb package" OFF) option(BUILD_RPM_PACKAGE "Build rpm package" OFF) # build details @@ -53,6 +54,9 @@ add_subdirectory("queued") add_subdirectory("queued-daemon") add_subdirectory("queued-server") add_subdirectory("queuedctl") +if (BUILD_PLUGINS) + add_subdirectory("plugins") +endif() if (BUILD_TESTING) enable_testing() add_subdirectory("test") diff --git a/sources/plugins/CMakeLists.txt b/sources/plugins/CMakeLists.txt new file mode 100644 index 0000000..ac1362c --- /dev/null +++ b/sources/plugins/CMakeLists.txt @@ -0,0 +1,9 @@ +set (SUBPROJECT "plugins") +message (STATUS "Subproject ${SUBPROJECT}") + +include_directories("${CMAKE_BINARY_DIR}" + "${PROJECT_LIBRARY_DIR}/include" # required by moc + "${PROJECT_TRDPARTY_DIR}") +find_package(Queued PATHS "${CMAKE_CURRENT_SOURCE_DIR}" NO_DEFAULT_PATH) + +queued_install_plugin("emailnotify" "emailnotify" curl) diff --git a/sources/plugins/QueuedConfig.cmake b/sources/plugins/QueuedConfig.cmake new file mode 100644 index 0000000..95e9b59 --- /dev/null +++ b/sources/plugins/QueuedConfig.cmake @@ -0,0 +1,13 @@ +set(QUEUED_DEFINITIONS "") +find_path(QUEUEDCORE_INCLUDE_DIR "queued/Queued.h" PATH_SUFFIXES "queued" + PATHS "${PROJECT_LIBRARY_DIR}/include" NO_DEFAULT_PATH) +set(QUEUED_INCLUDE_DIRS "${QUEUEDCORE_INCLUDE_DIR}") +set(QUEUED_LIBRARIES "${PROJECT_LIBRARY}") +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(Queued DEFAULT_MSG + QUEUED_LIBRARIES QUEUED_INCLUDE_DIRS) + +set(QUEUED_PLUGIN_ROOT "${DATA_INSTALL_DIR}/queued/plugins") + +include("${PROJECT_LIBRARY_DIR}/QueuedLibraries.cmake") +include("${PROJECT_LIBRARY_DIR}/QueuedMacros.cmake") diff --git a/sources/plugins/emailnotify/QueuedEmailNotify.cpp b/sources/plugins/emailnotify/QueuedEmailNotify.cpp new file mode 100644 index 0000000..1c06505 --- /dev/null +++ b/sources/plugins/emailnotify/QueuedEmailNotify.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2017 Queued team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + + +#include "QueuedEmailNotify.h" + +#include + +#include "QueuedEmailNotifyHelper.h" + + +void QueuedEmailNotify::init(const QVariantHash &_settings) +{ + m_helper = new QueuedEmailNotifyHelper(this); + + m_helper->setFrom(_settings.value("From", "mail@example.com").toString()); + m_helper->setInsecureCurl(_settings.value("InsecureCurl", false).toBool()); + m_helper->setPassword(_settings.value("Password", "").toString()); + m_helper->setPort(_settings.value("Port", 465).toInt()); + m_helper->setServer( + _settings.value("Server", "smtp://smtp.example.com").toString()); + m_helper->setSslEnabled(_settings.value("UseSSL", false).toBool()); + m_helper->setUsername(_settings.value("Username", "").toString()); +} + + +void QueuedEmailNotify::setToken(const QString &_token) +{ + m_token = _token; +} + + +void QueuedEmailNotify::setup(const QueuedPluginManagerInterface *_manager) +{ + connect(_manager, SIGNAL(onStopTask(const long long)), m_helper, + SLOT(sendEmail(const long long))); +} + + +void QueuedEmailNotify::updateSettings(const QString &_key, + const QVariant &_value) +{ + qCDebug(LOG_PL) << "Update settings for" << _key; + + if (!m_helper) { + qCWarning(LOG_PL) + << "Helper is not initialized. Did you forget to call ::init()?"; + return; + } + + if (_key == "From") { + m_helper->setFrom(_value.toString()); + } else if (_key == "Password") { + m_helper->setPassword(_value.toString()); + } else if (_key == "Port") { + m_helper->setPort(_value.toInt()); + } else if (_key == "Server") { + m_helper->setServer(_value.toString()); + } else if (_key == "Username") { + m_helper->setUsername(_value.toString()); + } +} diff --git a/sources/plugins/emailnotify/QueuedEmailNotify.h b/sources/plugins/emailnotify/QueuedEmailNotify.h new file mode 100644 index 0000000..4c29a12 --- /dev/null +++ b/sources/plugins/emailnotify/QueuedEmailNotify.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2017 Queued team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + + +#ifndef QUEUEDEMAILNOTIFY_H +#define QUEUEDEMAILNOTIFY_H + +#include + + +class QueuedEmailNotifyHelper; + +class QueuedEmailNotify : public QObject, public QueuedPluginInterface +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.queued.emailnotify/1.0") + Q_INTERFACES(QueuedPluginInterface) + +public: + virtual ~QueuedEmailNotify() = default; + void init(const QVariantHash &_settings) override; + void setToken(const QString &_token) override; + void setup(const QueuedPluginManagerInterface *_manager) override; + void updateSettings(const QString &_key, const QVariant &_value) override; + +private: + QueuedEmailNotifyHelper *m_helper = nullptr; + QString m_token; +}; + + +#endif /* QUEUEDEMAILNOTIFY_H */ diff --git a/sources/plugins/emailnotify/QueuedEmailNotifyHelper.cpp b/sources/plugins/emailnotify/QueuedEmailNotifyHelper.cpp new file mode 100644 index 0000000..524e30c --- /dev/null +++ b/sources/plugins/emailnotify/QueuedEmailNotifyHelper.cpp @@ -0,0 +1,249 @@ +/* + * Copyright (c) 2017 Queued team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + + +#include "QueuedEmailNotifyHelper.h" + +#include + +extern "C" { +#include +} + + +QueuedEmailNotifyHelper::QueuedEmailNotifyHelper(QObject *_parent) + : QObject(_parent) +{ + qCDebug(LOG_PL) << __PRETTY_FUNCTION__; +} + + +QString QueuedEmailNotifyHelper::curlEmail(const QString &_from) +{ + qCDebug(LOG_PL) << "Convert email to curl format from" << _from; + + return QString("<%1>").arg(_from); +} + + +char *QueuedEmailNotifyHelper::curlString(const QString &_source) +{ + return strdup(_source.toStdString().c_str()); +} + + +size_t QueuedEmailNotifyHelper::curlReadCallback(char *buffer, size_t size, + size_t nitems, void *instream) +{ + // FIXME not really best choice to use here + auto text = reinterpret_cast(instream); + + // check sizes and whatever + if ((size == 0) || (nitems == 0) || ((size * nitems) < 1)) + return 0; + if (text->text.count() <= text->currentLine) + return 0; + + // get char* string from related qstring + auto data = curlString(text->text.at(text->currentLine)); + size_t len = strlen(data); + memcpy(buffer, data, len); + text->currentLine++; + + return len; +} + + +QString QueuedEmailNotifyHelper::from() const +{ + return m_from; +} + + +bool QueuedEmailNotifyHelper::isInsecureCurl() const +{ + return m_insecure; +} + + +bool QueuedEmailNotifyHelper::isSslEnabled() const +{ + return m_ssl; +} + + +QString QueuedEmailNotifyHelper::password() const +{ + return m_password; +} + + +int QueuedEmailNotifyHelper::port() const +{ + return m_port; +} + + +QString QueuedEmailNotifyHelper::server() const +{ + return m_server; +} + + +QString QueuedEmailNotifyHelper::username() const +{ + return m_username; +} + + +void QueuedEmailNotifyHelper::setFrom(const QString &_from) +{ + qCDebug(LOG_PL) << "Set from" << _from; + + m_from = _from; +} + + +void QueuedEmailNotifyHelper::setInsecureCurl(const bool _insecureCurl) +{ + qCDebug(LOG_PL) << "Set insecure curl" << _insecureCurl; + + m_insecure = _insecureCurl; +} + + +void QueuedEmailNotifyHelper::setPassword(const QString &_password) +{ + qCDebug(LOG_PL) << "Set password"; + + m_password = _password; +} + + +void QueuedEmailNotifyHelper::setPort(const int &_port) +{ + qCDebug(LOG_PL) << "Set port" << _port; + + m_port = _port; +} + + +void QueuedEmailNotifyHelper::setServer(const QString &_server) +{ + qCDebug(LOG_PL) << "Set server" << _server; + + m_server = _server; +} + + +void QueuedEmailNotifyHelper::setSslEnabled(const bool _sslEnabled) +{ + qCDebug(LOG_PL) << "Set ssl enabled" << _sslEnabled; + + m_ssl = _sslEnabled; +} + + +void QueuedEmailNotifyHelper::setUsername(const QString &_username) +{ + qCDebug(LOG_PL) << "Set username" << _username; + + m_username = _username; +} + + +void QueuedEmailNotifyHelper::sendEmail(const long long _id) +{ + auto rcpt = getEmail(_id); + if (rcpt.isEmpty()) + return; + MailBody text = {getEmailText(_id, rcpt), 0}; + + CURL *curl = curl_easy_init(); + QString url = QString("%1:%2").arg(server()).arg(port()); + curl_easy_setopt(curl, CURLOPT_URL, curlString(url)); + + // ssl options + if (isSslEnabled()) + curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_ALL); + if (isInsecureCurl()) + curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L); + + // auth if applicable + if ((!username().isEmpty()) && (!password().isEmpty())) { + curl_easy_setopt(curl, CURLOPT_USERNAME, curlString(username())); + curl_easy_setopt(curl, CURLOPT_PASSWORD, curlString(password())); + } + + // from & to + curl_easy_setopt(curl, CURLOPT_MAIL_FROM, curlString(curlEmail(from()))); + curl_slist *recipients = nullptr; + recipients = curl_slist_append(recipients, curlString(curlEmail(rcpt))); + curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients); + + // mail body + curl_easy_setopt(curl, CURLOPT_READFUNCTION, + &QueuedEmailNotifyHelper::curlReadCallback); + curl_easy_setopt(curl, CURLOPT_READDATA, &text); + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); + + // send + auto res = curl_easy_perform(curl); + if (res != CURLE_OK) + qCWarning(LOG_PL) << "Could not perform curl action" + << curl_easy_strerror(res); + + // cleanup + curl_slist_free_all(recipients); + curl_easy_cleanup(curl); +} + + +QString QueuedEmailNotifyHelper::getEmail(const long long _id) const +{ + qCDebug(LOG_PL) << "Get email for task ID" << _id; + + auto task = QueuedCoreAdaptor::getTask(_id, "user"); + if (task.type() != Result::Content::Value) { + qCWarning(LOG_LIB) << "Could not get task information" << _id; + return ""; + } + + auto userId = task.get().toLongLong(); + auto user = QueuedCoreAdaptor::getUser(userId, "email"); + if (user.type() != Result::Content::Value) { + qCWarning(LOG_LIB) << "Could not get user information" << userId; + return ""; + } + + return user.get().toString(); +} + + +QStringList QueuedEmailNotifyHelper::getEmailText(const long long _id, + const QString &_to) const +{ + qCDebug(LOG_PL) << "Get email text for user" << _to << "for task" << _id; + + auto now + = QDateTime::currentDateTimeUtc().toString(Qt::DateFormat::RFC2822Date); + + return {QString("Date: %1\r\n").arg(now), + QString("To: %1\r\n").arg(curlEmail(_to)), + QString("From: %1\r\n").arg(curlEmail(from())), + // message-id? + QString("Subject: %1\r\n").arg("Job %1 done").arg(_id), "\r\n", + QString("Job %1 done\r\n").arg(_id)}; +} diff --git a/sources/plugins/emailnotify/QueuedEmailNotifyHelper.h b/sources/plugins/emailnotify/QueuedEmailNotifyHelper.h new file mode 100644 index 0000000..a8d7163 --- /dev/null +++ b/sources/plugins/emailnotify/QueuedEmailNotifyHelper.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2017 Queued team + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + */ + + +#ifndef QUEUEDEMAILNOTIFYHELPER_H +#define QUEUEDEMAILNOTIFYHELPER_H + +#include + + +class QueuedEmailNotifyHelper : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString from READ from WRITE setFrom) + Q_PROPERTY(bool insecureCurl READ isInsecureCurl WRITE setInsecureCurl) + Q_PROPERTY(QString password READ password WRITE setPassword) + Q_PROPERTY(int port READ port WRITE setPort) + Q_PROPERTY(QString server READ server WRITE setServer) + Q_PROPERTY(bool ssl READ isSslEnabled WRITE setSslEnabled) + Q_PROPERTY(QString username READ username WRITE setUsername) + +public: + typedef struct { + QStringList text; + int currentLine = 0; + } MailBody; + + explicit QueuedEmailNotifyHelper(QObject *_parent); + virtual ~QueuedEmailNotifyHelper() = default; + static QString curlEmail(const QString &_from); + static char *curlString(const QString &_source); + static size_t curlReadCallback(char *buffer, size_t size, size_t nitems, + void *instream); + // properties + QString from() const; + bool isInsecureCurl() const; + bool isSslEnabled() const; + QString password() const; + int port() const; + QString server() const; + QString username() const; + void setFrom(const QString &_from); + void setInsecureCurl(const bool _insecureCurl); + void setPassword(const QString &_password); + void setPort(const int &_port); + void setServer(const QString &_server); + void setSslEnabled(const bool _sslEnabled); + void setUsername(const QString &_username); + +public slots: + void sendEmail(const long long _id); + +private: + QString getEmail(const long long _id) const; + QStringList getEmailText(const long long _id, const QString &_to) const; + QString m_from; + bool m_insecure = false; + QString m_password; + int m_port = 0; + QString m_server; + bool m_ssl = false; + QString m_username; +}; + + +#endif /* QUEUEDEMAILNOTIFYHELPER_H */ diff --git a/sources/queued-daemon/src/CMakeLists.txt b/sources/queued-daemon/src/CMakeLists.txt index 0c22400..e663c50 100644 --- a/sources/queued-daemon/src/CMakeLists.txt +++ b/sources/queued-daemon/src/CMakeLists.txt @@ -4,10 +4,10 @@ file (GLOB_RECURSE SUBPROJECT_HEADERS "*.h") # include_path include_directories ("${PROJECT_LIBRARY_DIR}/include" - "${CMAKE_CURRENT_BINARY_DIR}" - "${CMAKE_BINARY_DIR}" - "${PROJECT_TRDPARTY_DIR}" - "${Qt_INCLUDE}") + "${CMAKE_CURRENT_BINARY_DIR}" + "${CMAKE_BINARY_DIR}" + "${PROJECT_TRDPARTY_DIR}" + "${Qt_INCLUDE}") qt5_wrap_cpp (SUBPROJECT_MOC_SOURCES "${SUBPROJECT_HEADERS}") diff --git a/sources/queued-server/src/CMakeLists.txt b/sources/queued-server/src/CMakeLists.txt index 0c22400..e663c50 100644 --- a/sources/queued-server/src/CMakeLists.txt +++ b/sources/queued-server/src/CMakeLists.txt @@ -4,10 +4,10 @@ file (GLOB_RECURSE SUBPROJECT_HEADERS "*.h") # include_path include_directories ("${PROJECT_LIBRARY_DIR}/include" - "${CMAKE_CURRENT_BINARY_DIR}" - "${CMAKE_BINARY_DIR}" - "${PROJECT_TRDPARTY_DIR}" - "${Qt_INCLUDE}") + "${CMAKE_CURRENT_BINARY_DIR}" + "${CMAKE_BINARY_DIR}" + "${PROJECT_TRDPARTY_DIR}" + "${Qt_INCLUDE}") qt5_wrap_cpp (SUBPROJECT_MOC_SOURCES "${SUBPROJECT_HEADERS}") diff --git a/sources/queued/QueuedConfig.h.in b/sources/queued/QueuedConfig.h.in index f702d04..a5b842c 100644 --- a/sources/queued/QueuedConfig.h.in +++ b/sources/queued/QueuedConfig.h.in @@ -115,7 +115,7 @@ static const char CG_FS_PATH[] = "/sys/fs/cgroup"; * @remark required by Qt macro */ #define PLUGIN_INTERFACE_NAME \ - "queued.plugin/@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@" + "org.queued.plugin/@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@" /** * @brief plugin interface name */ diff --git a/sources/queued/QueuedLibraries.cmake b/sources/queued/QueuedLibraries.cmake index 4c91b48..1d8549c 100644 --- a/sources/queued/QueuedLibraries.cmake +++ b/sources/queued/QueuedLibraries.cmake @@ -37,8 +37,8 @@ add_definitions( # Qt include paths ## set(Qt_INCLUDE - ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} ${Qt5Network_INCLUDE_DIRS} - ${Qt5Sql_INCLUDE_DIRS} + ${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS} + ${Qt5Network_INCLUDE_DIRS} ${Qt5Sql_INCLUDE_DIRS} ) ## # @def Qt_LIBRARIES diff --git a/sources/queued/QueuedMacros.cmake b/sources/queued/QueuedMacros.cmake index 53b94ba..5d0e7f2 100644 --- a/sources/queued/QueuedMacros.cmake +++ b/sources/queued/QueuedMacros.cmake @@ -27,11 +27,12 @@ ## # @fn queued_install_plugin root [name] [libraries] # @brief build and install plugin -# @param PLUGIN_ROOT plugin root directory -# @param PLUGIN plugin name (optional). Will be assigned from path -# if empty -# @param ADDS_LIBRARIES additional libraries (optional) -# +# @param PLUGIN_ROOT +# plugin root directory +# @param PLUGIN +# plugin name (optional). Will be assigned from path if empty +# @param ADDS_LIBRARIES +# additional libraries (optional) ## macro(queued_install_plugin PLUGIN_ROOT) set(PLUGIN "${ARGV1}") @@ -47,13 +48,13 @@ macro(queued_install_plugin PLUGIN_ROOT) # include directories include_directories ("${CMAKE_CURRENT_BINARY_DIR}" - "${Qt_INCLUDE}" - "${QUEUED_INCLUDE_DIRS}") + "${Qt_INCLUDE}" "${QUEUED_INCLUDE_DIRS}") # build - add_library ("${PLUGIN}" MODULE "${${PLUGIN}_SOURCES}" "${${PLUGIN}_HEADERS}" - "${${PLUGIN}_MOC_SOURCES}") - target_link_libraries ("${PLUGIN}" "${QUEUED_LIBRARIES}" "${Qt_LIBRARIES}" "${ADDS_LIBRARIES}") + add_library ("${PLUGIN}" MODULE "${${PLUGIN}_SOURCES}" + "${${PLUGIN}_HEADERS}" "${${PLUGIN}_MOC_SOURCES}") + target_link_libraries ("${PLUGIN}" "${QUEUED_LIBRARIES}" "${Qt_LIBRARIES}" + "${ADDS_LIBRARIES}") # install install (TARGETS "${PLUGIN}" DESTINATION "${QUEUED_PLUGIN_ROOT}") diff --git a/sources/queued/include/queued/QueuedCoreAdaptor.h b/sources/queued/include/queued/QueuedCoreAdaptor.h index 21848f9..8ca662b 100644 --- a/sources/queued/include/queued/QueuedCoreAdaptor.h +++ b/sources/queued/include/queued/QueuedCoreAdaptor.h @@ -305,19 +305,6 @@ template QDBusVariant toDBusVariant(const QueuedResult &_data) { return QDBusVariant(QVariant::fromValue>(_data)); }; -/** - * @brief additional method to avoid conversion from QDBusVariant to - * QueuedResult - * @tparam T - * QueuedResult payload class - * @param _data - * input data - * @return converted data to QueuedResult - */ -template QueuedResult toResult(const QDBusVariant &_data) -{ - return qdbus_cast>(_data.variant().value()); -}; /** * @brief additional method to avoid conversion from QVariant to * QueuedResult @@ -361,7 +348,7 @@ QueuedResult sendRequest(const QString &_service, const QString &_path, if (dbusResponse.isValid()) { auto response = dbusResponse.value(); - return toResult(response); + return toResult(response.variant()); } else { return QueuedError(dbusResponse.error().message().toStdString()); } diff --git a/sources/queued/include/queued/QueuedPluginInterface.h b/sources/queued/include/queued/QueuedPluginInterface.h index 3366d06..27e59f4 100644 --- a/sources/queued/include/queued/QueuedPluginInterface.h +++ b/sources/queued/include/queued/QueuedPluginInterface.h @@ -40,13 +40,7 @@ public: /** * @brief QueuedPluginInterface class destructor */ - virtual ~QueuedPluginInterface() = default; - /** - * @brief will be emitted to map interface signals to plugin slots - * @param _manager - * pointer to manager interface object - */ - virtual void connect(const QueuedPluginManagerInterface *_manager) = 0; + virtual ~QueuedPluginInterface(){}; /** * @brief plugin initialization method * @param _settings @@ -62,6 +56,12 @@ public: * new token ID */ virtual void setToken(const QString &_token) = 0; + /** + * @brief will be emitted to map interface signals to plugin slots + * @param _manager + * pointer to manager interface object + */ + virtual void setup(const QueuedPluginManagerInterface *_manager) = 0; /** * @brief method which will be called on option update * @param _key diff --git a/sources/queued/src/CMakeLists.txt b/sources/queued/src/CMakeLists.txt index 03383e6..8683e9a 100644 --- a/sources/queued/src/CMakeLists.txt +++ b/sources/queued/src/CMakeLists.txt @@ -4,15 +4,15 @@ file (GLOB_RECURSE SUBPROJECT_HEADERS "*.h" "${PROJECT_LIBRARY_DIR}/*h") # include_path include_directories ("${PROJECT_LIBRARY_DIR}/include" - "${CMAKE_CURRENT_BINARY_DIR}" - "${CMAKE_BINARY_DIR}" - "${PROJECT_TRDPARTY_DIR}" - "${Qt_INCLUDE}") + "${CMAKE_CURRENT_BINARY_DIR}" + "${CMAKE_BINARY_DIR}" + "${PROJECT_TRDPARTY_DIR}" + "${Qt_INCLUDE}") qt5_wrap_cpp (SUBPROJECT_MOC_SOURCES "${SUBPROJECT_HEADERS}") -add_library ("${SUBPROJECT}" SHARED "${SUBPROJECT_SOURCES}" "${SUBPROJECT_HEADERS}" - "${SUBPROJECT_MOC_SOURCES}") +add_library ("${SUBPROJECT}" SHARED "${SUBPROJECT_SOURCES}" + "${SUBPROJECT_HEADERS}" "${SUBPROJECT_MOC_SOURCES}") set_target_properties ("${SUBPROJECT}" PROPERTIES SOVERSION "${PROJECT_VERSION_MAJOR}" VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") diff --git a/sources/queued/src/QueuedCorePrivate.cpp b/sources/queued/src/QueuedCorePrivate.cpp index 1700ad5..1256ffd 100644 --- a/sources/queued/src/QueuedCorePrivate.cpp +++ b/sources/queued/src/QueuedCorePrivate.cpp @@ -386,8 +386,10 @@ QVariantHash QueuedCorePrivate::pluginSettings(const QString &_plugin) QString("WHERE key LIKE 'Plugin.%1.%'").arg(_plugin)); QVariantHash settings; std::for_each(dbSettings.cbegin(), dbSettings.cend(), - [&settings](const QVariantHash &value) { - settings[value["key"].toString()] = value["value"]; + [&settings, &_plugin](const QVariantHash &value) { + auto key = value["key"].toString(); + key.remove(QString("Plugin.%1.").arg(_plugin)); + settings[key] = value["value"]; }); return settings; diff --git a/sources/queued/src/QueuedPluginManager.cpp b/sources/queued/src/QueuedPluginManager.cpp index e7dba74..5bd741b 100644 --- a/sources/queued/src/QueuedPluginManager.cpp +++ b/sources/queued/src/QueuedPluginManager.cpp @@ -131,7 +131,7 @@ bool QueuedPluginManager::loadPlugin(const QString &_name, m_plugins[_name] = item; item->init(pluginSettings); item->setToken(m_token); - item->connect(interface()); + item->setup(interface()); } else { qCCritical(LOG_PL) << "Could not cast plugin" << _name; } diff --git a/sources/queuedctl/src/CMakeLists.txt b/sources/queuedctl/src/CMakeLists.txt index 0c22400..e663c50 100644 --- a/sources/queuedctl/src/CMakeLists.txt +++ b/sources/queuedctl/src/CMakeLists.txt @@ -4,10 +4,10 @@ file (GLOB_RECURSE SUBPROJECT_HEADERS "*.h") # include_path include_directories ("${PROJECT_LIBRARY_DIR}/include" - "${CMAKE_CURRENT_BINARY_DIR}" - "${CMAKE_BINARY_DIR}" - "${PROJECT_TRDPARTY_DIR}" - "${Qt_INCLUDE}") + "${CMAKE_CURRENT_BINARY_DIR}" + "${CMAKE_BINARY_DIR}" + "${PROJECT_TRDPARTY_DIR}" + "${Qt_INCLUDE}") qt5_wrap_cpp (SUBPROJECT_MOC_SOURCES "${SUBPROJECT_HEADERS}")