Simplify it a bit

pull/149/head
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 "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);

View File

@ -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 &params)
{
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 &params) 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 &params) const
JsonReply *SystemHandler::Shutdown(const QVariantMap &params) 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 &params) 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 &params)
{
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 &params)
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 &params)
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);
}

View File

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

View File

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

View File

@ -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)

View File

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

View File

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

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/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 += \

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);
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")

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
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

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