mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
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:
@@ -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
|
||||
|
19
src/hyperiond/configMigrator.cpp
Normal file
19
src/hyperiond/configMigrator.cpp
Normal 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;
|
||||
}
|
||||
|
17
src/hyperiond/configMigrator.h
Normal file
17
src/hyperiond/configMigrator.h
Normal 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;
|
||||
};
|
@@ -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()
|
||||
);
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user