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
This commit is contained in:
Paulchen Panther
2016-10-09 22:22:17 +02:00
committed by redPanther
parent 0a142b0e7d
commit d9c2a2d91a
20 changed files with 660 additions and 468 deletions

View File

@@ -1,16 +1,14 @@
#pragma once
// stl include
#include <string>
// json include
#include <json/value.h>
// QT include
#include <QString>
#include <QJsonObject>
struct ActiveEffectDefinition
{
std::string script;
std::string name;
QString script;
QString name;
int priority;
int timeout;
Json::Value args;
QJsonObject args;
};

View File

@@ -1,14 +1,12 @@
#pragma once
// stl include
#include <string>
// json include
#include <json/value.h>
// QT include
#include <QString>
#include <QJsonObject>
struct EffectDefinition
{
std::string name;
std::string script;
Json::Value args;
QString name;
QString script;
QJsonObject args;
};

View File

@@ -3,9 +3,10 @@
// Qt includes
#include <QObject>
#include <QString>
// Json includes
#include <json/value.h>
#include <QJsonObject>
#include <QJsonValue>
#include <QJsonDocument>
#include <QJsonArray>
// Hyperion includes
#include <hyperion/Hyperion.h>
@@ -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<EffectDefinition> & 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;

View File

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

View File

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

View File

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

View File

@@ -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<std::string> _currentPath;
/// The result messages collected during the schema verification