diff --git a/libnymea-core/jsonrpc/jsonrpcserver.cpp b/libnymea-core/jsonrpc/jsonrpcserver.cpp index 09e499af..5745e27b 100644 --- a/libnymea-core/jsonrpc/jsonrpcserver.cpp +++ b/libnymea-core/jsonrpc/jsonrpcserver.cpp @@ -47,6 +47,7 @@ #include "rule.h" #include "ruleengine.h" #include "loggingcategories.h" +#include "platform/platform.h" #include "devicehandler.h" #include "actionhandler.h" @@ -519,7 +520,7 @@ void JsonRPCServer::setup() registerHandler(new ConfigurationHandler(this)); registerHandler(new NetworkManagerHandler(this)); registerHandler(new TagsHandler(this)); - registerHandler(new SystemHandler(NymeaCore::instance()->system(), this)); + registerHandler(new SystemHandler(NymeaCore::instance()->platform(), this)); connect(NymeaCore::instance()->cloudManager(), &CloudManager::pairingReply, this, &JsonRPCServer::pairingFinished); connect(NymeaCore::instance()->cloudManager(), &CloudManager::connectionStateChanged, this, &JsonRPCServer::onCloudConnectionStateChanged); diff --git a/libnymea-core/jsonrpc/systemhandler.cpp b/libnymea-core/jsonrpc/systemhandler.cpp index a3e747c9..d222fd2f 100644 --- a/libnymea-core/jsonrpc/systemhandler.cpp +++ b/libnymea-core/jsonrpc/systemhandler.cpp @@ -1,10 +1,12 @@ #include "systemhandler.h" -#include "system/system.h" +#include "platform/platform.h" +#include "platform/platformupdatecontroller.h" +#include "platform/platformsystemcontroller.h" -SystemHandler::SystemHandler(System *system, QObject *parent): +SystemHandler::SystemHandler(Platform *platform, QObject *parent): JsonHandler(parent), - m_system(system) + m_platform(platform) { // Methods QVariantMap params; QVariantMap returns; @@ -62,7 +64,7 @@ SystemHandler::SystemHandler(System *system, QObject *parent): params.insert("updateInProgress", JsonTypes::basicTypeToString(JsonTypes::Bool)); setParams("UpdateStatusChanged", params); - connect(m_system, &System::updateStatusChanged, this, &SystemHandler::onUpdateStatusChanged); + connect(m_platform->updateController(), &PlatformUpdateController::updateStatusChanged, this, &SystemHandler::onUpdateStatusChanged); } QString SystemHandler::name() const @@ -74,15 +76,15 @@ JsonReply *SystemHandler::GetCapabilities(const QVariantMap ¶ms) { Q_UNUSED(params) QVariantMap data; - data.insert("powerManagement", m_system->powerManagementAvailable()); - data.insert("updateManagement", m_system->updateManagementAvailable()); + data.insert("powerManagement", m_platform->systemController()->powerManagementAvailable()); + data.insert("updateManagement", m_platform->updateController()->updateManagementAvailable()); return createReply(data); } JsonReply *SystemHandler::Reboot(const QVariantMap ¶ms) const { Q_UNUSED(params); - bool status = m_system->reboot(); + bool status = m_platform->systemController()->reboot(); QVariantMap returns; returns.insert("success", status); return createReply(returns); @@ -91,7 +93,7 @@ JsonReply *SystemHandler::Reboot(const QVariantMap ¶ms) const JsonReply *SystemHandler::Shutdown(const QVariantMap ¶ms) const { Q_UNUSED(params); - bool status = m_system->shutdown(); + bool status = m_platform->systemController()->shutdown(); QVariantMap returns; returns.insert("success", status); return createReply(returns); @@ -101,12 +103,12 @@ JsonReply *SystemHandler::GetUpdateStatus(const QVariantMap ¶ms) const { Q_UNUSED(params); QVariantMap returns; - returns.insert("updateAvailable", m_system->updateAvailable()); - returns.insert("currentVersion", m_system->currentVersion()); - returns.insert("candidateVersion", m_system->candidateVersion()); - returns.insert("availableChannels", m_system->availableChannels()); - returns.insert("currentChannel", m_system->currentChannel()); - returns.insert("updateInProgress", m_system->updateInProgress()); + returns.insert("updateAvailable", m_platform->updateController()->updateAvailable()); + returns.insert("currentVersion", m_platform->updateController()->currentVersion()); + returns.insert("candidateVersion", m_platform->updateController()->candidateVersion()); + returns.insert("availableChannels", m_platform->updateController()->availableChannels()); + returns.insert("currentChannel", m_platform->updateController()->currentChannel()); + returns.insert("updateInProgress", m_platform->updateController()->updateInProgress()); return createReply(returns); } @@ -114,7 +116,7 @@ JsonReply *SystemHandler::StartUpdate(const QVariantMap ¶ms) { Q_UNUSED(params) QVariantMap returns; - bool success = m_system->startUpdate(); + bool success = m_platform->updateController()->startUpdate(); returns.insert("success", success); return createReply(returns); } @@ -124,8 +126,8 @@ JsonReply *SystemHandler::SelectChannel(const QVariantMap ¶ms) QString channel = params.value("channel").toString(); QVariantMap returns; - if (m_system->availableChannels().contains(channel)) { - bool success = m_system->selectChannel(channel); + if (m_platform->updateController()->availableChannels().contains(channel)) { + bool success = m_platform->updateController()->selectChannel(channel); returns.insert("success", success); } else { returns.insert("success", false); @@ -136,12 +138,11 @@ JsonReply *SystemHandler::SelectChannel(const QVariantMap ¶ms) void SystemHandler::onUpdateStatusChanged() { QVariantMap params; - params.insert("updateAvailable", m_system->updateAvailable()); - params.insert("currentVersion", m_system->currentVersion()); - params.insert("candidateVersion", m_system->candidateVersion()); - params.insert("availableChannels", m_system->availableChannels()); - params.insert("currentChannel", m_system->currentChannel()); - params.insert("updateInProgress", m_system->updateInProgress()); + params.insert("updateAvailable", m_platform->updateController()->updateAvailable()); + params.insert("currentVersion", m_platform->updateController()->currentVersion()); + params.insert("candidateVersion", m_platform->updateController()->candidateVersion()); + params.insert("availableChannels", m_platform->updateController()->availableChannels()); + params.insert("currentChannel", m_platform->updateController()->currentChannel()); + params.insert("updateInProgress", m_platform->updateController()->updateInProgress()); emit UpdateStatusChanged(params); - } diff --git a/libnymea-core/jsonrpc/systemhandler.h b/libnymea-core/jsonrpc/systemhandler.h index 10ff913f..27c9fd93 100644 --- a/libnymea-core/jsonrpc/systemhandler.h +++ b/libnymea-core/jsonrpc/systemhandler.h @@ -25,15 +25,15 @@ #include "jsonhandler.h" -namespace nymeaserver { +#include "platform/platform.h" -class System; +namespace nymeaserver { class SystemHandler : public JsonHandler { Q_OBJECT public: - explicit SystemHandler(System* system, QObject *parent = nullptr); + explicit SystemHandler(Platform *platform, QObject *parent = nullptr); QString name() const override; @@ -52,7 +52,7 @@ signals: private slots: void onUpdateStatusChanged(); private: - System *m_system = nullptr; + Platform *m_platform = nullptr; }; } diff --git a/libnymea-core/libnymea-core.pro b/libnymea-core/libnymea-core.pro index 11f686ff..b66bc2c6 100644 --- a/libnymea-core/libnymea-core.pro +++ b/libnymea-core/libnymea-core.pro @@ -101,7 +101,6 @@ HEADERS += nymeacore.h \ cloud/cloudtransport.h \ debugreportgenerator.h \ platform/platform.h \ - system/system.h \ jsonrpc/systemhandler.h SOURCES += nymeacore.cpp \ @@ -188,5 +187,4 @@ SOURCES += nymeacore.cpp \ cloud/cloudtransport.cpp \ debugreportgenerator.cpp \ platform/platform.cpp \ - system/system.cpp \ jsonrpc/systemhandler.cpp diff --git a/libnymea-core/nymeacore.cpp b/libnymea-core/nymeacore.cpp index e213e4f8..e7d8ee2f 100644 --- a/libnymea-core/nymeacore.cpp +++ b/libnymea-core/nymeacore.cpp @@ -112,7 +112,7 @@ #include "networkmanager/networkmanager.h" #include "nymeasettings.h" #include "tagging/tagsstorage.h" -#include "system/system.h" +#include "platform/platform.h" #include "devicemanager.h" #include "plugin/device.h" @@ -154,9 +154,6 @@ void NymeaCore::init() { qCDebug(dcApplication()) << "Creating Time Manager"; m_timeManager = new TimeManager(m_configuration->timeZone(), this); - qCDebug(dcApplication()) << "Loading System platform integration"; - m_system = new System(m_platform, this); - qCDebug(dcApplication) << "Creating Log Engine"; m_logger = new LogEngine(m_configuration->logDBDriver(), m_configuration->logDBName(), m_configuration->logDBHost(), m_configuration->logDBUser(), m_configuration->logDBPassword(), m_configuration->logDBMaxEntries(), this); @@ -668,14 +665,15 @@ TagsStorage *NymeaCore::tagsStorage() const return m_tagsStorage; } -/*! Returns a pointer to the \l{System} instance owned by NymeaCore. */ -System *NymeaCore::system() const +/*! Returns a pointer to the \l{Platform} instance owned by NymeaCore. + The Platform represents the host system this nymea instance is running on. +*/ +Platform *NymeaCore::platform() const { - return m_system; + return m_platform; } - /*! Connected to the DeviceManager's emitEvent signal. Events received in here will be evaluated by the \l{RuleEngine} and the according \l{RuleAction}{RuleActions} are executed.*/ void NymeaCore::gotEvent(const Event &event) diff --git a/libnymea-core/nymeacore.h b/libnymea-core/nymeacore.h index 835a645f..4c1be9ec 100644 --- a/libnymea-core/nymeacore.h +++ b/libnymea-core/nymeacore.h @@ -90,7 +90,7 @@ public: CloudManager *cloudManager() const; DebugServerHandler *debugServerHandler() const; TagsStorage *tagsStorage() const; - System *system() const; + Platform *platform() const; static QStringList getAvailableLanguages(); diff --git a/libnymea-core/platform/platform.cpp b/libnymea-core/platform/platform.cpp index dab21d53..56750c20 100644 --- a/libnymea-core/platform/platform.cpp +++ b/libnymea-core/platform/platform.cpp @@ -1,5 +1,5 @@ #include "platform.h" -#include "plugin/platformplugin.h" +#include "platform/platformplugin.h" #include "loggingcategories.h" @@ -51,6 +51,7 @@ Platform::Platform(QObject *parent) : QObject(parent) } if (!m_platformPlugin) { qCWarning(dcPlatform()) << "Could not load a platform plugin. Platform related features won't be available."; + m_platformPlugin = new PlatformPlugin(this); } } diff --git a/libnymea-core/system/system.cpp b/libnymea-core/system/system.cpp deleted file mode 100644 index 46dcd599..00000000 --- a/libnymea-core/system/system.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include "system.h" - -#include "loggingcategories.h" -#include "platform/platform.h" -#include "plugin/platformsystemcontroller.h" -#include "plugin/platformupdatecontroller.h" - -namespace nymeaserver { - - -System::System(Platform *platform, QObject *parent): - QObject(parent), - m_platform(platform) -{ - connect(m_platform->updateController(), &PlatformUpdateController::updateStatusChanged, this, &System::updateStatusChanged); -} - -bool System::powerManagementAvailable() const -{ - return m_platform->systemController()->capabilities().testFlag(PlatformSystemController::CapabilityPower); -} - -bool System::reboot() -{ - return m_platform->systemController()->reboot(); -} - -bool System::shutdown() -{ - return m_platform->systemController()->shutdown(); -} - -bool System::updateManagementAvailable() const -{ - return m_platform->updateController()->updateManagementAvailable(); -} - -bool System::updateAvailable() const -{ - return m_platform->updateController()->updateAvailable(); -} - -QString System::currentVersion() const -{ - return m_platform->updateController()->currentVersion(); -} - -QString System::candidateVersion() const -{ - return m_platform->updateController()->candidateVersion(); -} - -QStringList System::availableChannels() const -{ - return m_platform->updateController()->channels(); -} - -QString System::currentChannel() const -{ - return m_platform->updateController()->currentChannel(); -} - -bool System::selectChannel(const QString &channel) const -{ - return m_platform->updateController()->selectChannel(channel); -} - -bool System::canUpdate() const -{ - return m_platform->updateController() ; -} - -bool System::startUpdate() -{ - return m_platform->updateController()->startUpdate(); -} - -bool System::updateInProgress() const -{ - return m_platform->updateController()->updateInProgress(); -} - -bool System::rollbackAvailable() const -{ - return m_platform->updateController()->rollbackAvailable(); -} - -} diff --git a/libnymea-core/system/system.h b/libnymea-core/system/system.h deleted file mode 100644 index d3bec8fb..00000000 --- a/libnymea-core/system/system.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef SYSTEM_H -#define SYSTEM_H - -#include - - -namespace nymeaserver { - -class Platform; - -class System : public QObject -{ - Q_OBJECT - -public: - explicit System(Platform *platform, QObject *parent = nullptr); - - bool powerManagementAvailable() const; - bool reboot(); - bool shutdown(); - - bool updateManagementAvailable() const; - bool updateAvailable() const; - QString currentVersion() const; - QString candidateVersion() const; - QStringList availableChannels() const; - QString currentChannel() const; - bool selectChannel(const QString &channel) const; - bool canUpdate() const; - bool startUpdate(); - bool updateInProgress() const; - - bool rollbackAvailable() const; - bool startRollback(); - -signals: - void updateStatusChanged(); - -private: - Platform *m_platform = nullptr; -}; - -} - -#endif // SYSTEM_H diff --git a/libnymea/libnymea.pro b/libnymea/libnymea.pro index 964940e3..97b7d889 100644 --- a/libnymea/libnymea.pro +++ b/libnymea/libnymea.pro @@ -66,9 +66,9 @@ HEADERS += devicemanager.h \ network/mqtt/mqttprovider.h \ network/mqtt/mqttchannel.h \ translator.h \ - plugin/platformplugin.h \ - plugin/platformsystemcontroller.h \ - plugin/platformupdatecontroller.h + platform/platformplugin.h \ + platform/platformsystemcontroller.h \ + platform/platformupdatecontroller.h SOURCES += devicemanager.cpp \ loggingcategories.cpp \ @@ -124,9 +124,9 @@ SOURCES += devicemanager.cpp \ network/mqtt/mqttprovider.cpp \ network/mqtt/mqttchannel.cpp \ translator.cpp \ - plugin/platformplugin.cpp \ - plugin/platformsystemcontroller.cpp \ - plugin/platformupdatecontroller.cpp + platform/platformplugin.cpp \ + platform/platformsystemcontroller.cpp \ + platform/platformupdatecontroller.cpp RESOURCES += \ diff --git a/libnymea/platform/platformplugin.cpp b/libnymea/platform/platformplugin.cpp new file mode 100644 index 00000000..d07ef052 --- /dev/null +++ b/libnymea/platform/platformplugin.cpp @@ -0,0 +1,16 @@ +#include "platformplugin.h" + +PlatformPlugin::PlatformPlugin(QObject *parent) : QObject(parent) +{ + +} + +PlatformSystemController *PlatformPlugin::systemController() const +{ + return m_systemStub; +} + +PlatformUpdateController *PlatformPlugin::updateController() const +{ + return m_updateStub; +} diff --git a/libnymea/plugin/platformplugin.h b/libnymea/platform/platformplugin.h similarity index 63% rename from libnymea/plugin/platformplugin.h rename to libnymea/platform/platformplugin.h index 52228241..177440d2 100644 --- a/libnymea/plugin/platformplugin.h +++ b/libnymea/platform/platformplugin.h @@ -15,8 +15,12 @@ public: explicit PlatformPlugin(QObject *parent = nullptr); virtual ~PlatformPlugin() = default; - virtual PlatformSystemController *systemController() const = 0; - virtual PlatformUpdateController *updateController() const = 0; + virtual PlatformSystemController *systemController() const; + virtual PlatformUpdateController *updateController() const; + +private: + PlatformSystemController *m_systemStub = nullptr; + PlatformUpdateController *m_updateStub = nullptr; }; Q_DECLARE_INTERFACE(PlatformPlugin, "io.nymea.PlatformPlugin") diff --git a/libnymea/platform/platformsystemcontroller.cpp b/libnymea/platform/platformsystemcontroller.cpp new file mode 100644 index 00000000..1034844a --- /dev/null +++ b/libnymea/platform/platformsystemcontroller.cpp @@ -0,0 +1,21 @@ +#include "platformsystemcontroller.h" + +PlatformSystemController::PlatformSystemController(QObject *parent) : QObject(parent) +{ + +} + +bool PlatformSystemController::powerManagementAvailable() const +{ + return false; +} + +bool PlatformSystemController::reboot() +{ + return false; +} + +bool PlatformSystemController::shutdown() +{ + return false; +} diff --git a/libnymea/plugin/platformsystemcontroller.h b/libnymea/platform/platformsystemcontroller.h similarity index 51% rename from libnymea/plugin/platformsystemcontroller.h rename to libnymea/platform/platformsystemcontroller.h index 36af00f1..2a56738b 100644 --- a/libnymea/plugin/platformsystemcontroller.h +++ b/libnymea/platform/platformsystemcontroller.h @@ -7,20 +7,12 @@ class PlatformSystemController : public QObject { Q_OBJECT public: - enum Capability { - CapabilityNone = 0x00, - CapabilityPower = 0x01, - CapabilityAll = 0xFF - }; - Q_ENUM(Capability) - Q_DECLARE_FLAGS(Capabilities, Capability) - explicit PlatformSystemController(QObject *parent = nullptr); virtual ~PlatformSystemController() = default; - virtual Capabilities capabilities() const = 0; - virtual bool reboot() = 0; - virtual bool shutdown() = 0; + virtual bool powerManagementAvailable() const; + virtual bool reboot(); + virtual bool shutdown(); }; #endif // PLATFORMSYSTEMCONTROLLER_H diff --git a/libnymea/platform/platformupdatecontroller.cpp b/libnymea/platform/platformupdatecontroller.cpp new file mode 100644 index 00000000..33a292bf --- /dev/null +++ b/libnymea/platform/platformupdatecontroller.cpp @@ -0,0 +1,71 @@ +#include "platformupdatecontroller.h" + +PlatformUpdateController::PlatformUpdateController(QObject *parent) : QObject(parent) +{ + +} + +/*! Override this to indicate whether update management is available. Defaults to false. + When a plugin returns true here, it is assumed that the system is capable of updating and nymea + has permissions to do so. + */ +bool PlatformUpdateController::updateManagementAvailable() +{ + return false; +} + +QString PlatformUpdateController::currentVersion() const +{ + return tr("N/A"); +} + +QString PlatformUpdateController::candidateVersion() const +{ + return tr("N/A"); +} + +void PlatformUpdateController::checkForUpdates() +{ + // Nothing to do here +} + +bool PlatformUpdateController::updateAvailable() const +{ + return false; +} + +bool PlatformUpdateController::startUpdate() +{ + return false; +} + +bool PlatformUpdateController::rollbackAvailable() const +{ + return false; +} + +bool PlatformUpdateController::startRollback() +{ + return false; +} + +bool PlatformUpdateController::updateInProgress() const +{ + return false; +} + +QStringList PlatformUpdateController::availableChannels() const +{ + return {}; +} + +QString PlatformUpdateController::currentChannel() const +{ + return tr("N/A"); +} + +bool PlatformUpdateController::selectChannel(const QString &channel) +{ + Q_UNUSED(channel) + return false; +} diff --git a/libnymea/platform/platformupdatecontroller.h b/libnymea/platform/platformupdatecontroller.h new file mode 100644 index 00000000..0a2c6b1a --- /dev/null +++ b/libnymea/platform/platformupdatecontroller.h @@ -0,0 +1,37 @@ +#ifndef PLATFORMUPDATECONTROLLER_H +#define PLATFORMUPDATECONTROLLER_H + +#include + +class PlatformUpdateController : public QObject +{ + Q_OBJECT +public: + explicit PlatformUpdateController(QObject *parent = nullptr); + virtual ~PlatformUpdateController() = default; + + virtual bool updateManagementAvailable(); + + virtual QString currentVersion() const; + virtual QString candidateVersion() const; + +// virtual QMap changelog() const = 0; + + virtual void checkForUpdates(); + virtual bool updateAvailable() const; + virtual bool startUpdate(); + + virtual bool rollbackAvailable() const; + virtual bool startRollback(); + + virtual bool updateInProgress() const; + + virtual QStringList availableChannels() const; + virtual QString currentChannel() const; + virtual bool selectChannel(const QString &channel); + +signals: + void updateStatusChanged(); +}; + +#endif // PLATFORMUPDATECONTROLLER_H diff --git a/libnymea/plugin/platformplugin.cpp b/libnymea/plugin/platformplugin.cpp deleted file mode 100644 index 6fa6d816..00000000 --- a/libnymea/plugin/platformplugin.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "platformplugin.h" - -PlatformPlugin::PlatformPlugin(QObject *parent) : QObject(parent) -{ - -} diff --git a/libnymea/plugin/platformsystemcontroller.cpp b/libnymea/plugin/platformsystemcontroller.cpp deleted file mode 100644 index a1d7dd6b..00000000 --- a/libnymea/plugin/platformsystemcontroller.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "platformsystemcontroller.h" - -PlatformSystemController::PlatformSystemController(QObject *parent) : QObject(parent) -{ - -} diff --git a/libnymea/plugin/platformupdatecontroller.cpp b/libnymea/plugin/platformupdatecontroller.cpp deleted file mode 100644 index 7464a4d8..00000000 --- a/libnymea/plugin/platformupdatecontroller.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "platformupdatecontroller.h" - -PlatformUpdateController::PlatformUpdateController(QObject *parent) : QObject(parent) -{ - -} - -/*! Override this to indicate whether update management is available. Defaults to false. - When a plugin returns true here, it is assumed that the system is capable of updating and nymea - has permissions to do so. - */ -bool PlatformUpdateController::updateManagementAvailable() -{ - return false; -} diff --git a/libnymea/plugin/platformupdatecontroller.h b/libnymea/plugin/platformupdatecontroller.h deleted file mode 100644 index 743d8212..00000000 --- a/libnymea/plugin/platformupdatecontroller.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef PLATFORMUPDATECONTROLLER_H -#define PLATFORMUPDATECONTROLLER_H - -#include - -class PlatformUpdateController : public QObject -{ - Q_OBJECT -public: - explicit PlatformUpdateController(QObject *parent = nullptr); - virtual ~PlatformUpdateController() = default; - - virtual bool updateManagementAvailable(); - - virtual QString currentVersion() const = 0; - virtual QString candidateVersion() const = 0; - -// virtual QMap changelog() const = 0; - - virtual void checkForUpdates() = 0; - virtual bool updateAvailable() const = 0; - virtual bool startUpdate() = 0; - - virtual bool rollbackAvailable() const = 0; - virtual bool startRollback() = 0; - - virtual bool updateInProgress() const = 0; - - virtual QStringList channels() const = 0; - virtual QString currentChannel() const = 0; - virtual bool selectChannel(const QString &channel) = 0; - -signals: - void updateStatusChanged(); -}; - -#endif // PLATFORMUPDATECONTROLLER_H