move 'name' to new config section general. (#345)

* move name to general
add a version for config file

* start impl. config migrator

* fix typo amd set access level

* fix schemaa name

* fix schema

* add structure for config migrator
This commit is contained in:
redPanther 2016-12-23 19:37:35 +01:00 committed by GitHub
parent be90981388
commit 0825937a3e
21 changed files with 1822 additions and 1261 deletions

View File

@ -0,0 +1,15 @@
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h2 class="page-header"><i class="fa fa-play-wrench-o fa-fw"></i><span data-i18n="conf_general_label_title">General</span></h2>
<div class="introd">
<h4 data-i18n="conf_general_label_intro"></h4>
</div>
<hr />
<div id='editor_container'/>
<button class="btn btn-success" id='btn_submit' data-i18n="general_button_savesettings">Save Settings</button>
</div>
</div>
</div>
<script src="/js/content_general.js"></script>

View File

@ -47,6 +47,7 @@
"dashboard_alert_message_confedit" : "Deine Hyperion Konfiguration wurde verändert. Um die Änderungen anzuwenden, starte Hyperion neu.",
"main_menu_dashboard_token" : "Dashboard",
"main_menu_configuration_token" : "Konfiguration",
"main_menu_general_conf_token" : "Allgemein",
"main_menu_leds_conf_token" : "LED Hardware",
"main_menu_grabber_conf_token" : "Aufnahme Hardware",
"main_menu_effect_conf_token" : "Effekte",
@ -60,7 +61,9 @@
"main_menu_system_token" : "System",
"main_menu_input_selection_token" : "Eingabeauswahl",
"main_menu_logging_token" : "Protokoll",
"main_menu_webconfig_token" : "Webkonfiguration",
"main_menu_webconfig_token" : "Web konfiguration",
"conf_general_label_title" : "All Einstellungen",
"conf_general_label_intro" : " ",
"conf_helptable_option" : "Option",
"conf_helptable_expl" : "Erklärung",
"conf_effects_label_intro" : "Stelle einen Effekt oder Farbe ein, der beim Starten sichtbar sein soll. Stelle einen Hintergrundeffekt/Farbe ein der erst sichtbar wird, wenn alle Bildquellen abgeschaltet sind (Das gilt ebenfalls für temporäres abschalten mithilfe der Kodi Überwachung).",
@ -206,11 +209,12 @@
"InfoDialog_lang_text" : "Sollte dir die Vorauswahl der automatischen Spracherkennung nicht gefallen, kannst du die Sprache hier manuell festlegen.",
"InfoDialog_access_title" : "Zugriffsstufe",
"InfoDialog_access_text" : "Abhängig von der Stufe hast du Zugriff auf mehr oder weniger Einstellungen. Empfohlen ist 'Standard'.",
"edt_general_heading_title" : "Allgemeine Einstellungen",
"edt_general_name_title" : "Name der Konfiguration",
"InfoDialog_nowrite_title" : "Fehler beim Schreibzugriff!",
"InfoDialog_nowrite_text" : "Hyperion hat keinen Schreibzugriff auf die aktuell geladene Konfiguration. Bitte korrigiere die Dateizugriffsrechte um fortzufahren.",
"InfoDialog_nowrite_foottext" : "Die Webkonfiguration wird automatisch wieder freigegeben, sobald das Problem behoben wurde!",
"edt_dev_general_heading_title" : "Allgemeine Einstellungen",
"edt_dev_general_name_title" : "Name der Konfiguration",
"edt_dev_general_ledCount_title" : "Anzahl Hardware LEDs",
"edt_dev_general_colorOrder_title" : "RGB Byte Reihenfolge",
"edt_dev_general_rewriteTime_title" : "Aktualisierungszeit",

View File

@ -47,6 +47,7 @@
"dashboard_alert_message_confedit" : "Your Hyperion configuration has been modified. To apply it, restart Hyperion.",
"main_menu_dashboard_token" : "Dashboard",
"main_menu_configuration_token" : "Configuration",
"main_menu_general_conf_token" : "General",
"main_menu_leds_conf_token" : "LED Hardware",
"main_menu_grabber_conf_token" : "Capturing Hardware",
"main_menu_effect_conf_token" : "Effects",
@ -58,9 +59,11 @@
"main_menu_support_token" : "Support",
"main_menu_update_token" : "Update",
"main_menu_system_token" : "System",
"main_menu_input_selection_token" : "Eingabeauswahl",
"main_menu_input_selection_token" : "Input Selection",
"main_menu_logging_token" : "Log",
"main_menu_webconfig_token" : "Webconfiguration",
"main_menu_webconfig_token" : "Web configuration",
"conf_general_label_title" : "General setings",
"conf_general_label_intro" : " ",
"conf_helptable_option" : "Option",
"conf_helptable_expl" : "Explanation",
"conf_effects_label_intro" : "Setting up a booteffect/color that is visible after Hyperion startup. Configure a background effect/color which is active, when all capture sources are disabled (also temporarily via Kodi Watch)",
@ -206,6 +209,8 @@
"InfoDialog_lang_text" : "If you don't like the result of the automatic language detection you could overwrite it here.",
"InfoDialog_access_title" : "Level setting",
"InfoDialog_access_text" : "Depending on settings level you could change more or less settings. Recommended is the default level.",
"edt_general_heading_title" : "General Settings",
"edt_general_name_title" : "Configuration name",
"InfoDialog_nowrite_title" : "write permission error!",
"InfoDialog_nowrite_text" : "Hyperion can't write to your current loaded configuration file. Please repair the file permissions to proceed.",
"InfoDialog_nowrite_foottext" : "The WebUI will be unlocked automatically after you solved the problem!",

View File

@ -185,6 +185,7 @@
<li>
<a class="inactive"><i class="fa fa-cog fa-fw"></i><span data-i18n="main_menu_configuration_token">Configuration</span><span class="fa arrow"></span></a>
<ul class="nav nav-second-level">
<li> <a class="inactive" id="load_confGeneral"><i class="fa fa-wrench fa-fw"></i><span data-i18n="main_menu_general_conf_token">General</span></a> </li>
<li> <a class="inactive" id="load_confLeds"><i class="fa fa-lightbulb-o fa-fw"></i><span data-i18n="main_menu_leds_conf_token">LED Hardware</span></a> </li>
<li> <a class="inactive" id="load_confGrabber"><i class="fa fa-camera fa-fw"></i><span data-i18n="main_menu_grabber_conf_token">Capturing Hardware</span></a> </li>
<li> <a class="inactive" id="load_confEffects"><i class="fa fa-spinner fa-fw"></i><span data-i18n="main_menu_effect_conf_token">Effects</span></a> </li>

View File

@ -0,0 +1,21 @@
var conf_editor = null;
$(hyperion).one("cmd-config-getschema", function(event) {
schema = parsedConfSchemaJSON.properties;
conf_editor = createJsonEditor('editor_container', {
general: schema.general
}, true);
$('#editor_container h3').remove();
$('#btn_submit').off().on('click',function() {
requestWriteConfig(conf_editor.getValue());
});
});
$(document).ready( function() {
performTranslation();
requestServerConfigSchema();
});

View File

@ -9,9 +9,10 @@ $(document).ready( function() {
bindNavToContent("#load_remote","remote",false);
bindNavToContent("#load_huebridge","huebridge",false);
bindNavToContent("#load_support","support",false);
bindNavToContent("#load_confKodi","kodiconf",false);
bindNavToContent("#load_update","update",false);
bindNavToContent("#load_confGeneral","general",false);
bindNavToContent("#load_confEffects","effects",false);
bindNavToContent("#load_confKodi","kodiconf",false);
bindNavToContent("#load_confLeds","leds",false);
bindNavToContent("#load_confGrabber","grabber",false);
bindNavToContent("#load_confColors","colors",false);

View File

@ -4,6 +4,14 @@
{
/// geenral Settings
/// * 'name' : The user friendly name of the hyperion instance (used for network things)
/// * 'configVersion' : don't touch it's an internal value regarding which validation schema for this config is used
"general" :
{
"name" : "MyHyperionConfig",
"configVersion" : 2
},
/// set log level: silent warn verbose debug
"logger" :
{
@ -19,7 +27,6 @@
/// * 'rewriteTime': in ms. Data is resend to leds, if no new data is available in thistime. 0 means no refresh
"device" :
{
"name" : "MyHyperionConfig",
"type" : "file",
"output" : "/dev/null",
"rate" : 1000000,

View File

@ -1,4 +1,9 @@
{
"general" :
{
"name" : "MyHyperionConfig",
"configVersion" : 2
},
"logger" :
{
"level" : "warn"

View File

@ -185,6 +185,8 @@ public:
/// gets the methode how image is maped to leds
int getLedMappingType() { return _ledMAppingType; };
int getConfigVersionId() { return _configVersionId; };
public slots:
///
@ -411,4 +413,6 @@ private:
QSize _ledGridSize;
int _ledMAppingType;
int _configVersionId;
};

View File

@ -587,6 +587,9 @@ Hyperion::Hyperion(const QJsonObject &qjsonConfig, const QString configFile)
// initialize hash of current config
configModified();
const QJsonObject & generalConfig = qjsonConfig["general"].toObject();
_configVersionId = generalConfig["configVersion"].toInt(-1);
// initialize the leds
update();
}

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,8 @@
<RCC>
<qresource prefix="/">
<file alias="hyperion-schema">hyperion.schema.json</file>
<file alias="hyperion-schema-1">schemas/hyperion.schema-1.json</file>
<file alias="hyperion-schema-2">schemas/hyperion.schema-2.json</file>
<file alias="hyperion_default.config">../../config/hyperion.config.json.default</file>
</qresource>
</RCC>

View File

@ -0,0 +1,386 @@
{
"type" : "object",
"required" : true,
"properties" : {
"device" : {
"type" : "object",
"required" : true,
"properties" : {
"name" : {
"type" : "string",
"required" : true
},
"type" : {
"type" : "string",
"required" : true
},
"output" : {
"type" : "string",
"required" : true
},
"rate" : {
"type" : "integer",
"required" : true,
"minimum" : 0
},
"colorOrder" : {
"type" : "string",
"required" : false
},
"bgr-output" : {
"type" : "boolean",
"required" : false
}
},
"additionalProperties" : false
},
"color": {
"type":"object",
"required":false,
"properties": {
"hsv" : {
"type" : "object",
"required" : false,
"properties" : {
"saturationGain" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
},
"valueGain" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
}
},
"additionalProperties" : false
},
"hsl" : {
"type" : "object",
"required" : false,
"properties" : {
"saturationGain" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
},
"luminanceGain" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
},
"luminanceMinimum" : {
"type" : "number",
"required" : false,
"minimum" : 0.0
}
},
"additionalProperties" : false
},
"red": {
"type":"object",
"required":false,
"properties":{
"gamma": {
"type":"number",
"required":false
},
"blacklevel": {
"type":"number",
"required":false
},
"whitelevel": {
"type":"number",
"required":false
},
"threshold": {
"type":"number",
"required":false,
"minimum" : 0.0,
"maximum" : 1.0
}
},
"additionalProperties" : false
},
"green": {
"type":"object",
"required":false,
"properties":{
"gamma": {
"type":"number",
"required":false
},
"blacklevel": {
"type":"number",
"required":false
},
"whitelevel": {
"type":"number",
"required":false
},
"threshold": {
"type":"number",
"required":false,
"minimum" : 0.0,
"maximum" : 1.0
}
},
"additionalProperties" : false
},
"blue": {
"type":"object",
"required":false,
"properties":{
"gamma": {
"type":"number",
"required":false
},
"whitelevel": {
"type":"number",
"required":false
},
"blacklevel": {
"type":"number",
"required":false
},
"threshold": {
"type":"number",
"required":false,
"minimum" : 0.0,
"maximum" : 1.0
}
},
"additionalProperties" : false
},
"smoothing" : {
"type" : "object",
"required" : false,
"properties" : {
"type" : {
"type" : "enum",
"required" : true,
"values" : ["none", "linear"]
},
"time_ms" : {
"type" : "integer",
"required" : false,
"minimum" : 10
},
"updateFrequency" : {
"type" : "number",
"required" : false,
"minimum" : 0.001
}
},
"additionalProperties" : false
}
},
"additionalProperties" : false
},
"leds": {
"type":"array",
"required":true,
"items": {
"type":"object",
"properties": {
"index": {
"type":"integer",
"required":true
},
"hscan": {
"type":"object",
"required":true,
"properties": {
"minimum": {
"type":"number",
"required":true
},
"maximum": {
"type":"number",
"required":true
}
},
"additionalProperties" : false
},
"vscan": {
"type":"object",
"required":true,
"properties": {
"minimum": {
"type":"number",
"required":true
},
"maximum": {
"type":"number",
"required":true
}
},
"additionalProperties" : false
},
"colorOrder" : {
"type" : "string",
"required" : false
}
},
"additionalProperties" : false
}
},
"effects" :
{
"type" : "object",
"required" : false,
"properties" : {
"paths" : {
"type" : "array",
"required" : false,
"items" : {
"type" : "string"
}
}
},
"additionalProperties" : false
},
"blackborderdetector" :
{
"type" : "object",
"required" : false,
"properties" : {
"enable" : {
"type" : "boolean",
"required" : true
},
"threshold" : {
"type" : "number",
"required" : false,
"minimum" : 0.0,
"maximum" : 1.0
}
},
"additionalProperties" : false
},
"xbmcVideoChecker" :
{
"type" : "object",
"required" : false,
"properties" : {
"xbmcAddress" : {
"type" : "string",
"required" : true
},
"xbmcTcpPort" : {
"type" : "integer",
"required" : true
},
"grabVideo" : {
"type" : "boolean",
"required" : true
},
"grabPictures" : {
"type" : "boolean",
"required" : true
},
"grabAudio" : {
"type" : "boolean",
"required" : true
},
"grabMenu" : {
"type" : "boolean",
"required" : true
},
"grabPause" : {
"type" : "boolean",
"required" : false
},
"grabScreensaver" : {
"type" : "boolean",
"required" : false
},
"enable3DDetection" : {
"type" : "boolean",
"required" : false
}
},
"additionalProperties" : false
},
"bootsequence" :
{
"type" : "object",
"required" : false,
"properties" : {
"path" : {
"type" : "string",
"required" : true
},
"effect" : {
"type" : "string",
"required" : true
}
},
"additionalProperties" : false
},
"framegrabber" :
{
"type" : "object",
"required" : false,
"properties" : {
"width" : {
"type" : "integer",
"required" : true
},
"height" : {
"type" : "integer",
"required" : true
},
"frequency_Hz" : {
"type" : "integer",
"required" : true
}
},
"additionalProperties" : false
},
"jsonServer" :
{
"type" : "object",
"required" : false,
"properties" : {
"port" : {
"type" : "integer",
"required" : true,
"minimum" : 0,
"maximum" : 65535
}
},
"additionalProperties" : false
},
"protoServer" :
{
"type" : "object",
"required" : false,
"properties" : {
"port" : {
"type" : "integer",
"required" : true,
"minimum" : 0,
"maximum" : 65535
}
},
"additionalProperties" : false
},
"boblightServer" :
{
"type" : "object",
"required" : false,
"properties" : {
"port" : {
"type" : "integer",
"required" : true,
"minimum" : 0,
"maximum" : 65535
}
},
"additionalProperties" : false
}
},
"additionalProperties" : false
}

File diff suppressed because it is too large Load Diff

View File

@ -1085,7 +1085,7 @@ void JsonClientConnection::handleSchemaGetCommand(const QJsonObject& message, co
QJsonParseError error;
// read the hyperion json schema from the resource
QFile schemaData(":/hyperion-schema");
QFile schemaData(":/hyperion-schema-"+QString::number(_hyperion->getConfigVersionId()));
if (!schemaData.open(QIODevice::ReadOnly))
{

View File

@ -1,6 +1,11 @@
add_executable(hyperiond
hyperiond.cpp hyperiond.h main.cpp)
add_executable(hyperiond
configMigrator.cpp
configMigrator.h
hyperiond.cpp
hyperiond.h
main.cpp
)
target_link_libraries(hyperiond
commandline

View File

@ -0,0 +1,19 @@
#include "configMigrator.h"
ConfigMigrator::ConfigMigrator()
: _log(Logger::getInstance("ConfigMigrator"))
{
}
ConfigMigrator::~ConfigMigrator()
{
}
bool ConfigMigrator::migrate(QString configFile, int fromVersion,int toVersion)
{
Debug(_log, "migrate config %s from version %d to %d.", configFile.toLocal8Bit().constData(), fromVersion, toVersion);
throw std::runtime_error("ERROR: config migration not implemented");
return true;
}

View File

@ -0,0 +1,17 @@
#pragma once
#include <utils/Logger.h>
#include <QString>
class ConfigMigrator
{
public:
ConfigMigrator();
~ConfigMigrator();
bool migrate(QString configFile, int fromVersion,int toVersion);
private:
Logger * _log;
};

View File

@ -31,7 +31,7 @@
#include <udplistener/UDPListener.h>
#include "hyperiond.h"
#include "configMigrator.h"
HyperionDaemon::HyperionDaemon(QString configFile, QObject *parent)
: QObject(parent)
@ -51,7 +51,7 @@ HyperionDaemon::HyperionDaemon(QString configFile, QObject *parent)
, _osxGrabber(nullptr)
, _hyperion(nullptr)
{
loadConfig(configFile);
loadConfig(configFile, CURRENT_CONFIG_VERSION );
if (Logger::getLogLevel() == Logger::WARNING)
{
@ -116,20 +116,21 @@ void HyperionDaemon::run()
}
void HyperionDaemon::loadConfig(const QString & configFile)
int HyperionDaemon::tryLoadConfig(const QString & configFile, const int schemaVersion)
{
Info(_log, "Selected configuration file: %s", configFile.toUtf8().constData());
// 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
QFile schemaData(":/hyperion-schema");
QString schemaFile = ":/hyperion-schema";
if (schemaVersion > 0)
schemaFile += "-" + QString::number(schemaVersion);
QFile schemaData(schemaFile);
if (!schemaData.open(QIODevice::ReadOnly))
{
std::stringstream error;
error << "Schema not found: " << schemaData.errorString().toStdString();
error << "Schema not found or not supported: " << schemaData.errorString().toStdString();
throw std::runtime_error(error.str());
}
@ -168,11 +169,42 @@ void HyperionDaemon::loadConfig(const QString & configFile)
{
std::cout << *i << std::endl;
}
throw std::runtime_error("ERROR: Json validation failed");
}
const QJsonObject & generalConfig = _qconfig["general"].toObject();
return generalConfig["configVersion"].toInt(-1);
}
void HyperionDaemon::loadConfig(const QString & configFile, const int neededConfigVersion)
{
Info(_log, "Selected configuration file: %s", configFile.toUtf8().constData());
int configVersionId = tryLoadConfig(configFile,0);
// no config id found, assume legacy hyperion
if (configVersionId < 0)
{
Debug(_log, "config file has no version, assume old hyperion.");
configVersionId = tryLoadConfig(configFile,1);
}
Debug(_log, "config version: %d", configVersionId);
configVersionId = tryLoadConfig(configFile, configVersionId);
if (neededConfigVersion == configVersionId)
{
return;
}
// migrate configVersionId
ConfigMigrator migrator;
migrator.migrate(configFile, configVersionId, neededConfigVersion);
}
void HyperionDaemon::startInitialEffect()
{
#define FGCONFIG_ARRAY fgEffectConfig.toArray()
@ -343,8 +375,8 @@ void HyperionDaemon::startNetworkServices()
connect( Hyperion::getInstance(), SIGNAL(componentStateChanged(hyperion::Components,bool)), _udpListener, SLOT(componentStateChanged(hyperion::Components,bool)));
// zeroconf description - $leddevicename@$hostname
const QJsonObject & deviceConfig = _qconfig["device"].toObject();
const std::string mDNSDescr = ( deviceConfig["name"].toString("").toStdString()
const QJsonObject & generalConfig = _qconfig["general"].toObject();
const std::string mDNSDescr = ( generalConfig["name"].toString("").toStdString()
+ "@" +
QHostInfo::localHostName().toStdString()
);

View File

@ -1,5 +1,7 @@
#pragma once
const int CURRENT_CONFIG_VERSION = 2;
#include <QObject>
#ifdef ENABLE_DISPMANX
@ -53,7 +55,8 @@ public:
HyperionDaemon(QString configFile, QObject *parent=nullptr);
~HyperionDaemon();
void loadConfig(const QString & configFile);
int tryLoadConfig(const QString & configFile, const int schemaVersion);
void loadConfig(const QString & configFile, const int neededConfigVersion);
void run();
void startInitialEffect();

View File

@ -16,13 +16,13 @@ bool loadConfig(const QString & configFile)
// make sure the resources are loaded (they may be left out after static linking)
Q_INIT_RESOURCE(resource);
QJsonParseError error;
////////////////////////////////////////////////////////////
// read and set the json schema from the resource
////////////////////////////////////////////////////////////
QFile schemaData(":/hyperion-schema");
if (!schemaData.open(QIODevice::ReadOnly))
{
std::stringstream error;