mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
JsonUtils & improvements (#476)
* add JsonUtils * update * repair * update * ident * Schema correct msg other adjusts * fix effDel, ExceptionLog, cleanup * fix travis qt5.2 * not so funny * use Qthread interrupt instead abort bool * update services
This commit is contained in:
@@ -24,6 +24,7 @@ add_executable(${PROJECT_NAME}
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
effectengine
|
||||
commandline
|
||||
hyperion-utils
|
||||
Qt5::Gui
|
||||
Qt5::Core
|
||||
Qt5::Network)
|
||||
|
@@ -14,8 +14,12 @@
|
||||
// hyperion-remote includes
|
||||
#include "JsonConnection.h"
|
||||
|
||||
// util includes
|
||||
#include <utils/JsonUtils.h>
|
||||
|
||||
JsonConnection::JsonConnection(const QString & address, bool printJson)
|
||||
: _printJson(printJson)
|
||||
, _log(Logger::getInstance("REMOTE"))
|
||||
, _socket()
|
||||
{
|
||||
QStringList parts = address.split(":");
|
||||
@@ -62,7 +66,7 @@ void JsonConnection::setColor(std::vector<QColor> colors, int priority, int dura
|
||||
rgbValue.append(color.blue());
|
||||
}
|
||||
command["color"] = rgbValue;
|
||||
|
||||
|
||||
if (duration > 0)
|
||||
{
|
||||
command["duration"] = duration;
|
||||
@@ -125,37 +129,20 @@ void JsonConnection::setEffect(const QString &effectName, const QString & effect
|
||||
command["origin"] = QString("hyperion-remote");
|
||||
command["priority"] = priority;
|
||||
effect["name"] = effectName;
|
||||
|
||||
|
||||
if (effectArgs.size() > 0)
|
||||
{
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(effectArgs.toUtf8() ,&error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
QJsonObject effObj;
|
||||
if(!JsonUtils::parse("hyperion-remote-args", effectArgs, effObj, _log))
|
||||
{
|
||||
// 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,effectArgs.size()); i<count; ++i )
|
||||
{
|
||||
++errorColumn;
|
||||
if(effectArgs.at(i) == '\n' )
|
||||
{
|
||||
errorColumn = 0;
|
||||
++errorLine;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream sstream;
|
||||
sstream << "Error in effect arguments: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
|
||||
throw std::runtime_error(sstream.str());
|
||||
throw std::runtime_error("Error in effect arguments, abort");
|
||||
}
|
||||
|
||||
effect["args"] = doc.object();
|
||||
|
||||
effect["args"] = effObj;
|
||||
}
|
||||
|
||||
|
||||
command["effect"] = effect;
|
||||
|
||||
|
||||
if (duration > 0)
|
||||
{
|
||||
command["duration"] = duration;
|
||||
@@ -177,33 +164,16 @@ void JsonConnection::createEffect(const QString &effectName, const QString &effe
|
||||
effect["command"] = QString("create-effect");
|
||||
effect["name"] = effectName;
|
||||
effect["script"] = effectScript;
|
||||
|
||||
|
||||
if (effectArgs.size() > 0)
|
||||
{
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(effectArgs.toUtf8() ,&error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
QJsonObject effObj;
|
||||
if(!JsonUtils::parse("hyperion-remote-args", effectScript, effObj, _log))
|
||||
{
|
||||
// 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,effectArgs.size()); i<count; ++i )
|
||||
{
|
||||
++errorColumn;
|
||||
if(effectArgs.at(i) == '\n' )
|
||||
{
|
||||
errorColumn = 0;
|
||||
++errorLine;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream sstream;
|
||||
sstream << "Error in effect arguments: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
|
||||
throw std::runtime_error(sstream.str());
|
||||
throw std::runtime_error("Error in effect arguments, abort");
|
||||
}
|
||||
|
||||
effect["args"] = doc.object();
|
||||
|
||||
effect["args"] = effObj;
|
||||
}
|
||||
|
||||
// send command message
|
||||
@@ -221,7 +191,7 @@ void JsonConnection::deleteEffect(const QString &effectName)
|
||||
QJsonObject effect;
|
||||
effect["command"] = QString("delete-effect");
|
||||
effect["name"] = effectName;
|
||||
|
||||
|
||||
// send command message
|
||||
QJsonObject reply = sendMessage(effect);
|
||||
|
||||
@@ -380,7 +350,7 @@ QString JsonConnection::getConfig(std::string type)
|
||||
{
|
||||
throw std::runtime_error("No configuration file available in result");
|
||||
}
|
||||
|
||||
|
||||
QJsonDocument doc(reply["result"].toObject());
|
||||
QString result(doc.toJson(QJsonDocument::Indented));
|
||||
return result;
|
||||
@@ -395,36 +365,22 @@ void JsonConnection::setConfig(const QString &jsonString)
|
||||
QJsonObject command;
|
||||
command["command"] = QString("config");
|
||||
command["subcommand"] = QString("setconfig");
|
||||
|
||||
|
||||
|
||||
|
||||
if (jsonString.size() > 0)
|
||||
{
|
||||
QJsonParseError error;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(jsonString.toUtf8() ,&error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
QJsonObject configObj;
|
||||
if(!JsonUtils::parse("hyperion-remote-args", jsonString, configObj, _log))
|
||||
{
|
||||
// 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,jsonString.size()); i<count; ++i )
|
||||
{
|
||||
++errorColumn;
|
||||
if(jsonString.at(i) == '\n' )
|
||||
{
|
||||
errorColumn = 0;
|
||||
++errorLine;
|
||||
}
|
||||
}
|
||||
|
||||
std::stringstream sstream;
|
||||
sstream << "Error in configset arguments: " << error.errorString().toStdString() << " at Line: " << errorLine << ", Column: " << errorColumn;
|
||||
throw std::runtime_error(sstream.str());
|
||||
throw std::runtime_error("Error in configset arguments, abort");
|
||||
}
|
||||
|
||||
command["config"] = doc.object();
|
||||
|
||||
command["config"] = configObj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// send command message
|
||||
QJsonObject reply = sendMessage(command);
|
||||
|
||||
@@ -460,7 +416,7 @@ void JsonConnection::setAdjustment(
|
||||
{
|
||||
adjust["id"] = adjustmentId;
|
||||
}
|
||||
|
||||
|
||||
if (redAdjustment.isValid())
|
||||
{
|
||||
QJsonArray red;
|
||||
|
@@ -6,6 +6,9 @@
|
||||
#include <QTcpSocket>
|
||||
#include <QJsonObject>
|
||||
|
||||
//forward class decl
|
||||
class Logger;
|
||||
|
||||
///
|
||||
/// Connection class to setup an connection to the hyperion server and execute commands
|
||||
///
|
||||
@@ -61,7 +64,7 @@ public:
|
||||
/// @param effectArgs The arguments of the effect
|
||||
///
|
||||
void createEffect(const QString &effectName, const QString &effectScript, const QString & effectArgs);
|
||||
|
||||
|
||||
///
|
||||
/// Delete a effect configuration file (.json)
|
||||
///
|
||||
@@ -116,7 +119,7 @@ public:
|
||||
void setSourceAutoSelect();
|
||||
|
||||
///
|
||||
/// Print the current loaded Hyperion configuration file
|
||||
/// Print the current loaded Hyperion configuration file
|
||||
///
|
||||
QString getConfig(std::string type);
|
||||
|
||||
@@ -188,10 +191,13 @@ private:
|
||||
///
|
||||
bool parseReply(const QJsonObject & reply);
|
||||
|
||||
private:
|
||||
/// Flag for printing all send and received json-messages to the standard out
|
||||
bool _printJson;
|
||||
|
||||
// Logger class
|
||||
Logger* _log;
|
||||
|
||||
/// The TCP-Socket with the connection to the server
|
||||
QTcpSocket _socket;
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user