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:
@@ -57,7 +57,7 @@ public slots:
|
||||
void allChannelsCleared();
|
||||
|
||||
private slots:
|
||||
void effectFinished(Effect * effect);
|
||||
void effectFinished();
|
||||
|
||||
private:
|
||||
bool loadEffectDefinition(const QString & path, const QString & effectConfigFile, EffectDefinition &effectDefinition);
|
||||
@@ -77,7 +77,7 @@ private:
|
||||
std::list<Effect *> _activeEffects;
|
||||
|
||||
std::list<ActiveEffectDefinition> _availableActiveEffects;
|
||||
|
||||
|
||||
std::list<EffectSchema> _effectSchemas;
|
||||
|
||||
PyThreadState * _mainThreadState;
|
||||
|
@@ -80,7 +80,18 @@ public:
|
||||
///
|
||||
void freeObjects(bool emitCloseSignal=false);
|
||||
|
||||
static Hyperion* initInstance(const QJsonObject& qjsonConfig, const QString configFile);
|
||||
///
|
||||
/// @brief creates a new Hyperion instance, usually called from the Hyperion Daemon
|
||||
/// @param[in] qjsonConfig The configuration file
|
||||
/// @param[in] rootPath Root path of all hyperion userdata
|
||||
/// @return Hyperion instance pointer
|
||||
///
|
||||
static Hyperion* initInstance(const QJsonObject& qjsonConfig, const QString configFile, const QString rootPath);
|
||||
|
||||
///
|
||||
/// @brief Get a pointer of this Hyperion instance
|
||||
/// @return Hyperion instance pointer
|
||||
///
|
||||
static Hyperion* getInstance();
|
||||
|
||||
///
|
||||
@@ -189,15 +200,17 @@ public:
|
||||
/// gets the methode how image is maped to leds
|
||||
int getLedMappingType() { return _ledMAppingType; };
|
||||
|
||||
int getConfigVersionId() { return _configVersionId; };
|
||||
|
||||
/// get the configuration
|
||||
QJsonObject getConfig() { return _qjsonConfig; };
|
||||
|
||||
/// get the root path for all hyperion user data files
|
||||
QString getRootPath() { return _rootPath; };
|
||||
|
||||
/// unique id per instance
|
||||
QString id;
|
||||
|
||||
int getLatchTime() const;
|
||||
|
||||
|
||||
/// forward smoothing config
|
||||
unsigned addSmoothingConfig(int settlingTime_ms, double ledUpdateFrequency_hz=25.0, unsigned updateDelay=0);
|
||||
|
||||
@@ -297,7 +310,7 @@ public slots:
|
||||
/// @param[in] mode The new video mode
|
||||
///
|
||||
void setVideoMode(VideoMode mode);
|
||||
|
||||
|
||||
///
|
||||
/// Set the grabbing mode
|
||||
/// @param[in] mode The new grabbing mode
|
||||
@@ -375,7 +388,7 @@ private:
|
||||
///
|
||||
/// @param[in] qjsonConfig The Json configuration
|
||||
///
|
||||
Hyperion(const QJsonObject& qjsonConfig, const QString configFile);
|
||||
Hyperion(const QJsonObject& qjsonConfig, const QString configFile, const QString rootPath);
|
||||
|
||||
/// The specifiation of the led frame construction and picture integration
|
||||
LedString _ledString;
|
||||
@@ -409,6 +422,9 @@ private:
|
||||
/// the name of config file
|
||||
QString _configFile;
|
||||
|
||||
/// root path for all hyperion user data files
|
||||
QString _rootPath;
|
||||
|
||||
/// The timer for handling priority channel timeouts
|
||||
QTimer _timer;
|
||||
QTimer _timerBonjourResolver;
|
||||
@@ -439,8 +455,6 @@ private:
|
||||
|
||||
int _ledMAppingType;
|
||||
|
||||
int _configVersionId;
|
||||
|
||||
hyperion::Components _prevCompId;
|
||||
BonjourServiceBrowser _bonjourBrowser;
|
||||
BonjourServiceResolver _bonjourResolver;
|
||||
@@ -461,8 +475,8 @@ private:
|
||||
|
||||
/// timers to handle severinfo blocking
|
||||
QTimer _fsi_timer;
|
||||
QTimer _fsi_blockTimer;
|
||||
|
||||
QTimer _fsi_blockTimer;
|
||||
|
||||
VideoMode _videoMode;
|
||||
GrabbingMode _grabbingMode;
|
||||
};
|
||||
|
@@ -19,7 +19,7 @@
|
||||
/// performed in two steps. First the average color per led-region is computed. Second a
|
||||
/// color-tranform is applied based on a gamma-correction.
|
||||
///
|
||||
class ImageProcessor : public QObject
|
||||
class ImageProcessor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -44,7 +44,7 @@ public:
|
||||
|
||||
/// Returns starte of black border detector
|
||||
bool blackBorderDetectorEnabled();
|
||||
|
||||
|
||||
/// Returns starte of black border detector
|
||||
int ledMappingType();
|
||||
|
||||
@@ -177,10 +177,10 @@ private:
|
||||
delete _imageToLeds;
|
||||
_imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), 0, 0, _ledString.leds());
|
||||
}
|
||||
|
||||
|
||||
if(_borderProcessor->enabled() && _borderProcessor->process(image))
|
||||
{
|
||||
Debug(Logger::getInstance("BLACKBORDER"), "BORDER SWITCH REQUIRED!!");
|
||||
//Debug(Logger::getInstance("BLACKBORDER"), "BORDER SWITCH REQUIRED!!");
|
||||
|
||||
const hyperion::BlackBorder border = _borderProcessor->getCurrentBorder();
|
||||
|
||||
@@ -198,8 +198,8 @@ private:
|
||||
_imageToLeds = new hyperion::ImageToLedsMap(image.width(), image.height(), border.horizontalSize, border.verticalSize, _ledString.leds());
|
||||
}
|
||||
|
||||
Debug(Logger::getInstance("BLACKBORDER"), "CURRENT BORDER TYPE: unknown=%d hor.size=%d vert.size=%d",
|
||||
border.unknown, border.horizontalSize, border.verticalSize );
|
||||
//Debug(Logger::getInstance("BLACKBORDER"), "CURRENT BORDER TYPE: unknown=%d hor.size=%d vert.size=%d",
|
||||
// border.unknown, border.horizontalSize, border.verticalSize );
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,10 +1,64 @@
|
||||
#pragma once
|
||||
|
||||
// qt includes
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
|
||||
// util includes
|
||||
#include "Logger.h"
|
||||
|
||||
namespace FileUtils {
|
||||
|
||||
QString getBaseName( QString sourceFile);
|
||||
QString getDirName( QString sourceFile);
|
||||
|
||||
///
|
||||
/// @brief check if the file exists
|
||||
/// @param[in] path The file path to check
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @param[in] ignError Ignore errors during file read (no log output)
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool fileExists(const QString& path, Logger* log, bool ignError=false);
|
||||
|
||||
///
|
||||
/// @brief read a file given by path.
|
||||
/// @param[in] path The file path to read
|
||||
/// @param[out] data The read data o success
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @param[in] ignError Ignore errors during file read (no log output)
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool readFile(const QString& path, QString& data, Logger* log, bool ignError=false);
|
||||
|
||||
///
|
||||
/// write a file given by path.
|
||||
/// @param[in] path The file path to read
|
||||
/// @param[in] data The data to write
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool writeFile(const QString& path, const QByteArray& data, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief delete a file by given path
|
||||
/// @param[in] path The file path to delete
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool removeFile(const QString& path, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Convert a path that may contain special placeholders
|
||||
/// @param[in] path The path to convert
|
||||
///
|
||||
QString convertPath(const QString path);
|
||||
|
||||
///
|
||||
/// @brief resolve the file error and print a message
|
||||
/// @param[in] file The file which caused the error
|
||||
/// @param[in] log The logger of the caller
|
||||
///
|
||||
void resolveFileError(const QFile& file, Logger* log);
|
||||
};
|
||||
|
@@ -45,9 +45,10 @@ public:
|
||||
/// Constructor
|
||||
///
|
||||
/// @param peerAddress provide the Address of the peer
|
||||
/// @param noListener if true, this instance won't listen for hyperion push events
|
||||
/// @param log The Logger class of the creator
|
||||
/// @param noListener if true, this instance won't listen for hyperion push events
|
||||
///
|
||||
JsonProcessor(QString peerAddress, bool noListener = false);
|
||||
JsonProcessor(QString peerAddress, Logger* log, bool noListener = false);
|
||||
~JsonProcessor();
|
||||
|
||||
///
|
||||
@@ -272,16 +273,4 @@ private:
|
||||
/// @param error String describing the error
|
||||
///
|
||||
void sendErrorReply(const QString & error, const QString &command="", const int tan=0);
|
||||
|
||||
///
|
||||
/// Check if a JSON messag is valid according to a given JSON schema
|
||||
///
|
||||
/// @param message JSON message which need to be checked
|
||||
/// @param schemaResource Qt Resource identifier with the JSON schema
|
||||
/// @param errors Output error message
|
||||
/// @param ignoreRequired ignore the required value in JSON schema
|
||||
///
|
||||
/// @return true if message conforms the given JSON schema
|
||||
///
|
||||
bool checkJson(const QJsonObject & message, const QString &schemaResource, QString & errors, bool ignoreRequired = false);
|
||||
};
|
||||
|
65
include/utils/JsonUtils.h
Normal file
65
include/utils/JsonUtils.h
Normal file
@@ -0,0 +1,65 @@
|
||||
#pragma once
|
||||
|
||||
#include <utils/FileUtils.h>
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
namespace JsonUtils{
|
||||
///
|
||||
/// @brief read a json file and get the parsed result on success
|
||||
/// @param[in] path The file path to read
|
||||
/// @param[out] obj Returns the parsed QJsonObject
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @param[in] ignError Ignore errors during file read (no log output)
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool readFile(const QString& path, QJsonObject& obj, Logger* log, bool ignError=false);
|
||||
|
||||
///
|
||||
/// @brief read a schema file and resolve $refs
|
||||
/// @param[in] path The file path to read
|
||||
/// @param[out] obj Returns the parsed QJsonObject
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool readSchema(const QString& path, QJsonObject& obj, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief parse a json QString and get the result on success
|
||||
/// @param[in] path The file path/name just used for log messages
|
||||
/// @param[in] data Data to parse
|
||||
/// @param[out] obj Retuns the parsed QJsonObject
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool parse(const QString& path, const QString& data, QJsonObject& obj, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Validate json data against a schema
|
||||
/// @param[in] file The path/name of json file just used for log messages
|
||||
/// @param[in] json The json data
|
||||
/// @param[in] schemaP The schema path
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool validate(const QString& file, const QJsonObject& json, const QString& schemaPath, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Write json data to file
|
||||
/// @param[in] filenameThe file path to write
|
||||
/// @param[in] json The json data to write
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool write(const QString& filename, const QJsonObject& json, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief resolve schema $ref attribute
|
||||
/// @param[in] schema the schema to iterate
|
||||
/// @param[out] obj the resolved object
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool resolveRefs(const QJsonObject& schema, QJsonObject& obj, Logger* log);
|
||||
};
|
@@ -25,7 +25,7 @@ public:
|
||||
// create the validator
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
schemaChecker.setSchema(schemaTree);
|
||||
|
||||
|
||||
QStringList messages = schemaChecker.getMessages();
|
||||
|
||||
if (!schemaChecker.validate(configTree).first)
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
json = configTree;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static QJsonObject readConfig(const QString& path)
|
||||
{
|
||||
QFile file(path);
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
//Allow Comments in Config
|
||||
QString config = QString(file.readAll());
|
||||
config.remove(QRegularExpression("([^:]?\\/\\/.*)"));
|
||||
|
||||
|
||||
QJsonDocument doc = QJsonDocument::fromJson(config.toUtf8(), &error);
|
||||
file.close();
|
||||
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
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.
|
||||
|
@@ -22,6 +22,8 @@
|
||||
/// - addtionalProperties
|
||||
/// - minItems
|
||||
/// - maxItems
|
||||
/// - minLength
|
||||
/// - maxLength
|
||||
|
||||
class QJsonSchemaChecker
|
||||
{
|
||||
@@ -39,7 +41,7 @@ public:
|
||||
/// @brief Validate a JSON structure
|
||||
/// @param value The JSON value to check
|
||||
/// @param ignoreRequired Ignore the "required" keyword in hyperion schema. Default is false
|
||||
/// @return The first boolean is true when the arguments is valid according to the schema. The second is true when the schema contains no errors
|
||||
/// @return The first boolean is true when the arguments is valid according to the schema. The second is true when the schema contains no errors
|
||||
/// @return TODO: Check the Schema in SetSchema() function and remove the QPair result
|
||||
///
|
||||
QPair<bool, bool> validate(const QJsonObject & value, bool ignoreRequired = false);
|
||||
@@ -84,7 +86,7 @@ private:
|
||||
/// @param[in] schema The specified type (as json-value)
|
||||
///
|
||||
void checkType(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
|
||||
|
||||
|
||||
///
|
||||
/// Checks is required properties of an json-object exist and if all properties are of the
|
||||
/// correct format. If this is not the case _error is set to true and an error-message is added
|
||||
@@ -127,7 +129,7 @@ private:
|
||||
/// Checks if the given value is hugher than the specified value. If this is the
|
||||
/// case _error is set to true and an error-message is added to the message-queue.
|
||||
///
|
||||
/// @param value The given value
|
||||
/// @param value The given value
|
||||
/// @param schema The minimum size specification (as json-value)
|
||||
///
|
||||
void checkMinLength(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
|
||||
@@ -136,7 +138,7 @@ private:
|
||||
/// Checks if the given value is smaller than the specified value. If this is the
|
||||
/// case _error is set to true and an error-message is added to the message-queue.
|
||||
///
|
||||
/// @param value The given value
|
||||
/// @param value The given value
|
||||
/// @param schema The maximum size specification (as json-value)
|
||||
///
|
||||
void checkMaxLength(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
|
||||
|
Reference in New Issue
Block a user