Simplify it a bit

This commit is contained in:
Michael Zanetti 2019-05-10 01:31:26 +02:00
parent 3944e94699
commit 02b97a686e
20 changed files with 200 additions and 257 deletions

View File

@ -47,6 +47,7 @@
#include "rule.h" #include "rule.h"
#include "ruleengine.h" #include "ruleengine.h"
#include "loggingcategories.h" #include "loggingcategories.h"
#include "platform/platform.h"
#include "devicehandler.h" #include "devicehandler.h"
#include "actionhandler.h" #include "actionhandler.h"
@ -519,7 +520,7 @@ void JsonRPCServer::setup()
registerHandler(new ConfigurationHandler(this)); registerHandler(new ConfigurationHandler(this));
registerHandler(new NetworkManagerHandler(this)); registerHandler(new NetworkManagerHandler(this));
registerHandler(new TagsHandler(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::pairingReply, this, &JsonRPCServer::pairingFinished);
connect(NymeaCore::instance()->cloudManager(), &CloudManager::connectionStateChanged, this, &JsonRPCServer::onCloudConnectionStateChanged); connect(NymeaCore::instance()->cloudManager(), &CloudManager::connectionStateChanged, this, &JsonRPCServer::onCloudConnectionStateChanged);

View File

@ -1,10 +1,12 @@
#include "systemhandler.h" #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), JsonHandler(parent),
m_system(system) m_platform(platform)
{ {
// Methods // Methods
QVariantMap params; QVariantMap returns; QVariantMap params; QVariantMap returns;
@ -62,7 +64,7 @@ SystemHandler::SystemHandler(System *system, QObject *parent):
params.insert("updateInProgress", JsonTypes::basicTypeToString(JsonTypes::Bool)); params.insert("updateInProgress", JsonTypes::basicTypeToString(JsonTypes::Bool));
setParams("UpdateStatusChanged", params); setParams("UpdateStatusChanged", params);
connect(m_system, &System::updateStatusChanged, this, &SystemHandler::onUpdateStatusChanged); connect(m_platform->updateController(), &PlatformUpdateController::updateStatusChanged, this, &SystemHandler::onUpdateStatusChanged);
} }
QString SystemHandler::name() const QString SystemHandler::name() const
@ -74,15 +76,15 @@ JsonReply *SystemHandler::GetCapabilities(const QVariantMap &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
QVariantMap data; QVariantMap data;
data.insert("powerManagement", m_system->powerManagementAvailable()); data.insert("powerManagement", m_platform->systemController()->powerManagementAvailable());
data.insert("updateManagement", m_system->updateManagementAvailable()); data.insert("updateManagement", m_platform->updateController()->updateManagementAvailable());
return createReply(data); return createReply(data);
} }
JsonReply *SystemHandler::Reboot(const QVariantMap &params) const JsonReply *SystemHandler::Reboot(const QVariantMap &params) const
{ {
Q_UNUSED(params); Q_UNUSED(params);
bool status = m_system->reboot(); bool status = m_platform->systemController()->reboot();
QVariantMap returns; QVariantMap returns;
returns.insert("success", status); returns.insert("success", status);
return createReply(returns); return createReply(returns);
@ -91,7 +93,7 @@ JsonReply *SystemHandler::Reboot(const QVariantMap &params) const
JsonReply *SystemHandler::Shutdown(const QVariantMap &params) const JsonReply *SystemHandler::Shutdown(const QVariantMap &params) const
{ {
Q_UNUSED(params); Q_UNUSED(params);
bool status = m_system->shutdown(); bool status = m_platform->systemController()->shutdown();
QVariantMap returns; QVariantMap returns;
returns.insert("success", status); returns.insert("success", status);
return createReply(returns); return createReply(returns);
@ -101,12 +103,12 @@ JsonReply *SystemHandler::GetUpdateStatus(const QVariantMap &params) const
{ {
Q_UNUSED(params); Q_UNUSED(params);
QVariantMap returns; QVariantMap returns;
returns.insert("updateAvailable", m_system->updateAvailable()); returns.insert("updateAvailable", m_platform->updateController()->updateAvailable());
returns.insert("currentVersion", m_system->currentVersion()); returns.insert("currentVersion", m_platform->updateController()->currentVersion());
returns.insert("candidateVersion", m_system->candidateVersion()); returns.insert("candidateVersion", m_platform->updateController()->candidateVersion());
returns.insert("availableChannels", m_system->availableChannels()); returns.insert("availableChannels", m_platform->updateController()->availableChannels());
returns.insert("currentChannel", m_system->currentChannel()); returns.insert("currentChannel", m_platform->updateController()->currentChannel());
returns.insert("updateInProgress", m_system->updateInProgress()); returns.insert("updateInProgress", m_platform->updateController()->updateInProgress());
return createReply(returns); return createReply(returns);
} }
@ -114,7 +116,7 @@ JsonReply *SystemHandler::StartUpdate(const QVariantMap &params)
{ {
Q_UNUSED(params) Q_UNUSED(params)
QVariantMap returns; QVariantMap returns;
bool success = m_system->startUpdate(); bool success = m_platform->updateController()->startUpdate();
returns.insert("success", success); returns.insert("success", success);
return createReply(returns); return createReply(returns);
} }
@ -124,8 +126,8 @@ JsonReply *SystemHandler::SelectChannel(const QVariantMap &params)
QString channel = params.value("channel").toString(); QString channel = params.value("channel").toString();
QVariantMap returns; QVariantMap returns;
if (m_system->availableChannels().contains(channel)) { if (m_platform->updateController()->availableChannels().contains(channel)) {
bool success = m_system->selectChannel(channel); bool success = m_platform->updateController()->selectChannel(channel);
returns.insert("success", success); returns.insert("success", success);
} else { } else {
returns.insert("success", false); returns.insert("success", false);
@ -136,12 +138,11 @@ JsonReply *SystemHandler::SelectChannel(const QVariantMap &params)
void SystemHandler::onUpdateStatusChanged() void SystemHandler::onUpdateStatusChanged()
{ {
QVariantMap params; QVariantMap params;
params.insert("updateAvailable", m_system->updateAvailable()); params.insert("updateAvailable", m_platform->updateController()->updateAvailable());
params.insert("currentVersion", m_system->currentVersion()); params.insert("currentVersion", m_platform->updateController()->currentVersion());
params.insert("candidateVersion", m_system->candidateVersion()); params.insert("candidateVersion", m_platform->updateController()->candidateVersion());
params.insert("availableChannels", m_system->availableChannels()); params.insert("availableChannels", m_platform->updateController()->availableChannels());
params.insert("currentChannel", m_system->currentChannel()); params.insert("currentChannel", m_platform->updateController()->currentChannel());
params.insert("updateInProgress", m_system->updateInProgress()); params.insert("updateInProgress", m_platform->updateController()->updateInProgress());
emit UpdateStatusChanged(params); emit UpdateStatusChanged(params);
} }

View File

@ -25,15 +25,15 @@
#include "jsonhandler.h" #include "jsonhandler.h"
namespace nymeaserver { #include "platform/platform.h"
class System; namespace nymeaserver {
class SystemHandler : public JsonHandler class SystemHandler : public JsonHandler
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit SystemHandler(System* system, QObject *parent = nullptr); explicit SystemHandler(Platform *platform, QObject *parent = nullptr);
QString name() const override; QString name() const override;
@ -52,7 +52,7 @@ signals:
private slots: private slots:
void onUpdateStatusChanged(); void onUpdateStatusChanged();
private: private:
System *m_system = nullptr; Platform *m_platform = nullptr;
}; };
} }

View File

@ -101,7 +101,6 @@ HEADERS += nymeacore.h \
cloud/cloudtransport.h \ cloud/cloudtransport.h \
debugreportgenerator.h \ debugreportgenerator.h \
platform/platform.h \ platform/platform.h \
system/system.h \
jsonrpc/systemhandler.h jsonrpc/systemhandler.h
SOURCES += nymeacore.cpp \ SOURCES += nymeacore.cpp \
@ -188,5 +187,4 @@ SOURCES += nymeacore.cpp \
cloud/cloudtransport.cpp \ cloud/cloudtransport.cpp \
debugreportgenerator.cpp \ debugreportgenerator.cpp \
platform/platform.cpp \ platform/platform.cpp \
system/system.cpp \
jsonrpc/systemhandler.cpp jsonrpc/systemhandler.cpp

View File

@ -112,7 +112,7 @@
#include "networkmanager/networkmanager.h" #include "networkmanager/networkmanager.h"
#include "nymeasettings.h" #include "nymeasettings.h"
#include "tagging/tagsstorage.h" #include "tagging/tagsstorage.h"
#include "system/system.h" #include "platform/platform.h"
#include "devicemanager.h" #include "devicemanager.h"
#include "plugin/device.h" #include "plugin/device.h"
@ -154,9 +154,6 @@ void NymeaCore::init() {
qCDebug(dcApplication()) << "Creating Time Manager"; qCDebug(dcApplication()) << "Creating Time Manager";
m_timeManager = new TimeManager(m_configuration->timeZone(), this); 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"; 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); 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; return m_tagsStorage;
} }
/*! Returns a pointer to the \l{System} instance owned by NymeaCore. */ /*! Returns a pointer to the \l{Platform} instance owned by NymeaCore.
System *NymeaCore::system() const 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 /*! 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.*/ here will be evaluated by the \l{RuleEngine} and the according \l{RuleAction}{RuleActions} are executed.*/
void NymeaCore::gotEvent(const Event &event) void NymeaCore::gotEvent(const Event &event)

View File

@ -90,7 +90,7 @@ public:
CloudManager *cloudManager() const; CloudManager *cloudManager() const;
DebugServerHandler *debugServerHandler() const; DebugServerHandler *debugServerHandler() const;
TagsStorage *tagsStorage() const; TagsStorage *tagsStorage() const;
System *system() const; Platform *platform() const;
static QStringList getAvailableLanguages(); static QStringList getAvailableLanguages();

View File

@ -1,5 +1,5 @@
#include "platform.h" #include "platform.h"
#include "plugin/platformplugin.h" #include "platform/platformplugin.h"
#include "loggingcategories.h" #include "loggingcategories.h"
@ -51,6 +51,7 @@ Platform::Platform(QObject *parent) : QObject(parent)
} }
if (!m_platformPlugin) { if (!m_platformPlugin) {
qCWarning(dcPlatform()) << "Could not load a platform plugin. Platform related features won't be available."; qCWarning(dcPlatform()) << "Could not load a platform plugin. Platform related features won't be available.";
m_platformPlugin = new PlatformPlugin(this);
} }
} }

View File

@ -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();
}
}

View File

@ -1,45 +0,0 @@
#ifndef SYSTEM_H
#define SYSTEM_H
#include <QObject>
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

View File

@ -66,9 +66,9 @@ HEADERS += devicemanager.h \
network/mqtt/mqttprovider.h \ network/mqtt/mqttprovider.h \
network/mqtt/mqttchannel.h \ network/mqtt/mqttchannel.h \
translator.h \ translator.h \
plugin/platformplugin.h \ platform/platformplugin.h \
plugin/platformsystemcontroller.h \ platform/platformsystemcontroller.h \
plugin/platformupdatecontroller.h platform/platformupdatecontroller.h
SOURCES += devicemanager.cpp \ SOURCES += devicemanager.cpp \
loggingcategories.cpp \ loggingcategories.cpp \
@ -124,9 +124,9 @@ SOURCES += devicemanager.cpp \
network/mqtt/mqttprovider.cpp \ network/mqtt/mqttprovider.cpp \
network/mqtt/mqttchannel.cpp \ network/mqtt/mqttchannel.cpp \
translator.cpp \ translator.cpp \
plugin/platformplugin.cpp \ platform/platformplugin.cpp \
plugin/platformsystemcontroller.cpp \ platform/platformsystemcontroller.cpp \
plugin/platformupdatecontroller.cpp platform/platformupdatecontroller.cpp
RESOURCES += \ RESOURCES += \

View File

@ -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;
}

View File

@ -15,8 +15,12 @@ public:
explicit PlatformPlugin(QObject *parent = nullptr); explicit PlatformPlugin(QObject *parent = nullptr);
virtual ~PlatformPlugin() = default; virtual ~PlatformPlugin() = default;
virtual PlatformSystemController *systemController() const = 0; virtual PlatformSystemController *systemController() const;
virtual PlatformUpdateController *updateController() const = 0; virtual PlatformUpdateController *updateController() const;
private:
PlatformSystemController *m_systemStub = nullptr;
PlatformUpdateController *m_updateStub = nullptr;
}; };
Q_DECLARE_INTERFACE(PlatformPlugin, "io.nymea.PlatformPlugin") Q_DECLARE_INTERFACE(PlatformPlugin, "io.nymea.PlatformPlugin")

View File

@ -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;
}

View File

@ -7,20 +7,12 @@ class PlatformSystemController : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
enum Capability {
CapabilityNone = 0x00,
CapabilityPower = 0x01,
CapabilityAll = 0xFF
};
Q_ENUM(Capability)
Q_DECLARE_FLAGS(Capabilities, Capability)
explicit PlatformSystemController(QObject *parent = nullptr); explicit PlatformSystemController(QObject *parent = nullptr);
virtual ~PlatformSystemController() = default; virtual ~PlatformSystemController() = default;
virtual Capabilities capabilities() const = 0; virtual bool powerManagementAvailable() const;
virtual bool reboot() = 0; virtual bool reboot();
virtual bool shutdown() = 0; virtual bool shutdown();
}; };
#endif // PLATFORMSYSTEMCONTROLLER_H #endif // PLATFORMSYSTEMCONTROLLER_H

View File

@ -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;
}

View File

@ -0,0 +1,37 @@
#ifndef PLATFORMUPDATECONTROLLER_H
#define PLATFORMUPDATECONTROLLER_H
#include <QObject>
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<QString, QString> 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

View File

@ -1,6 +0,0 @@
#include "platformplugin.h"
PlatformPlugin::PlatformPlugin(QObject *parent) : QObject(parent)
{
}

View File

@ -1,6 +0,0 @@
#include "platformsystemcontroller.h"
PlatformSystemController::PlatformSystemController(QObject *parent) : QObject(parent)
{
}

View File

@ -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;
}

View File

@ -1,37 +0,0 @@
#ifndef PLATFORMUPDATECONTROLLER_H
#define PLATFORMUPDATECONTROLLER_H
#include <QObject>
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<QString, QString> 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