From d9c2a2d91ab3614280d4d1e7bb3917094a97fd60 Mon Sep 17 00:00:00 2001 From: Paulchen Panther Date: Sun, 9 Oct 2016 22:22:17 +0200 Subject: [PATCH] JsonCpp to QTJson (Part 4) (#266) * Update ActiveEffectDefinition.h * Update EffectDefinition.h * Update EffectEngine.h * Update Hyperion.h * Update LedDevice.h * Update QJsonFactory.h * Update QJsonSchemaChecker.h * Update Effect.cpp * Update Effect.h * Update EffectEngine.cpp * Update Hyperion.cpp * Update JsonClientConnection.cpp * Update JsonClientConnection.h * Update schema-config.json * Update LedDevice.cpp * Update QJsonSchemaChecker.cpp * Update hyperion-remote.cpp * Update JsonConnection.cpp * Update JsonConnection.h * Update hyperiond.cpp --- include/effectengine/ActiveEffectDefinition.h | 14 +- include/effectengine/EffectDefinition.h | 14 +- include/effectengine/EffectEngine.h | 15 +- include/hyperion/Hyperion.h | 6 +- include/leddevice/LedDevice.h | 2 +- include/utils/jsonschema/QJsonFactory.h | 12 + include/utils/jsonschema/QJsonSchemaChecker.h | 5 +- libsrc/effectengine/Effect.cpp | 73 +- libsrc/effectengine/Effect.h | 8 +- libsrc/effectengine/EffectEngine.cpp | 160 +++-- libsrc/hyperion/Hyperion.cpp | 7 +- libsrc/jsonserver/JsonClientConnection.cpp | 662 ++++++++++-------- libsrc/jsonserver/JsonClientConnection.h | 53 +- libsrc/jsonserver/schema/schema-config.json | 6 - libsrc/leddevice/LedDevice.cpp | 55 +- .../utils/jsonschema/QJsonSchemaChecker.cpp | 5 +- src/hyperion-remote/JsonConnection.cpp | 4 +- src/hyperion-remote/JsonConnection.h | 2 +- src/hyperion-remote/hyperion-remote.cpp | 8 +- src/hyperiond/hyperiond.cpp | 17 +- 20 files changed, 660 insertions(+), 468 deletions(-) diff --git a/include/effectengine/ActiveEffectDefinition.h b/include/effectengine/ActiveEffectDefinition.h index 3ad6b474..c88d2d08 100644 --- a/include/effectengine/ActiveEffectDefinition.h +++ b/include/effectengine/ActiveEffectDefinition.h @@ -1,16 +1,14 @@ #pragma once -// stl include -#include - -// json include -#include +// QT include +#include +#include struct ActiveEffectDefinition { - std::string script; - std::string name; + QString script; + QString name; int priority; int timeout; - Json::Value args; + QJsonObject args; }; diff --git a/include/effectengine/EffectDefinition.h b/include/effectengine/EffectDefinition.h index d8c1ce27..3877ef09 100644 --- a/include/effectengine/EffectDefinition.h +++ b/include/effectengine/EffectDefinition.h @@ -1,14 +1,12 @@ #pragma once -// stl include -#include - -// json include -#include +// QT include +#include +#include struct EffectDefinition { - std::string name; - std::string script; - Json::Value args; + QString name; + QString script; + QJsonObject args; }; diff --git a/include/effectengine/EffectEngine.h b/include/effectengine/EffectEngine.h index c75bc14f..a7393637 100644 --- a/include/effectengine/EffectEngine.h +++ b/include/effectengine/EffectEngine.h @@ -3,9 +3,10 @@ // Qt includes #include #include - -// Json includes -#include +#include +#include +#include +#include // Hyperion includes #include @@ -24,7 +25,7 @@ class EffectEngine : public QObject Q_OBJECT public: - EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectConfig); + EffectEngine(Hyperion * hyperion, const QJsonObject & jsonEffectConfig); virtual ~EffectEngine(); const std::list & getEffects() const; @@ -35,10 +36,10 @@ public: public slots: /// Run the specified effect on the given priority channel and optionally specify a timeout - int runEffect(const std::string &effectName, int priority, int timeout = -1); + int runEffect(const QString &effectName, int priority, int timeout = -1); /// Run the specified effect on the given priority channel and optionally specify a timeout - int runEffect(const std::string &effectName, const Json::Value & args, int priority, int timeout = -1); + int runEffect(const QString &effectName, const QJsonObject & args, int priority, int timeout = -1); /// Clear any effect running on the provided channel void channelCleared(int priority); @@ -51,7 +52,7 @@ private slots: private: /// Run the specified effect on the given priority channel and optionally specify a timeout - int runEffectScript(const std::string &script, const std::string &name, const Json::Value & args, int priority, int timeout = -1); + int runEffectScript(const QString &script, const QString &name, const QJsonObject & args, int priority, int timeout = -1); private: Hyperion * _hyperion; diff --git a/include/hyperion/Hyperion.h b/include/hyperion/Hyperion.h index d721326c..ba5fee4d 100644 --- a/include/hyperion/Hyperion.h +++ b/include/hyperion/Hyperion.h @@ -128,6 +128,7 @@ public: /// gets the current json config object /// @return json config const Json::Value& getJsonConfig() { return _jsonConfig; }; + const QJsonObject& getQJsonConfig() { return _qjsonConfig; }; /// get filename of configfile /// @return the current config filename @@ -261,14 +262,14 @@ public slots: /// @param effectName Name of the effec to run /// @param priority The priority channel of the effect /// @param timout The timeout of the effect (after the timout, the effect will be cleared) - int setEffect(const std::string & effectName, int priority, int timeout = -1); + int setEffect(const QString & effectName, int priority, int timeout = -1); /// Run the specified effect on the given priority channel and optionally specify a timeout /// @param effectName Name of the effec to run /// @param args arguments of the effect script /// @param priority The priority channel of the effect /// @param timout The timeout of the effect (after the timout, the effect will be cleared) - int setEffect(const std::string & effectName, const Json::Value & args, int priority, int timeout = -1); + int setEffect(const QString & effectName, const QJsonObject & args, int priority, int timeout = -1); public: static Hyperion *_hyperion; @@ -360,6 +361,7 @@ private: // json configuration const Json::Value& _jsonConfig; + const QJsonObject& _qjsonConfig; // the name of config file std::string _configFile; diff --git a/include/leddevice/LedDevice.h b/include/leddevice/LedDevice.h index 31989fb2..8f57eadc 100644 --- a/include/leddevice/LedDevice.h +++ b/include/leddevice/LedDevice.h @@ -52,7 +52,7 @@ public: static const LedDeviceRegistry& getDeviceMap(); static void setActiveDevice(std::string dev); static std::string activeDevice() { return _activeDevice; } - static Json::Value getLedDeviceSchemas(); + static QJsonObject getLedDeviceSchemas(); static void setLedCount(int ledCount); static int getLedCount() { return _ledCount; } protected: diff --git a/include/utils/jsonschema/QJsonFactory.h b/include/utils/jsonschema/QJsonFactory.h index 0234ee96..63bbed3a 100644 --- a/include/utils/jsonschema/QJsonFactory.h +++ b/include/utils/jsonschema/QJsonFactory.h @@ -85,4 +85,16 @@ public: file.close(); return doc.object(); } + + static void writeJson(const QString& filename, QJsonObject& jsonTree) + { + QJsonDocument doc; + doc.setObject(jsonTree); + QByteArray configData = doc.toJson(QJsonDocument::Indented); + + QFile configFile(filename); + configFile.open(QIODevice::WriteOnly | QIODevice::Truncate); + configFile.write(configData); + configFile.close(); + } }; diff --git a/include/utils/jsonschema/QJsonSchemaChecker.h b/include/utils/jsonschema/QJsonSchemaChecker.h index 22df42d5..4cff1e52 100644 --- a/include/utils/jsonschema/QJsonSchemaChecker.h +++ b/include/utils/jsonschema/QJsonSchemaChecker.h @@ -43,7 +43,7 @@ public: /// @param value The JSON value to check /// @return true when the arguments is valid according to the schema /// - bool validate(const QJsonObject & value); + bool validate(const QJsonObject & value, bool ignoreRequired = false); /// /// @return A list of error messages @@ -180,7 +180,8 @@ private: private: /// The schema of the entire json-configuration QJsonObject _qSchema; - + /// ignore the required value in json schema + bool _ignoreRequired; /// The current location into a json-configuration structure being checked std::list _currentPath; /// The result messages collected during the schema verification diff --git a/libsrc/effectengine/Effect.cpp b/libsrc/effectengine/Effect.cpp index d5118c32..83cfb3c8 100644 --- a/libsrc/effectengine/Effect.cpp +++ b/libsrc/effectengine/Effect.cpp @@ -63,7 +63,7 @@ void Effect::registerHyperionExtensionModule() PyImport_AppendInittab("hyperion", &PyInit_hyperion); } -Effect::Effect(PyThreadState * mainThreadState, int priority, int timeout, const QString & script, const QString & name, const Json::Value & args) +Effect::Effect(PyThreadState * mainThreadState, int priority, int timeout, const QString & script, const QString & name, const QJsonObject & args) : QThread() , _mainThreadState(mainThreadState) , _priority(priority) @@ -178,43 +178,50 @@ void Effect::effectFinished() emit effectFinished(this); } -PyObject *Effect::json2python(const Json::Value &json) const -{ - switch (json.type()) +PyObject *Effect::json2python(const QJsonValue &jsonData) const +{ + switch (jsonData.type()) { - case Json::nullValue: - return Py_BuildValue(""); - case Json::realValue: - return Py_BuildValue("d", json.asDouble()); - case Json::intValue: - case Json::uintValue: - return Py_BuildValue("i", json.asInt()); - case Json::booleanValue: - return Py_BuildValue("i", json.asBool() ? 1 : 0); - case Json::stringValue: - return Py_BuildValue("s", json.asCString()); - case Json::objectValue: - { - PyObject * dict= PyDict_New(); - for (Json::Value::iterator i = json.begin(); i != json.end(); ++i) + case QJsonValue::Null: + return Py_BuildValue(""); + case QJsonValue::Undefined: + return Py_BuildValue(""); + case QJsonValue::Double: { - PyObject * obj = json2python(*i); - PyDict_SetItemString(dict, i.memberName(), obj); - Py_XDECREF(obj); + if (rint(jsonData.toDouble()) != jsonData.toDouble()) + Py_BuildValue("d", jsonData.toDouble()); + else + return Py_BuildValue("i", jsonData.toInt()); } - return dict; - } - case Json::arrayValue: - { - PyObject * list = PyList_New(json.size()); - for (Json::Value::iterator i = json.begin(); i != json.end(); ++i) + case QJsonValue::Bool: + return Py_BuildValue("i", jsonData.toBool() ? 1 : 0); + case QJsonValue::String: + return Py_BuildValue("s", jsonData.toString().toUtf8().constData()); + case QJsonValue::Object: { - PyObject * obj = json2python(*i); - PyList_SetItem(list, i.index(), obj); - Py_XDECREF(obj); + PyObject * dict= PyDict_New(); + QJsonObject objectData = jsonData.toObject(); + for (QJsonObject::iterator i = objectData.begin(); i != objectData.end(); ++i) + { + PyObject * obj = json2python(*i); + PyDict_SetItemString(dict, i.key().toStdString().c_str(), obj); + Py_XDECREF(obj); + } + return dict; + } + case QJsonValue::Array: + { + QJsonArray arrayData = jsonData.toArray(); + PyObject * list = PyList_New(arrayData.size()); + int index = 0; + for (QJsonArray::iterator i = arrayData.begin(); i != arrayData.end(); ++i, ++index) + { + PyObject * obj = json2python(*i); + PyList_SetItem(list, index, obj); + Py_XDECREF(obj); + } + return list; } - return list; - } } assert(false); diff --git a/libsrc/effectengine/Effect.h b/libsrc/effectengine/Effect.h index 4a475485..08eda412 100644 --- a/libsrc/effectengine/Effect.h +++ b/libsrc/effectengine/Effect.h @@ -17,7 +17,7 @@ class Effect : public QThread Q_OBJECT public: - Effect(PyThreadState * mainThreadState, int priority, int timeout, const QString & script, const QString & name, const Json::Value & args = Json::Value()); + Effect(PyThreadState * mainThreadState, int priority, int timeout, const QString & script, const QString & name, const QJsonObject & args = QJsonObject()); virtual ~Effect(); virtual void run(); @@ -29,7 +29,7 @@ public: int getTimeout() const {return _timeout; } - Json::Value getArgs() const { return _args; } + QJsonObject getArgs() const { return _args; } bool isAbortRequested() const; @@ -48,7 +48,7 @@ private slots: void effectFinished(); private: - PyObject * json2python(const Json::Value & json) const; + PyObject * json2python(const QJsonValue & jsonData) const; // Wrapper methods for Python interpreter extra buildin methods static PyMethodDef effectMethods[]; @@ -79,7 +79,7 @@ private: const QString _script; const QString _name; - const Json::Value _args; + const QJsonObject _args; int64_t _endTime; diff --git a/libsrc/effectengine/EffectEngine.cpp b/libsrc/effectengine/EffectEngine.cpp index 97eebb7d..1dd2391a 100644 --- a/libsrc/effectengine/EffectEngine.cpp +++ b/libsrc/effectengine/EffectEngine.cpp @@ -11,7 +11,7 @@ #include // hyperion util includes -#include +#include #include // effect engine includes @@ -19,7 +19,7 @@ #include "Effect.h" #include "HyperionConfig.h" -EffectEngine::EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectConfig) +EffectEngine::EffectEngine(Hyperion * hyperion, const QJsonObject & jsonEffectConfig) : _hyperion(hyperion) , _availableEffects() , _activeEffects() @@ -34,23 +34,23 @@ EffectEngine::EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectCo connect(_hyperion, SIGNAL(allChannelsCleared()), this, SLOT(allChannelsCleared())); // read all effects - const Json::Value & paths = jsonEffectConfig["paths"]; - const Json::Value & disabledEfx = jsonEffectConfig["disable"]; - + const QJsonArray & paths = jsonEffectConfig["paths"].toArray(); + const QJsonArray & disabledEfx = jsonEffectConfig["disable"].toArray(); + QStringList efxPathList; efxPathList << ":/effects/"; - for (Json::UInt i = 0; i < paths.size(); ++i) - { - efxPathList << QString::fromStdString(paths[i].asString()); - } - QStringList disableList; - for (Json::UInt i = 0; i < disabledEfx.size(); ++i) - { - disableList << QString::fromStdString(disabledEfx[i].asString()); + + QJsonArray::ConstIterator iterPaths = paths.begin(); + QJsonArray::ConstIterator iterDisabledEfx = disabledEfx.begin(); + + for(; iterPaths != paths.end() and iterDisabledEfx != disabledEfx.end() ; ++iterPaths, ++iterDisabledEfx) + { + efxPathList << (*iterPaths).toString(); + disableList << (*iterDisabledEfx).toString(); } - std::map availableEffects; + std::map availableEffects; foreach (const QString & path, efxPathList ) { QDir directory(path); @@ -65,12 +65,12 @@ EffectEngine::EffectEngine(Hyperion * hyperion, const Json::Value & jsonEffectCo { if (availableEffects.find(def.name) != availableEffects.end()) { - Info(_log, "effect overload effect '%s' is now taken from %s'", def.name.c_str(), path.toUtf8().constData() ); + Info(_log, "effect overload effect '%s' is now taken from %s'", def.name.toUtf8().constData(), path.toUtf8().constData() ); } - if ( disableList.contains(QString::fromStdString(def.name)) ) + if ( disableList.contains(def.name) ) { - Info(_log, "effect '%s' not loaded, because it is disabled in hyperion config", def.name.c_str()); + Info(_log, "effect '%s' not loaded, because it is disabled in hyperion config", def.name.toUtf8().constData()); } else { @@ -121,8 +121,8 @@ const std::list &EffectEngine::getActiveEffects() for (Effect * effect : _activeEffects) { ActiveEffectDefinition activeEffectDefinition; - activeEffectDefinition.script = effect->getScript().toStdString(); - activeEffectDefinition.name = effect->getName().toStdString(); + activeEffectDefinition.script = effect->getScript(); + activeEffectDefinition.name = effect->getName(); activeEffectDefinition.priority = effect->getPriority(); activeEffectDefinition.timeout = effect->getTimeout(); activeEffectDefinition.args = effect->getArgs(); @@ -134,67 +134,117 @@ const std::list &EffectEngine::getActiveEffects() bool EffectEngine::loadEffectDefinition(const QString &path, const QString &effectConfigFile, EffectDefinition & effectDefinition) { - QString fileName = path + QDir::separator() + effectConfigFile; - QFile file(fileName); - Logger * log = Logger::getInstance("EFFECTENGINE"); + + QString fileName = path + QDir::separator() + effectConfigFile; + QJsonParseError error; + + // ---------- Read the effect json config file ---------- + + QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) { Error( log, "Effect file '%s' could not be loaded", fileName.toUtf8().constData()); return false; } + QByteArray fileContent = file.readAll(); - // Read the json config file - Json::Reader jsonReader; - Json::Value config; - const char* fileContent_cStr = reinterpret_cast(fileContent.constData()); + QJsonDocument configEffect = QJsonDocument::fromJson(fileContent, &error); - if (! Json::Reader().parse(fileContent_cStr, fileContent_cStr+fileContent.size(), config, false) ) + if (error.error != QJsonParseError::NoError) { - Error( log, "Error while reading effect '%s': %s", fileName.toUtf8().constData(), jsonReader.getFormattedErrorMessages().c_str()); + // report to the user the failure and their locations in the document. + int errorLine(0), errorColumn(0); + + for( int i=0, count=qMin( error.offset,fileContent.size()); i(schemaData.data()), reinterpret_cast(schemaData.data()) + schemaData.size(), schema, false); - schemaChecker.setSchema(schema); - if (!schemaChecker.validate(config)) + + QByteArray schemaContent = schema.readAll(); + QJsonDocument configSchema = QJsonDocument::fromJson(schemaContent, &error); + + if (error.error != QJsonParseError::NoError) + { + // report to the user the failure and their locations in the document. + int errorLine(0), errorColumn(0); + + for( int i=0, count=qMin( error.offset,schemaContent.size()); i & errors = schemaChecker.getMessages(); - foreach (const std::string & error, errors) { + foreach (const std::string & error, errors) + { Error( log, "Error while checking '%s':%s", fileName.toUtf8().constData(), error.c_str()); } return false; } - // setup the definition - std::string scriptName = config["script"].asString(); - effectDefinition.name = config["name"].asString(); - if (scriptName.empty()) + // ---------- setup the definition ---------- + + QJsonObject config = configEffect.object(); + QString scriptName = config["script"].toString(); + effectDefinition.name = config["name"].toString(); + if (scriptName.isEmpty()) return false; - if (scriptName[0] == ':' ) - effectDefinition.script = ":/effects/"+scriptName.substr(1); + if (scriptName.mid(0, 1) == ":" ) + effectDefinition.script = ":/effects/"+scriptName.mid(1); else - effectDefinition.script = path.toStdString() + QDir::separator().toLatin1() + scriptName; + effectDefinition.script = path + QDir::separator().toLatin1() + scriptName; - effectDefinition.args = config["args"]; + effectDefinition.args = config["args"].toObject(); return true; } -int EffectEngine::runEffect(const std::string &effectName, int priority, int timeout) +int EffectEngine::runEffect(const QString &effectName, int priority, int timeout) { - return runEffect(effectName, Json::Value(Json::nullValue), priority, timeout); + return runEffect(effectName, QJsonObject(), priority, timeout); } -int EffectEngine::runEffect(const std::string &effectName, const Json::Value &args, int priority, int timeout) +int EffectEngine::runEffect(const QString &effectName, const QJsonObject &args, int priority, int timeout) { - Info( _log, "run effect %s on channel %d", effectName.c_str(), priority); + Info( _log, "run effect %s on channel %d", effectName.toUtf8().constData(), priority); const EffectDefinition * effectDefinition = nullptr; for (const EffectDefinition & e : _availableEffects) @@ -208,26 +258,26 @@ int EffectEngine::runEffect(const std::string &effectName, const Json::Value &ar if (effectDefinition == nullptr) { // no such effect - Error(_log, "effect %s not found", effectName.c_str()); + Error(_log, "effect %s not found", effectName.toUtf8().constData()); return -1; } - return runEffectScript(effectDefinition->script, effectName, args.isNull() ? effectDefinition->args : args, priority, timeout); + return runEffectScript(effectDefinition->script, effectName, args.isEmpty() ? effectDefinition->args : args, priority, timeout); } -int EffectEngine::runEffectScript(const std::string &script, const std::string &name, const Json::Value &args, int priority, int timeout) +int EffectEngine::runEffectScript(const QString &script, const QString &name, const QJsonObject &args, int priority, int timeout) { // clear current effect on the channel channelCleared(priority); // create the effect - Effect * effect = new Effect(_mainThreadState, priority, timeout, QString::fromStdString(script), QString::fromStdString(name), args); + Effect * effect = new Effect(_mainThreadState, priority, timeout, script, name, args); connect(effect, SIGNAL(setColors(int,std::vector,int,bool)), _hyperion, SLOT(setColors(int,std::vector,int,bool)), Qt::QueuedConnection); connect(effect, SIGNAL(effectFinished(Effect*)), this, SLOT(effectFinished(Effect*))); _activeEffects.push_back(effect); // start the effect - _hyperion->registerPriority("EFFECT: "+name, priority); + _hyperion->registerPriority("EFFECT: "+name.toStdString(), priority); effect->start(); return 0; diff --git a/libsrc/hyperion/Hyperion.cpp b/libsrc/hyperion/Hyperion.cpp index e4126775..a3567046 100644 --- a/libsrc/hyperion/Hyperion.cpp +++ b/libsrc/hyperion/Hyperion.cpp @@ -633,6 +633,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const QJsonObject &qjsonConfig , _effectEngine(nullptr) , _messageForwarder(createMessageForwarder(qjsonConfig["forwarder"].toObject())) , _jsonConfig(jsonConfig) + , _qjsonConfig(qjsonConfig) , _configFile(configFile) , _timer() , _log(Logger::getInstance("Core")) @@ -682,7 +683,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const QJsonObject &qjsonConfig QObject::connect(&_timer, SIGNAL(timeout()), this, SLOT(update())); // create the effect engine - _effectEngine = new EffectEngine(this,jsonConfig["effects"]); + _effectEngine = new EffectEngine(this,qjsonConfig["effects"].toObject()); const QJsonObject& device = qjsonConfig["device"].toObject(); unsigned int hwLedCount = device["ledCount"].toInt(getLedCount()); @@ -938,12 +939,12 @@ const std::list & Hyperion::getActiveEffects() return _effectEngine->getActiveEffects(); } -int Hyperion::setEffect(const std::string &effectName, int priority, int timeout) +int Hyperion::setEffect(const QString &effectName, int priority, int timeout) { return _effectEngine->runEffect(effectName, priority, timeout); } -int Hyperion::setEffect(const std::string &effectName, const Json::Value &args, int priority, int timeout) +int Hyperion::setEffect(const QString &effectName, const QJsonObject &args, int priority, int timeout) { return _effectEngine->runEffect(effectName, args, priority, timeout); } diff --git a/libsrc/jsonserver/JsonClientConnection.cpp b/libsrc/jsonserver/JsonClientConnection.cpp index 6a60f0fb..6e292a2f 100644 --- a/libsrc/jsonserver/JsonClientConnection.cpp +++ b/libsrc/jsonserver/JsonClientConnection.cpp @@ -17,6 +17,9 @@ #include #include #include +#include +#include +#include // hyperion util includes #include @@ -28,7 +31,7 @@ #include #include #include -#include +#include #include // project includes @@ -88,7 +91,7 @@ void JsonClientConnection::readData() _receiveBuffer = _receiveBuffer.mid(bytes); // handle message - handleMessage(message); + handleMessage(QString::fromStdString(message)); // try too look up '\n' again bytes = _receiveBuffer.indexOf('\n') + 1; @@ -159,7 +162,7 @@ void JsonClientConnection::handleWebSocketFrame() } } - handleMessage(QString(result).toStdString()); + handleMessage(QString(result)); } break; case 0x08: @@ -225,18 +228,37 @@ void JsonClientConnection::socketClosed() emit connectionClosed(this); } -void JsonClientConnection::handleMessage(const std::string &messageString) +void JsonClientConnection::handleMessage(const QString& messageString) { - Json::Reader reader; - Json::Value message; - std::string errors; + QString errors; + try { - if (!reader.parse(messageString, message, false)) + QJsonParseError error; + QJsonDocument doc = QJsonDocument::fromJson(messageString.toUtf8(), &error); + + if (error.error != QJsonParseError::NoError) { - sendErrorReply("Error while parsing json: " + reader.getFormattedErrorMessages()); + // report to the user the failure and their locations in the document. + int errorLine(0), errorColumn(0); + + for( int i=0, count=qMin( error.offset,messageString.size()); i colorData(_hyperion->getLedCount()); - const Json::Value & jsonColor = message["color"]; + const QJsonArray & jsonColor = message["color"].toArray(); Json::UInt i = 0; - for (; i < jsonColor.size()/3 && i < _hyperion->getLedCount(); ++i) + for (; i < unsigned(jsonColor.size()/3) && i < _hyperion->getLedCount(); ++i) { - colorData[i].red = uint8_t(message["color"][3u*i].asInt()); - colorData[i].green = uint8_t(message["color"][3u*i+1u].asInt()); - colorData[i].blue = uint8_t(message["color"][3u*i+2u].asInt()); + colorData[i].red = uint8_t(jsonColor.at(3u*i).toInt()); + colorData[i].green = uint8_t(jsonColor.at(3u*i+1u).toInt()); + colorData[i].blue = uint8_t(jsonColor.at(3u*i+2u).toInt()); } // copy full blocks of led colors @@ -359,16 +380,16 @@ void JsonClientConnection::handleColorCommand(const Json::Value &message, const sendSuccessReply(command, tan); } -void JsonClientConnection::handleImageCommand(const Json::Value &message, const std::string &command, const int tan) +void JsonClientConnection::handleImageCommand(const QJsonObject& message, const QString& command, const int tan) { forwardJsonMessage(message); // extract parameters - int priority = message["priority"].asInt(); - int duration = message.get("duration", -1).asInt(); - int width = message["imagewidth"].asInt(); - int height = message["imageheight"].asInt(); - QByteArray data = QByteArray::fromBase64(QByteArray(message["imagedata"].asCString())); + int priority = message["priority"].toInt(); + int duration = message["duration"].toInt(-1); + int width = message["imagewidth"].toInt(); + int height = message["imageheight"].toInt(); + QByteArray data = QByteArray::fromBase64(QByteArray(message["imagedata"].toString().toUtf8())); // check consistency of the size of the received data if (data.size() != width*height*3) @@ -392,20 +413,20 @@ void JsonClientConnection::handleImageCommand(const Json::Value &message, const sendSuccessReply(command, tan); } -void JsonClientConnection::handleEffectCommand(const Json::Value &message, const std::string &command, const int tan) +void JsonClientConnection::handleEffectCommand(const QJsonObject& message, const QString& command, const int tan) { forwardJsonMessage(message); // extract parameters - int priority = message["priority"].asInt(); - int duration = message.get("duration", -1).asInt(); - const Json::Value & effect = message["effect"]; - const std::string & effectName = effect["name"].asString(); + int priority = message["priority"].toInt(); + int duration = message["duration"].toInt(-1); + const QJsonObject & effect = message["effect"].toObject(); + const QString & effectName = effect["name"].toString(); // set output - if (effect.isMember("args")) + if (effect.contains("args")) { - _hyperion->setEffect(effectName, effect["args"], priority, duration); + _hyperion->setEffect(effectName, effect["args"].toObject(), priority, duration); } else { @@ -416,57 +437,66 @@ void JsonClientConnection::handleEffectCommand(const Json::Value &message, const sendSuccessReply(command, tan); } -void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const std::string &command, const int tan) +void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QString& command, const int tan) { // create result - Json::Value result; + QJsonObject result; result["success"] = true; result["command"] = command; result["tan"] = tan; - Json::Value & info = result["info"]; + QJsonObject info; + // add host name for remote clients - info["hostname"] = QHostInfo::localHostName().toStdString(); + info["hostname"] = QHostInfo::localHostName(); // collect priority information - Json::Value & priorities = info["priorities"] = Json::Value(Json::arrayValue); + QJsonArray priorities; uint64_t now = QDateTime::currentMSecsSinceEpoch(); QList activePriorities = _hyperion->getActivePriorities(); Hyperion::PriorityRegister priorityRegister = _hyperion->getPriorityRegister(); int currentPriority = _hyperion->getCurrentPriority(); + foreach (int priority, activePriorities) { const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo(priority); - Json::Value & item = priorities[priorities.size()]; + QJsonObject item; item["priority"] = priority; if (priorityInfo.timeoutTime_ms != -1) { - item["duration_ms"] = Json::Value::UInt(priorityInfo.timeoutTime_ms - now); + item["duration_ms"] = int(priorityInfo.timeoutTime_ms - now); } - item["owner"] = "unknown"; + item["owner"] = QString("unknown"); item["active"] = true; item["visible"] = (priority == currentPriority); foreach(auto const &entry, priorityRegister) { if (entry.second == priority) { - item["owner"] = entry.first; + item["owner"] = QString::fromStdString(entry.first); priorityRegister.erase(entry.first); break; } } + + // priorities[priorities.size()] = item; + priorities.append(item); } + foreach(auto const &entry, priorityRegister) { - Json::Value & item = priorities[priorities.size()]; + QJsonObject item; item["priority"] = entry.second; item["active"] = false; item["visible"] = false; - item["owner"] = entry.first; + item["owner"] = QString::fromStdString(entry.first); + priorities.append(item); } + info["priorities"] = priorities; + // collect temperature correction information - Json::Value & temperatureArray = info["temperature"]; + QJsonArray temperatureArray; for (const std::string& tempId : _hyperion->getTemperatureIds()) { const ColorCorrection * colorTemp = _hyperion->getTemperature(tempId); @@ -476,18 +506,22 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const st continue; } - Json::Value & temperature = temperatureArray.append(Json::Value()); - temperature["id"] = tempId; - - Json::Value & tempValues = temperature["correctionValues"]; + QJsonObject temperature; + temperature["id"] = QString::fromStdString(tempId); + + QJsonArray tempValues; tempValues.append(colorTemp->_rgbCorrection.getAdjustmentR()); tempValues.append(colorTemp->_rgbCorrection.getAdjustmentG()); tempValues.append(colorTemp->_rgbCorrection.getAdjustmentB()); + temperature.insert("correctionValues", tempValues); + temperatureArray.append(temperature); } + + info["temperature"] = temperatureArray; // collect transform information - Json::Value & transformArray = info["transform"]; + QJsonArray transformArray; for (const std::string& transformId : _hyperion->getTransformIds()) { const ColorTransform * colorTransform = _hyperion->getTransform(transformId); @@ -497,35 +531,47 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const st continue; } - Json::Value & transform = transformArray.append(Json::Value()); - transform["id"] = transformId; + QJsonObject transform; + transform["id"] = QString::fromStdString(transformId); transform["saturationGain"] = colorTransform->_hsvTransform.getSaturationGain(); transform["valueGain"] = colorTransform->_hsvTransform.getValueGain(); transform["saturationLGain"] = colorTransform->_hslTransform.getSaturationGain(); transform["luminanceGain"] = colorTransform->_hslTransform.getLuminanceGain(); transform["luminanceMinimum"] = colorTransform->_hslTransform.getLuminanceMinimum(); + - Json::Value & threshold = transform["threshold"]; + QJsonArray threshold; threshold.append(colorTransform->_rgbRedTransform.getThreshold()); threshold.append(colorTransform->_rgbGreenTransform.getThreshold()); threshold.append(colorTransform->_rgbBlueTransform.getThreshold()); - Json::Value & gamma = transform["gamma"]; + transform.insert("threshold", threshold); + + QJsonArray gamma; gamma.append(colorTransform->_rgbRedTransform.getGamma()); gamma.append(colorTransform->_rgbGreenTransform.getGamma()); gamma.append(colorTransform->_rgbBlueTransform.getGamma()); - Json::Value & blacklevel = transform["blacklevel"]; + transform.insert("gamma", gamma); + + QJsonArray blacklevel; blacklevel.append(colorTransform->_rgbRedTransform.getBlacklevel()); blacklevel.append(colorTransform->_rgbGreenTransform.getBlacklevel()); blacklevel.append(colorTransform->_rgbBlueTransform.getBlacklevel()); - Json::Value & whitelevel = transform["whitelevel"]; + transform.insert("blacklevel", blacklevel); + + QJsonArray whitelevel; whitelevel.append(colorTransform->_rgbRedTransform.getWhitelevel()); whitelevel.append(colorTransform->_rgbGreenTransform.getWhitelevel()); whitelevel.append(colorTransform->_rgbBlueTransform.getWhitelevel()); + transform.insert("whitelevel", whitelevel); + + transformArray.append(transform); } + info["transform"] = transformArray; + // collect adjustment information - Json::Value & adjustmentArray = info["adjustment"]; + QJsonArray adjustmentArray; for (const std::string& adjustmentId : _hyperion->getAdjustmentIds()) { const ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId); @@ -535,66 +581,71 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const st continue; } - Json::Value & adjustment = adjustmentArray.append(Json::Value()); - adjustment["id"] = adjustmentId; + QJsonObject adjustment; + adjustment["id"] = QString::fromStdString(adjustmentId); - Json::Value & redAdjust = adjustment["redAdjust"]; + QJsonArray redAdjust; redAdjust.append(colorAdjustment->_rgbRedAdjustment.getAdjustmentR()); redAdjust.append(colorAdjustment->_rgbRedAdjustment.getAdjustmentG()); redAdjust.append(colorAdjustment->_rgbRedAdjustment.getAdjustmentB()); - Json::Value & greenAdjust = adjustment["greenAdjust"]; + adjustment.insert("redAdjust", redAdjust); + + QJsonArray greenAdjust; greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getAdjustmentR()); greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getAdjustmentG()); greenAdjust.append(colorAdjustment->_rgbGreenAdjustment.getAdjustmentB()); - Json::Value & blueAdjust = adjustment["blueAdjust"]; + adjustment.insert("greenAdjust", greenAdjust); + + QJsonArray blueAdjust; blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getAdjustmentR()); blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getAdjustmentG()); blueAdjust.append(colorAdjustment->_rgbBlueAdjustment.getAdjustmentB()); + adjustment.insert("blueAdjust", blueAdjust); + + adjustmentArray.append(adjustment); } + + info["adjustment"] = adjustmentArray; // collect effect info - Json::Value & effects = info["effects"] = Json::Value(Json::arrayValue); + QJsonArray effects; const std::list & effectsDefinitions = _hyperion->getEffects(); for (const EffectDefinition & effectDefinition : effectsDefinitions) { - Json::Value effect; + QJsonObject effect; effect["name"] = effectDefinition.name; effect["script"] = effectDefinition.script; effect["args"] = effectDefinition.args; - effects.append(effect); } + info["effects"] = effects; + // collect active effect info - Json::Value & activeEffects = info["activeEffects"] = Json::Value(Json::arrayValue); + QJsonArray activeEffects; const std::list & activeEffectsDefinitions = _hyperion->getActiveEffects(); for (const ActiveEffectDefinition & activeEffectDefinition : activeEffectsDefinitions) { if (activeEffectDefinition.priority != PriorityMuxer::LOWEST_PRIORITY -1) { - Json::Value activeEffect; + QJsonObject activeEffect; activeEffect["script"] = activeEffectDefinition.script; activeEffect["name"] = activeEffectDefinition.name; activeEffect["priority"] = activeEffectDefinition.priority; activeEffect["timeout"] = activeEffectDefinition.timeout; activeEffect["args"] = activeEffectDefinition.args; - activeEffects.append(activeEffect); } } - //////////////////////////////////// - // collect active static led color// - //////////////////////////////////// - - // create New JSON Array Value "activeLEDColor" - Json::Value & activeLedColors = info["activeLedColor"] = Json::Value(Json::arrayValue); - // get current Priority from Hyperion Muxer + info["activeEffects"] = activeEffects; + + // collect active static led color + QJsonArray activeLedColors; const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority()); - // check if current Priority exist if (priorityInfo.priority != std::numeric_limits::max()) { - Json::Value LEDcolor; + QJsonObject LEDcolor; // check if all LEDs has the same Color if (std::all_of(priorityInfo.ledColors.begin(), priorityInfo.ledColors.end(), [&](ColorRgb color) { @@ -609,24 +660,29 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const st priorityInfo.ledColors.begin()->blue != 0)) { // add RGB Value to Array - LEDcolor["RGB Value"].append(priorityInfo.ledColors.begin()->red); - LEDcolor["RGB Value"].append(priorityInfo.ledColors.begin()->green); - LEDcolor["RGB Value"].append(priorityInfo.ledColors.begin()->blue); + QJsonArray RGBValue; + RGBValue.append(priorityInfo.ledColors.begin()->red); + RGBValue.append(priorityInfo.ledColors.begin()->green); + RGBValue.append(priorityInfo.ledColors.begin()->blue); + LEDcolor.insert("RGB Value", RGBValue); uint16_t Hue; float Saturation, Luminace; // add HSL Value to Array + QJsonArray HSLValue; HslTransform::rgb2hsl(priorityInfo.ledColors.begin()->red, priorityInfo.ledColors.begin()->green, priorityInfo.ledColors.begin()->blue, Hue, Saturation, Luminace); - LEDcolor["HSL Value"].append(Hue); - LEDcolor["HSL Value"].append(Saturation); - LEDcolor["HSL Value"].append(Luminace); + HSLValue.append(Hue); + HSLValue.append(Saturation); + HSLValue.append(Luminace); + LEDcolor.insert("HSL Value", HSLValue); - // add HEX Value to Array + // add HEX Value to Array ["HEX Value"] + QJsonArray HEXValue; std::stringstream hex; hex << "0x" << std::uppercase << std::setw(2) << std::setfill('0') @@ -636,55 +692,67 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const st << std::uppercase << std::setw(2) << std::setfill('0') << std::hex << unsigned(priorityInfo.ledColors.begin()->blue); - LEDcolor["HEX Value"].append(hex.str()); + HEXValue.append(QString::fromStdString(hex.str())); + LEDcolor.insert("HEX Value", HEXValue); activeLedColors.append(LEDcolor); } } } + + info["activeLedColor"] = activeLedColors; // get available led devices - info["ledDevices"]["active"] = LedDevice::activeDevice(); - info["ledDevices"]["available"] = Json::Value(Json::arrayValue); - for ( auto dev: LedDevice::getDeviceMap()) + QJsonObject ledDevices; + ledDevices["active"] = QString::fromStdString(LedDevice::activeDevice()); + QJsonArray available; + for (auto dev: LedDevice::getDeviceMap()) { - info["ledDevices"]["available"].append(dev.first); + available.append(QString::fromStdString(dev.first)); } + + ledDevices["available"] = available; + info["ledDevices"] = ledDevices; - // get components - info["components"] = Json::Value(Json::arrayValue); + // get available components + QJsonArray component; std::map components = _hyperion->getComponentRegister().getRegister(); for(auto comp : components) { - Json::Value item; + QJsonObject item; item["id"] = comp.first; - item["name"] = hyperion::componentToIdString(comp.first); - item["title"] = hyperion::componentToString(comp.first); + item["name"] = QString::fromStdString(hyperion::componentToIdString(comp.first)); + item["title"] = QString::fromStdString(hyperion::componentToString(comp.first)); item["enabled"] = comp.second; - info["components"].append(item); + + component.append(item); } + info["components"] = component; + // Add Hyperion Version, build time - //Json::Value & version = - info["hyperion"] = Json::Value(Json::arrayValue); - Json::Value ver; - ver["jsonrpc_version"] = HYPERION_JSON_VERSION; - ver["version"] = HYPERION_VERSION; - ver["build"] = HYPERION_BUILD_ID; - ver["time"] = __DATE__ " " __TIME__; + QJsonArray hyperion; + QJsonObject ver; + ver["jsonrpc_version"] = QString(HYPERION_JSON_VERSION); + ver["version"] = QString(HYPERION_VERSION); + ver["build"] = QString(HYPERION_BUILD_ID); + ver["time"] = QString(__DATE__ " " __TIME__); ver["config_modified"] = _hyperion->configModified(); - info["hyperion"].append(ver); + hyperion.append(ver); + info["hyperion"] = hyperion; + // send the result + result["info"] = info; sendMessage(result); } -void JsonClientConnection::handleClearCommand(const Json::Value &message, const std::string &command, const int tan) +void JsonClientConnection::handleClearCommand(const QJsonObject& message, const QString& command, const int tan) { forwardJsonMessage(message); // extract parameters - int priority = message["priority"].asInt(); + int priority = message["priority"].toInt(); // clear priority _hyperion->clear(priority); @@ -693,7 +761,7 @@ void JsonClientConnection::handleClearCommand(const Json::Value &message, const sendSuccessReply(command, tan); } -void JsonClientConnection::handleClearallCommand(const Json::Value & message, const std::string &command, const int tan) +void JsonClientConnection::handleClearallCommand(const QJsonObject& message, const QString& command, const int tan) { forwardJsonMessage(message); @@ -704,73 +772,74 @@ void JsonClientConnection::handleClearallCommand(const Json::Value & message, co sendSuccessReply(command, tan); } -void JsonClientConnection::handleTransformCommand(const Json::Value &message, const std::string &command, const int tan) +void JsonClientConnection::handleTransformCommand(const QJsonObject& message, const QString& command, const int tan) { - const Json::Value & transform = message["transform"]; + + const QJsonObject & transform = message["transform"].toObject(); - const std::string transformId = transform.get("id", _hyperion->getTransformIds().front()).asString(); - ColorTransform * colorTransform = _hyperion->getTransform(transformId); + const QString transformId = transform["id"].toString(QString::fromStdString(_hyperion->getTransformIds().front())); + ColorTransform * colorTransform = _hyperion->getTransform(transformId.toStdString()); if (colorTransform == nullptr) { - //sendErrorReply(std::string("Incorrect transform identifier: ") + transformId); + Warning(_log, "Incorrect transform identifier: %s", transformId.toStdString().c_str()); return; } - if (transform.isMember("saturationGain")) + if (transform.contains("saturationGain")) { - colorTransform->_hsvTransform.setSaturationGain(transform["saturationGain"].asDouble()); + colorTransform->_hsvTransform.setSaturationGain(transform["saturationGain"].toDouble()); } - if (transform.isMember("valueGain")) + if (transform.contains("valueGain")) { - colorTransform->_hsvTransform.setValueGain(transform["valueGain"].asDouble()); + colorTransform->_hsvTransform.setValueGain(transform["valueGain"].toDouble()); } - if (transform.isMember("saturationLGain")) + if (transform.contains("saturationLGain")) { - colorTransform->_hslTransform.setSaturationGain(transform["saturationLGain"].asDouble()); + colorTransform->_hslTransform.setSaturationGain(transform["saturationLGain"].toDouble()); } - if (transform.isMember("luminanceGain")) + if (transform.contains("luminanceGain")) { - colorTransform->_hslTransform.setLuminanceGain(transform["luminanceGain"].asDouble()); + colorTransform->_hslTransform.setLuminanceGain(transform["luminanceGain"].toDouble()); } - if (transform.isMember("luminanceMinimum")) + if (transform.contains("luminanceMinimum")) { - colorTransform->_hslTransform.setLuminanceMinimum(transform["luminanceMinimum"].asDouble()); + colorTransform->_hslTransform.setLuminanceMinimum(transform["luminanceMinimum"].toDouble()); } - if (transform.isMember("threshold")) + if (transform.contains("threshold")) { - const Json::Value & values = transform["threshold"]; - colorTransform->_rgbRedTransform .setThreshold(values[0u].asDouble()); - colorTransform->_rgbGreenTransform.setThreshold(values[1u].asDouble()); - colorTransform->_rgbBlueTransform .setThreshold(values[2u].asDouble()); + const QJsonArray & values = transform["threshold"].toArray(); + colorTransform->_rgbRedTransform .setThreshold(values[0u].toDouble()); + colorTransform->_rgbGreenTransform.setThreshold(values[1u].toDouble()); + colorTransform->_rgbBlueTransform .setThreshold(values[2u].toDouble()); } - if (transform.isMember("gamma")) + if (transform.contains("gamma")) { - const Json::Value & values = transform["gamma"]; - colorTransform->_rgbRedTransform .setGamma(values[0u].asDouble()); - colorTransform->_rgbGreenTransform.setGamma(values[1u].asDouble()); - colorTransform->_rgbBlueTransform .setGamma(values[2u].asDouble()); + const QJsonArray & values = transform["gamma"].toArray(); + colorTransform->_rgbRedTransform .setGamma(values[0u].toDouble()); + colorTransform->_rgbGreenTransform.setGamma(values[1u].toDouble()); + colorTransform->_rgbBlueTransform .setGamma(values[2u].toDouble()); } - if (transform.isMember("blacklevel")) + if (transform.contains("blacklevel")) { - const Json::Value & values = transform["blacklevel"]; - colorTransform->_rgbRedTransform .setBlacklevel(values[0u].asDouble()); - colorTransform->_rgbGreenTransform.setBlacklevel(values[1u].asDouble()); - colorTransform->_rgbBlueTransform .setBlacklevel(values[2u].asDouble()); + const QJsonArray & values = transform["blacklevel"].toArray(); + colorTransform->_rgbRedTransform .setBlacklevel(values[0u].toDouble()); + colorTransform->_rgbGreenTransform.setBlacklevel(values[1u].toDouble()); + colorTransform->_rgbBlueTransform .setBlacklevel(values[2u].toDouble()); } - if (transform.isMember("whitelevel")) + if (transform.contains("whitelevel")) { - const Json::Value & values = transform["whitelevel"]; - colorTransform->_rgbRedTransform .setWhitelevel(values[0u].asDouble()); - colorTransform->_rgbGreenTransform.setWhitelevel(values[1u].asDouble()); - colorTransform->_rgbBlueTransform .setWhitelevel(values[2u].asDouble()); + const QJsonArray & values = transform["whitelevel"].toArray(); + colorTransform->_rgbRedTransform .setWhitelevel(values[0u].toDouble()); + colorTransform->_rgbGreenTransform.setWhitelevel(values[1u].toDouble()); + colorTransform->_rgbBlueTransform .setWhitelevel(values[2u].toDouble()); } // commit the changes @@ -780,24 +849,24 @@ void JsonClientConnection::handleTransformCommand(const Json::Value &message, co } -void JsonClientConnection::handleTemperatureCommand(const Json::Value &message, const std::string &command, const int tan) +void JsonClientConnection::handleTemperatureCommand(const QJsonObject& message, const QString& command, const int tan) { - const Json::Value & temperature = message["temperature"]; + const QJsonObject & temperature = message["temperature"].toObject(); - const std::string tempId = temperature.get("id", _hyperion->getTemperatureIds().front()).asString(); - ColorCorrection * colorTemperature = _hyperion->getTemperature(tempId); + const QString tempId = temperature["id"].toString(QString::fromStdString(_hyperion->getTemperatureIds().front())); + ColorCorrection * colorTemperature = _hyperion->getTemperature(tempId.toStdString()); if (colorTemperature == nullptr) { - //sendErrorReply(std::string("Incorrect temperature identifier: ") + tempId); + Warning(_log, "Incorrect temperature identifier: %s", tempId.toStdString().c_str()); return; } - if (temperature.isMember("correctionValues")) + if (temperature.contains("correctionValues")) { - const Json::Value & values = temperature["correctionValues"]; - colorTemperature->_rgbCorrection.setAdjustmentR(values[0u].asInt()); - colorTemperature->_rgbCorrection.setAdjustmentG(values[1u].asInt()); - colorTemperature->_rgbCorrection.setAdjustmentB(values[2u].asInt()); + const QJsonArray & values = temperature["correctionValues"].toArray(); + colorTemperature->_rgbCorrection.setAdjustmentR(values[0u].toInt()); + colorTemperature->_rgbCorrection.setAdjustmentG(values[1u].toInt()); + colorTemperature->_rgbCorrection.setAdjustmentB(values[2u].toInt()); } // commit the changes @@ -806,40 +875,40 @@ void JsonClientConnection::handleTemperatureCommand(const Json::Value &message, sendSuccessReply(command, tan); } -void JsonClientConnection::handleAdjustmentCommand(const Json::Value &message, const std::string &command, const int tan) +void JsonClientConnection::handleAdjustmentCommand(const QJsonObject& message, const QString& command, const int tan) { - const Json::Value & adjustment = message["adjustment"]; + const QJsonObject & adjustment = message["adjustment"].toObject(); - const std::string adjustmentId = adjustment.get("id", _hyperion->getAdjustmentIds().front()).asString(); - ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId); + const QString adjustmentId = adjustment["id"].toString(QString::fromStdString(_hyperion->getAdjustmentIds().front())); + ColorAdjustment * colorAdjustment = _hyperion->getAdjustment(adjustmentId.toStdString()); if (colorAdjustment == nullptr) { - //sendErrorReply(std::string("Incorrect transform identifier: ") + transformId); + Warning(_log, "Incorrect adjustment identifier: %s", adjustmentId.toStdString().c_str()); return; } - if (adjustment.isMember("redAdjust")) + if (adjustment.contains("redAdjust")) { - const Json::Value & values = adjustment["redAdjust"]; - colorAdjustment->_rgbRedAdjustment.setAdjustmentR(values[0u].asInt()); - colorAdjustment->_rgbRedAdjustment.setAdjustmentG(values[1u].asInt()); - colorAdjustment->_rgbRedAdjustment.setAdjustmentB(values[2u].asInt()); + const QJsonArray & values = adjustment["redAdjust"].toArray(); + colorAdjustment->_rgbRedAdjustment.setAdjustmentR(values[0u].toInt()); + colorAdjustment->_rgbRedAdjustment.setAdjustmentG(values[1u].toInt()); + colorAdjustment->_rgbRedAdjustment.setAdjustmentB(values[2u].toInt()); } - if (adjustment.isMember("greenAdjust")) + if (adjustment.contains("greenAdjust")) { - const Json::Value & values = adjustment["greenAdjust"]; - colorAdjustment->_rgbGreenAdjustment.setAdjustmentR(values[0u].asInt()); - colorAdjustment->_rgbGreenAdjustment.setAdjustmentG(values[1u].asInt()); - colorAdjustment->_rgbGreenAdjustment.setAdjustmentB(values[2u].asInt()); + const QJsonArray & values = adjustment["greenAdjust"].toArray(); + colorAdjustment->_rgbGreenAdjustment.setAdjustmentR(values[0u].toInt()); + colorAdjustment->_rgbGreenAdjustment.setAdjustmentG(values[1u].toInt()); + colorAdjustment->_rgbGreenAdjustment.setAdjustmentB(values[2u].toInt()); } - if (adjustment.isMember("blueAdjust")) + if (adjustment.contains("blueAdjust")) { - const Json::Value & values = adjustment["blueAdjust"]; - colorAdjustment->_rgbBlueAdjustment.setAdjustmentR(values[0u].asInt()); - colorAdjustment->_rgbBlueAdjustment.setAdjustmentG(values[1u].asInt()); - colorAdjustment->_rgbBlueAdjustment.setAdjustmentB(values[2u].asInt()); + const QJsonArray & values = adjustment["blueAdjust"].toArray(); + colorAdjustment->_rgbBlueAdjustment.setAdjustmentR(values[0u].toInt()); + colorAdjustment->_rgbBlueAdjustment.setAdjustmentG(values[1u].toInt()); + colorAdjustment->_rgbBlueAdjustment.setAdjustmentB(values[2u].toInt()); } // commit the changes _hyperion->adjustmentsUpdated(); @@ -847,17 +916,17 @@ void JsonClientConnection::handleAdjustmentCommand(const Json::Value &message, c sendSuccessReply(command, tan); } -void JsonClientConnection::handleSourceSelectCommand(const Json::Value & message, const std::string &command, const int tan) +void JsonClientConnection::handleSourceSelectCommand(const QJsonObject& message, const QString& command, const int tan) { bool success = false; - if (message.get("auto",false).asBool()) + if (message["auto"].toBool(false)) { _hyperion->setSourceAutoSelectEnabled(true); success = true; } - else if (message.isMember("priority")) + else if (message.contains("priority")) { - success = _hyperion->setCurrentSourcePriority(message["priority"].asInt()); + success = _hyperion->setCurrentSourcePriority(message["priority"].toInt()); } if (success) @@ -870,10 +939,10 @@ void JsonClientConnection::handleSourceSelectCommand(const Json::Value & message } } -void JsonClientConnection::handleConfigCommand(const Json::Value & message, const std::string &command, const int tan) +void JsonClientConnection::handleConfigCommand(const QJsonObject& message, const QString& command, const int tan) { - std::string subcommand = message.get("subcommand","").asString(); - std::string full_command = command + "-" + subcommand; + QString subcommand = message["subcommand"].toString(""); + QString full_command = command + "-" + subcommand; if (subcommand == "getschema") { handleSchemaGetCommand(message, full_command, tan); @@ -897,105 +966,111 @@ void JsonClientConnection::handleConfigCommand(const Json::Value & message, cons } } -void JsonClientConnection::handleConfigGetCommand(const Json::Value & message, const std::string &command, const int tan) +void JsonClientConnection::handleConfigGetCommand(const QJsonObject& message, const QString& command, const int tan) { // create result - Json::Value result; + QJsonObject result; result["success"] = true; result["command"] = command; result["tan"] = tan; - Json::Value & config = result["result"]; - config = _hyperion->getJsonConfig(); - + const QJsonObject & config = _hyperion->getQJsonConfig(); + result["result"] = config; + // send the result sendMessage(result); } -void JsonClientConnection::handleSchemaGetCommand(const Json::Value & message, const std::string &command, const int tan) +void JsonClientConnection::handleSchemaGetCommand(const QJsonObject& message, const QString& command, const int tan) { // create result - Json::Value result; + QJsonObject result, schemaJson, alldevices, properties; result["success"] = true; result["command"] = command; result["tan"] = tan; - Json::Value & schemaJson = result["result"]; - - // make sure the resources are loaded (they may be left out after static linking) Q_INIT_RESOURCE(resource); + QJsonParseError error; // read the json schema from the resource - QResource schemaData(":/hyperion-schema"); - assert(schemaData.isValid()); - - Json::Reader jsonReader; - if (!jsonReader.parse(reinterpret_cast(schemaData.data()), reinterpret_cast(schemaData.data()) + schemaData.size(), schemaJson, false)) + QFile schemaData(":/hyperion-schema"); + + if (!schemaData.open(QIODevice::ReadOnly)) { - throw std::runtime_error("ERROR: Json schema wrong: " + jsonReader.getFormattedErrorMessages()) ; + std::stringstream error; + error << "Schema not found: " << schemaData.errorString().toStdString(); + throw std::runtime_error(error.str()); } - result["result"]["properties"]["alldevices"] = LedDevice::getLedDeviceSchemas(); + + QByteArray schema = schemaData.readAll(); + QJsonDocument doc = QJsonDocument::fromJson(schema, &error); + schemaData.close(); + + if (error.error != QJsonParseError::NoError) + { + // report to the user the failure and their locations in the document. + int errorLine(0), errorColumn(0); + + for( int i=0, count=qMin( error.offset,schema.size()); i 0) { - if (message.isObject() && message.isMember("config")) + if (message.contains("config")) { - std::string errors; - if (!checkJson(message["config"], ":/hyperion-schema", errors, true)) + QString errors; + if (!checkJson(message["config"].toObject(), ":/hyperion-schema", errors, true)) { sendErrorReply("Error while validating json: " + errors, command, tan); return; } - bool createKey = message["create"].asBool(); - Json::Value hyperionConfig; - message["overwrite"].asBool() ? createKey = true : hyperionConfig = _hyperion->getJsonConfig(); - nested::configSetCommand(message["config"], hyperionConfig, createKey); - - JsonFactory::writeJson(_hyperion->getConfigFileName(), hyperionConfig); + QJsonObject hyperionConfig = message["config"].toObject(); + QJsonFactory::writeJson(QString::fromStdString(_hyperion->getConfigFileName()), hyperionConfig); sendSuccessReply(command, tan); } } else - sendErrorReply("Error while parsing json: Message size " + std::to_string(message.size()), command, tan); + sendErrorReply("Error while parsing json: Message size " + QString(message.size()), command, tan); } -void JsonClientConnection::handleComponentStateCommand(const Json::Value& message, const std::string &command, const int tan) +void JsonClientConnection::handleComponentStateCommand(const QJsonObject& message, const QString &command, const int tan) { - const Json::Value & componentState = message["componentstate"]; - Components component = stringToComponent(QString::fromStdString(componentState.get("component", "invalid").asString())); + const QJsonObject & componentState = message["componentstate"].toObject(); + Components component = stringToComponent(componentState["component"].toString("invalid")); if (component != COMP_INVALID) { - _hyperion->setComponentState(component, componentState.get("state", true).asBool()); + _hyperion->setComponentState(component, componentState["state"].toBool(true)); sendSuccessReply(command, tan); } else @@ -1004,10 +1079,10 @@ void JsonClientConnection::handleComponentStateCommand(const Json::Value& messag } } -void JsonClientConnection::handleLedColorsCommand(const Json::Value& message, const std::string &command, const int tan) +void JsonClientConnection::handleLedColorsCommand(const QJsonObject& message, const QString &command, const int tan) { // create result - std::string subcommand = message.get("subcommand","").asString(); + QString subcommand = message["subcommand"].toString(""); _streaming_leds_reply["success"] = true; _streaming_leds_reply["command"] = command; _streaming_leds_reply["tan"] = tan; @@ -1035,10 +1110,10 @@ void JsonClientConnection::handleNotImplemented() sendErrorReply("Command not implemented"); } -void JsonClientConnection::sendMessage(const Json::Value &message) +void JsonClientConnection::sendMessage(const QJsonObject &message) { - Json::FastWriter writer; - std::string serializedReply = writer.write(message); + QJsonDocument writer(message); + QByteArray serializedReply = writer.toJson(QJsonDocument::Compact) + "\n"; if (!_webSocketHandshakeDone) { @@ -1061,20 +1136,21 @@ void JsonClientConnection::sendMessage(const Json::Value &message) response.append(size); } - response.append(serializedReply.c_str(), serializedReply.length()); + response.append(serializedReply, serializedReply.length()); _socket->write(response.data(), response.length()); } } -void JsonClientConnection::sendMessage(const Json::Value & message, QTcpSocket * socket) +void JsonClientConnection::sendMessage(const QJsonObject & message, QTcpSocket * socket) { - // serialize message (FastWriter already appends a newline) - std::string serializedMessage = Json::FastWriter().write(message); + // serialize message + QJsonDocument writer(message); + QByteArray serializedMessage = writer.toJson(QJsonDocument::Compact) + "\n"; // write message - socket->write(serializedMessage.c_str()); + socket->write(serializedMessage); if (!socket->waitForBytesWritten()) { Debug(_log, "Error while writing data to host"); @@ -1094,12 +1170,12 @@ void JsonClientConnection::sendMessage(const Json::Value & message, QTcpSocket * serializedReply += socket->readAll(); } - int bytes = serializedReply.indexOf('\n') + 1; // Find the end of message // parse reply data - Json::Reader jsonReader; - Json::Value reply; - if (!jsonReader.parse(serializedReply.constData(), serializedReply.constData() + bytes, reply)) + QJsonParseError error; + QJsonDocument reply = QJsonDocument::fromJson(serializedReply ,&error); + + if (error.error != QJsonParseError::NoError) { Error(_log, "Error while parsing reply: invalid json"); return; @@ -1107,10 +1183,10 @@ void JsonClientConnection::sendMessage(const Json::Value & message, QTcpSocket * } -void JsonClientConnection::sendSuccessReply(const std::string &command, const int tan) +void JsonClientConnection::sendSuccessReply(const QString &command, const int tan) { // create reply - Json::Value reply; + QJsonObject reply; reply["success"] = true; reply["command"] = command; reply["tan"] = tan; @@ -1119,10 +1195,10 @@ void JsonClientConnection::sendSuccessReply(const std::string &command, const in sendMessage(reply); } -void JsonClientConnection::sendErrorReply(const std::string &error, const std::string &command, const int tan) +void JsonClientConnection::sendErrorReply(const QString &error, const QString &command, const int tan) { // create reply - Json::Value reply; + QJsonObject reply; reply["success"] = false; reply["error"] = error; reply["command"] = command; @@ -1132,61 +1208,87 @@ void JsonClientConnection::sendErrorReply(const std::string &error, const std::s sendMessage(reply); } -bool JsonClientConnection::checkJson(const Json::Value & message, const QString & schemaResource, std::string & errorMessage, bool ignoreRequired) +bool JsonClientConnection::checkJson(const QJsonObject& message, const QString& schemaResource, QString& errorMessage, bool ignoreRequired) { + // make sure the resources are loaded (they may be left out after static linking) + Q_INIT_RESOURCE(JsonSchemas); + QJsonParseError error; + // read the json schema from the resource - QResource schemaData(schemaResource); - assert(schemaData.isValid()); - Json::Reader jsonReader; - Json::Value schemaJson; - if (!jsonReader.parse(reinterpret_cast(schemaData.data()), reinterpret_cast(schemaData.data()) + schemaData.size(), schemaJson, false)) + QFile schemaData(schemaResource); + if (!schemaData.open(QIODevice::ReadOnly)) { - errorMessage = "Schema error: " + jsonReader.getFormattedErrorMessages(); + errorMessage = "Schema error: " + schemaData.errorString(); return false; } // create schema checker - JsonSchemaChecker schema; - schema.setSchema(schemaJson); + QByteArray schema = schemaData.readAll(); + QJsonDocument schemaJson = QJsonDocument::fromJson(schema, &error); + schemaData.close(); + + if (error.error != QJsonParseError::NoError) + { + // report to the user the failure and their locations in the document. + int errorLine(0), errorColumn(0); + + for( int i=0, count=qMin( error.offset,schema.size()); i & errors = schema.getMessages(); + const std::list & errors = schemaChecker.getMessages(); std::stringstream ss; ss << "{"; - foreach (const std::string & error, errors) { + foreach (const std::string & error, errors) + { ss << error << " "; } ss << "}"; - errorMessage = ss.str(); + errorMessage = QString::fromStdString(ss.str()); return false; } return true; } - void JsonClientConnection::streamLedcolorsUpdate() { - Json::Value & leds = _streaming_leds_reply["result"]["leds"] = Json::Value(Json::arrayValue); - //QImage pngImage((const uint8_t *) image.memptr(), image.width(), image.height(), 3*image.width(), QImage::Format_RGB888); + QJsonObject result; + QJsonArray leds; const PriorityMuxer::InputInfo & priorityInfo = _hyperion->getPriorityInfo(_hyperion->getCurrentPriority()); - std::vector ledBuffer = priorityInfo.ledColors; - - for (ColorRgb& color : ledBuffer) + for(auto color = priorityInfo.ledColors.begin(); color != priorityInfo.ledColors.end(); ++color) { - int idx = leds.size(); - Json::Value & item = leds[idx]; - item["index"] = idx; - item["red"] = color.red; - item["green"] = color.green; - item["blue"] = color.blue; + QJsonObject item; + item["index"] = int(color - priorityInfo.ledColors.begin()); + item["red"] = color->red; + item["green"] = color->green; + item["blue"] = color->blue; + leds.append(item); } + + result["leds"] = leds; + _streaming_leds_reply["result"] = result; // send the result sendMessage(_streaming_leds_reply); } - diff --git a/libsrc/jsonserver/JsonClientConnection.h b/libsrc/jsonserver/JsonClientConnection.h index 6e0cb824..1c61cdba 100644 --- a/libsrc/jsonserver/JsonClientConnection.h +++ b/libsrc/jsonserver/JsonClientConnection.h @@ -7,14 +7,11 @@ #include #include -// jsoncpp includes -#include - // Hyperion includes #include // util includes -#include +#include #include #include @@ -69,113 +66,113 @@ private: /// /// @param message the incoming message as string /// - void handleMessage(const std::string & message); + void handleMessage(const QString & message); /// /// Handle an incoming JSON Color message /// /// @param message the incoming message /// - void handleColorCommand(const Json::Value & message, const std::string &command, const int tan); + void handleColorCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON Image message /// /// @param message the incoming message /// - void handleImageCommand(const Json::Value & message, const std::string &command, const int tan); + void handleImageCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON Effect message /// /// @param message the incoming message /// - void handleEffectCommand(const Json::Value & message, const std::string &command, const int tan); + void handleEffectCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON Server info message /// /// @param message the incoming message /// - void handleServerInfoCommand(const Json::Value & message, const std::string &command, const int tan); + void handleServerInfoCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON Clear message /// /// @param message the incoming message /// - void handleClearCommand(const Json::Value & message, const std::string &command, const int tan); + void handleClearCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON Clearall message /// /// @param message the incoming message /// - void handleClearallCommand(const Json::Value & message, const std::string &command, const int tan); + void handleClearallCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON Transform message /// /// @param message the incoming message /// - void handleTransformCommand(const Json::Value & message, const std::string &command, const int tan); + void handleTransformCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON Temperature message /// /// @param message the incoming message /// - void handleTemperatureCommand(const Json::Value & message, const std::string &command, const int tan); + void handleTemperatureCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON Adjustment message /// /// @param message the incoming message /// - void handleAdjustmentCommand(const Json::Value & message, const std::string &command, const int tan); + void handleAdjustmentCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON SourceSelect message /// /// @param message the incoming message /// - void handleSourceSelectCommand(const Json::Value & message, const std::string &command, const int tan); + void handleSourceSelectCommand(const QJsonObject & message, const QString &command, const int tan); /// Handle an incoming JSON GetConfig message /// /// @param message the incoming message /// - void handleConfigCommand(const Json::Value & message, const std::string &command, const int tan); + void handleConfigCommand(const QJsonObject & message, const QString &command, const int tan); /// Handle an incoming JSON GetConfig message /// /// @param message the incoming message /// - void handleSchemaGetCommand(const Json::Value & message, const std::string &command, const int tan); + void handleSchemaGetCommand(const QJsonObject & message, const QString &command, const int tan); /// Handle an incoming JSON GetConfig message /// /// @param message the incoming message /// - void handleConfigGetCommand(const Json::Value & message, const std::string &command, const int tan); + void handleConfigGetCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON SetConfig message /// - void handleConfigSetCommand(const Json::Value & message, const std::string &command, const int tan); + void handleConfigSetCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON Component State message /// /// @param message the incoming message /// - void handleComponentStateCommand(const Json::Value & message, const std::string &command, const int tan); + void handleComponentStateCommand(const QJsonObject & message, const QString &command, const int tan); /// Handle an incoming JSON Led Colors message /// /// @param message the incoming message /// - void handleLedColorsCommand(const Json::Value & message, const std::string &command, const int tan); + void handleLedColorsCommand(const QJsonObject & message, const QString &command, const int tan); /// /// Handle an incoming JSON message of unknown type @@ -187,20 +184,20 @@ private: /// /// @param message The JSON message to send /// - void sendMessage(const Json::Value & message); - void sendMessage(const Json::Value & message, QTcpSocket * socket); + void sendMessage(const QJsonObject & message); + void sendMessage(const QJsonObject & message, QTcpSocket * socket); /// /// Send a standard reply indicating success /// - void sendSuccessReply(const std::string &command="", const int tan=0); + void sendSuccessReply(const QString &command="", const int tan=0); /// /// Send an error message back to the client /// /// @param error String describing the error /// - void sendErrorReply(const std::string & error, const std::string &command="", const int tan=0); + void sendErrorReply(const QString & error, const QString &command="", const int tan=0); /// /// Do handshake for a websocket connection @@ -215,7 +212,7 @@ private: /// /// forward json message /// - void forwardJsonMessage(const Json::Value & message); + void forwardJsonMessage(const QJsonObject & message); private: /// @@ -228,7 +225,7 @@ private: /// /// @return true if message conforms the given JSON schema /// - bool checkJson(const Json::Value & message, const QString &schemaResource, std::string & errors, bool ignoreRequired = false); + bool checkJson(const QJsonObject & message, const QString &schemaResource, QString & errors, bool ignoreRequired = false); /// The TCP-Socket that is connected tot the Json-client QTcpSocket * _socket; @@ -254,6 +251,6 @@ private: /// QTimer _timer_ledcolors; - Json::Value _streaming_leds_reply; + QJsonObject _streaming_leds_reply; }; diff --git a/libsrc/jsonserver/schema/schema-config.json b/libsrc/jsonserver/schema/schema-config.json index bb574dd3..8cd7e0bf 100644 --- a/libsrc/jsonserver/schema/schema-config.json +++ b/libsrc/jsonserver/schema/schema-config.json @@ -17,12 +17,6 @@ }, "config": { "type" : "object" - }, - "create": { - "type" : "boolean" - }, - "overwrite": { - "type" : "boolean" } }, "additionalProperties": false diff --git a/libsrc/leddevice/LedDevice.cpp b/libsrc/leddevice/LedDevice.cpp index 0b6570af..51cc5ace 100644 --- a/libsrc/leddevice/LedDevice.cpp +++ b/libsrc/leddevice/LedDevice.cpp @@ -1,9 +1,12 @@ #include +#include +//QT include #include #include #include -#include +#include +#include LedDeviceRegistry LedDevice::_ledDeviceMap = LedDeviceRegistry(); std::string LedDevice::_activeDevice = ""; @@ -43,29 +46,57 @@ void LedDevice::setActiveDevice(std::string dev) _activeDevice = dev; } -Json::Value LedDevice::getLedDeviceSchemas() +QJsonObject LedDevice::getLedDeviceSchemas() { // make sure the resources are loaded (they may be left out after static linking) Q_INIT_RESOURCE(LedDeviceSchemas); + QJsonParseError error; // read the json schema from the resource QDir d(":/leddevices/"); QStringList l = d.entryList(); - Json::Value result; + QJsonObject result, schemaJson; + for(QString &item : l) { - QResource schemaData(QString(":/leddevices/")+item); - std::string devName = item.remove("schema-").toStdString(); - Json::Value & schemaJson = result[devName]; + QFile schemaData(QString(":/leddevices/")+item); + QString devName = item.remove("schema-"); - Json::Reader jsonReader; - if (!jsonReader.parse(reinterpret_cast(schemaData.data()), reinterpret_cast(schemaData.data()) + schemaData.size(), schemaJson, false)) + if (!schemaData.open(QIODevice::ReadOnly)) { - Error(Logger::getInstance("LedDevice"), "LedDevice JSON schema error in %s (%s)", item.toUtf8().constData(), jsonReader.getFormattedErrorMessages().c_str() ); - throw std::runtime_error("ERROR: Json schema wrong: " + jsonReader.getFormattedErrorMessages()) ; + Error(Logger::getInstance("LedDevice"), "Schema not found: %s", item.toUtf8().constData()); + throw std::runtime_error("ERROR: Schema not found: " + item.toStdString()); } - schemaJson["title"] = "LED Device Specific"; - + + QByteArray schema = schemaData.readAll(); + QJsonDocument doc = QJsonDocument::fromJson(schema, &error); + schemaData.close(); + + if (error.error != QJsonParseError::NoError) + { + // report to the user the failure and their locations in the document. + int errorLine(0), errorColumn(0); + + for( int i=0, count=qMin( error.offset,schema.size()); i 0) { diff --git a/src/hyperion-remote/JsonConnection.h b/src/hyperion-remote/JsonConnection.h index d7149d95..9b585271 100644 --- a/src/hyperion-remote/JsonConnection.h +++ b/src/hyperion-remote/JsonConnection.h @@ -111,7 +111,7 @@ public: /// @param jsonString The JSON String(s) to write /// @param create Specifies whether the nonexistent json string to be created /// - void setConfig(const QString &jsonString, bool create, bool overwrite); + void setConfig(const QString &jsonString); /// /// Set the color transform of the leds diff --git a/src/hyperion-remote/hyperion-remote.cpp b/src/hyperion-remote/hyperion-remote.cpp index 4855cd17..3e6384a8 100644 --- a/src/hyperion-remote/hyperion-remote.cpp +++ b/src/hyperion-remote/hyperion-remote.cpp @@ -91,10 +91,8 @@ int main(int argc, char * argv[]) BooleanOption & argSourceAuto = parser.add(0x0, "sourceAutoSelect", "Enables auto source, if disabled prio by manual selecting input source"); BooleanOption & argSourceOff = parser.add(0x0, "sourceOff", "select no source, this results in leds activly set to black (=off)"); BooleanOption & argConfigGet = parser.add(0x0, "configGet" , "Print the current loaded Hyperion configuration file"); - Option & argSchemaGet = parser.add