diff --git a/include/utils/jsonschema/QJsonFactory.h b/include/utils/jsonschema/QJsonFactory.h index 63bbed3a..83b2a53e 100644 --- a/include/utils/jsonschema/QJsonFactory.h +++ b/include/utils/jsonschema/QJsonFactory.h @@ -21,8 +21,8 @@ public: static int load(const QString& schema, const QString& config, QJsonObject& json) { // Load the schema and the config trees - QJsonObject schemaTree = readJson(schema); - QJsonObject configTree = readJson(config); + QJsonObject schemaTree = readSchema(schema); + QJsonObject configTree = readConfig(config); // create the validator QJsonSchemaChecker schemaChecker; @@ -45,15 +45,15 @@ public: return 0; } - static QJsonObject readJson(const QString& path) + static QJsonObject readConfig(const QString& path) { QFile file(path); QJsonParseError error; - + if (!file.open(QIODevice::ReadOnly)) { std::stringstream sstream; - sstream << "Configuration file not found: " << file.errorString().toStdString(); + sstream << "Configuration file not found: '" << path.toStdString() << "' (" << file.errorString().toStdString() << ")"; throw std::runtime_error(sstream.str()); } @@ -61,12 +61,13 @@ public: config.remove(QRegularExpression("([^:]?\\/\\/.*)")); QJsonDocument doc = QJsonDocument::fromJson(config.toUtf8(), &error); - + file.close(); + if (error.error != QJsonParseError::NoError) { // 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,config.size()); igetConfigFileName())); + result["result"] = QJsonFactory::readConfig(QString::fromStdString(_hyperion->getConfigFileName())); } catch(...) { diff --git a/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp b/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp index 5f53a578..6b3e738d 100644 --- a/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp +++ b/libsrc/utils/jsonschema/QJsonSchemaChecker.cpp @@ -115,6 +115,7 @@ void QJsonSchemaChecker::validate(const QJsonValue & value, const QJsonObject &s else { // no check function defined for this attribute + _error = true; setMessage(std::string("No check function defined for attribute ") + attribute.toStdString()); continue; } diff --git a/libsrc/webconfig/WebConfig.cpp b/libsrc/webconfig/WebConfig.cpp index 9e776dba..6d1f0696 100644 --- a/libsrc/webconfig/WebConfig.cpp +++ b/libsrc/webconfig/WebConfig.cpp @@ -23,7 +23,7 @@ WebConfig::WebConfig(QObject * parent) _baseUrl = webconfigConfig["document_root"].toString(_baseUrl); } - if (_baseUrl != ":/webconfig") + if ( (_baseUrl != ":/webconfig") && !_baseUrl.trimmed().isEmpty()) { QFileInfo info(_baseUrl); if (!info.exists() || !info.isDir()) @@ -32,6 +32,8 @@ WebConfig::WebConfig(QObject * parent) _baseUrl = WEBCONFIG_DEFAULT_PATH; } } + else + _baseUrl = WEBCONFIG_DEFAULT_PATH; Debug(log, "WebUI initialized, document root: %s", _baseUrl.toUtf8().constData()); if ( webconfigEnable ) diff --git a/src/hyperiond/hyperiond.cpp b/src/hyperiond/hyperiond.cpp index 77bb9196..ff5a7b33 100644 --- a/src/hyperiond/hyperiond.cpp +++ b/src/hyperiond/hyperiond.cpp @@ -136,49 +136,26 @@ int HyperionDaemon::tryLoadConfig(const QString & configFile, const int schemaVe { // 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 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 or not supported: " << schemaData.errorString().toStdString(); - throw std::runtime_error(error.str()); - } - - QByteArray schema = schemaData.readAll(); - QJsonDocument schemaJson = QJsonDocument::fromJson(schema, &error); - schemaData.close(); - - if (error.error != QJsonParseError::NoError) - { - // 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,schema.size()); i::const_iterator i = schemaChecker.getMessages().begin(); i != schemaChecker.getMessages().end(); ++i) @@ -193,7 +170,6 @@ int HyperionDaemon::tryLoadConfig(const QString & configFile, const int schemaVe return generalConfig["configVersion"].toInt(-1); } - void HyperionDaemon::loadConfig(const QString & configFile, const int neededConfigVersion) { Info(_log, "Selected configuration file: %s", configFile.toUtf8().constData()); @@ -488,7 +464,7 @@ void HyperionDaemon::createSystemFrameGrabber() else if (type == "x11") createGrabberX11(grabberConfig); else { Warning( _log, "unknown framegrabber type '%s'", type.toUtf8().constData()); grabberCompState = false; } - _hyperion->getComponentRegister().componentStateChanged(hyperion::COMP_GRABBER, grabberCompState); +// _hyperion->getComponentRegister().componentStateChanged(hyperion::COMP_GRABBER, grabberCompState); _hyperion->setComponentState(hyperion::COMP_GRABBER, grabberCompState ); } } diff --git a/test/TestConfigFile.cpp b/test/TestConfigFile.cpp index 9c8d31c3..a654816c 100644 --- a/test/TestConfigFile.cpp +++ b/test/TestConfigFile.cpp @@ -16,53 +16,30 @@ 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-"+QString::number(CURRENT_CONFIG_VERSION)); - - if (!schemaData.open(QIODevice::ReadOnly)) + QJsonObject schemaJson; + + try { - std::stringstream error; - error << "Schema not found: " << schemaData.errorString().toStdString(); - throw std::runtime_error(error.str()); + schemaJson = QJsonFactory::readSchema(":/hyperion-schema"); } - - QByteArray schema = schemaData.readAll(); - QJsonDocument schemaJson = QJsonDocument::fromJson(schema, &error); - - if (error.error != QJsonParseError::NoError) + catch(const std::runtime_error& error) { - // 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,schema.size()); i