From 28624e264df554fef94acaa84a91c6c7ca031283 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Fri, 1 May 2020 20:45:19 +0200 Subject: [PATCH] Add support for restarting nymea in system api --- debian/control | 2 +- libnymea-core/jsonrpc/systemhandler.cpp | 16 +++++++++++++++- libnymea-core/jsonrpc/systemhandler.h | 1 + libnymea/platform/platformsystemcontroller.cpp | 5 +++++ libnymea/platform/platformsystemcontroller.h | 1 + nymea.pro | 2 +- tests/auto/api.json | 12 ++++++++++-- 7 files changed, 34 insertions(+), 5 deletions(-) diff --git a/debian/control b/debian/control index 13dcc03a..8913230d 100644 --- a/debian/control +++ b/debian/control @@ -161,7 +161,7 @@ Depends: ${shlibs:Depends}, Replaces: libguh1 Provides: nymea-update-plugin-api-1, nymea-zeroconf-plugin-api-1, - nymea-system-plugin-api-1 + nymea-system-plugin-api-2 Description: An open source IoT server - core library The nymea daemon is a plugin based IoT (Internet of Things) server. The server works like a translator for devices, things and services and diff --git a/libnymea-core/jsonrpc/systemhandler.cpp b/libnymea-core/jsonrpc/systemhandler.cpp index 61ae5f29..81a2396d 100644 --- a/libnymea-core/jsonrpc/systemhandler.cpp +++ b/libnymea-core/jsonrpc/systemhandler.cpp @@ -47,7 +47,7 @@ SystemHandler::SystemHandler(Platform *platform, QObject *parent): // Methods QString description; QVariantMap params; QVariantMap returns; description = "Get the list of capabilites on this system. The property \"powerManagement\" indicates whether " - "rebooting or shutting down is supported on this system. The property \"updateManagement indicates " + "restarting nymea and rebooting or shutting down is supported on this system. The property \"updateManagement indicates " "whether system update features are available in this system. The property \"timeManagement\" " "indicates whether the system time can be configured on this system. Note that GetTime will be " "available in any case."; @@ -56,6 +56,11 @@ SystemHandler::SystemHandler(Platform *platform, QObject *parent): returns.insert("timeManagement", enumValueName(Bool)); registerMethod("GetCapabilities", description, params, returns); + params.clear(); returns.clear(); + description = "Initiate a restart of the nymea service. The return value will indicate whether the procedure has been initiated successfully."; + returns.insert("success", enumValueName(Bool)); + registerMethod("Restart", description, params, returns); + params.clear(); returns.clear(); description = "Initiate a reboot of the system. The return value will indicate whether the procedure has been initiated successfully."; returns.insert("success", enumValueName(Bool)); @@ -283,6 +288,15 @@ JsonReply *SystemHandler::GetCapabilities(const QVariantMap ¶ms) return createReply(data); } +JsonReply *SystemHandler::Restart(const QVariantMap ¶ms) const +{ + Q_UNUSED(params) + bool status = m_platform->systemController()->restart(); + QVariantMap returns; + returns.insert("success", status); + return createReply(returns); +} + JsonReply *SystemHandler::Reboot(const QVariantMap ¶ms) const { Q_UNUSED(params) diff --git a/libnymea-core/jsonrpc/systemhandler.h b/libnymea-core/jsonrpc/systemhandler.h index d5b1833c..ee8e2043 100644 --- a/libnymea-core/jsonrpc/systemhandler.h +++ b/libnymea-core/jsonrpc/systemhandler.h @@ -51,6 +51,7 @@ public: Q_INVOKABLE JsonReply *GetCapabilities(const QVariantMap ¶ms); + Q_INVOKABLE JsonReply *Restart(const QVariantMap ¶ms) const; Q_INVOKABLE JsonReply *Reboot(const QVariantMap ¶ms) const; Q_INVOKABLE JsonReply *Shutdown(const QVariantMap ¶ms) const; diff --git a/libnymea/platform/platformsystemcontroller.cpp b/libnymea/platform/platformsystemcontroller.cpp index 98dea803..2666ff3e 100644 --- a/libnymea/platform/platformsystemcontroller.cpp +++ b/libnymea/platform/platformsystemcontroller.cpp @@ -42,6 +42,11 @@ bool PlatformSystemController::powerManagementAvailable() const return false; } +bool PlatformSystemController::restart() +{ + return false; +} + bool PlatformSystemController::reboot() { return false; diff --git a/libnymea/platform/platformsystemcontroller.h b/libnymea/platform/platformsystemcontroller.h index c9fa8f15..9206d475 100644 --- a/libnymea/platform/platformsystemcontroller.h +++ b/libnymea/platform/platformsystemcontroller.h @@ -42,6 +42,7 @@ public: virtual ~PlatformSystemController() = default; virtual bool powerManagementAvailable() const; + virtual bool restart(); virtual bool reboot(); virtual bool shutdown(); diff --git a/nymea.pro b/nymea.pro index 94a7cd35..1f3b20ef 100644 --- a/nymea.pro +++ b/nymea.pro @@ -5,7 +5,7 @@ NYMEA_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p" # define protocol versions JSON_PROTOCOL_VERSION_MAJOR=5 -JSON_PROTOCOL_VERSION_MINOR=0 +JSON_PROTOCOL_VERSION_MINOR=1 JSON_PROTOCOL_VERSION="$${JSON_PROTOCOL_VERSION_MAJOR}.$${JSON_PROTOCOL_VERSION_MINOR}" LIBNYMEA_API_VERSION_MAJOR=5 LIBNYMEA_API_VERSION_MINOR=0 diff --git a/tests/auto/api.json b/tests/auto/api.json index 92665af5..da334d21 100644 --- a/tests/auto/api.json +++ b/tests/auto/api.json @@ -1,4 +1,4 @@ -5.0 +5.1 { "enums": { "BasicType": [ @@ -1653,7 +1653,7 @@ } }, "System.GetCapabilities": { - "description": "Get the list of capabilites on this system. The property \"powerManagement\" indicates whether rebooting or shutting down is supported on this system. The property \"updateManagement indicates whether system update features are available in this system. The property \"timeManagement\" indicates whether the system time can be configured on this system. Note that GetTime will be available in any case.", + "description": "Get the list of capabilites on this system. The property \"powerManagement\" indicates whether restarting nymea and rebooting or shutting down is supported on this system. The property \"updateManagement indicates whether system update features are available in this system. The property \"timeManagement\" indicates whether the system time can be configured on this system. Note that GetTime will be available in any case.", "params": { }, "returns": { @@ -1725,6 +1725,14 @@ "success": "Bool" } }, + "System.Restart": { + "description": "Initiate a restart of the nymea service. The return value will indicate whether the procedure has been initiated successfully.", + "params": { + }, + "returns": { + "success": "Bool" + } + }, "System.RollbackPackages": { "description": "Starts a rollback. Returns true if the rollback has been started successfully. Before calling this method, clients should check whether the package can be rolled back (canRollback set to true).", "params": {