From 125106309b16394fdb4e9f117eb770aeeed779d2 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 29 Jun 2021 12:38:19 +0200 Subject: [PATCH] Simplify json notification api --- libnymea-app/appdata.cpp | 9 +--- libnymea-app/appdata.h | 7 +-- libnymea-app/configuration/networkmanager.cpp | 9 +--- libnymea-app/configuration/networkmanager.h | 6 +-- .../configuration/nymeaconfiguration.cpp | 9 +--- .../configuration/nymeaconfiguration.h | 6 +-- libnymea-app/jsonrpc/jsonhandler.cpp | 36 ------------- libnymea-app/jsonrpc/jsonhandler.h | 45 ----------------- libnymea-app/jsonrpc/jsonrpcclient.cpp | 30 ++++++----- libnymea-app/jsonrpc/jsonrpcclient.h | 16 +++--- libnymea-app/libnymea-app.pri | 2 - libnymea-app/logmanager.cpp | 9 +--- libnymea-app/logmanager.h | 6 +-- libnymea-app/modbus/modbusrtumanager.cpp | 9 +--- libnymea-app/modbus/modbusrtumanager.h | 5 +- libnymea-app/models/barseriesadapter.cpp | 2 + libnymea-app/models/logsmodel.h | 1 - libnymea-app/models/xyseriesadapter.cpp | 2 + libnymea-app/rulemanager.cpp | 9 +--- libnymea-app/rulemanager.h | 5 +- libnymea-app/scriptmanager.cpp | 13 ++--- libnymea-app/scriptmanager.h | 4 +- libnymea-app/system/systemcontroller.cpp | 9 +--- libnymea-app/system/systemcontroller.h | 3 +- libnymea-app/tagsmanager.cpp | 9 +--- libnymea-app/tagsmanager.h | 4 +- libnymea-app/thingmanager.cpp | 9 +--- libnymea-app/thingmanager.h | 50 +------------------ libnymea-app/usermanager.cpp | 9 +--- libnymea-app/usermanager.h | 4 +- libnymea-app/zigbee/zigbeemanager.cpp | 9 +--- libnymea-app/zigbee/zigbeemanager.h | 5 +- 32 files changed, 69 insertions(+), 282 deletions(-) delete mode 100644 libnymea-app/jsonrpc/jsonhandler.cpp delete mode 100644 libnymea-app/jsonrpc/jsonhandler.h diff --git a/libnymea-app/appdata.cpp b/libnymea-app/appdata.cpp index 19b57923..caf6c65f 100644 --- a/libnymea-app/appdata.cpp +++ b/libnymea-app/appdata.cpp @@ -8,7 +8,7 @@ #include "logging.h" NYMEA_LOGGING_CATEGORY(dcAppData, "AppData") -AppData::AppData(QObject *parent) : JsonHandler(parent) +AppData::AppData(QObject *parent) : QObject(parent) { m_syncTimer.setSingleShot(true); connect(&m_syncTimer, &QTimer::timeout, this, &AppData::store); @@ -43,11 +43,6 @@ void AppData::componentComplete() load(); } -QString AppData::nameSpace() const -{ - return "AppData"; -} - Engine *AppData::engine() const { return m_engine; @@ -66,7 +61,7 @@ void AppData::setEngine(Engine *engine) m_engine = engine; if (m_engine) { - m_engine->jsonRpcClient()->registerNotificationHandler(this, "notificationReceived"); + m_engine->jsonRpcClient()->registerNotificationHandler(this, "AppData", "notificationReceived"); } emit engineChanged(); } diff --git a/libnymea-app/appdata.h b/libnymea-app/appdata.h index bd36315e..9ca8f290 100644 --- a/libnymea-app/appdata.h +++ b/libnymea-app/appdata.h @@ -1,14 +1,13 @@ #ifndef APPDATA_H #define APPDATA_H -#include "jsonrpc/jsonhandler.h" - #include #include +#include class Engine; -class AppData : public JsonHandler, public QQmlParserStatus +class AppData : public QObject, public QQmlParserStatus { Q_OBJECT Q_INTERFACES(QQmlParserStatus) @@ -22,8 +21,6 @@ public: void classBegin() override; void componentComplete() override; - QString nameSpace() const override; - Engine *engine() const; void setEngine(Engine *engine); diff --git a/libnymea-app/configuration/networkmanager.cpp b/libnymea-app/configuration/networkmanager.cpp index c1ad6396..0312f916 100644 --- a/libnymea-app/configuration/networkmanager.cpp +++ b/libnymea-app/configuration/networkmanager.cpp @@ -41,7 +41,7 @@ #include NetworkManager::NetworkManager(QObject *parent): - JsonHandler(parent), + QObject(parent), m_wiredNetworkDevices(new WiredNetworkDevices(this)), m_wirelessNetworkDevices(new WirelessNetworkDevices(this)) { @@ -64,7 +64,7 @@ void NetworkManager::setEngine(Engine *engine) m_engine = engine; emit engineChanged(); - m_engine->jsonRpcClient()->registerNotificationHandler(this, "notificationReceived"); + m_engine->jsonRpcClient()->registerNotificationHandler(this, "NetworkManager", "notificationReceived"); init(); connect(m_engine->jsonRpcClient(), &JsonRpcClient::connectedChanged, this, &NetworkManager::init); @@ -80,11 +80,6 @@ bool NetworkManager::loading() return m_loading; } -QString NetworkManager::nameSpace() const -{ - return "NetworkManager"; -} - void NetworkManager::init() { m_wiredNetworkDevices->clear(); diff --git a/libnymea-app/configuration/networkmanager.h b/libnymea-app/configuration/networkmanager.h index 75a7b9e5..29e9661b 100644 --- a/libnymea-app/configuration/networkmanager.h +++ b/libnymea-app/configuration/networkmanager.h @@ -34,14 +34,12 @@ #include #include -#include "jsonrpc/jsonhandler.h" - class Engine; class NetworkDevices; class WiredNetworkDevices; class WirelessNetworkDevices; -class NetworkManager : public JsonHandler +class NetworkManager : public QObject { Q_OBJECT Q_PROPERTY(Engine *engine READ engine WRITE setEngine NOTIFY engineChanged) @@ -77,8 +75,6 @@ public: bool loading(); - QString nameSpace() const override; - bool available() const; NetworkManagerState state() const; bool networkingEnabled() const; diff --git a/libnymea-app/configuration/nymeaconfiguration.cpp b/libnymea-app/configuration/nymeaconfiguration.cpp index 7e739f7e..097287d1 100644 --- a/libnymea-app/configuration/nymeaconfiguration.cpp +++ b/libnymea-app/configuration/nymeaconfiguration.cpp @@ -44,7 +44,7 @@ NYMEA_LOGGING_CATEGORY(dcNymeaConfiguration, "NymeaConfiguration") NymeaConfiguration::NymeaConfiguration(JsonRpcClient *client, QObject *parent): - JsonHandler(parent), + QObject(parent), m_client(client), m_tcpServerConfigurations(new ServerConfigurations(this)), m_webSocketServerConfigurations(new ServerConfigurations(this)), @@ -52,12 +52,7 @@ NymeaConfiguration::NymeaConfiguration(JsonRpcClient *client, QObject *parent): m_mqttServerConfigurations(new ServerConfigurations(this)), m_mqttPolicies(new MqttPolicies(this)) { - client->registerNotificationHandler(this, "notificationReceived"); -} - -QString NymeaConfiguration::nameSpace() const -{ - return "Configuration"; + client->registerNotificationHandler(this, "Configuration", "notificationReceived"); } void NymeaConfiguration::init() diff --git a/libnymea-app/configuration/nymeaconfiguration.h b/libnymea-app/configuration/nymeaconfiguration.h index 30ebb5d8..9f752d03 100644 --- a/libnymea-app/configuration/nymeaconfiguration.h +++ b/libnymea-app/configuration/nymeaconfiguration.h @@ -33,8 +33,6 @@ #include -#include "jsonrpc/jsonhandler.h" - class JsonRpcClient; class ServerConfiguration; class ServerConfigurations; @@ -43,7 +41,7 @@ class WebServerConfigurations; class MqttPolicy; class MqttPolicies; -class NymeaConfiguration : public JsonHandler +class NymeaConfiguration : public QObject { Q_OBJECT @@ -62,8 +60,6 @@ class NymeaConfiguration : public JsonHandler public: explicit NymeaConfiguration(JsonRpcClient* client, QObject *parent = nullptr); - QString nameSpace() const override; - QString serverName() const; void setServerName(const QString &serverName); diff --git a/libnymea-app/jsonrpc/jsonhandler.cpp b/libnymea-app/jsonrpc/jsonhandler.cpp deleted file mode 100644 index b3fd7548..00000000 --- a/libnymea-app/jsonrpc/jsonhandler.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* -* Copyright 2013 - 2020, nymea GmbH -* Contact: contact@nymea.io -* -* This file is part of nymea. -* This project including source code and documentation is protected by -* copyright law, and remains the property of nymea GmbH. All rights, including -* reproduction, publication, editing and translation, are reserved. The use of -* this project is subject to the terms of a license agreement to be concluded -* with nymea GmbH in accordance with the terms of use of nymea GmbH, available -* under https://nymea.io/license -* -* GNU General Public License Usage -* Alternatively, this project may be redistributed and/or modified under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, GNU version 3. This project is distributed in the hope that it -* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -* Public License for more details. -* -* You should have received a copy of the GNU General Public License along with -* this project. If not, see . -* -* For any further details and any questions please contact us under -* contact@nymea.io or see our FAQ/Licensing Information on -* https://nymea.io/license/faq -* -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#include "jsonhandler.h" - -JsonHandler::JsonHandler(QObject *parent) : - QObject(parent) -{ -} diff --git a/libnymea-app/jsonrpc/jsonhandler.h b/libnymea-app/jsonrpc/jsonhandler.h deleted file mode 100644 index 7a44c507..00000000 --- a/libnymea-app/jsonrpc/jsonhandler.h +++ /dev/null @@ -1,45 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * -* -* Copyright 2013 - 2020, nymea GmbH -* Contact: contact@nymea.io -* -* This file is part of nymea. -* This project including source code and documentation is protected by -* copyright law, and remains the property of nymea GmbH. All rights, including -* reproduction, publication, editing and translation, are reserved. The use of -* this project is subject to the terms of a license agreement to be concluded -* with nymea GmbH in accordance with the terms of use of nymea GmbH, available -* under https://nymea.io/license -* -* GNU General Public License Usage -* Alternatively, this project may be redistributed and/or modified under the -* terms of the GNU General Public License as published by the Free Software -* Foundation, GNU version 3. This project is distributed in the hope that it -* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty -* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -* Public License for more details. -* -* You should have received a copy of the GNU General Public License along with -* this project. If not, see . -* -* For any further details and any questions please contact us under -* contact@nymea.io or see our FAQ/Licensing Information on -* https://nymea.io/license/faq -* -* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#ifndef JSONHANDLER_H -#define JSONHANDLER_H - -#include -#include - -class JsonHandler : public QObject -{ - Q_OBJECT -public: - JsonHandler(QObject *parent = nullptr); - virtual QString nameSpace() const = 0; -}; - -#endif // JSONHANDLER_H diff --git a/libnymea-app/jsonrpc/jsonrpcclient.cpp b/libnymea-app/jsonrpc/jsonrpcclient.cpp index 20884f18..aa3ac5df 100644 --- a/libnymea-app/jsonrpc/jsonrpcclient.cpp +++ b/libnymea-app/jsonrpc/jsonrpcclient.cpp @@ -53,7 +53,7 @@ NYMEA_LOGGING_CATEGORY(dcJsonRpc, "JsonRpc") JsonRpcClient::JsonRpcClient(QObject *parent) : - JsonHandler(parent), + QObject(parent), m_id(0) { m_connection = new NymeaConnection(this); @@ -69,28 +69,25 @@ JsonRpcClient::JsonRpcClient(QObject *parent) : connect(m_connection, &NymeaConnection::currentConnectionChanged, this, &JsonRpcClient:: currentConnectionChanged); connect(m_connection, &NymeaConnection::dataAvailable, this, &JsonRpcClient::dataReceived); - registerNotificationHandler(this, "notificationReceived"); + registerNotificationHandler(this, QStringLiteral("JSONRPC"), "notificationReceived"); } -QString JsonRpcClient::nameSpace() const -{ - return QStringLiteral("JSONRPC"); -} - -void JsonRpcClient::registerNotificationHandler(JsonHandler *handler, const QString &method) +void JsonRpcClient::registerNotificationHandler(QObject *handler, const QString &nameSpace, const QString &method) { if (m_notificationHandlerMethods.contains(handler)) { qWarning() << "Notification handler" << handler << " already registered"; return; } - m_notificationHandlers.insert(handler->nameSpace(), handler); + m_notificationHandlers.insert(nameSpace, handler); m_notificationHandlerMethods.insert(handler, method); setNotificationsEnabled(); } -void JsonRpcClient::unregisterNotificationHandler(JsonHandler *handler) +void JsonRpcClient::unregisterNotificationHandler(QObject *handler) { - m_notificationHandlers.remove(handler->nameSpace(), handler); + foreach (const QString nameSpace, m_notificationHandlers.keys(handler)) { + m_notificationHandlers.remove(nameSpace, handler); + } m_notificationHandlerMethods.remove(handler); setNotificationsEnabled(); } @@ -358,6 +355,11 @@ QString JsonRpcClient::serverQtBuildVersion() return m_serverQtBuildVersion; } +QVariantMap JsonRpcClient::experiences() const +{ + return m_experiences; +} + int JsonRpcClient::createUser(const QString &username, const QString &password) { QVariantMap params; @@ -572,7 +574,7 @@ void JsonRpcClient::dataReceived(const QByteArray &data) // qDebug() << "Incoming notification:" << jsonDoc.toJson(); QStringList notification = dataMap.value("notification").toString().split("."); QString nameSpace = notification.first(); - foreach (JsonHandler *handler, m_notificationHandlers.values(nameSpace)) { + foreach (QObject *handler, m_notificationHandlers.values(nameSpace)) { QMetaObject::invokeMethod(handler, m_notificationHandlerMethods.value(handler).toLatin1().data(), Q_ARG(QVariantMap, dataMap)); } return; @@ -644,6 +646,10 @@ void JsonRpcClient::helloReply(int /*commandId*/, const QVariantMap ¶ms) m_serverUuid = params.value("uuid").toString(); m_serverVersion = params.value("version").toString(); + m_experiences.clear(); + foreach (const QVariant &experience, params.value("experiences").toList()) { + m_experiences.insert(experience.toMap().value("name").toString(), experience.toMap().value("version").toString()); + } QString protoVersionString = params.value("protocol version").toString(); if (!protoVersionString.contains('.')) { diff --git a/libnymea-app/jsonrpc/jsonrpcclient.h b/libnymea-app/jsonrpc/jsonrpcclient.h index 1e169f1f..557eae0d 100644 --- a/libnymea-app/jsonrpc/jsonrpcclient.h +++ b/libnymea-app/jsonrpc/jsonrpcclient.h @@ -37,13 +37,12 @@ #include #include "connection/nymeaconnection.h" -#include "jsonhandler.h" class JsonRpcReply; class Param; class Params; -class JsonRpcClient : public JsonHandler +class JsonRpcClient : public QObject { Q_OBJECT Q_PROPERTY(NymeaConnection::BearerTypes availableBearerTypes READ availableBearerTypes NOTIFY availableBearerTypesChanged) @@ -62,6 +61,7 @@ class JsonRpcClient : public JsonHandler Q_PROPERTY(QString serverQtVersion READ serverQtVersion NOTIFY serverQtVersionChanged) Q_PROPERTY(QString serverQtBuildVersion READ serverQtBuildVersion NOTIFY serverQtVersionChanged) Q_PROPERTY(QVariantMap certificateIssuerInfo READ certificateIssuerInfo NOTIFY currentConnectionChanged) + Q_PROPERTY(QVariantMap experiences READ experiences NOTIFY currentConnectionChanged) public: enum CloudConnectionState { @@ -74,10 +74,8 @@ public: explicit JsonRpcClient(QObject *parent = nullptr); - QString nameSpace() const override; - - void registerNotificationHandler(JsonHandler *handler, const QString &method); - void unregisterNotificationHandler(JsonHandler *handler); + void registerNotificationHandler(QObject *handler, const QString &nameSpace, const QString &method); + void unregisterNotificationHandler(QObject *handler); int sendCommand(const QString &method, const QVariantMap ¶ms, QObject *caller = nullptr, const QString &callbackMethod = QString()); int sendCommand(const QString &method, QObject *caller = nullptr, const QString &callbackMethod = QString()); @@ -101,6 +99,7 @@ public: QString serverUuid() const; QString serverQtVersion(); QString serverQtBuildVersion(); + QVariantMap experiences() const; // ui methods Q_INVOKABLE void connectToHost(NymeaHost *host, Connection *connection = nullptr); @@ -150,8 +149,8 @@ private slots: private: int m_id; // < namespace, method> > - QHash m_notificationHandlerMethods; - QMultiHash m_notificationHandlers; + QHash m_notificationHandlerMethods; + QMultiHash m_notificationHandlers; QHash m_replies; NymeaConnection *m_connection = nullptr; @@ -172,6 +171,7 @@ private: QByteArray m_token; QByteArray m_receiveBuffer; QHash m_cacheHashes; + QVariantMap m_experiences; void setNotificationsEnabled(); void getCloudConnectionStatus(); diff --git a/libnymea-app/libnymea-app.pri b/libnymea-app/libnymea-app.pri index ded89edb..dd779de7 100644 --- a/libnymea-app/libnymea-app.pri +++ b/libnymea-app/libnymea-app.pri @@ -121,7 +121,6 @@ SOURCES += \ $${PWD}/connection/discovery/bluetoothservicediscovery.cpp \ $${PWD}/thingmanager.cpp \ $${PWD}/jsonrpc/jsonrpcclient.cpp \ - $${PWD}/jsonrpc/jsonhandler.cpp \ $${PWD}/things.cpp \ $${PWD}/thingsproxy.cpp \ $${PWD}/thingclasses.cpp \ @@ -279,7 +278,6 @@ HEADERS += \ $${PWD}/connection/discovery/bluetoothservicediscovery.h \ $${PWD}/thingmanager.h \ $${PWD}/jsonrpc/jsonrpcclient.h \ - $${PWD}/jsonrpc/jsonhandler.h \ $${PWD}/things.h \ $${PWD}/thingsproxy.h \ $${PWD}/thingclasses.h \ diff --git a/libnymea-app/logmanager.cpp b/libnymea-app/logmanager.cpp index 3976c6e2..633904e4 100644 --- a/libnymea-app/logmanager.cpp +++ b/libnymea-app/logmanager.cpp @@ -33,15 +33,10 @@ #include "engine.h" LogManager::LogManager(JsonRpcClient *jsonClient, QObject *parent) : - JsonHandler(parent), + QObject(parent), m_client(jsonClient) { - m_client->registerNotificationHandler(this, "notificationReceived"); -} - -QString LogManager::nameSpace() const -{ - return "Logging"; + m_client->registerNotificationHandler(this, "Logging", "notificationReceived"); } void LogManager::notificationReceived(const QVariantMap &data) diff --git a/libnymea-app/logmanager.h b/libnymea-app/logmanager.h index d36bfec5..5a2945d1 100644 --- a/libnymea-app/logmanager.h +++ b/libnymea-app/logmanager.h @@ -33,18 +33,14 @@ #include -#include "jsonrpc/jsonhandler.h" - class JsonRpcClient; -class LogManager : public JsonHandler +class LogManager : public QObject { Q_OBJECT public: explicit LogManager(JsonRpcClient *jsonClient, QObject *parent = nullptr); - QString nameSpace() const override; - signals: void logEntryReceived(const QVariantMap &data); diff --git a/libnymea-app/modbus/modbusrtumanager.cpp b/libnymea-app/modbus/modbusrtumanager.cpp index 22daae60..493faea7 100644 --- a/libnymea-app/modbus/modbusrtumanager.cpp +++ b/libnymea-app/modbus/modbusrtumanager.cpp @@ -38,7 +38,7 @@ #include ModbusRtuManager::ModbusRtuManager(QObject *parent) : - JsonHandler(parent), + QObject(parent), m_serialPorts(new SerialPorts(this)), m_modbusRtuMasters(new ModbusRtuMasters(this)) { @@ -54,11 +54,6 @@ ModbusRtuManager::~ModbusRtuManager() } } -QString ModbusRtuManager::nameSpace() const -{ - return "ModbusRtu"; -} - Engine *ModbusRtuManager::engine() const { return m_engine; @@ -137,7 +132,7 @@ void ModbusRtuManager::init() m_serialPorts->clear(); m_modbusRtuMasters->clear(); - m_engine->jsonRpcClient()->registerNotificationHandler(this, "notificationReceived"); + m_engine->jsonRpcClient()->registerNotificationHandler(this, "ModbusRtu", "notificationReceived"); m_engine->jsonRpcClient()->sendCommand("ModbusRtu.GetModbusRtuMasters", this, "getModbusRtuMastersResponse"); } diff --git a/libnymea-app/modbus/modbusrtumanager.h b/libnymea-app/modbus/modbusrtumanager.h index e40b8b5b..61ea64d5 100644 --- a/libnymea-app/modbus/modbusrtumanager.h +++ b/libnymea-app/modbus/modbusrtumanager.h @@ -34,14 +34,13 @@ #include #include "types/serialports.h" -#include "jsonrpc/jsonhandler.h" class Engine; class JsonRpcClient; class ModbusRtuMaster; class ModbusRtuMasters; -class ModbusRtuManager : public JsonHandler +class ModbusRtuManager : public QObject { Q_OBJECT Q_PROPERTY(Engine *engine READ engine WRITE setEngine NOTIFY engineChanged) @@ -53,8 +52,6 @@ public: explicit ModbusRtuManager(QObject *parent = nullptr); ~ModbusRtuManager(); - QString nameSpace() const override; - Engine *engine() const; void setEngine(Engine *engine); diff --git a/libnymea-app/models/barseriesadapter.cpp b/libnymea-app/models/barseriesadapter.cpp index 5c1e9fd2..778907a2 100644 --- a/libnymea-app/models/barseriesadapter.cpp +++ b/libnymea-app/models/barseriesadapter.cpp @@ -1,5 +1,7 @@ #include "barseriesadapter.h" +#include + BarSeriesAdapter::BarSeriesAdapter(QObject *parent) : QObject(parent) { diff --git a/libnymea-app/models/logsmodel.h b/libnymea-app/models/logsmodel.h index f52179d2..efc07ad4 100644 --- a/libnymea-app/models/logsmodel.h +++ b/libnymea-app/models/logsmodel.h @@ -34,7 +34,6 @@ #include #include -#include "jsonrpc/jsonhandler.h" #include "types/logentry.h" class Engine; diff --git a/libnymea-app/models/xyseriesadapter.cpp b/libnymea-app/models/xyseriesadapter.cpp index 5d431ee8..5c26253e 100644 --- a/libnymea-app/models/xyseriesadapter.cpp +++ b/libnymea-app/models/xyseriesadapter.cpp @@ -1,5 +1,7 @@ #include "xyseriesadapter.h" +#include + XYSeriesAdapter::XYSeriesAdapter(QObject *parent) : QObject(parent) { diff --git a/libnymea-app/rulemanager.cpp b/libnymea-app/rulemanager.cpp index d906d7bb..b18e6e01 100644 --- a/libnymea-app/rulemanager.cpp +++ b/libnymea-app/rulemanager.cpp @@ -55,16 +55,11 @@ NYMEA_LOGGING_CATEGORY(dcRuleManager, "RuleManager") #include RuleManager::RuleManager(JsonRpcClient* jsonClient, QObject *parent) : - JsonHandler(parent), + QObject(parent), m_jsonClient(jsonClient), m_rules(new Rules(this)) { - m_jsonClient->registerNotificationHandler(this, "handleRulesNotification"); -} - -QString RuleManager::nameSpace() const -{ - return "Rules"; + m_jsonClient->registerNotificationHandler(this, "Rules", "handleRulesNotification"); } void RuleManager::clear() diff --git a/libnymea-app/rulemanager.h b/libnymea-app/rulemanager.h index 67d5b2dc..33b9203c 100644 --- a/libnymea-app/rulemanager.h +++ b/libnymea-app/rulemanager.h @@ -34,7 +34,6 @@ #include #include "types/rules.h" -#include "jsonrpc/jsonhandler.h" class JsonRpcClient; class EventDescriptors; @@ -46,7 +45,7 @@ class StateEvaluator; class RuleAction; class RuleActions; -class RuleManager : public JsonHandler +class RuleManager : public QObject { Q_OBJECT Q_PROPERTY(Rules* rules READ rules CONSTANT) @@ -82,8 +81,6 @@ public: explicit RuleManager(JsonRpcClient *jsonClient, QObject *parent = nullptr); - QString nameSpace() const override; - void clear(); void init(); bool fetchingData() const; diff --git a/libnymea-app/scriptmanager.cpp b/libnymea-app/scriptmanager.cpp index e4bbe17e..41426fd6 100644 --- a/libnymea-app/scriptmanager.cpp +++ b/libnymea-app/scriptmanager.cpp @@ -37,12 +37,12 @@ NYMEA_LOGGING_CATEGORY(dcScriptManager, "Scripts") ScriptManager::ScriptManager(JsonRpcClient *jsonClient, QObject *parent): - JsonHandler(parent), + QObject(parent), m_client(jsonClient) { m_scripts = new Scripts(this); - m_client->registerNotificationHandler(this, "onNotificationReceived"); + m_client->registerNotificationHandler(this, "Scripts", "onNotificationReceived"); } void ScriptManager::init() @@ -58,11 +58,6 @@ bool ScriptManager::fetchingData() const return m_fetchingData; } -QString ScriptManager::nameSpace() const -{ - return "Scripts"; -} - Scripts *ScriptManager::scripts() const { return m_scripts; @@ -155,7 +150,7 @@ void ScriptManager::onScriptRemoved(int commandId, const QVariantMap ¶ms) void ScriptManager::onNotificationReceived(const QVariantMap ¶ms) { - qDebug() << "noticication" << params.value("notification").toString(); + qCDebug(dcScriptManager()) << "noticication" << params.value("notification").toString(); if (params.value("notification").toString() == "Scripts.ScriptLogMessage") { emit scriptMessage(params.value("params").toMap().value("scriptId").toUuid(), params.value("params").toMap().value("type").toString(), @@ -181,6 +176,6 @@ void ScriptManager::onNotificationReceived(const QVariantMap ¶ms) } else { - qWarning() << "Unhandled notification" << params.value("notification").toString(); + qCWarning(dcScriptManager()) << "Unhandled notification" << params.value("notification").toString(); } } diff --git a/libnymea-app/scriptmanager.h b/libnymea-app/scriptmanager.h index f9f7e35a..dc31249d 100644 --- a/libnymea-app/scriptmanager.h +++ b/libnymea-app/scriptmanager.h @@ -37,7 +37,7 @@ class Scripts; -class ScriptManager : public JsonHandler +class ScriptManager : public QObject { Q_OBJECT Q_PROPERTY(Scripts* scripts READ scripts CONSTANT) @@ -49,8 +49,6 @@ public: void init(); bool fetchingData() const; - QString nameSpace() const override; - Scripts *scripts() const; public slots: diff --git a/libnymea-app/system/systemcontroller.cpp b/libnymea-app/system/systemcontroller.cpp index fcae1c65..2fd97bcb 100644 --- a/libnymea-app/system/systemcontroller.cpp +++ b/libnymea-app/system/systemcontroller.cpp @@ -38,10 +38,10 @@ #include SystemController::SystemController(JsonRpcClient *jsonRpcClient, QObject *parent): - JsonHandler(parent), + QObject(parent), m_jsonRpcClient(jsonRpcClient) { - m_jsonRpcClient->registerNotificationHandler(this, "notificationReceived"); + m_jsonRpcClient->registerNotificationHandler(this, "System", "notificationReceived"); m_packages = new Packages(this); m_repositories = new Repositories(this); @@ -66,11 +66,6 @@ void SystemController::init() } } -QString SystemController::nameSpace() const -{ - return "System"; -} - bool SystemController::powerManagementAvailable() const { return m_powerManagementAvailable; diff --git a/libnymea-app/system/systemcontroller.h b/libnymea-app/system/systemcontroller.h index e74f9de2..441de94b 100644 --- a/libnymea-app/system/systemcontroller.h +++ b/libnymea-app/system/systemcontroller.h @@ -38,7 +38,7 @@ class Repositories; class Packages; -class SystemController : public JsonHandler +class SystemController : public QObject { Q_OBJECT Q_PROPERTY(bool powerManagementAvailable READ powerManagementAvailable NOTIFY powerManagementAvailableChanged) @@ -63,7 +63,6 @@ public: explicit SystemController(JsonRpcClient *jsonRpcClient, QObject *parent = nullptr); void init(); - QString nameSpace() const override; bool powerManagementAvailable() const; Q_INVOKABLE int restart(); diff --git a/libnymea-app/tagsmanager.cpp b/libnymea-app/tagsmanager.cpp index be8f3959..07129bea 100644 --- a/libnymea-app/tagsmanager.cpp +++ b/libnymea-app/tagsmanager.cpp @@ -36,16 +36,11 @@ #include TagsManager::TagsManager(JsonRpcClient *jsonClient, QObject *parent): - JsonHandler(parent), + QObject(parent), m_jsonClient(jsonClient), m_tags(new Tags(this)) { - jsonClient->registerNotificationHandler(this, "handleTagsNotification"); -} - -QString TagsManager::nameSpace() const -{ - return "Tags"; + jsonClient->registerNotificationHandler(this, "Tags", "handleTagsNotification"); } void TagsManager::init() diff --git a/libnymea-app/tagsmanager.h b/libnymea-app/tagsmanager.h index dd3dcae6..6f7d8f9e 100644 --- a/libnymea-app/tagsmanager.h +++ b/libnymea-app/tagsmanager.h @@ -31,12 +31,11 @@ #ifndef TAGSMANAGER_H #define TAGSMANAGER_H -#include "jsonrpc/jsonhandler.h" #include "jsonrpc/jsonrpcclient.h" #include "types/tags.h" -class TagsManager : public JsonHandler +class TagsManager : public QObject { Q_OBJECT Q_PROPERTY(Tags* tags READ tags CONSTANT) @@ -52,7 +51,6 @@ public: Q_ENUM(TagError) explicit TagsManager(JsonRpcClient *jsonClient, QObject *parent = nullptr); - QString nameSpace() const override; void init(); void clear(); diff --git a/libnymea-app/thingmanager.cpp b/libnymea-app/thingmanager.cpp index 815c99b0..51c366a9 100644 --- a/libnymea-app/thingmanager.cpp +++ b/libnymea-app/thingmanager.cpp @@ -45,7 +45,7 @@ NYMEA_LOGGING_CATEGORY(dcThingManager, "ThingManager") ThingManager::ThingManager(JsonRpcClient* jsonclient, QObject *parent) : - JsonHandler(parent), + QObject(parent), m_vendors(new Vendors(this)), m_plugins(new Plugins(this)), m_things(new Things(this)), @@ -53,7 +53,7 @@ ThingManager::ThingManager(JsonRpcClient* jsonclient, QObject *parent) : m_ioConnections(new IOConnections(this)), m_jsonClient(jsonclient) { - m_jsonClient->registerNotificationHandler(this, "notificationReceived"); + m_jsonClient->registerNotificationHandler(this, "Integrations", "notificationReceived"); } void ThingManager::clear() @@ -75,11 +75,6 @@ void ThingManager::init() m_jsonClient->sendCommand("Integrations.GetThingClasses", this, "getThingClassesResponse"); } -QString ThingManager::nameSpace() const -{ - return "Integrations"; -} - Vendors *ThingManager::vendors() const { return m_vendors; diff --git a/libnymea-app/thingmanager.h b/libnymea-app/thingmanager.h index 5a2e679a..75ee4a2a 100644 --- a/libnymea-app/thingmanager.h +++ b/libnymea-app/thingmanager.h @@ -38,7 +38,6 @@ #include "thingclasses.h" #include "interfacesmodel.h" #include "types/plugins.h" -#include "jsonrpc/jsonhandler.h" #include "jsonrpc/jsonrpcclient.h" class BrowserItem; @@ -47,9 +46,8 @@ class ThingGroup; class Interface; class IOConnections; class EventHandler; -class IntegrationsHandler; -class ThingManager : public JsonHandler +class ThingManager : public QObject { Q_OBJECT Q_PROPERTY(Vendors* vendors READ vendors CONSTANT) @@ -74,8 +72,6 @@ public: void clear(); void init(); - QString nameSpace() const override; - Vendors* vendors() const; Plugins* plugins() const; Things* things() const; @@ -189,50 +185,6 @@ private: QHash > m_browserDetailsRequests; QDateTime m_connectionBenchmark; - - // Deprecated stuff for nymea < 0.17 (JSONRPC < 4.0) - EventHandler *m_eventHandler = nullptr; - // Register notifications for new stuff that's only available in the Integrations namespace for now - IntegrationsHandler *m_integrationsHandler = nullptr; - -}; - -// TODO: This is deprecated in nymea now (JSONRPC 4.0/nymea 0.17). Keeping it for a bit for backwards compatibility -class EventHandler: public JsonHandler { - Q_OBJECT - -public: - EventHandler(QObject *parent = nullptr): JsonHandler(parent) {} - QString nameSpace() const override { - return "Events"; - } - -signals: - void eventReceived(const QVariantMap &event); - -private: - Q_INVOKABLE void notificationReceived(const QVariantMap &data) { - emit eventReceived(data.value("params").toMap().value("event").toMap()); - } - -}; - -class IntegrationsHandler: public JsonHandler { - Q_OBJECT - -public: - IntegrationsHandler(QObject *parent = nullptr): JsonHandler(parent) {} - QString nameSpace() const override { - return "Integrations"; - } - -signals: - void onNotificationReceived(const QVariantMap &data); - -private: - Q_INVOKABLE void notificationReceived(const QVariantMap &data) { - emit onNotificationReceived(data); - } }; #endif // THINGMANAGER_H diff --git a/libnymea-app/usermanager.cpp b/libnymea-app/usermanager.cpp index e60aeffb..20062e39 100644 --- a/libnymea-app/usermanager.cpp +++ b/libnymea-app/usermanager.cpp @@ -5,7 +5,7 @@ #include UserManager::UserManager(QObject *parent): - JsonHandler(parent) + QObject(parent) { m_userInfo = new UserInfo(this); m_tokenInfos = new TokenInfos(this); @@ -20,7 +20,7 @@ void UserManager::setEngine(Engine *engine) { if (m_engine != engine) { m_engine = engine; - m_engine->jsonRpcClient()->registerNotificationHandler(this, "notificationReceived"); + m_engine->jsonRpcClient()->registerNotificationHandler(this, "Users", "notificationReceived"); emit engineChanged(); m_loading = true; @@ -46,11 +46,6 @@ TokenInfos *UserManager::tokenInfos() const return m_tokenInfos; } -QString UserManager::nameSpace() const -{ - return "Users"; -} - int UserManager::changePassword(const QString &newPassword) { QVariantMap params; diff --git a/libnymea-app/usermanager.h b/libnymea-app/usermanager.h index 9e874588..260172ad 100644 --- a/libnymea-app/usermanager.h +++ b/libnymea-app/usermanager.h @@ -9,7 +9,7 @@ #include "types/tokeninfos.h" #include "types/userinfo.h" -class UserManager: public JsonHandler +class UserManager: public QObject { Q_OBJECT Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged) @@ -40,8 +40,6 @@ public: UserInfo* userInfo() const; TokenInfos* tokenInfos() const; - QString nameSpace() const override; - Q_INVOKABLE int changePassword(const QString &newPassword); Q_INVOKABLE int removeToken(const QUuid &id); diff --git a/libnymea-app/zigbee/zigbeemanager.cpp b/libnymea-app/zigbee/zigbeemanager.cpp index 3ab45bfa..1766df15 100644 --- a/libnymea-app/zigbee/zigbeemanager.cpp +++ b/libnymea-app/zigbee/zigbeemanager.cpp @@ -45,7 +45,7 @@ NYMEA_LOGGING_CATEGORY(dcZigbee, "Zigbee") ZigbeeManager::ZigbeeManager(QObject *parent) : - JsonHandler(parent), + QObject(parent), m_adapters(new ZigbeeAdapters(this)), m_networks(new ZigbeeNetworks(this)) { @@ -59,11 +59,6 @@ ZigbeeManager::~ZigbeeManager() } } -QString ZigbeeManager::nameSpace() const -{ - return "Zigbee"; -} - void ZigbeeManager::setEngine(Engine *engine) { if (m_engine != engine) { @@ -153,7 +148,7 @@ void ZigbeeManager::init() m_networks->clear(); m_availableBackends.clear(); - m_engine->jsonRpcClient()->registerNotificationHandler(this, "notificationReceived"); + m_engine->jsonRpcClient()->registerNotificationHandler(this, "Zigbee", "notificationReceived"); m_engine->jsonRpcClient()->sendCommand("Zigbee.GetAvailableBackends", this, "getAvailableBackendsResponse"); m_engine->jsonRpcClient()->sendCommand("Zigbee.GetAdapters", this, "getAdaptersResponse"); diff --git a/libnymea-app/zigbee/zigbeemanager.h b/libnymea-app/zigbee/zigbeemanager.h index 920165cd..cfa8bf73 100644 --- a/libnymea-app/zigbee/zigbeemanager.h +++ b/libnymea-app/zigbee/zigbeemanager.h @@ -33,7 +33,6 @@ #include #include "zigbeeadapter.h" -#include "jsonrpc/jsonhandler.h" class Engine; class JsonRpcClient; @@ -43,7 +42,7 @@ class ZigbeeNetworks; class ZigbeeNode; class ZigbeeNodes; -class ZigbeeManager : public JsonHandler +class ZigbeeManager : public QObject { Q_OBJECT Q_PROPERTY(Engine* engine READ engine WRITE setEngine NOTIFY engineChanged) @@ -56,8 +55,6 @@ public: explicit ZigbeeManager(QObject *parent = nullptr); ~ZigbeeManager(); - QString nameSpace() const override; - void setEngine(Engine *engine); Engine *engine() const;