mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Refactor Settings DB and Handling (#1786)
* Refactor config API * Corrections * Test Qt 6.8 * Revert "Test Qt 6.8" This reverts commit eceebec49ecf1a3eda281a0630a9a7577b44ef0a. * Corrections 2 * Update Changelog * Add configFilter element for getconfig call * Do not create errors for DB updates when in read-only mode * Have configuration migration and validation before Hyperion starts * Correct Tests * Corrections * Add migration items * Correct windows build * Ensure that first instance as default one exists * Remove dependency between AuthManager and SSDPHandler * Correct typos * Address CodeQL findings * Replace CamkeSettings by Presets and provide debug scenarios
This commit is contained in:
parent
aed4abc03b
commit
ecceb4e7ae
12
.gitignore
vendored
12
.gitignore
vendored
@ -39,3 +39,15 @@ NULL
|
||||
|
||||
# Docker deploy folder
|
||||
deploy/*
|
||||
|
||||
# ccache/buildcache
|
||||
.*cache/
|
||||
|
||||
# release-deps/debug-deps
|
||||
*-deps/
|
||||
|
||||
# User defined CMake preset file.
|
||||
CMakeUserPresets.json
|
||||
|
||||
#Configurations created under config for testing
|
||||
/configs
|
||||
|
@ -6,12 +6,42 @@
|
||||
"type": "default",
|
||||
"project": "CMakeLists.txt",
|
||||
"projectTarget": "hyperiond.exe (bin\\hyperiond.exe)",
|
||||
"name": "Run hyperion with debug option and external console",
|
||||
"name": "Run Hyperion"
|
||||
},
|
||||
{
|
||||
"type": "default",
|
||||
"project": "CMakeLists.txt",
|
||||
"projectTarget": "hyperiond.exe (bin\\hyperiond.exe)",
|
||||
"name": "Run hyperion with debug logging and external console",
|
||||
"args": [
|
||||
"-d",
|
||||
"-c"
|
||||
],
|
||||
"externalConsole": true
|
||||
},
|
||||
{
|
||||
"type": "default",
|
||||
"project": "CMakeLists.txt",
|
||||
"projectTarget": "hyperiond.exe (bin\\hyperiond.exe)",
|
||||
"name": "Run hyperion with verbose logging with external console",
|
||||
"args": [
|
||||
"-v",
|
||||
"-c"
|
||||
],
|
||||
"externalConsole": true
|
||||
},
|
||||
{
|
||||
"type": "default",
|
||||
"project": "CMakeLists.txt",
|
||||
"projectTarget": "hyperiond.exe (bin\\hyperiond.exe)",
|
||||
"name": "Run hyperion with debug logging and a test configuration DB",
|
||||
"args": [
|
||||
"-d",
|
||||
"-c",
|
||||
"-u",
|
||||
"${workspaceRoot}\\configs\\testConfig"
|
||||
],
|
||||
"externalConsole": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
**JSON-API**
|
||||
- Align JSON subscription update elements. `ledcolors-imagestream-update, ledcolors-ledstream-update, logmsg-update` now return data via `data` and not `result
|
||||
- Global global configuration elements are now separated form instance specific ones
|
||||
|
||||
### Added
|
||||
|
||||
@ -18,6 +19,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Support gaps on Matrix Layout (#1696)
|
||||
- Windows: Added a new grabber that uses the DXGI DDA (Desktop Duplication API). This has much better performance than the DX grabber as it does more of its work on the GPU.
|
||||
|
||||
- Support to import, export and backup Hyperion's full configuration via the UI, JSON-API and commandline (`--importConfig, --exportConfig`) (#804)
|
||||
- Allow to force starting Hyperion in read-only mode (`--readonlyMode`)
|
||||
- JSON-API: Support to query for a dedicated set of configuration items for a set of instances
|
||||
- JSON-API: Support to save a dedicated set of configuration items for a set of instances
|
||||
|
||||
**JSON-API**
|
||||
- New subscription support for event updates, i.e. `Suspend, Resume, Idle, idleResume, Restart, Quit`.
|
||||
- Support direct or multiple instance addressing via single requests (#809)
|
||||
@ -33,12 +39,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Fixed: Kodi Color Calibration, Refactor Wizards (#1674)
|
||||
- Fixed: Token Dialog not closing
|
||||
- Fixed: Philip Hue APIv2 support without Entertainment group defined (#1742)
|
||||
- Refactored: Database access layer
|
||||
- Refactored: Hyperion's configuration database is validated before start-up (and migrated, if required)
|
||||
|
||||
**JSON-API**
|
||||
- Refactored JSON-API to ensure consistent authorization behaviour across sessions and single requests with token authorization.
|
||||
- Provide additional error details with API responses, esp. on JSON parsing, validation or token errors.
|
||||
- Generate random TANs for every API request from the Hyperion UI
|
||||
- Fixed: Handling of IP4 addresses wrapped in IPv6 for external network connections-
|
||||
- Fixed: Local Admin API Authentication rejects valid tokens (#1251)
|
||||
|
||||
### Removed
|
||||
|
||||
|
@ -20,11 +20,10 @@ PROJECT(hyperion)
|
||||
include (${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.cmake)
|
||||
file (STRINGS ".version" HYPERION_VERSION)
|
||||
SetVersionNumber(HYPERION ${HYPERION_VERSION})
|
||||
set(DEFAULT_JSON_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/config/hyperion.config.json.default)
|
||||
set(DEFAULT_JSON_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/settings/hyperion.settings.json.default)
|
||||
file(READ ${DEFAULT_JSON_CONFIG_FILE} DEFAULT_JSON_CONFIG_VAR)
|
||||
string(REPLACE "configVersionValue" ${HYPERION_VERSION} DEFAULT_JSON_CONFIG_VAR "${DEFAULT_JSON_CONFIG_VAR}")
|
||||
string(REPLACE "previousVersionValue" ${HYPERION_VERSION} DEFAULT_JSON_CONFIG_VAR "${DEFAULT_JSON_CONFIG_VAR}")
|
||||
file(WRITE ${CMAKE_BINARY_DIR}/config/hyperion.config.json.default "${DEFAULT_JSON_CONFIG_VAR}")
|
||||
file(WRITE ${CMAKE_BINARY_DIR}/settings/hyperion.settings.json.default "${DEFAULT_JSON_CONFIG_VAR}")
|
||||
|
||||
# Instruct CMake to run moc automatically when needed.
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
@ -227,7 +226,7 @@ message(STATUS "HYPERION_LIGHT = ${HYPERION_LIGHT}")
|
||||
|
||||
if(HYPERION_LIGHT)
|
||||
message(STATUS "HYPERION_LIGHT: Hyperion is build with a reduced set of functionality.")
|
||||
# Disable Grabbers
|
||||
# Disable Screen/Video Grabbers
|
||||
SET ( DEFAULT_AMLOGIC OFF )
|
||||
SET ( DEFAULT_DISPMANX OFF )
|
||||
SET ( DEFAULT_DX OFF )
|
||||
@ -240,22 +239,37 @@ if(HYPERION_LIGHT)
|
||||
SET ( DEFAULT_X11 OFF )
|
||||
SET ( DEFAULT_XCB OFF )
|
||||
|
||||
# Disable Audio Grabbers
|
||||
SET ( DEFAULT_AUDIO OFF )
|
||||
|
||||
# LED-Devices
|
||||
#SET ( DEFAULT_DEV_NETWORK OFF )
|
||||
#SET ( DEFAULT_DEV_FTDI OFF )
|
||||
#SET ( DEFAULT_DEV_SERIAL OFF )
|
||||
#SET ( DEFAULT_DEV_SPI OFF )
|
||||
#SET ( DEFAULT_DEV_TINKERFORGE OFF )
|
||||
#SET ( DEFAULT_DEV_USB_HID OFF )
|
||||
#SET ( DEFAULT_DEV_WS281XPWM OFF )
|
||||
|
||||
# Disable Input Servers
|
||||
set(DEFAULT_BOBLIGHT_SERVER OFF)
|
||||
set(DEFAULT_CEC OFF)
|
||||
set(DEFAULT_FLATBUF_SERVER OFF)
|
||||
set(DEFAULT_PROTOBUF_SERVER OFF)
|
||||
SET ( DEFAULT_BOBLIGHT_SERVER OFF )
|
||||
SET ( DEFAULT_CEC OFF )
|
||||
SET ( DEFAULT_FLATBUF_SERVER OFF )
|
||||
SET ( DEFAULT_PROTOBUF_SERVER OFF )
|
||||
|
||||
# Disable Output Connectors
|
||||
set(DEFAULT_FORWARDER OFF)
|
||||
set(DEFAULT_FLATBUF_CONNECT OFF)
|
||||
SET ( DEFAULT_FORWARDER OFF )
|
||||
SET ( DEFAULT_FLATBUF_CONNECT OFF )
|
||||
|
||||
# Disable Services
|
||||
set(DEFAULT_EFFECTENGINE OFF)
|
||||
endif()
|
||||
SET ( DEFAULT_EFFECTENGINE OFF )
|
||||
#SET ( DEFAULT_EXPERIMENTAL OFF )
|
||||
#SET ( DEFAULT_MDNS OFF )
|
||||
#SET ( DEFAULT_REMOTE_CTL OFF )
|
||||
|
||||
#SET ( ENABLE_JSONCHECKS OFF )
|
||||
#SET ( ENABLE_DEPLOY_DEPENDENCIES OFF )
|
||||
endif()
|
||||
message(STATUS "Grabber options:")
|
||||
|
||||
addIndent(" - ")
|
||||
@ -430,7 +444,7 @@ endif()
|
||||
if(ENABLE_JSONCHECKS)
|
||||
# check all json files
|
||||
file (GLOB_RECURSE HYPERION_SCHEMAS RELATIVE ${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/libsrc/*schema*.json)
|
||||
set(JSON_FILES ${CMAKE_BINARY_DIR}/config/hyperion.config.json.default ${HYPERION_SCHEMAS})
|
||||
set(JSON_FILES ${CMAKE_BINARY_DIR}/settings/hyperion.settings.json.default ${HYPERION_SCHEMAS})
|
||||
|
||||
execute_process (
|
||||
COMMAND ${PYTHON_EXECUTABLE} test/jsonchecks/checkjson.py ${JSON_FILES}
|
||||
@ -453,7 +467,7 @@ if(ENABLE_JSONCHECKS)
|
||||
endif()
|
||||
|
||||
execute_process (
|
||||
COMMAND ${PYTHON_EXECUTABLE} test/jsonchecks/checkschema.py ${CMAKE_BINARY_DIR}/config/hyperion.config.json.default libsrc/hyperion/hyperion.schema.json
|
||||
COMMAND ${PYTHON_EXECUTABLE} test/jsonchecks/checkschema.py ${CMAKE_BINARY_DIR}/settings/hyperion.settings.json.default libsrc/hyperion/schema/schema-settings-default.json
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
RESULT_VARIABLE CHECK_CONFIG_FAILED
|
||||
)
|
||||
|
273
CMakePresets.json
Normal file
273
CMakePresets.json
Normal file
@ -0,0 +1,273 @@
|
||||
{
|
||||
"version": 8,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "base",
|
||||
"description": "Base settings that apply to all configurations",
|
||||
"hidden": true,
|
||||
"binaryDir": "${sourceDir}/build"
|
||||
},
|
||||
{
|
||||
"name": "ccache",
|
||||
"description": "Set ccache variables",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"USE_COMPILER_CACHE": "ON"
|
||||
},
|
||||
"environment": {
|
||||
"CCACHE_NODEBUG": "true",
|
||||
"CCACHE_DIRECT": "true",
|
||||
"CCACHE_MAXSIZE": "500M",
|
||||
"CCACHE_COMPRESS": "true",
|
||||
"CCACHE_COMPRESSLEVEL": "1",
|
||||
"CCACHE_NOSTATS": "true",
|
||||
"CCACHE_DIR": "${sourceDir}/.ccache"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "buildcache",
|
||||
"description": "Set buildcache variables",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"USE_COMPILER_CACHE": "ON"
|
||||
},
|
||||
"environment": {
|
||||
"BUILDCACHE_DEBUG": "-1",
|
||||
"BUILDCACHE_DIRECT_MODE": "true",
|
||||
"BUILDCACHE_MAX_CACHE_SIZE": "524288000",
|
||||
"BUILDCACHE_COMPRESS": "true",
|
||||
"BUILDCACHE_COMPRESS_FORMAT": "LZ4",
|
||||
"BUILDCACHE_DIR": "${sourceDir}/.buildcache"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "debug",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Debug"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "release",
|
||||
"hidden": true,
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "clang",
|
||||
"hidden": true,
|
||||
"generator": "Ninja",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "/usr/bin/clang",
|
||||
"CMAKE_CXX_COMPILER": "/usr/bin/clang++"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "msvc",
|
||||
"hidden": true,
|
||||
"generator": "Visual Studio 17 2022",
|
||||
"architecture": "x64",
|
||||
"toolset": "host=x64"
|
||||
},
|
||||
{
|
||||
"name": "gcc",
|
||||
"hidden": true,
|
||||
"generator": "Ninja",
|
||||
"cacheVariables": {
|
||||
"CMAKE_C_COMPILER": "/usr/bin/gcc",
|
||||
"CMAKE_CXX_COMPILER": "/usr/bin/g++"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "macos-release",
|
||||
"displayName": "MacOS (release) (clang)",
|
||||
"description": "Build with Clang as Release without Debug Symbols",
|
||||
"inherits": [ "base", "release", "clang" ],
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Darwin"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "macos-release-deps",
|
||||
"displayName": "MacOS Dependencies (release) (clang)",
|
||||
"description": "Build Dependencies with Clang as Release without Debug Symbols",
|
||||
"inherits": [ "macos-release" ],
|
||||
"cacheVariables": {
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/${presetName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "macos-debug",
|
||||
"displayName": "MacOS Debug (clang)",
|
||||
"description": "Build with Clang with Debug Symbols",
|
||||
"inherits": [ "base", "debug", "clang" ],
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Darwin"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "macos-debug-deps",
|
||||
"displayName": "MacOS Dependencies (debug) (clang)",
|
||||
"description": "Build Dependencies with Clang with Debug Symbols",
|
||||
"inherits": [ "macos-debug" ],
|
||||
"cacheVariables": {
|
||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/${presetName}"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "windows-release",
|
||||
"displayName": "Windows Release (msvc)",
|
||||
"description": "Build with MSVC's CL as Release without Debug Symbols",
|
||||
"inherits": [ "base", "msvc" ],
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "windows-debug",
|
||||
"displayName": "Windows Debug (msvc)",
|
||||
"description": "Build with MSVC's CL with Debug Symbols",
|
||||
"inherits": [ "base", "msvc" ],
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "linux-release",
|
||||
"displayName": "Linux Release (gcc)",
|
||||
"description": "Build with GCC as Release without Debug Symbols",
|
||||
"inherits": [ "base", "release", "gcc" ],
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Linux"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "linux-debug",
|
||||
"displayName": "Linux Debug (gcc)",
|
||||
"description": "Build with GCC with Debug Symbols",
|
||||
"inherits": [ "base", "debug", "gcc" ],
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Linux"
|
||||
}
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{
|
||||
"name": "macos-release",
|
||||
"displayName": "MacOS (release) (clang)",
|
||||
"description": "Build with Clang as Release without Debug Symbols",
|
||||
"targets": "all",
|
||||
"configurePreset": "macos-release",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Darwin"
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
"name": "macos-release-deps",
|
||||
"displayName": "MacOS Dependencies (release) (clang)",
|
||||
"description": "Build Dependencies with Clang as Release without Debug Symbols",
|
||||
"targets": "dependencies/all",
|
||||
"configurePreset": "macos-release-deps",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Darwin"
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
"name": "macos-debug",
|
||||
"displayName": "MacOS (debug) (clang)",
|
||||
"description": "Build with Clang as Debug",
|
||||
"targets": "all",
|
||||
"configurePreset": "macos-debug",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Darwin"
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
"name": "macos-debug-deps",
|
||||
"displayName": "MacOS Dependencies (debug) (clang)",
|
||||
"description": "Build Dependencies with Clang as Debug",
|
||||
"targets": "dependencies/all",
|
||||
"configurePreset": "macos-debug-deps",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Darwin"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "windows-release",
|
||||
"displayName": "Windows (release) (msvc)",
|
||||
"description": "Build with MSVC's CL as Release without Debug Symbols",
|
||||
"configuration": "Release",
|
||||
"targets": "ALL_BUILD",
|
||||
"configurePreset": "windows-release",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
"name": "windows-debug",
|
||||
"displayName": "Windows (debug) (msvc)",
|
||||
"description": "Build with MSVC's CL with Debug Symbols",
|
||||
"configuration": "Debug",
|
||||
"targets": "ALL_BUILD",
|
||||
"configurePreset": "windows-debug",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Windows"
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
"name": "linux-release",
|
||||
"displayName": "Linux (release) (gcc)",
|
||||
"description": "Build with GCC as Release without Debug Symbols",
|
||||
"targets": "all",
|
||||
"configurePreset": "linux-release",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Linux"
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
"name": "linux-debug",
|
||||
"displayName": "Linux (debug) (gcc)",
|
||||
"description": "Build with GCC with Debug Symbols",
|
||||
"targets": "all",
|
||||
"configurePreset": "linux-debug",
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
"lhs": "${hostSystemName}",
|
||||
"rhs": "Linux"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "x64-Debug",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Debug",
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
||||
"buildRoot": "${projectDir}\\build-${name}",
|
||||
"installRoot": "${projectDir}\\install-${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "",
|
||||
"ctestCommandArgs": "",
|
||||
"variables": [
|
||||
// Replace path with your TurboJPEG installation path
|
||||
//{ "name": "TurboJPEG_INCLUDE_DIRS", "type": "PATH", "value": "YourTurboJPEGPath/libjpeg-turbo64/include" },
|
||||
//{ "name": "TurboJPEG_LIBRARY", "value": "YourTurboJPEGPath/libjpeg-turbo64/lib/turbojpeg.lib", "type": "FILEPATH" }
|
||||
],
|
||||
"environments": [
|
||||
// Replace path with your installation path
|
||||
//{ "QTDIR": "C:/Qt/6.2.2/msvc2019_64/" },
|
||||
//{ "VULKAN_SDK": "C:/VulkanSDK/1.2.182.0" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "x64-Release",
|
||||
"generator": "Ninja",
|
||||
"configurationType": "Release",
|
||||
"buildRoot": "${projectDir}\\build-${name}",
|
||||
"installRoot": "${projectDir}\\install-${name}",
|
||||
"cmakeCommandArgs": "",
|
||||
"buildCommandArgs": "package",
|
||||
"ctestCommandArgs": "",
|
||||
"inheritEnvironments": [ "msvc_x64_x64" ],
|
||||
"variables": [
|
||||
// Replace path with your TurboJPEG installation path
|
||||
//{ "name": "TurboJPEG_INCLUDE_DIRS", "type": "PATH", "value": "YourTurboJPEGPath/libjpeg-turbo64/include" },
|
||||
//{ "name": "TurboJPEG_LIBRARY", "value": "YourTurboJPEGPath/libjpeg-turbo64/lib/turbojpeg.lib", "type": "FILEPATH" }
|
||||
],
|
||||
"environments": [
|
||||
// Replace path with your installation path
|
||||
//{ "QTDIR": "C:/Qt/6.2.2/msvc2019_64/" },
|
||||
//{ "VULKAN_SDK": "C:/VulkanSDK/1.2.182.0" }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -1014,8 +1014,8 @@
|
||||
"infoDialog_import_comperror_text": "Sad! Your browser doesn't support importing. Please try again with another browser.",
|
||||
"infoDialog_import_confirm_text": "Are you sure to import \"$1\"? This process can't be reverted!",
|
||||
"infoDialog_import_confirm_title": "Confirm import",
|
||||
"infoDialog_import_hyperror_text": "The selected configuration file \"$1\" can't be imported. It's not compatible with Hyperion 2.0 and higher!",
|
||||
"infoDialog_import_jsonerror_text": "The selected configuration file \"$1\" is not a .json file, or it's corrupted. Error message: ($2)",
|
||||
"infoDialog_import_version_error_text": "The selected configuration file \"$1\" can not be imported. It's not compatible with Hyperion 2.0.17 and higher!",
|
||||
"infoDialog_wizrgb_text": "Your RGB Byte Order is already well adjusted.",
|
||||
"infoDialog_writeconf_error_text": "Saving your configuration failed.",
|
||||
"infoDialog_writeimage_error_text": "The selected file \"$1\" is not an image file, or it's corrupted! Please select another image file.",
|
||||
|
@ -28,11 +28,6 @@ $(document).ready(function () {
|
||||
// Instance handling
|
||||
function handleInstanceRename(e) {
|
||||
|
||||
conf_editor.on('change', function () {
|
||||
window.readOnlyMode ? $('#btn_cl_save').prop('disabled', true) : $('#btn_submit').prop('disabled', false);
|
||||
window.readOnlyMode ? $('#btn_ma_save').prop('disabled', true) : $('#btn_submit').prop('disabled', false);
|
||||
});
|
||||
|
||||
var inst = e.currentTarget.id.split("_")[1];
|
||||
showInfoDialog('renInst', $.i18n('conf_general_inst_renreq_t'), getInstanceNameByIndex(inst));
|
||||
|
||||
@ -119,14 +114,14 @@ $(document).ready(function () {
|
||||
//check file is json
|
||||
var check = isJsonString(content);
|
||||
if (check.length != 0) {
|
||||
showInfoDialog('error', "", $.i18n('infoDialog_import_jsonerror_text', f.name, JSON.stringify(check)));
|
||||
showInfoDialog('error', "", $.i18n('infoDialog_import_jsonerror_text', f.name, JSON.stringify(check.message)));
|
||||
dis_imp_btn(true);
|
||||
}
|
||||
else {
|
||||
content = JSON.parse(content);
|
||||
//check for hyperion json
|
||||
if (typeof content.leds === 'undefined' || typeof content.general === 'undefined') {
|
||||
showInfoDialog('error', "", $.i18n('infoDialog_import_hyperror_text', f.name));
|
||||
if (typeof content.global === 'undefined' || typeof content.instances === 'undefined') {
|
||||
showInfoDialog('error', "", $.i18n('infoDialog_import_version_error_text', f.name));
|
||||
dis_imp_btn(true);
|
||||
}
|
||||
else {
|
||||
@ -145,8 +140,8 @@ $(document).ready(function () {
|
||||
|
||||
$('#id_btn_import').off().on('click', function () {
|
||||
requestRestoreConfig(importedConf);
|
||||
setTimeout(initRestart, 100);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
$('#select_import_conf').off().on('change', function (e) {
|
||||
@ -157,18 +152,17 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
//export
|
||||
$('#btn_export_conf').off().on('click', function () {
|
||||
var name = window.serverConfig.general.name;
|
||||
$('#btn_export_conf').off().on('click', async () =>
|
||||
{
|
||||
const d = new Date();
|
||||
const month = String(d.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(d.getDate()).padStart(2, '0');
|
||||
const timestamp = `${d.getFullYear()}-${month}-${day}`;
|
||||
|
||||
var d = new Date();
|
||||
var month = d.getMonth() + 1;
|
||||
var day = d.getDate();
|
||||
|
||||
var timestamp = d.getFullYear() + '.' +
|
||||
(month < 10 ? '0' : '') + month + '.' +
|
||||
(day < 10 ? '0' : '') + day;
|
||||
|
||||
download(JSON.stringify(window.serverConfig, null, "\t"), 'Hyperion-' + window.currentVersion + '-Backup (' + name + ') ' + timestamp + '.json', "application/json");
|
||||
const configBackup = await requestConfig();
|
||||
if (configBackup.success === true) {
|
||||
download(JSON.stringify(configBackup.info, null, "\t"), 'HyperionBackup-' + timestamp + '_v' + window.currentVersion + '.json', "application/json");
|
||||
}
|
||||
});
|
||||
|
||||
//create introduction
|
||||
@ -180,3 +174,8 @@ $(document).ready(function () {
|
||||
|
||||
removeOverlay();
|
||||
});
|
||||
|
||||
$(window.hyperion).on("cmd-config-restoreconfig", function (event) {
|
||||
setTimeout(initRestart, 100);
|
||||
});
|
||||
|
||||
|
@ -128,7 +128,7 @@ $(document).ready(function () {
|
||||
requestSysInfo();
|
||||
});
|
||||
|
||||
$(window.hyperion).on("cmd-config-getconfig", function (event) {
|
||||
$(window.hyperion).on("cmd-config-getconfig-old", function (event) {
|
||||
window.serverConfig = event.response.info;
|
||||
|
||||
window.showOptHelp = window.serverConfig.general.showOptHelp;
|
||||
@ -278,7 +278,7 @@ $(document).ready(function () {
|
||||
window.currentHyperionInstance = 0;
|
||||
window.currentHyperionInstanceName = getInstanceNameByIndex(0);
|
||||
|
||||
requestServerConfig();
|
||||
requestServerConfigOld();
|
||||
setTimeout(requestServerInfo, 100)
|
||||
setTimeout(requestTokenInfo, 200)
|
||||
}
|
||||
@ -296,7 +296,7 @@ $(document).ready(function () {
|
||||
});
|
||||
|
||||
$(window.hyperion).on("cmd-instance-switchTo", function (event) {
|
||||
requestServerConfig();
|
||||
requestServerConfigOld();
|
||||
setTimeout(requestServerInfo, 200)
|
||||
setTimeout(requestTokenInfo, 400)
|
||||
});
|
||||
@ -338,11 +338,6 @@ $(function () {
|
||||
});
|
||||
});
|
||||
|
||||
// hotfix body padding when bs modals overlap
|
||||
$(document.body).on('hide.bs.modal,hidden.bs.modal', function () {
|
||||
$('body').css('padding-right', '0');
|
||||
});
|
||||
|
||||
//Dark Mode
|
||||
$("#btn_darkmode").off().on("click", function (e) {
|
||||
if (getStorage("darkMode") != "on") {
|
||||
|
@ -37,7 +37,6 @@ const ENDLESS = -1;
|
||||
function initRestart()
|
||||
{
|
||||
$(window.hyperion).off();
|
||||
requestServerConfigReload();
|
||||
window.watchdog = 10;
|
||||
connectionLostDetection('restart');
|
||||
}
|
||||
@ -140,7 +139,8 @@ function initWebSocket()
|
||||
} else {
|
||||
$(window.hyperion).trigger({type:"error", reason:error});
|
||||
}
|
||||
console.log("[window.websocket::onmessage] ",error)
|
||||
let errorData = response.hasOwnProperty("errorData")? response.errorData : "";
|
||||
console.log("[window.websocket::onmessage] ",error, ", Description:", errorData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -344,6 +344,11 @@ function requestServerConfig()
|
||||
sendToHyperion("config", "getconfig");
|
||||
}
|
||||
|
||||
function requestServerConfigOld()
|
||||
{
|
||||
sendToHyperion("config", "getconfig-old");
|
||||
}
|
||||
|
||||
function requestServerConfigReload()
|
||||
{
|
||||
sendToHyperion("config", "reload");
|
||||
@ -522,3 +527,12 @@ async function requestServiceDiscovery(type, params) {
|
||||
return sendAsyncToHyperion("service", "discover", data);
|
||||
}
|
||||
|
||||
async function requestConfig(globalTypes, instances, instanceTypes) {
|
||||
let globalFilter = { "global": { "types": globalTypes } };
|
||||
let instanceFilter = { "instances": { "ids": instances, "types": instanceTypes } };
|
||||
let filter = { "configFilter" : globalFilter, instanceFilter };
|
||||
|
||||
return sendAsyncToHyperion("config", "getconfig", filter);
|
||||
}
|
||||
|
||||
|
||||
|
@ -129,7 +129,7 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
// apply new serverinfos
|
||||
$(window.hyperion).on("cmd-config-getconfig", function (event) {
|
||||
$(window.hyperion).on("cmd-config-getconfig-old", function (event) {
|
||||
leds = event.response.info.leds;
|
||||
grabberConfig = event.response.info.grabberV4L2;
|
||||
updateLedLayout();
|
||||
|
@ -239,7 +239,7 @@ function showInfoDialog(type, header, message) {
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-warning modal-icon-error">');
|
||||
if (header == "")
|
||||
$('#id_body').append('<h4 style="font-weight:bold;text-transform:uppercase;">' + $.i18n('infoDialog_general_error_title') + '</h4>');
|
||||
$('#id_footer').html('<button type="button" class="btn btn-danger" data-dismiss="modal">' + $.i18n('general_btn_ok') + '</button>');
|
||||
$('#id_footer').html('<button type="button" class="btn btn-danger" data-dismiss-modal="#modal_dialog">' + $.i18n('general_btn_ok') + '</button>');
|
||||
}
|
||||
else if (type == "select") {
|
||||
$('#id_body').html('<img style="margin-bottom:20px" id="id_logo" src="img/hyperion/logo_positiv.png" alt="Redefine ambient light!">');
|
||||
@ -256,9 +256,9 @@ function showInfoDialog(type, header, message) {
|
||||
$('#id_footer').html('<b>' + $.i18n('InfoDialog_nowrite_foottext') + '</b>');
|
||||
}
|
||||
else if (type == "import") {
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-warning modal-icon-warning">');
|
||||
$('#id_footer').html('<button type="button" id="id_btn_import" class="btn btn-warning" data-dismiss="modal"><i class="fa fa-fw fa-save"></i>' + $.i18n('general_btn_saverestart') + '</button>');
|
||||
$('#id_footer').append('<button type="button" class="btn btn-danger" data-dismiss="modal"><i class="fa fa-fw fa-close"></i>' + $.i18n('general_btn_cancel') + '</button>');
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-warning modal-icon-warning"></i>');
|
||||
$('#id_footer').html('<button type="button" id="id_btn_import" class="btn btn-warning"><i class="fa fa-fw fa-save"></i>' + $.i18n('general_btn_saverestart') + '</button>');
|
||||
$('#id_footer').append('<button type="button" class="btn btn-danger" data-dismiss-modal="#modal_dialog"><i class="fa fa-fw fa-close"></i>' + $.i18n('general_btn_cancel') + '</button>');
|
||||
}
|
||||
else if (type == "delInst") {
|
||||
$('#id_body').html('<i style="margin-bottom:20px" class="fa fa-remove modal-icon-warning">');
|
||||
@ -1222,7 +1222,7 @@ function getSystemInfo() {
|
||||
info += '- Avail Video Cap.: ' + window.serverInfo.grabbers.video.available + '\n';
|
||||
info += '- Avail Audio Cap.: ' + window.serverInfo.grabbers.audio.available + '\n';
|
||||
info += '- Avail Services: ' + window.serverInfo.services + '\n';
|
||||
info += '- Config path: ' + shy.rootPath + '\n';
|
||||
info += '- Config database: ' + shy.configDatabaseFile + '\n';
|
||||
info += '- Database: ' + (shy.readOnlyMode ? "ready-only" : "read/write") + '\n';
|
||||
info += '- Mode: ' + (shy.isGuiMode ? "GUI" : "Non-GUI") + '\n';
|
||||
|
||||
|
@ -1,276 +0,0 @@
|
||||
{
|
||||
"general": {
|
||||
"name": "My Hyperion Config",
|
||||
"configVersion": "configVersionValue",
|
||||
"previousVersion": "previousVersionValue",
|
||||
"watchedVersionBranch": "Stable",
|
||||
"showOptHelp": true
|
||||
},
|
||||
"logger": {
|
||||
"level": "warn"
|
||||
},
|
||||
|
||||
"device": {
|
||||
"type": "file",
|
||||
"hardwareLedCount": 1,
|
||||
"autoStart": true,
|
||||
"output": "/dev/null",
|
||||
"colorOrder": "rgb",
|
||||
"latchTime": 0,
|
||||
"rewriteTime": 0,
|
||||
"enableAttempts": 6,
|
||||
"enableAttemptsInterval": 15
|
||||
},
|
||||
|
||||
"schedEvents": {
|
||||
"enable": false
|
||||
},
|
||||
|
||||
"cecEvents": {
|
||||
"actions": [
|
||||
{
|
||||
"action": "Suspend",
|
||||
"event": "standby"
|
||||
},
|
||||
{
|
||||
"action": "Resume",
|
||||
"event": "set stream path"
|
||||
}
|
||||
],
|
||||
"enable": false
|
||||
},
|
||||
|
||||
"color": {
|
||||
"imageToLedMappingType": "multicolor_mean",
|
||||
"channelAdjustment": [
|
||||
{
|
||||
"id": "default",
|
||||
"leds": "*",
|
||||
"white": [ 255, 255, 255 ],
|
||||
"red": [ 255, 0, 0 ],
|
||||
"green": [ 0, 255, 0 ],
|
||||
"blue": [ 0, 0, 255 ],
|
||||
"cyan": [ 0, 255, 255 ],
|
||||
"magenta": [ 255, 0, 255 ],
|
||||
"yellow": [ 255, 255, 0 ],
|
||||
"gammaRed": 2.2,
|
||||
"gammaGreen": 2.2,
|
||||
"gammaBlue": 2.2,
|
||||
"backlightThreshold": 0,
|
||||
"backlightColored": false,
|
||||
"brightness": 100,
|
||||
"brightnessCompensation": 100,
|
||||
"saturationGain": 1.0,
|
||||
"brightnessGain": 1.0
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"smoothing": {
|
||||
"enable": true,
|
||||
"type": "linear",
|
||||
"time_ms": 150,
|
||||
"updateFrequency": 25.0000,
|
||||
"interpolationRate": 25.0000,
|
||||
"decay": 1,
|
||||
"dithering": false,
|
||||
"updateDelay": 0
|
||||
},
|
||||
|
||||
"grabberV4L2": {
|
||||
"enable": false,
|
||||
"device": "none",
|
||||
"input": 0,
|
||||
"encoding": "NO_CHANGE",
|
||||
"width": 0,
|
||||
"height": 0,
|
||||
"fps": 15,
|
||||
"flip": "NO_CHANGE",
|
||||
"fpsSoftwareDecimation": 0,
|
||||
"sizeDecimation": 8,
|
||||
"cropLeft": 0,
|
||||
"cropRight": 0,
|
||||
"cropTop": 0,
|
||||
"cropBottom": 0,
|
||||
"redSignalThreshold": 0,
|
||||
"greenSignalThreshold": 100,
|
||||
"blueSignalThreshold": 0,
|
||||
"signalDetection": false,
|
||||
"noSignalCounterThreshold": 200,
|
||||
"sDVOffsetMin": 0.1,
|
||||
"sDVOffsetMax": 0.9,
|
||||
"sDHOffsetMin": 0.4,
|
||||
"sDHOffsetMax": 0.46,
|
||||
"hardware_brightness": 0,
|
||||
"hardware_contrast": 0,
|
||||
"hardware_saturation": 0,
|
||||
"hardware_hue": 0
|
||||
},
|
||||
|
||||
"grabberAudio": {
|
||||
"enable": false,
|
||||
"device": "auto",
|
||||
"audioEffect": "vuMeter",
|
||||
"vuMeter": {
|
||||
"flip": "NO_CHANGE",
|
||||
"hotColor": [ 255, 0, 0 ],
|
||||
"multiplier": 1,
|
||||
"safeColor": [ 0, 255, 0 ],
|
||||
"safeValue": 45,
|
||||
"tolerance": 5,
|
||||
"warnColor": [ 255, 255, 0 ],
|
||||
"warnValue": 80
|
||||
}
|
||||
},
|
||||
|
||||
"framegrabber": {
|
||||
"enable": false,
|
||||
"device": "auto",
|
||||
"input": 0,
|
||||
"width": 80,
|
||||
"height": 45,
|
||||
"fps": 10,
|
||||
"pixelDecimation": 8,
|
||||
"cropLeft": 0,
|
||||
"cropRight": 0,
|
||||
"cropTop": 0,
|
||||
"cropBottom": 0
|
||||
},
|
||||
|
||||
"blackborderdetector": {
|
||||
"enable": true,
|
||||
"threshold": 5,
|
||||
"unknownFrameCnt": 600,
|
||||
"borderFrameCnt": 50,
|
||||
"maxInconsistentCnt": 10,
|
||||
"blurRemoveCnt": 1,
|
||||
"mode": "default"
|
||||
},
|
||||
|
||||
"foregroundEffect": {
|
||||
"enable": true,
|
||||
"type": "effect",
|
||||
"color": [ 0, 0, 255 ],
|
||||
"effect": "Rainbow swirl fast",
|
||||
"duration_ms": 3000
|
||||
},
|
||||
|
||||
"backgroundEffect": {
|
||||
"enable": false,
|
||||
"type": "effect",
|
||||
"color": [ 255, 138, 0 ],
|
||||
"effect": "Warm mood blobs"
|
||||
},
|
||||
|
||||
"forwarder": {
|
||||
"enable": false,
|
||||
"jsonapi": [],
|
||||
"flatbuffer": []
|
||||
},
|
||||
|
||||
"jsonServer": {
|
||||
"port": 19444
|
||||
},
|
||||
|
||||
"flatbufServer": {
|
||||
"enable": true,
|
||||
"port": 19400,
|
||||
"timeout": 5
|
||||
},
|
||||
|
||||
"protoServer": {
|
||||
"enable": true,
|
||||
"port": 19445,
|
||||
"timeout": 5
|
||||
},
|
||||
|
||||
"boblightServer": {
|
||||
"enable": false,
|
||||
"port": 19333,
|
||||
"priority": 128
|
||||
},
|
||||
|
||||
"webConfig": {
|
||||
"document_root": "",
|
||||
"port": 8090,
|
||||
"sslPort": 8092,
|
||||
"crtPath": "",
|
||||
"keyPath": "",
|
||||
"keyPassPhrase": ""
|
||||
},
|
||||
|
||||
"effects": {
|
||||
"paths": [ "$ROOT/custom-effects" ],
|
||||
"disable": [ "" ]
|
||||
},
|
||||
|
||||
"instCapture": {
|
||||
"systemEnable": false,
|
||||
"systemGrabberDevice": "NONE",
|
||||
"systemPriority": 250,
|
||||
"v4lEnable": false,
|
||||
"v4lGrabberDevice": "NONE",
|
||||
"v4lPriority": 240,
|
||||
"audioEnable": false,
|
||||
"audioGrabberDevice": "NONE",
|
||||
"audioPriority": 230
|
||||
},
|
||||
|
||||
"network": {
|
||||
"internetAccessAPI": false,
|
||||
"restirctedInternetAccessAPI": false,
|
||||
"ipWhitelist": [],
|
||||
"localApiAuth": false
|
||||
},
|
||||
|
||||
"ledConfig": {
|
||||
"classic": {
|
||||
"top": 1,
|
||||
"bottom": 0,
|
||||
"left": 0,
|
||||
"right": 0,
|
||||
"glength": 0,
|
||||
"gpos": 0,
|
||||
"position": 0,
|
||||
"reverse": false,
|
||||
"hdepth": 8,
|
||||
"vdepth": 5,
|
||||
"overlap": 0,
|
||||
"edgegap": 0,
|
||||
"ptlh": 0,
|
||||
"ptlv": 0,
|
||||
"ptrh": 100,
|
||||
"ptrv": 0,
|
||||
"pblh": 0,
|
||||
"pblv": 100,
|
||||
"pbrh": 100,
|
||||
"pbrv": 100
|
||||
},
|
||||
|
||||
"matrix": {
|
||||
"ledshoriz": 1,
|
||||
"ledsvert": 1,
|
||||
"cabling": "snake",
|
||||
"direction": "horizontal",
|
||||
"start": "top-left"
|
||||
}
|
||||
},
|
||||
|
||||
"leds": [
|
||||
{
|
||||
"hmax": 1,
|
||||
"hmin": 0,
|
||||
"vmax": 0.08,
|
||||
"vmin": 0
|
||||
}
|
||||
],
|
||||
|
||||
"osEvents": {
|
||||
"suspendEnable": true,
|
||||
"lockEnable": true
|
||||
},
|
||||
|
||||
"cecEvents": {
|
||||
"enable": false
|
||||
}
|
||||
}
|
@ -239,18 +239,6 @@ protected:
|
||||
QString saveEffect(const QJsonObject &data);
|
||||
#endif
|
||||
|
||||
///
|
||||
/// @brief Save settings object. Requires ADMIN ACCESS
|
||||
/// @param data The data object
|
||||
///
|
||||
bool saveSettings(const QJsonObject &data);
|
||||
|
||||
///
|
||||
/// @brief Restore settings object. Requires ADMIN ACCESS
|
||||
/// @param data The data object
|
||||
///
|
||||
bool restoreSettings(const QJsonObject &data);
|
||||
|
||||
///
|
||||
/// @brief Set the authorizationn state
|
||||
/// @param authorized True, if authorized
|
||||
|
@ -186,7 +186,7 @@ private:
|
||||
///
|
||||
void handleSourceSelectCommand(const QJsonObject &message, const JsonApiCommand& cmd);
|
||||
|
||||
/// Handle an incoming JSON GetConfig message and check subcommand
|
||||
/// Handle an incoming JSON Config message and check subcommand
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
@ -204,6 +204,12 @@ private:
|
||||
///
|
||||
void handleConfigSetCommand(const QJsonObject &message, const JsonApiCommand& cmd);
|
||||
|
||||
/// Handle an incoming JSON GetConfig message from handleConfigCommand()
|
||||
///
|
||||
/// @param message the incoming message
|
||||
///
|
||||
void handleConfigGetCommand(const QJsonObject &message, const JsonApiCommand& cmd);
|
||||
|
||||
/// Handle an incoming JSON RestoreConfig message from handleConfigCommand()
|
||||
///
|
||||
/// @param message the incoming message
|
||||
|
@ -84,6 +84,7 @@ public:
|
||||
DeleteToken,
|
||||
Discover,
|
||||
GetConfig,
|
||||
GetConfigOld,
|
||||
GetInfo,
|
||||
GetPendingTokenRequests,
|
||||
GetProperties,
|
||||
@ -134,6 +135,7 @@ public:
|
||||
case DeleteToken: return "deleteToken";
|
||||
case Discover: return "discover";
|
||||
case GetConfig: return "getconfig";
|
||||
case GetConfigOld: return "getconfig-old";
|
||||
case GetInfo: return "getInfo";
|
||||
case GetPendingTokenRequests: return "getPendingTokenRequests";
|
||||
case GetProperties: return "getProperties";
|
||||
@ -274,6 +276,7 @@ public:
|
||||
{ {"color", ""}, { Command::Color, SubCommand::Empty, Authorization::Yes, InstanceCmd::Multi, NoListenerCmd::Yes} },
|
||||
{ {"componentstate", ""}, { Command::ComponentState, SubCommand::Empty, Authorization::Yes, InstanceCmd::Multi, NoListenerCmd::Yes} },
|
||||
{ {"config", "getconfig"}, { Command::Config, SubCommand::GetConfig, Authorization::Admin, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||
{ {"config", "getconfig-old"}, { Command::Config, SubCommand::GetConfigOld, Authorization::Admin, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||
{ {"config", "getschema"}, { Command::Config, SubCommand::GetSchema, Authorization::Admin, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||
{ {"config", "reload"}, { Command::Config, SubCommand::Reload, Authorization::Admin, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||
{ {"config", "restoreconfig"}, { Command::Config, SubCommand::RestoreConfig, Authorization::Admin, InstanceCmd::Yes, NoListenerCmd::Yes} },
|
||||
|
@ -31,6 +31,8 @@ public:
|
||||
static QJsonObject getSystemInfo(const Hyperion* hyperion);
|
||||
QJsonObject discoverSources (const QString& sourceType, const QJsonObject& params);
|
||||
|
||||
static QJsonObject getConfiguration(const QList<quint8>& instances = {}, const QStringList& instanceFilteredTypes = {}, const QStringList& globalFilterTypes = {} );
|
||||
|
||||
private:
|
||||
|
||||
template<typename GrabberType>
|
||||
|
@ -1,12 +1,7 @@
|
||||
#pragma once
|
||||
#ifndef AUTHSTABLE_H
|
||||
#define AUTHSTABLE_H
|
||||
|
||||
// hyperion
|
||||
#include <db/DBManager.h>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
// qt
|
||||
#include <QDateTime>
|
||||
#include <QUuid>
|
||||
|
||||
namespace hyperion {
|
||||
const char DEFAULT_USER[] = "Hyperion";
|
||||
@ -21,69 +16,30 @@ class AuthTable : public DBManager
|
||||
|
||||
public:
|
||||
/// construct wrapper with auth table
|
||||
AuthTable(const QString& rootPath = "", QObject* parent = nullptr, bool readonlyMode = false)
|
||||
: DBManager(parent)
|
||||
{
|
||||
setReadonlyMode(readonlyMode);
|
||||
if(!rootPath.isEmpty()){
|
||||
// Init Hyperion database usage
|
||||
setRootPath(rootPath);
|
||||
setDatabaseName("hyperion");
|
||||
}
|
||||
// init Auth table
|
||||
setTable("auth");
|
||||
// create table columns
|
||||
createTable(QStringList()<<"user TEXT"<<"password BLOB"<<"token BLOB"<<"salt BLOB"<<"comment TEXT"<<"id TEXT"<<"created_at TEXT"<<"last_use TEXT");
|
||||
};
|
||||
explicit AuthTable(QObject* parent = nullptr);
|
||||
|
||||
///
|
||||
/// @brief Create a user record, if called on a existing user the auth is recreated
|
||||
/// @param[in] user The username
|
||||
/// @param[in] pw The password
|
||||
/// @param[in] password The password
|
||||
/// @return true on success else false
|
||||
///
|
||||
inline bool createUser(const QString& user, const QString& pw)
|
||||
{
|
||||
// new salt
|
||||
QByteArray salt = QCryptographicHash::hash(QUuid::createUuid().toByteArray(), QCryptographicHash::Sha512).toHex();
|
||||
QVariantMap map;
|
||||
map["user"] = user;
|
||||
map["salt"] = salt;
|
||||
map["password"] = hashPasswordWithSalt(pw,salt);
|
||||
map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("user",user));
|
||||
return createRecord(cond, map);
|
||||
}
|
||||
bool createUser(const QString& user, const QString& password);
|
||||
|
||||
///
|
||||
/// @brief Test if user record exists
|
||||
/// @param[in] user The user id
|
||||
/// @return true on success else false
|
||||
///
|
||||
inline bool userExist(const QString& user)
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("user",user));
|
||||
return recordExists(cond);
|
||||
}
|
||||
bool userExist(const QString& user);
|
||||
|
||||
///
|
||||
/// @brief Test if a user is authorized for access with given pw.
|
||||
/// @param user The user name
|
||||
/// @param pw The password
|
||||
/// @param password The password
|
||||
/// @return True on success else false
|
||||
///
|
||||
inline bool isUserAuthorized(const QString& user, const QString& pw)
|
||||
{
|
||||
if(userExist(user) && (calcPasswordHashOfUser(user, pw) == getPasswordHashOfUser(user)))
|
||||
{
|
||||
updateUserUsed(user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool isUserAuthorized(const QString& user, const QString& password);
|
||||
|
||||
///
|
||||
/// @brief Test if a user token is authorized for access.
|
||||
@ -91,197 +47,92 @@ public:
|
||||
/// @param token The token
|
||||
/// @return True on success else false
|
||||
///
|
||||
inline bool isUserTokenAuthorized(const QString& usr, const QString& token)
|
||||
{
|
||||
if(getUserToken(usr) == token.toUtf8())
|
||||
{
|
||||
updateUserUsed(usr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool isUserTokenAuthorized(const QString& usr, const QString& token);
|
||||
|
||||
///
|
||||
/// @brief Update token of a user. It's an alternate login path which is replaced on startup. This token is NOT hashed(!)
|
||||
/// @param user The user name
|
||||
/// @return True on success else false
|
||||
///
|
||||
inline bool setUserToken(const QString& user)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["token"] = QCryptographicHash::hash(QUuid::createUuid().toByteArray(), QCryptographicHash::Sha512).toHex();
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("user", user));
|
||||
return updateRecord(cond, map);
|
||||
}
|
||||
bool setUserToken(const QString& user);
|
||||
|
||||
///
|
||||
/// @brief Get token of a user. This token is NOT hashed(!)
|
||||
/// @param user The user name
|
||||
/// @return The token
|
||||
///
|
||||
inline const QByteArray getUserToken(const QString& user)
|
||||
{
|
||||
QVariantMap results;
|
||||
VectorPair cond;
|
||||
cond.append(CPair("user", user));
|
||||
getRecord(cond, results, QStringList()<<"token");
|
||||
|
||||
return results["token"].toByteArray();
|
||||
}
|
||||
const QByteArray getUserToken(const QString& user);
|
||||
|
||||
///
|
||||
/// @brief update password of given user. The user should be tested (isUserAuthorized) to verify this change
|
||||
/// @param user The user name
|
||||
/// @param newPw The new password to set
|
||||
/// @param newassword The new password to set
|
||||
/// @return True on success else false
|
||||
///
|
||||
inline bool updateUserPassword(const QString& user, const QString& newPw)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["password"] = calcPasswordHashOfUser(user, newPw);
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("user", user));
|
||||
return updateRecord(cond, map);
|
||||
}
|
||||
bool updateUserPassword(const QString& user, const QString& newPassword);
|
||||
|
||||
///
|
||||
/// @brief Reset password of Hyperion user !DANGER! Used in Hyperion main.cpp
|
||||
/// @return True on success else false
|
||||
///
|
||||
inline bool resetHyperionUser()
|
||||
{
|
||||
QVariantMap map;
|
||||
map["password"] = calcPasswordHashOfUser(hyperion::DEFAULT_USER, hyperion::DEFAULT_PASSWORD);
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("user", hyperion::DEFAULT_USER));
|
||||
return updateRecord(cond, map);
|
||||
}
|
||||
bool resetHyperionUser();
|
||||
|
||||
///
|
||||
/// @brief Update 'last_use' column entry for the corresponding user
|
||||
/// @param[in] user The user to search for
|
||||
///
|
||||
inline void updateUserUsed(const QString& user)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["last_use"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("user", user));
|
||||
updateRecord(cond, map);
|
||||
}
|
||||
void updateUserUsed(const QString& user);
|
||||
|
||||
///
|
||||
/// @brief Test if token record exists, updates last_use on success
|
||||
/// @param[in] token The token id
|
||||
/// @return true on success else false
|
||||
///
|
||||
inline bool tokenExist(const QString& token)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["last_use"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("token", hashToken(token)));
|
||||
if(recordExists(cond))
|
||||
{
|
||||
// update it
|
||||
createRecord(cond,map);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool tokenExist(const QString& token);
|
||||
|
||||
///
|
||||
/// @brief Create a new token record with comment
|
||||
/// @param[in] token The token id as plaintext
|
||||
/// @param[in] comment The comment for the token (eg a human readable identifier)
|
||||
/// @param[in] id The id for the token
|
||||
/// @param[in] identifier The identifier for the token
|
||||
/// @return true on success else false
|
||||
///
|
||||
inline bool createToken(const QString& token, const QString& comment, const QString& id)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["comment"] = comment;
|
||||
map["id"] = idExist(id) ? QUuid::createUuid().toString().remove("{").remove("}").left(5) : id;
|
||||
map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("token", hashToken(token)));
|
||||
return createRecord(cond, map);
|
||||
}
|
||||
bool createToken(const QString& token, const QString& comment, const QString& identifier);
|
||||
|
||||
///
|
||||
/// @brief Delete token record by id
|
||||
/// @param[in] id The token id
|
||||
/// @brief Delete token record by identifier
|
||||
/// @param[in] identifier The token identifier
|
||||
/// @return true on success else false
|
||||
///
|
||||
inline bool deleteToken(const QString& id)
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("id", id));
|
||||
return deleteRecord(cond);
|
||||
}
|
||||
bool deleteToken(const QString& identifier);
|
||||
|
||||
///
|
||||
/// @brief Rename token record by id
|
||||
/// @param[in] id The token id
|
||||
/// @brief Rename token record by identifier
|
||||
/// @param[in] identifier The token identifier
|
||||
/// @param[in] comment The new comment
|
||||
/// @return true on success else false
|
||||
///
|
||||
inline bool renameToken(const QString &id, const QString &comment)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["comment"] = comment;
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("id", id));
|
||||
return updateRecord(cond, map);
|
||||
}
|
||||
bool renameToken(const QString &identifier, const QString &comment);
|
||||
|
||||
///
|
||||
/// @brief Get all 'comment', 'last_use' and 'id' column entries
|
||||
/// @return A vector of all lists
|
||||
///
|
||||
inline const QVector<QVariantMap> getTokenList()
|
||||
{
|
||||
QVector<QVariantMap> results;
|
||||
getRecords(results, QStringList() << "comment" << "id" << "last_use");
|
||||
|
||||
return results;
|
||||
}
|
||||
const QVector<QVariantMap> getTokenList();
|
||||
|
||||
///
|
||||
/// @brief Test if id exists
|
||||
/// @param[in] id The id
|
||||
/// @brief Test if identifier exists
|
||||
/// @param[in] identifier The identifier
|
||||
/// @return true on success else false
|
||||
///
|
||||
inline bool idExist(const QString& id)
|
||||
{
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("id", id));
|
||||
return recordExists(cond);
|
||||
}
|
||||
bool identifierExist(const QString& identifier);
|
||||
|
||||
///
|
||||
/// @brief Get the passwort hash of a user from db
|
||||
/// @param user The user name
|
||||
/// @return password as hash
|
||||
///
|
||||
inline const QByteArray getPasswordHashOfUser(const QString& user)
|
||||
{
|
||||
QVariantMap results;
|
||||
VectorPair cond;
|
||||
cond.append(CPair("user", user));
|
||||
getRecord(cond, results, QStringList()<<"password");
|
||||
|
||||
return results["password"].toByteArray();
|
||||
}
|
||||
const QByteArray getPasswordHashOfUser(const QString& user);
|
||||
|
||||
///
|
||||
/// @brief Calc the password hash of a user based on user name and password
|
||||
@ -289,36 +140,22 @@ public:
|
||||
/// @param pw The password
|
||||
/// @return The calced password hash
|
||||
///
|
||||
inline const QByteArray calcPasswordHashOfUser(const QString& user, const QString& pw)
|
||||
{
|
||||
// get salt
|
||||
QVariantMap results;
|
||||
VectorPair cond;
|
||||
cond.append(CPair("user", user));
|
||||
getRecord(cond, results, QStringList()<<"salt");
|
||||
|
||||
// calc
|
||||
return hashPasswordWithSalt(pw,results["salt"].toByteArray());
|
||||
}
|
||||
const QByteArray calcPasswordHashOfUser(const QString& user, const QString& password);
|
||||
|
||||
///
|
||||
/// @brief Create a password hash of plaintex password + salt
|
||||
/// @param pw The plaintext password
|
||||
/// @param password The plaintext password
|
||||
/// @param salt The salt
|
||||
/// @return The password hash with salt
|
||||
///
|
||||
inline const QByteArray hashPasswordWithSalt(const QString& pw, const QByteArray& salt)
|
||||
{
|
||||
return QCryptographicHash::hash(pw.toUtf8().append(salt), QCryptographicHash::Sha512).toHex();
|
||||
}
|
||||
const QByteArray hashPasswordWithSalt(const QString& password, const QByteArray& salt);
|
||||
|
||||
///
|
||||
/// @brief Create a token hash
|
||||
/// @param token The plaintext token
|
||||
/// @return The token hash
|
||||
///
|
||||
inline const QByteArray hashToken(const QString& token)
|
||||
{
|
||||
return QCryptographicHash::hash(token.toUtf8(), QCryptographicHash::Sha512).toHex();
|
||||
}
|
||||
const QByteArray hashToken(const QString& token);
|
||||
};
|
||||
|
||||
#endif // AUTHSTABLE_H
|
||||
|
42
include/db/DBConfigManager.h
Normal file
42
include/db/DBConfigManager.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef DBCONFGMANAGER_H
|
||||
#define DBConfigManager_H
|
||||
|
||||
#include <db/DBManager.h>
|
||||
#include "db/SettingsTable.h"
|
||||
#include "db/InstanceTable.h"
|
||||
|
||||
class DBConfigManager : public DBManager
|
||||
{
|
||||
public:
|
||||
DBConfigManager(QObject* parent = nullptr);
|
||||
|
||||
QPair<bool, QStringList> importJson(const QString& configFile);
|
||||
bool exportJson(const QString& path = "") const;
|
||||
|
||||
QJsonObject getConfiguration(const QList<quint8>& instances = {}, const QStringList& instanceFilteredTypes = {}, const QStringList& globalFilterTypes = {} ) const;
|
||||
|
||||
QPair<bool, QStringList> validateConfiguration();
|
||||
QPair<bool, QStringList> validateConfiguration(QJsonObject& config, bool doCorrections = false);
|
||||
|
||||
QPair<bool, QStringList> addMissingDefaults();
|
||||
|
||||
QPair<bool, QStringList> updateConfiguration();
|
||||
QPair<bool, QStringList> updateConfiguration(QJsonObject& config, bool doCorrections = false);
|
||||
|
||||
QPair<bool, QStringList> migrateConfiguration();
|
||||
|
||||
private:
|
||||
// Function to import global settings from the configuration
|
||||
bool importGlobalSettings(const QJsonObject& config, QStringList& errorList);
|
||||
|
||||
// Function to import all instances from the configuration
|
||||
bool importInstances(const QJsonObject& config, QStringList& errorList);
|
||||
|
||||
// Function to import a single instance
|
||||
bool importInstance(InstanceTable& instanceTable, const QJsonObject& instanceConfig, quint8 instanceIdx, QStringList& errorList);
|
||||
|
||||
// Function to import settings for a specific instance
|
||||
bool importInstanceSettings(SettingsTable& settingsTable, const QJsonObject& instanceSettings, QStringList& errorList);
|
||||
};
|
||||
|
||||
#endif // DBCONFGMANAGER_H
|
@ -1,10 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef Unsorted
|
||||
#undef Unsorted
|
||||
#endif
|
||||
|
||||
#include <utils/Logger.h>
|
||||
#include <QMap>
|
||||
#include <QVariant>
|
||||
#include <QPair>
|
||||
#include <QVector>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QThreadStorage>
|
||||
|
||||
class QSqlDatabase;
|
||||
class QSqlQuery;
|
||||
@ -26,13 +33,22 @@ class DBManager : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DBManager(QObject* parent = nullptr);
|
||||
~DBManager() override;
|
||||
explicit DBManager(QObject* parent = nullptr);
|
||||
|
||||
static void initializeDatabase(const QDir& dataDirectory, bool isReadOnly);
|
||||
|
||||
static QDir getDataDirectory() { return _dataDirectory;}
|
||||
static QDir getDirectory() { return _databaseDirectory;}
|
||||
static QFileInfo getFileInfo() { return _databaseFile;}
|
||||
static bool isReadOnly() { return _isReadOnly; }
|
||||
|
||||
///
|
||||
/// @brief Sets the database in read-only mode.
|
||||
/// Updates will not written to the tables
|
||||
/// @param[in] readOnly True read-only, false - read/write
|
||||
///
|
||||
static void setReadonly(bool isReadOnly) { _isReadOnly = isReadOnly; }
|
||||
|
||||
/// set root path
|
||||
void setRootPath(const QString& rootPath);
|
||||
/// define the database to work with
|
||||
void setDatabaseName(const QString& dbn) { _dbn = dbn; };
|
||||
/// set a table to work with
|
||||
void setTable(const QString& table);
|
||||
|
||||
@ -61,6 +77,8 @@ public:
|
||||
///
|
||||
bool recordExists(const VectorPair& conditions) const;
|
||||
|
||||
bool recordsNotExisting(const QVariantList& testValues,const QString& column, QStringList& nonExistingRecs, const QString& condition ) const;
|
||||
|
||||
///
|
||||
/// @brief Create a new record in table when the conditions find no existing entry. Add additional key:value pairs in columns
|
||||
/// DO NOT repeat column keys between 'conditions' and 'columns' as they will be merged on creation
|
||||
@ -98,6 +116,18 @@ public:
|
||||
///
|
||||
bool getRecords(QVector<QVariantMap>& results, const QStringList& tColumns = QStringList(), const QStringList& tOrder = QStringList()) const;
|
||||
|
||||
///
|
||||
/// @brief Get data of multiple records, you need to specify the columns. This search is without conditions. Good to grab all data from db
|
||||
/// @param[in] conditions condition to search for (WHERE)
|
||||
/// @param[out] results results of query
|
||||
/// @param[in] tColumns target columns to search in (optional) if not provided returns all columns
|
||||
/// @param[in] tOrder target order columns with order by ASC/DESC (optional)
|
||||
/// @return True on success else false
|
||||
///
|
||||
bool getRecords(const VectorPair& conditions, QVector<QVariantMap>& results, const QStringList& tColumns = {}, const QStringList& tOrder = {}) const;
|
||||
|
||||
bool getRecords(const QString& condition, const QVariantList& bindValues, QVector<QVariantMap>& results, const QStringList& tColumns = {}, const QStringList& tOrder = {}) const;
|
||||
|
||||
///
|
||||
/// @brief Delete a record determined by conditions
|
||||
/// @param[in] conditions conditions of the row to delete it (WHERE)
|
||||
@ -119,23 +149,36 @@ public:
|
||||
///
|
||||
bool deleteTable(const QString& table) const;
|
||||
|
||||
///
|
||||
/// @brief Sets a table in read-only mode.
|
||||
/// Updates will not written to the table
|
||||
/// @param[in] readOnly True read-only, false - read/write
|
||||
///
|
||||
void setReadonlyMode(bool readOnly) { _readonlyMode = readOnly; };
|
||||
bool executeQuery(QSqlQuery& query) const;
|
||||
|
||||
bool startTransaction(QSqlDatabase& idb) const;
|
||||
bool startTransaction(QSqlDatabase& idb, QStringList& errorList);
|
||||
bool commiTransaction(QSqlDatabase& idb) const;
|
||||
bool commiTransaction(QSqlDatabase& idb, QStringList& errorList);
|
||||
bool rollbackTransaction(QSqlDatabase& idb) const;
|
||||
bool rollbackTransaction(QSqlDatabase& idb, QStringList& errorList);
|
||||
|
||||
// Utility function to log errors and append to error list
|
||||
void logErrorAndAppend(const QString& errorText, QStringList& errorList);
|
||||
|
||||
protected:
|
||||
Logger* _log;
|
||||
|
||||
private:
|
||||
static QDir _dataDirectory;
|
||||
static QDir _databaseDirectory;
|
||||
static QFileInfo _databaseFile;
|
||||
static QThreadStorage<QSqlDatabase> _databasePool;
|
||||
static bool _isReadOnly;
|
||||
|
||||
Logger* _log;
|
||||
/// databse connection & file name, defaults to hyperion
|
||||
QString _dbn = "hyperion";
|
||||
|
||||
/// table in database
|
||||
QString _table;
|
||||
|
||||
bool _readonlyMode;
|
||||
/// addBindValues to query given by QVariantList
|
||||
void addBindValues(QSqlQuery& query, const QVariantList& variants) const;
|
||||
|
||||
/// addBindValue to query given by QVariantList
|
||||
void doAddBindValue(QSqlQuery& query, const QVariantList& variants) const;
|
||||
QString constructExecutedQuery(const QSqlQuery& query) const;
|
||||
};
|
||||
|
33
include/db/DBMigrationManager.h
Normal file
33
include/db/DBMigrationManager.h
Normal file
@ -0,0 +1,33 @@
|
||||
#ifndef DBMIGRATIONMANAGER_H
|
||||
#define DBMIGRATIONMANAGER_H
|
||||
|
||||
#include <db/DBManager.h>
|
||||
#include <utils/version.hpp>
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class DBMigrationManager : public DBManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit DBMigrationManager(QObject *parent = nullptr);
|
||||
|
||||
bool isMigrationRequired();
|
||||
bool migrateSettings(QJsonObject& config);
|
||||
|
||||
private:
|
||||
|
||||
bool upgradeGlobalSettings(const semver::version& currentVersion, QJsonObject& config);
|
||||
bool upgradeGlobalSettings_alpha_9(semver::version& currentVersion, QJsonObject& config);
|
||||
bool upgradeGlobalSettings_2_0_12(semver::version& currentVersion, QJsonObject& config);
|
||||
bool upgradeGlobalSettings_2_0_16(semver::version& currentVersion, QJsonObject& config);
|
||||
bool upgradeGlobalSettings_2_1_0(semver::version& currentVersion, QJsonObject& config);
|
||||
|
||||
bool upgradeInstanceSettings(const semver::version& currentVersion, quint8 instance, QJsonObject& config);
|
||||
bool upgradeInstanceSettings_alpha_9(semver::version& currentVersion, quint8 instance, QJsonObject& config);
|
||||
bool upgradeInstanceSettings_2_0_12(semver::version& currentVersion, quint8 instance, QJsonObject& config);
|
||||
bool upgradeInstanceSettings_2_0_13(semver::version& currentVersion, quint8 instance, QJsonObject& config);
|
||||
bool upgradeInstanceSettings_2_0_16(semver::version& currentVersion, quint8 instance, QJsonObject& config);
|
||||
};
|
||||
|
||||
#endif // DBMIGRATIONMANAGER_H
|
@ -1,11 +1,7 @@
|
||||
#pragma once
|
||||
#ifndef INSTANCETABLE_H
|
||||
#define INSTANCETABLE_H
|
||||
|
||||
// db
|
||||
#include <db/DBManager.h>
|
||||
#include <db/SettingsTable.h>
|
||||
|
||||
// qt
|
||||
#include <QDateTime>
|
||||
|
||||
///
|
||||
/// @brief Hyperion instance manager specific database interface. prepares also the Hyperion database for all follow up usage (Init QtSqlConnection) along with db name
|
||||
@ -14,22 +10,7 @@ class InstanceTable : public DBManager
|
||||
{
|
||||
|
||||
public:
|
||||
InstanceTable(const QString& rootPath, QObject* parent = nullptr, bool readonlyMode = false)
|
||||
: DBManager(parent)
|
||||
{
|
||||
|
||||
setReadonlyMode(readonlyMode);
|
||||
// Init Hyperion database usage
|
||||
setRootPath(rootPath);
|
||||
setDatabaseName("hyperion");
|
||||
|
||||
// Init instance table
|
||||
setTable("instances");
|
||||
createTable(QStringList()<<"instance INTEGER"<<"friendly_name TEXT"<<"enabled INTEGER DEFAULT 0"<<"last_use TEXT");
|
||||
|
||||
// start/create the first Hyperion instance index 0
|
||||
createInstance();
|
||||
};
|
||||
explicit InstanceTable(QObject* parent = nullptr);
|
||||
|
||||
///
|
||||
/// @brief Create a new Hyperion instance entry, the name needs to be unique
|
||||
@ -37,53 +18,19 @@ public:
|
||||
/// @param[out] inst The id that has been assigned
|
||||
/// @return True on success else false
|
||||
///
|
||||
inline bool createInstance(const QString& name, quint8& inst)
|
||||
{
|
||||
VectorPair fcond;
|
||||
fcond.append(CPair("friendly_name",name));
|
||||
bool createInstance(const QString& name, quint8& inst);
|
||||
|
||||
// check duplicate
|
||||
if(!recordExists(fcond))
|
||||
{
|
||||
inst = 0;
|
||||
VectorPair cond;
|
||||
cond.append(CPair("instance",inst));
|
||||
|
||||
// increment to next avail index
|
||||
while(recordExists(cond))
|
||||
{
|
||||
inst++;
|
||||
cond.removeFirst();
|
||||
cond.append(CPair("instance",inst));
|
||||
}
|
||||
// create
|
||||
QVariantMap data;
|
||||
data["friendly_name"] = name;
|
||||
data["instance"] = inst;
|
||||
VectorPair lcond;
|
||||
return createRecord(lcond, data);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
///
|
||||
/// @brief Create first Hyperion instance entry, if index 0 is not found.
|
||||
///
|
||||
void createDefaultInstance();
|
||||
|
||||
///
|
||||
/// @brief Delete a Hyperion instance
|
||||
/// @param inst The id that has been assigned
|
||||
/// @return True on success else false
|
||||
///
|
||||
inline bool deleteInstance(quint8 inst)
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("instance",inst));
|
||||
if(deleteRecord(cond))
|
||||
{
|
||||
// delete settings entries
|
||||
SettingsTable settingsTable(inst);
|
||||
settingsTable.deleteInstance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool deleteInstance(quint8 inst);
|
||||
|
||||
///
|
||||
/// @brief Assign a new name for the given instance
|
||||
@ -91,141 +38,59 @@ public:
|
||||
/// @param name The new name of the instance
|
||||
/// @return True on success else false (instance not found)
|
||||
///
|
||||
inline bool saveName(quint8 inst, const QString& name)
|
||||
{
|
||||
VectorPair fcond;
|
||||
fcond.append(CPair("friendly_name",name));
|
||||
|
||||
// check duplicate
|
||||
if(!recordExists(fcond))
|
||||
{
|
||||
if(instanceExist(inst))
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("instance",inst));
|
||||
QVariantMap data;
|
||||
data["friendly_name"] = name;
|
||||
|
||||
return updateRecord(cond, data);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool saveName(quint8 inst, const QString& name);
|
||||
|
||||
///
|
||||
/// @brief Get all instances with all columns
|
||||
/// @param justEnabled return just enabled instances if true
|
||||
/// @param onlyEnabled return only enabled instances if true
|
||||
/// @return The found instances
|
||||
///
|
||||
inline QVector<QVariantMap> getAllInstances(bool justEnabled = false)
|
||||
{
|
||||
QVector<QVariantMap> results;
|
||||
getRecords(results, QStringList(), QStringList() << "instance ASC");
|
||||
if(justEnabled)
|
||||
{
|
||||
for (auto it = results.begin(); it != results.end();)
|
||||
{
|
||||
if( ! (*it)["enabled"].toBool())
|
||||
{
|
||||
it = results.erase(it);
|
||||
continue;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
QVector<QVariantMap> getAllInstances(bool onlyEnabled = false);
|
||||
|
||||
///
|
||||
/// @brief Get all instance IDs
|
||||
/// @param onlyEnabled return only enabled instance IDs if true
|
||||
/// @return The found instances
|
||||
///
|
||||
QList<quint8> getAllInstanceIDs (bool onlyEnabled = false);
|
||||
|
||||
///
|
||||
/// @brief Test if instance record exists
|
||||
/// @param[in] user The user id
|
||||
/// @return true on success else false
|
||||
///
|
||||
inline bool instanceExist(quint8 inst)
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("instance",inst));
|
||||
return recordExists(cond);
|
||||
}
|
||||
bool instanceExist(quint8 inst);
|
||||
|
||||
///
|
||||
/// @brief Get instance name by instance index
|
||||
/// @param index The index to search for
|
||||
/// @return The name of this index, may return NOT FOUND if not found
|
||||
///
|
||||
inline const QString getNamebyIndex(quint8 index)
|
||||
{
|
||||
QVariantMap results;
|
||||
VectorPair cond;
|
||||
cond.append(CPair("instance", index));
|
||||
getRecord(cond, results, QStringList("friendly_name"));
|
||||
|
||||
QString name = results["friendly_name"].toString();
|
||||
return name.isEmpty() ? "NOT FOUND" : name;
|
||||
}
|
||||
QString getNamebyIndex(quint8 index);
|
||||
|
||||
///
|
||||
/// @brief Update 'last_use' timestamp
|
||||
/// @param inst The instance to update
|
||||
/// @return True on success else false
|
||||
///
|
||||
inline void setLastUse(quint8 inst)
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("instance", inst));
|
||||
QVariantMap map;
|
||||
map["last_use"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
updateRecord(cond, map);
|
||||
}
|
||||
bool setLastUse(quint8 inst);
|
||||
|
||||
///
|
||||
/// @brief Update 'enabled' column by instance index
|
||||
/// @param inst The instance to update
|
||||
/// @param newState True when enabled else false
|
||||
/// @return True on success else false
|
||||
///
|
||||
inline void setEnable(quint8 inst, bool newState)
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("instance", inst));
|
||||
QVariantMap map;
|
||||
map["enabled"] = newState;
|
||||
updateRecord(cond, map);
|
||||
}
|
||||
bool setEnable(quint8 inst, bool newState);
|
||||
|
||||
///
|
||||
/// @brief Get state of 'enabled' column by instance index
|
||||
/// @param inst The instance to get
|
||||
/// @return True when enabled else false
|
||||
///
|
||||
inline bool isEnabled(quint8 inst)
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("instance", inst));
|
||||
QVariantMap results;
|
||||
getRecord(cond, results);
|
||||
|
||||
return results["enabled"].toBool();
|
||||
}
|
||||
bool isEnabled(quint8 inst);
|
||||
|
||||
private:
|
||||
///
|
||||
/// @brief Create first Hyperion instance entry, if index 0 is not found.
|
||||
///
|
||||
inline void createInstance()
|
||||
{
|
||||
if(instanceExist(0))
|
||||
setEnable(0, true);
|
||||
else
|
||||
{
|
||||
QVariantMap data;
|
||||
data["friendly_name"] = "First LED Hardware instance";
|
||||
VectorPair cond;
|
||||
cond.append(CPair("instance", 0));
|
||||
if(createRecord(cond, data))
|
||||
setEnable(0, true);
|
||||
else
|
||||
throw std::runtime_error("Failed to create Hyperion root instance in db! This should never be the case...");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // INSTANCETABLE_H
|
||||
|
@ -1,14 +1,9 @@
|
||||
#pragma once
|
||||
#ifndef METATABLE_H
|
||||
#define METATABLE_H
|
||||
|
||||
// hyperion
|
||||
#include <db/DBManager.h>
|
||||
|
||||
// qt
|
||||
#include <QDateTime>
|
||||
#include <QUuid>
|
||||
#include <QNetworkInterface>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
///
|
||||
/// @brief meta table specific database interface
|
||||
///
|
||||
@ -17,47 +12,13 @@ class MetaTable : public DBManager
|
||||
|
||||
public:
|
||||
/// construct wrapper with plugins table and columns
|
||||
MetaTable(QObject* parent = nullptr, bool readonlyMode = false)
|
||||
: DBManager(parent)
|
||||
{
|
||||
setReadonlyMode(readonlyMode);
|
||||
|
||||
setTable("meta");
|
||||
createTable(QStringList()<<"uuid TEXT"<<"created_at TEXT");
|
||||
};
|
||||
explicit MetaTable(QObject* parent = nullptr);
|
||||
|
||||
///
|
||||
/// @brief Get the uuid, if the uuid is not set it will be created
|
||||
/// @return The uuid
|
||||
///
|
||||
inline QString getUUID() const
|
||||
{
|
||||
QVector<QVariantMap> results;
|
||||
getRecords(results, QStringList() << "uuid");
|
||||
|
||||
for(const auto & entry : results)
|
||||
{
|
||||
if(!entry["uuid"].toString().isEmpty())
|
||||
return entry["uuid"].toString();
|
||||
}
|
||||
|
||||
// create new uuidv5 based on net adapter MAC, save to db and return
|
||||
QString hash;
|
||||
foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
|
||||
{
|
||||
if (!(interface.flags() & QNetworkInterface::IsLoopBack))
|
||||
{
|
||||
hash = QCryptographicHash::hash(interface.hardwareAddress().toLocal8Bit(),QCryptographicHash::Sha1).toHex();
|
||||
break;
|
||||
}
|
||||
}
|
||||
const QString newUuid = QUuid::createUuidV5(QUuid(), hash).toString().mid(1, 36);
|
||||
VectorPair cond;
|
||||
cond.append(CPair("uuid",newUuid));
|
||||
QVariantMap map;
|
||||
map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
createRecord(cond, map);
|
||||
|
||||
return newUuid;
|
||||
}
|
||||
QString getUUID() const;
|
||||
};
|
||||
|
||||
#endif // METATABLE_H
|
||||
|
@ -1,12 +1,20 @@
|
||||
#pragma once
|
||||
#ifndef SETTINGSTABLE_H
|
||||
#define SETTINGSTABLE_H
|
||||
|
||||
#include <limits>
|
||||
|
||||
#ifdef WIN32
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
// hyperion
|
||||
#include <db/DBManager.h>
|
||||
#include <utils/version.hpp>
|
||||
|
||||
// qt
|
||||
#include <QDateTime>
|
||||
#include <QJsonDocument>
|
||||
|
||||
const int GLOABL_INSTANCE_ID = std::numeric_limits<quint8>::max();;
|
||||
const char DEFAULT_CONFIG_VERSION[] = "2.0.0-alpha.8";
|
||||
|
||||
///
|
||||
/// @brief settings table db interface
|
||||
///
|
||||
@ -15,14 +23,7 @@ class SettingsTable : public DBManager
|
||||
|
||||
public:
|
||||
/// construct wrapper with settings table
|
||||
SettingsTable(quint8 instance, QObject* parent = nullptr)
|
||||
: DBManager(parent)
|
||||
, _hyperion_inst(instance)
|
||||
{
|
||||
setTable("settings");
|
||||
// create table columns
|
||||
createTable(QStringList()<<"type TEXT"<<"config TEXT"<<"hyperion_inst INTEGER"<<"updated_at TEXT");
|
||||
};
|
||||
SettingsTable(quint8 instance = GLOABL_INSTANCE_ID, QObject* parent = nullptr);
|
||||
|
||||
///
|
||||
/// @brief Create or update a settings record
|
||||
@ -30,19 +31,7 @@ public:
|
||||
/// @param[in] config The configuration data
|
||||
/// @return true on success else false
|
||||
///
|
||||
inline bool createSettingsRecord(const QString& type, const QString& config) const
|
||||
{
|
||||
QVariantMap map;
|
||||
map["config"] = config;
|
||||
map["updated_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("type",type));
|
||||
// when a setting is not global we are searching also for the instance
|
||||
if(!isSettingGlobal(type))
|
||||
cond.append(CPair("AND hyperion_inst",_hyperion_inst));
|
||||
return createRecord(cond, map);
|
||||
}
|
||||
bool createSettingsRecord(const QString& type, const QString& config) const;
|
||||
|
||||
///
|
||||
/// @brief Test if record exist, type can be global setting or local (instance)
|
||||
@ -50,76 +39,64 @@ public:
|
||||
/// @param[in] hyperion_inst The instance of hyperion assigned (might be empty)
|
||||
/// @return true on success else false
|
||||
///
|
||||
inline bool recordExist(const QString& type) const
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("type",type));
|
||||
// when a setting is not global we are searching also for the instance
|
||||
if(!isSettingGlobal(type))
|
||||
cond.append(CPair("AND hyperion_inst",_hyperion_inst));
|
||||
return recordExists(cond);
|
||||
}
|
||||
bool recordExist(const QString& type) const;
|
||||
|
||||
///
|
||||
/// @brief Get 'config' column of settings entry as QJsonDocument
|
||||
/// @param[in] type The settings type
|
||||
/// @return The QJsonDocument
|
||||
///
|
||||
inline QJsonDocument getSettingsRecord(const QString& type) const
|
||||
{
|
||||
QVariantMap results;
|
||||
VectorPair cond;
|
||||
cond.append(CPair("type",type));
|
||||
// when a setting is not global we are searching also for the instance
|
||||
if(!isSettingGlobal(type))
|
||||
cond.append(CPair("AND hyperion_inst",_hyperion_inst));
|
||||
getRecord(cond, results, QStringList("config"));
|
||||
return QJsonDocument::fromJson(results["config"].toByteArray());
|
||||
}
|
||||
QJsonDocument getSettingsRecord(const QString& type) const;
|
||||
|
||||
///
|
||||
/// @brief Get 'config' column of settings entry as QString
|
||||
/// @param[in] type The settings type
|
||||
/// @return The QString
|
||||
///
|
||||
inline QString getSettingsRecordString(const QString& type) const
|
||||
{
|
||||
QVariantMap results;
|
||||
VectorPair cond;
|
||||
cond.append(CPair("type",type));
|
||||
// when a setting is not global we are searching also for the instance
|
||||
if(!isSettingGlobal(type))
|
||||
cond.append(CPair("AND hyperion_inst",_hyperion_inst));
|
||||
getRecord(cond, results, QStringList("config"));
|
||||
return results["config"].toString();
|
||||
}
|
||||
QString getSettingsRecordString(const QString& type) const;
|
||||
|
||||
QJsonObject getSettings(const QStringList& filteredTypes = {} ) const;
|
||||
QJsonObject getSettings(const QVariant& instance, const QStringList& filteredTypes = {} ) const;
|
||||
|
||||
QStringList nonExtingTypes() const;
|
||||
QPair<bool, QStringList> addMissingDefaults();
|
||||
|
||||
///
|
||||
/// @brief Delete all settings entries associated with this instance, called from InstanceTable of HyperionIManager
|
||||
///
|
||||
inline void deleteInstance() const
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("hyperion_inst",_hyperion_inst));
|
||||
deleteRecord(cond);
|
||||
}
|
||||
void deleteInstance() const;
|
||||
|
||||
inline bool isSettingGlobal(const QString& type) const
|
||||
{
|
||||
// list of global settings
|
||||
QStringList list;
|
||||
// server port services
|
||||
list << "jsonServer" << "protoServer" << "flatbufServer" << "forwarder" << "webConfig" << "network"
|
||||
// capture
|
||||
<< "framegrabber" << "grabberV4L2" << "grabberAudio"
|
||||
//Events
|
||||
<< "osEvents" << "cecEvents" << "schedEvents"
|
||||
// other
|
||||
<< "logger" << "general";
|
||||
const QVector<QString>& getGlobalSettingTypes() const;
|
||||
bool isGlobalSettingType(const QString& type) const;
|
||||
|
||||
return list.contains(type);
|
||||
}
|
||||
const QVector<QString>& getInstanceSettingTypes() const;
|
||||
bool isInstanceSettingType(const QString& type) const;
|
||||
|
||||
const QJsonObject& getDefaultSettings() const;
|
||||
|
||||
semver::version getConfigVersion();
|
||||
QString getConfigVersionString();
|
||||
|
||||
bool resolveConfigVersion();
|
||||
bool resolveConfigVersion(QJsonObject generalConfig);
|
||||
|
||||
private:
|
||||
const quint8 _hyperion_inst;
|
||||
QString fixVersion(const QString& version);
|
||||
|
||||
QVector<QString> initializeGlobalSettingTypes() const;
|
||||
static QVector<QString> globalSettingTypes;
|
||||
static bool areGlobalSettingTypesInitialised;
|
||||
|
||||
QVector<QString> initializeInstanceSettingTypes() const;
|
||||
static QVector<QString> instanceSettingTypes;
|
||||
static bool areInstanceSettingTypesInitialised;
|
||||
|
||||
QJsonObject initializeDefaultSettings() const;
|
||||
static QJsonObject defaultSettings;
|
||||
static bool areDefaultSettingsInitialised;
|
||||
|
||||
const quint8 _instance;
|
||||
semver::version _configVersion;
|
||||
};
|
||||
|
||||
#endif // SETTINGSTABLE_H
|
||||
|
@ -23,7 +23,7 @@ class AuthManager : public QObject
|
||||
private:
|
||||
friend class HyperionDaemon;
|
||||
/// constructor is private, can be called from HyperionDaemon
|
||||
AuthManager(QObject *parent = nullptr, bool readonlyMode = false);
|
||||
AuthManager(QObject *parent = nullptr);
|
||||
|
||||
public:
|
||||
struct AuthDefinition
|
||||
|
@ -108,8 +108,6 @@ public:
|
||||
///
|
||||
QString getActiveDeviceType() const;
|
||||
|
||||
bool getReadOnlyMode() const {return _readOnlyMode; }
|
||||
|
||||
public slots:
|
||||
|
||||
///
|
||||
@ -335,18 +333,9 @@ public slots:
|
||||
///
|
||||
/// @brief Save a complete json config
|
||||
/// @param config The entire config object
|
||||
/// @param correct If true will correct json against schema before save
|
||||
/// @return True on success else false
|
||||
///
|
||||
bool saveSettings(const QJsonObject& config, bool correct = false);
|
||||
|
||||
///
|
||||
/// @brief Restore a complete json config
|
||||
/// @param config The entire config object
|
||||
/// @param correct If true will correct json against schema before save
|
||||
/// @return True on success else false
|
||||
///
|
||||
bool restoreSettings(const QJsonObject& config, bool correct = false);
|
||||
QPair<bool, QStringList> saveSettings(const QJsonObject& config);
|
||||
|
||||
/// ############
|
||||
/// COMPONENTREGISTER
|
||||
@ -552,7 +541,7 @@ private:
|
||||
/// @brief Constructs the Hyperion instance, just accessible for HyperionIManager
|
||||
/// @param instance The instance index
|
||||
///
|
||||
Hyperion(quint8 instance, bool readonlyMode = false);
|
||||
Hyperion(quint8 instance);
|
||||
|
||||
/// instance index
|
||||
const quint8 _instIndex;
|
||||
@ -615,6 +604,4 @@ private:
|
||||
/// Boblight instance
|
||||
BoblightServer* _boblightServer;
|
||||
#endif
|
||||
|
||||
bool _readOnlyMode;
|
||||
};
|
||||
|
@ -59,12 +59,18 @@ public slots:
|
||||
///
|
||||
QVector<QVariantMap> getInstanceData() const;
|
||||
|
||||
QString getInstanceName(quint8 inst = 0);
|
||||
|
||||
///
|
||||
/// @brief Get all instance indicies of running instances
|
||||
///
|
||||
QList<quint8> getRunningInstanceIdx() const;
|
||||
|
||||
///
|
||||
/// @brief Get all instance indicies configured
|
||||
///
|
||||
QList<quint8> getInstanceIds() const;
|
||||
|
||||
///
|
||||
/// @brief Start a Hyperion instance
|
||||
/// @param instance Instance index
|
||||
@ -115,8 +121,6 @@ public slots:
|
||||
///
|
||||
bool saveName(quint8 inst, const QString& name);
|
||||
|
||||
QString getRootPath() const { return _rootPath; }
|
||||
|
||||
signals:
|
||||
///
|
||||
/// @brief Emits whenever the state of a instance changes according to enum instanceState
|
||||
@ -195,9 +199,8 @@ private:
|
||||
friend class HyperionDaemon;
|
||||
///
|
||||
/// @brief Construct the Manager
|
||||
/// @param The root path of all userdata
|
||||
///
|
||||
HyperionIManager(const QString& rootPath, QObject* parent = nullptr, bool readonlyMode = false);
|
||||
HyperionIManager(QObject* parent = nullptr);
|
||||
|
||||
///
|
||||
/// @brief Start all instances that are marked as enabled in db. Non blocking
|
||||
@ -218,12 +221,9 @@ private:
|
||||
private:
|
||||
Logger* _log;
|
||||
InstanceTable* _instanceTable;
|
||||
const QString _rootPath;
|
||||
QMap<quint8, Hyperion*> _runningInstances;
|
||||
|
||||
QList<quint8> _startQueue;
|
||||
|
||||
bool _readonlyMode;
|
||||
|
||||
/// All pending requests
|
||||
QMap<quint8, PendingRequests> _pendingRequests;
|
||||
};
|
||||
|
@ -3,14 +3,11 @@
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/settings.h>
|
||||
|
||||
#include <utils/version.hpp>
|
||||
using namespace semver;
|
||||
#include <db/SettingsTable.h>
|
||||
|
||||
// qt includes
|
||||
#include <QJsonObject>
|
||||
|
||||
const int GLOABL_INSTANCE_ID = 255;
|
||||
|
||||
class Hyperion;
|
||||
class SettingsTable;
|
||||
|
||||
@ -26,23 +23,21 @@ public:
|
||||
/// @params instance Instance index of HyperionInstanceManager
|
||||
/// @params parent The parent hyperion instance
|
||||
///
|
||||
SettingsManager(quint8 instance, QObject* parent = nullptr, bool readonlyMode = false);
|
||||
SettingsManager(quint8 instance = GLOABL_INSTANCE_ID, QObject* parent = nullptr);
|
||||
|
||||
///
|
||||
/// @brief Save a complete json configuration
|
||||
/// @brief Save a complete JSON configuration
|
||||
/// @param config The entire config object
|
||||
/// @param correct If true will correct json against schema before save
|
||||
/// @return True on success else false
|
||||
/// @return True on success else false, plus validation errors
|
||||
///
|
||||
bool saveSettings(QJsonObject config, bool correct = false);
|
||||
QPair<bool, QStringList> saveSettings(const QJsonObject& config);
|
||||
|
||||
///
|
||||
/// @brief Restore a complete json configuration
|
||||
/// @brief Correct a complete JSON configuration
|
||||
/// @param config The entire config object
|
||||
/// @param correct If true will correct json against schema before save
|
||||
/// @return True on success else false
|
||||
/// @return True on success else false, plus correction details
|
||||
///
|
||||
bool restoreSettings(QJsonObject config, bool correct = false);
|
||||
QPair<bool, QStringList> correctSettings(QJsonObject& config);
|
||||
|
||||
///
|
||||
/// @brief get a single setting json from configuration
|
||||
@ -52,10 +47,18 @@ public:
|
||||
QJsonDocument getSetting(settings::type type) const;
|
||||
|
||||
///
|
||||
/// @brief get the full settings object of this instance (with global settings)
|
||||
/// @brief get a single setting json from configuration
|
||||
/// @param type The type as string
|
||||
/// @return The requested json data as QJsonDocument
|
||||
///
|
||||
QJsonDocument getSetting(const QString& type) const;
|
||||
|
||||
///
|
||||
/// @brief get the selected settings objects of this instance (including global settings)
|
||||
/// @return The requested json
|
||||
///
|
||||
QJsonObject getSettings() const;
|
||||
QJsonObject getSettings(const QStringList& filteredTypes = {}) const;
|
||||
QJsonObject getSettings(const QVariant& instance, const QStringList& filteredTypes = {} ) const;
|
||||
|
||||
signals:
|
||||
///
|
||||
@ -71,31 +74,19 @@ private:
|
||||
/// @param config The configuration object
|
||||
/// @return True when a migration has been triggered
|
||||
///
|
||||
bool handleConfigUpgrade(QJsonObject& config);
|
||||
bool upgradeConfig(QJsonObject& config);
|
||||
|
||||
|
||||
bool resolveConfigVersion(QJsonObject& config);
|
||||
|
||||
/// Logger instance
|
||||
Logger* _log;
|
||||
|
||||
/// Hyperion instance
|
||||
Hyperion* _hyperion;
|
||||
|
||||
/// Instance number
|
||||
quint8 _instance;
|
||||
|
||||
/// instance of database table interface
|
||||
SettingsTable* _sTable;
|
||||
|
||||
/// the schema
|
||||
static QJsonObject schemaJson;
|
||||
|
||||
/// the current configuration of this instance
|
||||
QJsonObject _qconfig;
|
||||
|
||||
semver::version _configVersion;
|
||||
semver::version _previousVersion;
|
||||
|
||||
bool _readonlyMode;
|
||||
};
|
||||
|
@ -3,13 +3,14 @@
|
||||
#include <utils/FileUtils.h>
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
#include <QPair>
|
||||
#include <QStringList>
|
||||
#include <utils/Logger.h>
|
||||
|
||||
namespace JsonUtils {
|
||||
///
|
||||
/// @brief read a json file and get the parsed result on success
|
||||
/// @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
|
||||
@ -17,6 +18,7 @@ namespace JsonUtils {
|
||||
/// @return true on success else false
|
||||
///
|
||||
QPair<bool, QStringList> readFile(const QString& path, QJsonObject& obj, Logger* log, bool ignError=false);
|
||||
QPair<bool, QStringList> readFile(const QString& path, QJsonValue& obj, Logger* log, bool ignError=false);
|
||||
|
||||
///
|
||||
/// @brief read a schema file and resolve $refs
|
||||
@ -28,18 +30,19 @@ namespace JsonUtils {
|
||||
bool readSchema(const QString& path, QJsonObject& obj, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief parse a json QString and get a QJsonObject. Overloaded funtion
|
||||
/// @param[in] path The file path/name just used for log messages
|
||||
/// @brief parse a JSON QString and get a QJsonObject. Overloaded funtion
|
||||
/// @param[in] path The file path/name context 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
|
||||
///
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonObject& obj, Logger* log);
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonValue& value, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief parse a json QString and get a QJsonArray. Overloaded function
|
||||
/// @param[in] path The file path/name just used for log messages
|
||||
/// @brief parse a JSON QString and get a QJsonArray. Overloaded function
|
||||
/// @param[in] path The file path/name context used for log messages
|
||||
/// @param[in] data Data to parse
|
||||
/// @param[out] arr Retuns the parsed QJsonArray
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
@ -48,8 +51,8 @@ namespace JsonUtils {
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonArray& arr, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief parse a json QString and get a QJsonDocument
|
||||
/// @param[in] path The file path/name just used for log messages
|
||||
/// @brief parse a JSON QString and get a QJsonDocument
|
||||
/// @param[in] path The file path/name context used for log messages
|
||||
/// @param[in] data Data to parse
|
||||
/// @param[out] doc Retuns the parsed QJsonDocument
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
@ -58,29 +61,39 @@ namespace JsonUtils {
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonDocument& doc, 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
|
||||
/// @brief Validate JSON data against a schema
|
||||
/// @param[in] file The path/name of JSON file context 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
|
||||
/// @return true on success else false, plus validation errors
|
||||
///
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonObject& json, const QString& schemaPath, Logger* log);
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonValue& json, const QString& schemaPath, 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
|
||||
/// @brief Validate JSON data against a schema
|
||||
/// @param[in] file The path/name of JSON file context used for log messages
|
||||
/// @param[in] json The JSON data
|
||||
/// @param[in] schema The schema object
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
/// @return true on success else false, plus validation errors
|
||||
///
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonObject& json, const QJsonObject& schema, Logger* log);
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonValue& json, const QJsonObject& schema, Logger* log);
|
||||
|
||||
///
|
||||
/// @brief Write json data to file
|
||||
/// @brief Validate JSON data against a schema
|
||||
/// @param[in] file The path/name of JSON file context used for log messages
|
||||
/// @param[in/out] json The JSON data
|
||||
/// @param[in] schema The schema object
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false, plus correction messages
|
||||
///
|
||||
QPair<bool, QStringList> correct(const QString& file, QJsonValue& json, const QJsonObject& schema, 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] json The JSON data to write
|
||||
/// @param[in] log The logger of the caller to print errors
|
||||
/// @return true on success else false
|
||||
///
|
||||
@ -94,4 +107,15 @@ namespace JsonUtils {
|
||||
/// @return true on success else false
|
||||
///
|
||||
bool resolveRefs(const QJsonObject& schema, QJsonObject& obj, Logger* log);
|
||||
|
||||
|
||||
///
|
||||
/// @brief Function to convert QJsonValue to QString using QJsonDocument
|
||||
///
|
||||
QString jsonValueToQString(const QJsonValue &value, QJsonDocument::JsonFormat format = QJsonDocument::Compact);
|
||||
|
||||
///
|
||||
/// @brief Function to merge two QJsonObjects
|
||||
///
|
||||
QJsonObject mergeJsonObjects(const QJsonObject &obj1, const QJsonObject &obj2, bool overrideObj1 = false);
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ public:
|
||||
/// @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);
|
||||
QPair<bool, bool> validate(const QJsonValue& value, bool ignoreRequired = false);
|
||||
|
||||
///
|
||||
/// @brief Auto correct a JSON structure
|
||||
@ -52,7 +52,7 @@ public:
|
||||
/// @param ignoreRequired Ignore the "required" keyword in hyperion schema. Default is false
|
||||
/// @return The corrected JSON structure
|
||||
///
|
||||
QJsonObject getAutoCorrectedConfig(const QJsonObject& value, bool ignoreRequired = false);
|
||||
QJsonValue getAutoCorrectedConfig(const QJsonValue& value, bool ignoreRequired = false);
|
||||
|
||||
///
|
||||
/// @return A list of error messages
|
||||
@ -207,7 +207,7 @@ private:
|
||||
/// Auto correction variable
|
||||
QString _correct;
|
||||
/// The auto corrected json-configuration
|
||||
QJsonObject _autoCorrected;
|
||||
QJsonValue _autoCorrected;
|
||||
/// The current location into a json-configuration structure being checked
|
||||
QStringList _currentPath;
|
||||
/// The result messages collected during the schema verification
|
||||
|
@ -11,7 +11,7 @@ class QJsonUtils
|
||||
{
|
||||
public:
|
||||
|
||||
static void modify(QJsonObject& value, QStringList path, const QJsonValue& newValue = QJsonValue::Null, QString propertyName = "")
|
||||
static void modify(QJsonValue& value, QStringList path, const QJsonValue& newValue = QJsonValue::Null, QString propertyName = "")
|
||||
{
|
||||
QJsonObject result;
|
||||
|
||||
@ -27,7 +27,7 @@ public:
|
||||
*it = current.mid(1, current.size()-1);
|
||||
}
|
||||
|
||||
if (!value.isEmpty())
|
||||
if (! (value.toObject().isEmpty() && value.toArray().isEmpty()) )
|
||||
modifyValue(value, result, path, newValue, propertyName);
|
||||
else if (newValue != QJsonValue::Null && !propertyName.isEmpty())
|
||||
result[propertyName] = newValue;
|
||||
|
@ -385,7 +385,7 @@ namespace semver {
|
||||
return -1;
|
||||
}
|
||||
|
||||
version& operator= (version& rgt)
|
||||
version& operator= (const version& rgt)
|
||||
{
|
||||
if ((*this) != rgt)
|
||||
{
|
||||
@ -404,17 +404,17 @@ namespace semver {
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend bool operator== (version &lft, version &rgt)
|
||||
friend bool operator== (const version &lft, const version &rgt)
|
||||
{
|
||||
return !(lft != rgt);
|
||||
}
|
||||
|
||||
friend bool operator!= (version &lft, version &rgt)
|
||||
friend bool operator!= (const version &lft, const version &rgt)
|
||||
{
|
||||
return (lft > rgt) || (lft < rgt);
|
||||
}
|
||||
|
||||
friend bool operator> (version &lft, version &rgt)
|
||||
friend bool operator> (const version &lft, const version &rgt)
|
||||
{
|
||||
// Major
|
||||
if (lft.getMajor() < 0 && rgt.getMajor() >= 0)
|
||||
@ -522,17 +522,17 @@ namespace semver {
|
||||
return false;
|
||||
}
|
||||
|
||||
friend bool operator>= (version &lft, version &rgt)
|
||||
friend bool operator>= (const version &lft, const version &rgt)
|
||||
{
|
||||
return (lft > rgt) || (lft == rgt);
|
||||
}
|
||||
|
||||
friend bool operator< (version &lft, version &rgt)
|
||||
friend bool operator< (const version &lft, const version &rgt)
|
||||
{
|
||||
return (rgt > lft);
|
||||
}
|
||||
|
||||
friend bool operator<= (version &lft, version &rgt)
|
||||
friend bool operator<= (const version &lft, const version &rgt)
|
||||
{
|
||||
return (lft < rgt) || (lft == rgt);
|
||||
}
|
||||
|
@ -391,34 +391,6 @@ QString API::saveEffect(const QJsonObject &data)
|
||||
}
|
||||
#endif
|
||||
|
||||
bool API::saveSettings(const QJsonObject &data)
|
||||
{
|
||||
bool isSaved {true};
|
||||
if (!_adminAuthorized)
|
||||
{
|
||||
isSaved = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
QMetaObject::invokeMethod(_hyperion, "saveSettings", Qt::DirectConnection, Q_RETURN_ARG(bool, isSaved), Q_ARG(QJsonObject, data), Q_ARG(bool, true));
|
||||
}
|
||||
return isSaved;
|
||||
}
|
||||
|
||||
bool API::restoreSettings(const QJsonObject &data)
|
||||
{
|
||||
bool isRestored {true};
|
||||
if (!_adminAuthorized)
|
||||
{
|
||||
isRestored = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
QMetaObject::invokeMethod(_hyperion, "restoreSettings", Qt::DirectConnection, Q_RETURN_ARG(bool, isRestored), Q_ARG(QJsonObject, data), Q_ARG(bool, true));
|
||||
}
|
||||
return isRestored;
|
||||
}
|
||||
|
||||
bool API::updateHyperionPassword(const QString &password, const QString &newPassword)
|
||||
{
|
||||
bool isPwUpdated {true};
|
||||
|
@ -10,18 +10,42 @@
|
||||
"subcommand": {
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["getconfig","getschema","setconfig","restoreconfig","reload"]
|
||||
},
|
||||
"instance" : {
|
||||
"type" : "integer",
|
||||
"minimum": 0,
|
||||
"maximum": 255
|
||||
"enum" : ["getconfig","getconfig-old","getschema","setconfig","restoreconfig","reload"]
|
||||
},
|
||||
"tan" : {
|
||||
"type" : "integer"
|
||||
},
|
||||
"configFilter": {
|
||||
"global" : {
|
||||
"types": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"instances" : {
|
||||
"ids" : {
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"items" : {},
|
||||
"minItems": 1
|
||||
},
|
||||
"types": {
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" :{
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"type" : "object"
|
||||
"required": false,
|
||||
"$ref": "schema-settings-full-relaxed.json",
|
||||
"required": false,
|
||||
"$ref": "schema-settings-ui.json"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
// auth manager
|
||||
#include <hyperion/AuthManager.h>
|
||||
#include <db/DBConfigManager.h>
|
||||
|
||||
#ifdef ENABLE_MDNS
|
||||
// mDNS discover
|
||||
@ -67,6 +68,8 @@ constexpr int BEARER_TOKEN_TAG_LENGTH = sizeof(BEARER_TOKEN_TAG) - 1;
|
||||
const int MIN_PASSWORD_LENGTH = 8;
|
||||
const int APP_TOKEN_LENGTH = 36;
|
||||
|
||||
const char SETTINGS_UI_SCHEMA_FILE[] = ":/schema-settings-ui.json";
|
||||
|
||||
const bool verbose = false;
|
||||
}
|
||||
|
||||
@ -698,6 +701,10 @@ void JsonAPI::handleConfigCommand(const QJsonObject& message, const JsonApiComma
|
||||
break;
|
||||
|
||||
case SubCommand::GetConfig:
|
||||
handleConfigGetCommand(message, cmd);
|
||||
break;
|
||||
|
||||
case SubCommand::GetConfigOld:
|
||||
sendSuccessDataReply(_hyperion->getQJsonConfig(), cmd);
|
||||
break;
|
||||
|
||||
@ -722,38 +729,185 @@ void JsonAPI::handleConfigCommand(const QJsonObject& message, const JsonApiComma
|
||||
|
||||
void JsonAPI::handleConfigSetCommand(const QJsonObject &message, const JsonApiCommand& cmd)
|
||||
{
|
||||
if (message.contains("config"))
|
||||
if (DBManager::isReadOnly())
|
||||
{
|
||||
QJsonObject config = message["config"].toObject();
|
||||
if (API::isHyperionEnabled())
|
||||
{
|
||||
if ( API::saveSettings(config) ) {
|
||||
sendSuccessReply(cmd);
|
||||
} else {
|
||||
sendErrorReply("Save settings failed", cmd);
|
||||
sendErrorReply("Database Error", {"Hyperion is running in read-only mode","Configuration updates are not possible"}, cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonObject config = message["config"].toObject();
|
||||
if (config.contains("global") || config.contains("instances"))
|
||||
{
|
||||
QStringList errorDetails;
|
||||
|
||||
QMap<quint8, QJsonObject> instancesNewConfigs;
|
||||
|
||||
const QJsonArray instances = config["instances"].toArray();
|
||||
if (!instances.isEmpty())
|
||||
{
|
||||
QList<quint8> configuredInstanceIds = _instanceManager->getInstanceIds();
|
||||
for (const auto &instance : instances)
|
||||
{
|
||||
QJsonObject instanceObject = instance.toObject();
|
||||
const QJsonValue idx = instanceObject["id"];
|
||||
if (idx.isDouble())
|
||||
{
|
||||
quint8 instanceId = static_cast<quint8>(idx.toInt());
|
||||
if (configuredInstanceIds.contains(instanceId))
|
||||
{
|
||||
instancesNewConfigs.insert(instanceId,instanceObject.value("settings").toObject());
|
||||
}
|
||||
else
|
||||
{
|
||||
sendErrorReply("It is not possible saving a configuration while Hyperion is disabled", cmd);
|
||||
errorDetails.append(QString("Given instance id '%1' does not exist. Configuration item will be ignored").arg(instanceId));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QJsonObject globalSettings = config["global"].toObject().value("settings").toObject();
|
||||
if (!globalSettings.isEmpty())
|
||||
{
|
||||
const QJsonObject instanceZeroConfig = instancesNewConfigs.value(0);
|
||||
instancesNewConfigs.insert(0, JsonUtils::mergeJsonObjects(instanceZeroConfig, globalSettings));
|
||||
}
|
||||
|
||||
QMapIterator<quint8, QJsonObject> i (instancesNewConfigs);
|
||||
while (i.hasNext()) {
|
||||
i.next();
|
||||
|
||||
quint8 idx = i.key();
|
||||
Hyperion* instance = HyperionIManager::getInstance()->getHyperionInstance(idx);
|
||||
|
||||
QPair<bool, QStringList> isSaved = instance->saveSettings(i.value());
|
||||
errorDetails.append(isSaved.second);
|
||||
}
|
||||
|
||||
if (!errorDetails.isEmpty())
|
||||
{
|
||||
sendErrorReply("Update configuration failed", errorDetails, cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
sendSuccessReply(cmd);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (config.isEmpty())
|
||||
{
|
||||
sendErrorReply("Update configuration failed", {"No configuration data provided!"}, cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
//Backward compatability until UI mesages are updated
|
||||
if (API::isHyperionEnabled())
|
||||
{
|
||||
QStringList errorDetails;
|
||||
|
||||
QPair<bool, QStringList> isSaved = _hyperion->saveSettings(config);
|
||||
errorDetails.append(isSaved.second);
|
||||
|
||||
if (!errorDetails.isEmpty())
|
||||
{
|
||||
sendErrorReply("Save settings failed", errorDetails, cmd);
|
||||
return;
|
||||
}
|
||||
|
||||
sendSuccessReply(cmd);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendErrorReply("Updating the configuration while Hyperion is disabled is not possible", cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void JsonAPI::handleConfigGetCommand(const QJsonObject &message, const JsonApiCommand& cmd)
|
||||
{
|
||||
QJsonObject settings;
|
||||
QStringList errorDetails;
|
||||
|
||||
QJsonObject filter = message["configFilter"].toObject();
|
||||
if (!filter.isEmpty())
|
||||
{
|
||||
QStringList globalFilterTypes;
|
||||
|
||||
const QJsonObject globalConfig = filter["global"].toObject();
|
||||
if (!globalConfig.isEmpty())
|
||||
{
|
||||
const QJsonArray globalTypes = globalConfig["types"].toArray();
|
||||
for (const auto &type : globalTypes) {
|
||||
if (type.isString()) {
|
||||
globalFilterTypes.append(type.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QList<quint8> instanceListFilter;
|
||||
QStringList instanceFilterTypes;
|
||||
|
||||
const QJsonObject instances = filter["instances"].toObject();
|
||||
if (!instances.isEmpty())
|
||||
{
|
||||
QList<quint8> configuredInstanceIds = _instanceManager->getInstanceIds();
|
||||
const QJsonArray instanceIds = instances["ids"].toArray();
|
||||
for (const auto &idx : instanceIds) {
|
||||
if (idx.isDouble()) {
|
||||
quint8 instanceId = static_cast<quint8>(idx.toInt());
|
||||
if (configuredInstanceIds.contains(instanceId))
|
||||
{
|
||||
instanceListFilter.append(instanceId);
|
||||
}
|
||||
else
|
||||
{
|
||||
errorDetails.append(QString("Given instance number '%1' does not exist.").arg(instanceId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QJsonArray instanceTypes = instances["types"].toArray();
|
||||
for (const auto &type : instanceTypes) {
|
||||
if (type.isString()) {
|
||||
instanceFilterTypes.append(type.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
settings = JsonInfo::getConfiguration(instanceListFilter, instanceFilterTypes, globalFilterTypes);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Get complete configuration
|
||||
settings = JsonInfo::getConfiguration();
|
||||
}
|
||||
|
||||
if (!settings.empty())
|
||||
{
|
||||
sendSuccessDataReplyWithError(settings, cmd, errorDetails);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendErrorReply("Generating full config failed", cmd);
|
||||
}
|
||||
}
|
||||
|
||||
void JsonAPI::handleConfigRestoreCommand(const QJsonObject &message, const JsonApiCommand& cmd)
|
||||
{
|
||||
if (message.contains("config"))
|
||||
{
|
||||
QJsonObject config = message["config"].toObject();
|
||||
if (API::isHyperionEnabled())
|
||||
{
|
||||
if ( API::restoreSettings(config) )
|
||||
DBConfigManager configManager;
|
||||
QPair<bool, QStringList> result = configManager.updateConfiguration(config, false);
|
||||
if (result.first)
|
||||
{
|
||||
sendSuccessReply(cmd);
|
||||
QString infoMsg {"Restarting after importing configuration successfully."};
|
||||
sendSuccessDataReply(infoMsg, cmd);
|
||||
Info(_log, "%s", QSTRING_CSTR(infoMsg));
|
||||
emit signalEvent(Event::Restart);
|
||||
}
|
||||
else
|
||||
{
|
||||
sendErrorReply("Restore settings failed", cmd);
|
||||
sendErrorReply("Restore configuration failed", result.second, cmd);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -761,7 +915,6 @@ void JsonAPI::handleConfigRestoreCommand(const QJsonObject &message, const JsonA
|
||||
sendErrorReply("Restoring configuration while Hyperion is disabled is not possible", cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void JsonAPI::handleSchemaGetCommand(const QJsonObject& /*message*/, const JsonApiCommand& cmd)
|
||||
{
|
||||
@ -774,7 +927,7 @@ void JsonAPI::handleSchemaGetCommand(const QJsonObject& /*message*/, const JsonA
|
||||
Q_INIT_RESOURCE(resource);
|
||||
|
||||
// read the hyperion json schema from the resource
|
||||
QString schemaFile = ":/hyperion-schema";
|
||||
QString schemaFile = SETTINGS_UI_SCHEMA_FILE;
|
||||
|
||||
try
|
||||
{
|
||||
@ -1156,7 +1309,7 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
||||
{
|
||||
QString replyMsg;
|
||||
|
||||
const quint8 &inst = static_cast<quint8>(message["instance"].toInt());
|
||||
const quint8 inst = static_cast<quint8>(message["instance"].toInt());
|
||||
const QString &name = message["name"].toString();
|
||||
|
||||
switch (cmd.subCommand) {
|
||||
@ -1191,7 +1344,6 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
||||
break;
|
||||
|
||||
case SubCommand::DeleteInstance:
|
||||
handleConfigRestoreCommand(message, cmd);
|
||||
if (API::deleteInstance(inst, replyMsg))
|
||||
{
|
||||
sendSuccessReply(cmd);
|
||||
@ -1213,7 +1365,7 @@ void JsonAPI::handleInstanceCommand(const QJsonObject &message, const JsonApiCom
|
||||
if (cmd.subCommand == SubCommand::CreateInstance) {
|
||||
replyMsg = API::createInstance(name);
|
||||
} else {
|
||||
replyMsg = setInstanceName(inst, name);
|
||||
replyMsg = API::setInstanceName(inst, name);
|
||||
}
|
||||
|
||||
if (replyMsg.isEmpty()) {
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <db/DBConfigManager.h>
|
||||
#include <api/JsonInfo.h>
|
||||
#include <api/API.h>
|
||||
|
||||
@ -498,8 +499,8 @@ QJsonObject JsonInfo::getSystemInfo(const Hyperion* hyperion)
|
||||
hyperionInfo["gitremote"] = QString(HYPERION_GIT_REMOTE);
|
||||
hyperionInfo["time"] = QString(__DATE__ " " __TIME__);
|
||||
hyperionInfo["id"] = AuthManager::getInstance()->getID();
|
||||
hyperionInfo["rootPath"] = HyperionIManager::getInstance()->getRootPath();
|
||||
hyperionInfo["readOnlyMode"] = hyperion->getReadOnlyMode();
|
||||
hyperionInfo["configDatabaseFile"] = DBManager::getFileInfo().absoluteFilePath();
|
||||
hyperionInfo["readOnlyMode"] = DBManager::isReadOnly();
|
||||
|
||||
QCoreApplication* app = QCoreApplication::instance();
|
||||
hyperionInfo["isGuiMode"] = qobject_cast<QApplication*>(app) != nullptr;
|
||||
@ -622,3 +623,9 @@ QJsonArray JsonInfo::discoverScreenInputs(const QJsonObject& params) const
|
||||
|
||||
return screenInputs;
|
||||
}
|
||||
|
||||
QJsonObject JsonInfo::getConfiguration(const QList<quint8>& instancesfilter, const QStringList& instanceFilteredTypes, const QStringList& globalFilterTypes )
|
||||
{
|
||||
DBConfigManager configManager;
|
||||
return configManager.getConfiguration(instancesfilter, instanceFilteredTypes, globalFilterTypes );
|
||||
}
|
||||
|
176
libsrc/db/AuthTable.cpp
Normal file
176
libsrc/db/AuthTable.cpp
Normal file
@ -0,0 +1,176 @@
|
||||
|
||||
// hyperion
|
||||
#include <db/AuthTable.h>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
// qt
|
||||
#include <QDateTime>
|
||||
#include <QUuid>
|
||||
|
||||
/// construct wrapper with auth table
|
||||
AuthTable::AuthTable(QObject* parent)
|
||||
: DBManager(parent)
|
||||
{
|
||||
// init Auth table
|
||||
setTable("auth");
|
||||
// create table columns
|
||||
createTable(QStringList()<<"user TEXT"<<"password BLOB"<<"token BLOB"<<"salt BLOB"<<"comment TEXT"<<"id TEXT"<<"created_at TEXT"<<"last_use TEXT");
|
||||
};
|
||||
|
||||
bool AuthTable::createUser(const QString& user, const QString& password)
|
||||
{
|
||||
// new salt
|
||||
QByteArray salt = QCryptographicHash::hash(QUuid::createUuid().toByteArray(), QCryptographicHash::Sha512).toHex();
|
||||
QVariantMap map;
|
||||
map["user"] = user;
|
||||
map["salt"] = salt;
|
||||
map["password"] = hashPasswordWithSalt(password,salt);
|
||||
map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
return createRecord({{"user",user}}, map);
|
||||
}
|
||||
|
||||
bool AuthTable::userExist(const QString& user)
|
||||
{
|
||||
return recordExists({{"user",user}});
|
||||
}
|
||||
|
||||
bool AuthTable::isUserAuthorized(const QString& user, const QString& password)
|
||||
{
|
||||
if(userExist(user) && (calcPasswordHashOfUser(user, password) == getPasswordHashOfUser(user)))
|
||||
{
|
||||
updateUserUsed(user);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AuthTable::isUserTokenAuthorized(const QString& usr, const QString& token)
|
||||
{
|
||||
if(getUserToken(usr) == token.toUtf8())
|
||||
{
|
||||
updateUserUsed(usr);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AuthTable::setUserToken(const QString& user)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["token"] = QCryptographicHash::hash(QUuid::createUuid().toByteArray(), QCryptographicHash::Sha512).toHex();
|
||||
|
||||
return updateRecord({{"user",user}}, map);
|
||||
}
|
||||
|
||||
const QByteArray AuthTable::getUserToken(const QString& user)
|
||||
{
|
||||
QVariantMap results;
|
||||
getRecord({{"user",user}}, results, QStringList()<<"token");
|
||||
|
||||
return results["token"].toByteArray();
|
||||
}
|
||||
|
||||
bool AuthTable::updateUserPassword(const QString& user, const QString& newPassword)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["password"] = calcPasswordHashOfUser(user, newPassword);
|
||||
|
||||
return updateRecord({{"user",user}}, map);
|
||||
}
|
||||
|
||||
bool AuthTable::resetHyperionUser()
|
||||
{
|
||||
QVariantMap map;
|
||||
map["password"] = calcPasswordHashOfUser(hyperion::DEFAULT_USER, hyperion::DEFAULT_PASSWORD);
|
||||
|
||||
return updateRecord({{"user", hyperion::DEFAULT_USER}}, map);
|
||||
}
|
||||
|
||||
void AuthTable::updateUserUsed(const QString& user)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["last_use"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
updateRecord({{"user",user}}, map);
|
||||
}
|
||||
|
||||
bool AuthTable::tokenExist(const QString& token)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["last_use"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("token", hashToken(token)));
|
||||
if(recordExists(cond))
|
||||
{
|
||||
// update it
|
||||
createRecord(cond,map);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AuthTable::createToken(const QString& token, const QString& comment, const QString& identifier)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["comment"] = comment;
|
||||
map["id"] = identifierExist(identifier) ? QUuid::createUuid().toString().remove("{").remove("}").left(5) : identifier;
|
||||
map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
return createRecord({{"token", hashToken(token)}}, map);
|
||||
}
|
||||
|
||||
bool AuthTable::deleteToken(const QString& identifier)
|
||||
{
|
||||
return deleteRecord({{"id", identifier}});
|
||||
}
|
||||
|
||||
bool AuthTable::renameToken(const QString &identifier, const QString &comment)
|
||||
{
|
||||
QVariantMap map;
|
||||
map["comment"] = comment;
|
||||
|
||||
return updateRecord({{"id", identifier}}, map);
|
||||
}
|
||||
|
||||
const QVector<QVariantMap> AuthTable::getTokenList()
|
||||
{
|
||||
QVector<QVariantMap> results;
|
||||
getRecords(results, QStringList() << "comment" << "id" << "last_use");
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
bool AuthTable::identifierExist(const QString& identifier)
|
||||
{
|
||||
return recordExists({{"id", identifier}});
|
||||
}
|
||||
|
||||
const QByteArray AuthTable::getPasswordHashOfUser(const QString& user)
|
||||
{
|
||||
QVariantMap results;
|
||||
getRecord({{"user",user}}, results, QStringList()<<"password");
|
||||
|
||||
return results["password"].toByteArray();
|
||||
}
|
||||
|
||||
const QByteArray AuthTable::calcPasswordHashOfUser(const QString& user, const QString& password)
|
||||
{
|
||||
// get salt
|
||||
QVariantMap results;
|
||||
getRecord({{"user",user}}, results, QStringList()<<"salt");
|
||||
|
||||
// calc
|
||||
return hashPasswordWithSalt(password,results["salt"].toByteArray());
|
||||
}
|
||||
|
||||
const QByteArray AuthTable::hashPasswordWithSalt(const QString& password, const QByteArray& salt)
|
||||
{
|
||||
return QCryptographicHash::hash(password.toUtf8().append(salt), QCryptographicHash::Sha512).toHex();
|
||||
}
|
||||
|
||||
const QByteArray AuthTable::hashToken(const QString& token)
|
||||
{
|
||||
return QCryptographicHash::hash(token.toUtf8(), QCryptographicHash::Sha512).toHex();
|
||||
}
|
@ -1,10 +1,18 @@
|
||||
add_library(database
|
||||
${CMAKE_SOURCE_DIR}/include/db/AuthTable.h
|
||||
${CMAKE_SOURCE_DIR}/include/db/DBManager.h
|
||||
${CMAKE_SOURCE_DIR}/include/db/DBConfigManager.h
|
||||
${CMAKE_SOURCE_DIR}/include/db/DBMigrationManager.h
|
||||
${CMAKE_SOURCE_DIR}/include/db/InstanceTable.h
|
||||
${CMAKE_SOURCE_DIR}/include/db/MetaTable.h
|
||||
${CMAKE_SOURCE_DIR}/include/db/SettingsTable.h
|
||||
${CMAKE_SOURCE_DIR}/libsrc/db/AuthTable.cpp
|
||||
${CMAKE_SOURCE_DIR}/libsrc/db/DBManager.cpp
|
||||
${CMAKE_SOURCE_DIR}/libsrc/db/DBConfigManager.cpp
|
||||
${CMAKE_SOURCE_DIR}/libsrc/db/DBMigrationManager.cpp
|
||||
${CMAKE_SOURCE_DIR}/libsrc/db/InstanceTable.cpp
|
||||
${CMAKE_SOURCE_DIR}/libsrc/db/MetaTable.cpp
|
||||
${CMAKE_SOURCE_DIR}/libsrc/db/SettingsTable.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(database
|
||||
|
382
libsrc/db/DBConfigManager.cpp
Normal file
382
libsrc/db/DBConfigManager.cpp
Normal file
@ -0,0 +1,382 @@
|
||||
#include <db/DBConfigManager.h>
|
||||
|
||||
#include <db/DBMigrationManager.h>
|
||||
#include "db/SettingsTable.h"
|
||||
#include <db/MetaTable.h>
|
||||
|
||||
#include <db/InstanceTable.h>
|
||||
#include <hyperion/SettingsManager.h>
|
||||
|
||||
#include <qsqlrecord.h>
|
||||
#include <utils/JsonUtils.h>
|
||||
#include <utils/jsonschema/QJsonFactory.h>
|
||||
|
||||
#include <HyperionConfig.h>
|
||||
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlError>
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace {
|
||||
const char SETTINGS_FULL_SCHEMA_FILE[] = ":/schema-settings-full.json";
|
||||
}
|
||||
|
||||
DBConfigManager::DBConfigManager(QObject* parent)
|
||||
: DBManager(parent)
|
||||
{
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> DBConfigManager::importJson(const QString& configFile)
|
||||
{
|
||||
Info(_log,"Import configuration file '%s'", QSTRING_CSTR(configFile));
|
||||
|
||||
QJsonObject config;
|
||||
QPair<bool, QStringList> result = JsonUtils::readFile(configFile, config, _log, false);
|
||||
|
||||
if (!result.first)
|
||||
{
|
||||
QString errorText = QString("Import configuration file '%1' failed!").arg(configFile);
|
||||
result.second.prepend(errorText);
|
||||
Error(_log, "%s", QSTRING_CSTR(errorText));
|
||||
return result;
|
||||
}
|
||||
|
||||
DBMigrationManager migtrationManger;
|
||||
migtrationManger.migrateSettings(config);
|
||||
|
||||
return updateConfiguration(config, true);
|
||||
}
|
||||
|
||||
bool DBConfigManager::exportJson(const QString& path) const
|
||||
{
|
||||
bool isExported {false};
|
||||
|
||||
QDir exportPath{path};
|
||||
if (path.isEmpty())
|
||||
{
|
||||
exportPath.setPath(getDataDirectory().absoluteFilePath("archive"));
|
||||
}
|
||||
|
||||
QString jsonFile;
|
||||
if (QDir().mkpath(exportPath.absolutePath()))
|
||||
{
|
||||
const QJsonObject configurtion = getConfiguration();
|
||||
if (!configurtion.isEmpty())
|
||||
{
|
||||
const QJsonObject generalSettings = configurtion.value("global").toObject().value("settings").toObject().value("general").toObject();
|
||||
const QString configVersion = generalSettings.value("configVersion").toString();
|
||||
|
||||
jsonFile = exportPath.absoluteFilePath(QString("HyperionBackup_%1_v%2.json").arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_hh:mm:ss:zzz"), configVersion ));
|
||||
if (FileUtils::writeFile(jsonFile, QJsonDocument(configurtion).toJson(QJsonDocument::Indented), _log))
|
||||
{
|
||||
isExported = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isExported)
|
||||
{
|
||||
Info(_log, "Successfully exported configuration to '%s'", QSTRING_CSTR(jsonFile));
|
||||
}
|
||||
else
|
||||
{
|
||||
Error(_log, "Failed to export configuration to '%s'", QSTRING_CSTR(jsonFile));
|
||||
}
|
||||
|
||||
return isExported;
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> DBConfigManager::validateConfiguration()
|
||||
{
|
||||
QJsonObject config = getConfiguration();
|
||||
return validateConfiguration(config, false);
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> DBConfigManager::validateConfiguration(QJsonObject& config, bool doCorrections)
|
||||
{
|
||||
Info(_log, "Validate configuration%s", doCorrections ? " and apply corrections, if required" : "");
|
||||
|
||||
QStringList errorList;
|
||||
if (config.isEmpty())
|
||||
{
|
||||
QString errorText {"No configuration data provided!"};
|
||||
Error(_log, "'%s'", QSTRING_CSTR(errorText));
|
||||
errorList.append(errorText);
|
||||
return qMakePair (false, errorList );
|
||||
}
|
||||
|
||||
QJsonObject schema = QJsonFactory::readSchema(SETTINGS_FULL_SCHEMA_FILE);
|
||||
|
||||
bool wasCorrected {false};
|
||||
if (doCorrections)
|
||||
{
|
||||
QJsonValue configValue(config);
|
||||
QPair<bool, QStringList> correctionResult = JsonUtils::correct(__FUNCTION__, configValue, schema, _log);
|
||||
|
||||
wasCorrected = correctionResult.first;
|
||||
if (wasCorrected)
|
||||
{
|
||||
config = configValue.toObject();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
QPair<bool, QStringList> validationResult = JsonUtils::validate(__FUNCTION__, config, schema, _log);
|
||||
if (!validationResult.first)
|
||||
{
|
||||
Error(_log, "Configuration has errors!");
|
||||
return qMakePair (false, validationResult.second );
|
||||
}
|
||||
}
|
||||
|
||||
Info(_log, "Configuration is valid%s", wasCorrected ? ", but had to be corrected" : "");
|
||||
return qMakePair (true, errorList );
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> DBConfigManager::updateConfiguration()
|
||||
{
|
||||
QJsonObject config = getConfiguration();
|
||||
return updateConfiguration(config, true);
|
||||
}
|
||||
|
||||
|
||||
QPair<bool, QStringList> DBConfigManager::addMissingDefaults()
|
||||
{
|
||||
Debug(_log, "Add default settings for missing configuration items");
|
||||
|
||||
QStringList errorList;
|
||||
|
||||
SettingsTable globalSettingsTable;
|
||||
QPair<bool, QStringList> result = globalSettingsTable.addMissingDefaults();
|
||||
errorList.append(result.second);
|
||||
|
||||
InstanceTable instanceTable;
|
||||
|
||||
//Ensure that first instance as default one exists
|
||||
instanceTable.createDefaultInstance();
|
||||
|
||||
const QList<quint8> instances = instanceTable.getAllInstanceIDs();
|
||||
for (const auto &instanceIdx : instances)
|
||||
{
|
||||
SettingsTable instanceSettingsTable(instanceIdx);
|
||||
result = instanceSettingsTable.addMissingDefaults();
|
||||
errorList.append(result.second);
|
||||
}
|
||||
|
||||
if(errorList.isEmpty())
|
||||
{
|
||||
Debug(_log, "Successfully defaulted settings for missing configuration items");
|
||||
}
|
||||
|
||||
return qMakePair (errorList.isEmpty(), errorList );
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> DBConfigManager::updateConfiguration(QJsonObject& config, bool doCorrections)
|
||||
{
|
||||
Info(_log, "Update configuration database");
|
||||
|
||||
QPair<bool, QStringList> validationResult = validateConfiguration(config, doCorrections);
|
||||
if (!validationResult.first)
|
||||
{
|
||||
return validationResult;
|
||||
}
|
||||
|
||||
Info(_log, "Create backup of current configuration");
|
||||
if (!exportJson())
|
||||
{
|
||||
Warning(_log, "Backup of current configuration failed");
|
||||
}
|
||||
|
||||
QStringList errorList;
|
||||
QSqlDatabase idb = getDB();
|
||||
|
||||
if (!startTransaction(idb, errorList))
|
||||
{
|
||||
return qMakePair(false, errorList);
|
||||
}
|
||||
|
||||
// Clear existing tables and import the new configuration.
|
||||
bool errorOccurred = false;
|
||||
if (!deleteTable("instances") && deleteTable("settings"))
|
||||
{
|
||||
errorOccurred = true;
|
||||
logErrorAndAppend("Failed to clear tables before import", errorList);
|
||||
}
|
||||
else
|
||||
{
|
||||
errorOccurred = !importGlobalSettings(config, errorList) || !importInstances(config, errorList);
|
||||
}
|
||||
|
||||
// Rollback if any error occurred during the import process.
|
||||
if (errorOccurred)
|
||||
{
|
||||
if (!rollbackTransaction(idb, errorList))
|
||||
{
|
||||
return qMakePair(false, errorList);
|
||||
}
|
||||
}
|
||||
|
||||
commiTransaction(idb, errorList);
|
||||
|
||||
if (errorList.isEmpty())
|
||||
{
|
||||
Info(_log, "Successfully imported new configuration");
|
||||
}
|
||||
|
||||
return qMakePair(errorList.isEmpty(), errorList);
|
||||
}
|
||||
|
||||
// Function to import global settings
|
||||
bool DBConfigManager::importGlobalSettings(const QJsonObject& config, QStringList& errorList)
|
||||
{
|
||||
SettingsTable settingsTableGlobal;
|
||||
const QJsonObject globalConfig = config.value("global").toObject();
|
||||
const QJsonObject globalSettings = globalConfig.value("settings").toObject();
|
||||
|
||||
bool errorOccurred = false;
|
||||
for (QJsonObject::const_iterator it = globalSettings.constBegin(); it != globalSettings.constEnd(); ++it)
|
||||
{
|
||||
if (!settingsTableGlobal.createSettingsRecord(it.key(), JsonUtils::jsonValueToQString(it.value())))
|
||||
{
|
||||
errorOccurred = true;
|
||||
logErrorAndAppend("Failed to import global setting", errorList);
|
||||
}
|
||||
}
|
||||
|
||||
return !errorOccurred;
|
||||
}
|
||||
|
||||
// Function to import instances
|
||||
bool DBConfigManager::importInstances(const QJsonObject& config, QStringList& errorList)
|
||||
{
|
||||
InstanceTable instanceTable;
|
||||
const QJsonArray instancesConfig = config.value("instances").toArray();
|
||||
|
||||
bool errorOccurred = false;
|
||||
quint8 instanceIdx = 0;
|
||||
for (const auto& instanceItem : instancesConfig)
|
||||
{
|
||||
if (!importInstance(instanceTable, instanceItem.toObject(), instanceIdx, errorList))
|
||||
{
|
||||
errorOccurred = true;
|
||||
}
|
||||
++instanceIdx;
|
||||
}
|
||||
|
||||
return !errorOccurred;
|
||||
}
|
||||
|
||||
// Function to import a single instance
|
||||
bool DBConfigManager::importInstance(InstanceTable& instanceTable, const QJsonObject& instanceConfig, quint8 instanceIdx, QStringList& errorList)
|
||||
{
|
||||
QString instanceName = instanceConfig.value("name").toString(QString("Instance %1").arg(instanceIdx));
|
||||
bool isInstanceEnabled = instanceConfig.value("enabled").toBool(true);
|
||||
|
||||
if (instanceIdx == 0)
|
||||
{
|
||||
isInstanceEnabled = true; // The first instance must be enabled.
|
||||
}
|
||||
|
||||
if (!instanceTable.createInstance(instanceName, instanceIdx) ||
|
||||
!instanceTable.setEnable(instanceIdx, isInstanceEnabled))
|
||||
{
|
||||
logErrorAndAppend("Failed to import instance", errorList);
|
||||
return false;
|
||||
}
|
||||
|
||||
SettingsTable settingsTableInstance(instanceIdx);
|
||||
const QJsonObject instanceSettings = instanceConfig.value("settings").toObject();
|
||||
return importInstanceSettings(settingsTableInstance, instanceSettings, errorList);
|
||||
}
|
||||
|
||||
// Function to import instance settings
|
||||
bool DBConfigManager::importInstanceSettings(SettingsTable& settingsTable, const QJsonObject& instanceSettings, QStringList& errorList)
|
||||
{
|
||||
bool errorOccurred = false;
|
||||
for (QJsonObject::const_iterator it = instanceSettings.constBegin(); it != instanceSettings.constEnd(); ++it)
|
||||
{
|
||||
if (!settingsTable.createSettingsRecord(it.key(), JsonUtils::jsonValueToQString(it.value())))
|
||||
{
|
||||
errorOccurred = true;
|
||||
logErrorAndAppend("Failed to import instance setting", errorList);
|
||||
}
|
||||
}
|
||||
|
||||
return !errorOccurred;
|
||||
}
|
||||
|
||||
QJsonObject DBConfigManager::getConfiguration(const QList<quint8>& instancesFilter, const QStringList& instanceFilteredTypes, const QStringList& globalFilterTypes ) const
|
||||
{
|
||||
QSqlDatabase idb = getDB();
|
||||
|
||||
if (!startTransaction(idb))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
InstanceTable instanceTable;
|
||||
SettingsTable settingsTable;
|
||||
|
||||
QJsonObject config;
|
||||
|
||||
QJsonObject globalConfig;
|
||||
MetaTable metaTable;
|
||||
globalConfig.insert("uuid", metaTable.getUUID());
|
||||
globalConfig.insert("settings", settingsTable.getSettings(globalFilterTypes));
|
||||
config.insert("global", globalConfig);
|
||||
|
||||
QList<quint8> instances {instancesFilter};
|
||||
if (instances.isEmpty())
|
||||
{
|
||||
instances = instanceTable.getAllInstanceIDs();
|
||||
}
|
||||
|
||||
QList<quint8> sortedInstances = instances;
|
||||
std::sort(sortedInstances.begin(), sortedInstances.end());
|
||||
|
||||
QJsonArray instanceIdList;
|
||||
QJsonArray configInstanceList;
|
||||
for (const quint8 instanceIdx : sortedInstances)
|
||||
{
|
||||
QJsonObject instanceConfig;
|
||||
instanceConfig.insert("id",instanceIdx);
|
||||
instanceConfig.insert("name", instanceTable.getNamebyIndex(instanceIdx));
|
||||
instanceConfig.insert("enabled", instanceTable.isEnabled(instanceIdx));
|
||||
instanceConfig.insert("settings", settingsTable.getSettings(static_cast<quint8>(instanceIdx), instanceFilteredTypes));
|
||||
configInstanceList.append(instanceConfig);
|
||||
|
||||
instanceIdList.append(instanceIdx);
|
||||
}
|
||||
|
||||
config.insert("instanceIds", instanceIdList);
|
||||
config.insert("instances", configInstanceList);
|
||||
|
||||
if (!commiTransaction(idb))
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> DBConfigManager::migrateConfiguration()
|
||||
{
|
||||
Info(_log, "Check, if configuration database is required to be migrated");
|
||||
|
||||
DBMigrationManager migtrationManger;
|
||||
if (migtrationManger.isMigrationRequired())
|
||||
{
|
||||
QJsonObject config = getConfiguration();
|
||||
|
||||
if (migtrationManger.migrateSettings(config))
|
||||
{
|
||||
return updateConfiguration(config, true);
|
||||
}
|
||||
}
|
||||
|
||||
Info(_log, "Database migration is not required");
|
||||
return qMakePair (true, QStringList{} );
|
||||
}
|
||||
|
@ -1,38 +1,48 @@
|
||||
#include "utils/settings.h"
|
||||
#include <db/DBManager.h>
|
||||
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlError>
|
||||
#include <QSqlQuery>
|
||||
#include <QSqlRecord>
|
||||
#include <QThreadStorage>
|
||||
#include <QUuid>
|
||||
#include <QDir>
|
||||
#include <QMetaType>
|
||||
#include <QJsonObject>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <stdexcept>
|
||||
#endif
|
||||
|
||||
// not in header because of linking
|
||||
static QString _rootPath;
|
||||
static QThreadStorage<QSqlDatabase> _databasePool;
|
||||
#define NO_SQLQUERY_LOGGING
|
||||
|
||||
// Constants
|
||||
namespace {
|
||||
const char DATABASE_DIRECTORYNAME[] = "db";
|
||||
const char DATABASE_FILENAME[] = "hyperion.db";
|
||||
|
||||
} //End of constants
|
||||
|
||||
|
||||
QDir DBManager::_dataDirectory;
|
||||
QDir DBManager::_databaseDirectory;
|
||||
QFileInfo DBManager::_databaseFile;
|
||||
QThreadStorage<QSqlDatabase> DBManager::_databasePool;
|
||||
bool DBManager::_isReadOnly {false};
|
||||
|
||||
DBManager::DBManager(QObject* parent)
|
||||
: QObject(parent)
|
||||
, _log(Logger::getInstance("DB"))
|
||||
, _readonlyMode (false)
|
||||
{
|
||||
}
|
||||
|
||||
DBManager::~DBManager()
|
||||
void DBManager::initializeDatabase(const QDir& dataDirectory, bool isReadOnly)
|
||||
{
|
||||
}
|
||||
|
||||
void DBManager::setRootPath(const QString& rootPath)
|
||||
{
|
||||
_rootPath = rootPath;
|
||||
// create directory
|
||||
QDir().mkpath(_rootPath+"/db");
|
||||
_dataDirectory = dataDirectory;
|
||||
_databaseDirectory.setPath(_dataDirectory.absoluteFilePath(DATABASE_DIRECTORYNAME));
|
||||
QDir().mkpath(_databaseDirectory.absolutePath());
|
||||
_databaseFile.setFile(_databaseDirectory,DATABASE_FILENAME);
|
||||
_isReadOnly = isReadOnly;
|
||||
}
|
||||
|
||||
void DBManager::setTable(const QString& table)
|
||||
@ -43,38 +53,42 @@ void DBManager::setTable(const QString& table)
|
||||
QSqlDatabase DBManager::getDB() const
|
||||
{
|
||||
if(_databasePool.hasLocalData())
|
||||
{
|
||||
return _databasePool.localData();
|
||||
else
|
||||
}
|
||||
auto database = QSqlDatabase::addDatabase("QSQLITE", QUuid::createUuid().toString());
|
||||
|
||||
if (isReadOnly())
|
||||
{
|
||||
auto db = QSqlDatabase::addDatabase("QSQLITE", QUuid::createUuid().toString());
|
||||
_databasePool.setLocalData(db);
|
||||
db.setDatabaseName(_rootPath+"/db/"+_dbn+".db");
|
||||
if(!db.open())
|
||||
database.setConnectOptions("QSQLITE_OPEN_READONLY");
|
||||
}
|
||||
|
||||
#ifdef SQLQUERY_LOGGING
|
||||
Debug(Logger::getInstance("DB"), "Database is opened in %s mode", _isReadOnly ? "read-only" : "read/write");
|
||||
#endif
|
||||
|
||||
_databasePool.setLocalData(database);
|
||||
database.setDatabaseName(_databaseFile.absoluteFilePath());
|
||||
if(!database.open())
|
||||
{
|
||||
Error(_log, "%s", QSTRING_CSTR(db.lastError().text()));
|
||||
Error(_log, "%s", QSTRING_CSTR(database.lastError().text()));
|
||||
throw std::runtime_error("Failed to open database connection!");
|
||||
}
|
||||
return db;
|
||||
}
|
||||
|
||||
return database;
|
||||
}
|
||||
|
||||
bool DBManager::createRecord(const VectorPair& conditions, const QVariantMap& columns) const
|
||||
{
|
||||
if ( _readonlyMode )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(recordExists(conditions))
|
||||
{
|
||||
// if there is no column data, return
|
||||
if(columns.isEmpty())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if(!updateRecord(conditions, columns))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return updateRecord(conditions, columns);
|
||||
}
|
||||
|
||||
QSqlDatabase idb = getDB();
|
||||
@ -84,14 +98,15 @@ bool DBManager::createRecord(const VectorPair& conditions, const QVariantMap& co
|
||||
QVariantList cValues;
|
||||
QStringList prep;
|
||||
QStringList placeh;
|
||||
|
||||
// prep merge columns & condition
|
||||
QVariantMap::const_iterator i = columns.constBegin();
|
||||
while (i != columns.constEnd()) {
|
||||
prep.append(i.key());
|
||||
cValues += i.value();
|
||||
QVariantMap::const_iterator columnIter = columns.constBegin();
|
||||
while (columnIter != columns.constEnd()) {
|
||||
prep.append(columnIter.key());
|
||||
cValues += columnIter.value();
|
||||
placeh.append("?");
|
||||
|
||||
++i;
|
||||
++columnIter;
|
||||
}
|
||||
for(const auto& pair : conditions)
|
||||
{
|
||||
@ -101,21 +116,19 @@ bool DBManager::createRecord(const VectorPair& conditions, const QVariantMap& co
|
||||
cValues << pair.second;
|
||||
placeh.append("?");
|
||||
}
|
||||
query.prepare(QString("INSERT INTO %1 ( %2 ) VALUES ( %3 )").arg(_table,prep.join(", ")).arg(placeh.join(", ")));
|
||||
query.prepare(QString("INSERT INTO %1 ( %2 ) VALUES ( %3 )").arg(_table,prep.join(", "), placeh.join(", ")));
|
||||
// add column & condition values
|
||||
doAddBindValue(query, cValues);
|
||||
if(!query.exec())
|
||||
{
|
||||
Error(_log, "Failed to create record: '%s' in table: '%s' Error: %s", QSTRING_CSTR(prep.join(", ")), QSTRING_CSTR(_table), QSTRING_CSTR(idb.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
addBindValues(query, cValues);
|
||||
|
||||
return executeQuery(query);
|
||||
}
|
||||
|
||||
bool DBManager::recordExists(const VectorPair& conditions) const
|
||||
{
|
||||
if(conditions.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlDatabase idb = getDB();
|
||||
QSqlQuery query(idb);
|
||||
@ -131,29 +144,62 @@ bool DBManager::recordExists(const VectorPair& conditions) const
|
||||
bindVal << pair.second;
|
||||
}
|
||||
query.prepare(QString("SELECT * FROM %1 %2").arg(_table,prepCond.join(" ")));
|
||||
doAddBindValue(query, bindVal);
|
||||
if(!query.exec())
|
||||
addBindValues(query, bindVal);
|
||||
|
||||
if (!executeQuery(query))
|
||||
{
|
||||
Error(_log, "Failed recordExists(): '%s' in table: '%s' Error: %s", QSTRING_CSTR(prepCond.join(" ")), QSTRING_CSTR(_table), QSTRING_CSTR(idb.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
|
||||
int entry = 0;
|
||||
while (query.next()) {
|
||||
while (query.next())
|
||||
{
|
||||
entry++;
|
||||
}
|
||||
|
||||
if(entry)
|
||||
return true;
|
||||
return entry > 0;
|
||||
}
|
||||
|
||||
bool DBManager::recordsNotExisting(const QVariantList& testValues,const QString& column, QStringList& nonExistingRecs, const QString& condition ) const
|
||||
{
|
||||
QSqlDatabase idb = getDB();
|
||||
|
||||
QSqlQuery query(idb);
|
||||
query.setForwardOnly(true);
|
||||
|
||||
// prep conditions
|
||||
QString prepCond;
|
||||
if(!condition.isEmpty())
|
||||
{
|
||||
prepCond = QString("WHERE %1").arg(condition);
|
||||
}
|
||||
|
||||
QVector<QString> valueItem(testValues.size(), "(?)");
|
||||
QString values = QStringList::fromVector(valueItem).join(",");
|
||||
query.prepare(
|
||||
QString("SELECT v.[column1] [%1] FROM ( VALUES %2 ) [v] WHERE %1 NOT IN ( SELECT %1 from settings %3 )")
|
||||
.arg(column,values, prepCond)
|
||||
);
|
||||
|
||||
addBindValues(query, testValues);
|
||||
|
||||
if (!executeQuery(query))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
while (query.next()) {
|
||||
nonExistingRecs << query.value(0).toString();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBManager::updateRecord(const VectorPair& conditions, const QVariantMap& columns) const
|
||||
{
|
||||
if ( _readonlyMode )
|
||||
if (isReadOnly())
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
QSqlDatabase idb = getDB();
|
||||
@ -164,19 +210,20 @@ bool DBManager::updateRecord(const VectorPair& conditions, const QVariantMap& co
|
||||
QStringList prep;
|
||||
|
||||
// prepare columns valus
|
||||
QVariantMap::const_iterator i = columns.constBegin();
|
||||
while (i != columns.constEnd()) {
|
||||
prep += i.key()+"=?";
|
||||
values += i.value();
|
||||
QVariantMap::const_iterator columnIter = columns.constBegin();
|
||||
while (columnIter != columns.constEnd()) {
|
||||
prep += columnIter.key()+"= ?";
|
||||
values += columnIter.value();
|
||||
|
||||
++i;
|
||||
++columnIter;
|
||||
}
|
||||
|
||||
// prepare condition values
|
||||
QStringList prepCond;
|
||||
QVariantList prepBindVal;
|
||||
if(!conditions.isEmpty())
|
||||
if(!conditions.isEmpty()) {
|
||||
prepCond << "WHERE";
|
||||
}
|
||||
|
||||
for(const auto& pair : conditions)
|
||||
{
|
||||
@ -184,68 +231,54 @@ bool DBManager::updateRecord(const VectorPair& conditions, const QVariantMap& co
|
||||
prepBindVal << pair.second;
|
||||
}
|
||||
|
||||
query.prepare(QString("UPDATE %1 SET %2 %3").arg(_table,prep.join(", ")).arg(prepCond.join(" ")));
|
||||
query.prepare(QString("UPDATE %1 SET %2 %3").arg(_table,prep.join(", "), prepCond.join(" ")));
|
||||
// add column values
|
||||
doAddBindValue(query, values);
|
||||
addBindValues(query, values);
|
||||
// add condition values
|
||||
doAddBindValue(query, prepBindVal);
|
||||
if(!query.exec())
|
||||
{
|
||||
Error(_log, "Failed to update record: '%s' in table: '%s' Error: %s", QSTRING_CSTR(prepCond.join(" ")), QSTRING_CSTR(_table), QSTRING_CSTR(idb.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
addBindValues(query, prepBindVal);
|
||||
|
||||
return executeQuery(query);
|
||||
}
|
||||
|
||||
bool DBManager::getRecord(const VectorPair& conditions, QVariantMap& results, const QStringList& tColumns, const QStringList& tOrder) const
|
||||
{
|
||||
QSqlDatabase idb = getDB();
|
||||
QSqlQuery query(idb);
|
||||
query.setForwardOnly(true);
|
||||
|
||||
QString sColumns("*");
|
||||
if(!tColumns.isEmpty())
|
||||
sColumns = tColumns.join(", ");
|
||||
|
||||
QString sOrder("");
|
||||
if(!tOrder.isEmpty())
|
||||
{
|
||||
sOrder = " ORDER BY ";
|
||||
sOrder.append(tOrder.join(", "));
|
||||
QVector<QVariantMap> resultVector{};
|
||||
bool success = getRecords(conditions, resultVector, tColumns, tOrder);
|
||||
if (success && !resultVector.isEmpty()) {
|
||||
results = resultVector.first();
|
||||
}
|
||||
// prep conditions
|
||||
QStringList prepCond;
|
||||
QVariantList bindVal;
|
||||
if(!conditions.isEmpty())
|
||||
prepCond << " WHERE";
|
||||
|
||||
for(const auto& pair : conditions)
|
||||
{
|
||||
prepCond << pair.first+"=?";
|
||||
bindVal << pair.second;
|
||||
}
|
||||
query.prepare(QString("SELECT %1 FROM %2%3%4").arg(sColumns,_table).arg(prepCond.join(" ")).arg(sOrder));
|
||||
doAddBindValue(query, bindVal);
|
||||
|
||||
if(!query.exec())
|
||||
{
|
||||
Error(_log, "Failed to get record: '%s' in table: '%s' Error: %s", QSTRING_CSTR(prepCond.join(" ")), QSTRING_CSTR(_table), QSTRING_CSTR(idb.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
|
||||
// go to first row
|
||||
query.next();
|
||||
|
||||
QSqlRecord rec = query.record();
|
||||
for(int i = 0; i<rec.count(); i++)
|
||||
{
|
||||
results[rec.fieldName(i)] = rec.value(i);
|
||||
}
|
||||
|
||||
return true;
|
||||
return success;
|
||||
}
|
||||
|
||||
bool DBManager::getRecords(QVector<QVariantMap>& results, const QStringList& tColumns, const QStringList& tOrder) const
|
||||
{
|
||||
return getRecords({}, results, tColumns, tOrder);
|
||||
}
|
||||
|
||||
bool DBManager::getRecords(const VectorPair& conditions, QVector<QVariantMap>& results, const QStringList& tColumns, const QStringList& tOrder) const
|
||||
{
|
||||
// prep conditions
|
||||
QStringList conditionList;
|
||||
QVariantList bindValues;
|
||||
|
||||
for(const auto& pair : conditions)
|
||||
{
|
||||
conditionList << pair.first;
|
||||
if (pair.second.isNull())
|
||||
{
|
||||
conditionList << "IS NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
conditionList << "= ?";
|
||||
bindValues << pair.second;
|
||||
}
|
||||
}
|
||||
|
||||
return getRecords(conditionList.join((" ")), bindValues, results, tColumns, tOrder);
|
||||
}
|
||||
|
||||
bool DBManager::getRecords(const QString& condition, const QVariantList& bindValues, QVector<QVariantMap>& results, const QStringList& tColumns, const QStringList& tOrder) const
|
||||
{
|
||||
QSqlDatabase idb = getDB();
|
||||
QSqlQuery query(idb);
|
||||
@ -253,7 +286,9 @@ bool DBManager::getRecords(QVector<QVariantMap>& results, const QStringList& tCo
|
||||
|
||||
QString sColumns("*");
|
||||
if(!tColumns.isEmpty())
|
||||
{
|
||||
sColumns = tColumns.join(", ");
|
||||
}
|
||||
|
||||
QString sOrder("");
|
||||
if(!tOrder.isEmpty())
|
||||
@ -262,11 +297,17 @@ bool DBManager::getRecords(QVector<QVariantMap>& results, const QStringList& tCo
|
||||
sOrder.append(tOrder.join(", "));
|
||||
}
|
||||
|
||||
query.prepare(QString("SELECT %1 FROM %2%3").arg(sColumns,_table,sOrder));
|
||||
|
||||
if(!query.exec())
|
||||
// prep conditions
|
||||
QString prepCond;
|
||||
if(!condition.isEmpty())
|
||||
{
|
||||
prepCond = QString("WHERE %1").arg(condition);
|
||||
}
|
||||
|
||||
query.prepare(QString("SELECT %1 FROM %2 %3 %4").arg(sColumns,_table, prepCond, sOrder));
|
||||
addBindValues(query, bindValues);
|
||||
if (!executeQuery(query))
|
||||
{
|
||||
Error(_log, "Failed to get records: '%s' in table: '%s' Error: %s", QSTRING_CSTR(sColumns), QSTRING_CSTR(_table), QSTRING_CSTR(idb.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -285,12 +326,11 @@ bool DBManager::getRecords(QVector<QVariantMap>& results, const QStringList& tCo
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool DBManager::deleteRecord(const VectorPair& conditions) const
|
||||
{
|
||||
if ( _readonlyMode )
|
||||
if (_isReadOnly)
|
||||
{
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if(conditions.isEmpty())
|
||||
@ -315,24 +355,15 @@ bool DBManager::deleteRecord(const VectorPair& conditions) const
|
||||
}
|
||||
|
||||
query.prepare(QString("DELETE FROM %1 %2").arg(_table,prepCond.join(" ")));
|
||||
doAddBindValue(query, bindValues);
|
||||
if(!query.exec())
|
||||
{
|
||||
Error(_log, "Failed to delete record: '%s' in table: '%s' Error: %s", QSTRING_CSTR(prepCond.join(" ")), QSTRING_CSTR(_table), QSTRING_CSTR(idb.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
addBindValues(query, bindValues);
|
||||
|
||||
return executeQuery(query);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DBManager::createTable(QStringList& columns) const
|
||||
{
|
||||
if ( _readonlyMode )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(columns.isEmpty())
|
||||
{
|
||||
Error(_log,"Empty tables aren't supported!");
|
||||
@ -347,9 +378,9 @@ bool DBManager::createTable(QStringList& columns) const
|
||||
// empty tables aren't supported by sqlite, add one column
|
||||
QString tcolumn = columns.takeFirst();
|
||||
// default CURRENT_TIMESTAMP is not supported by ALTER TABLE
|
||||
if(!query.exec(QString("CREATE TABLE %1 ( %2 )").arg(_table,tcolumn)))
|
||||
query.prepare(QString("CREATE TABLE %1 ( %2 )").arg(_table,tcolumn));
|
||||
if (!executeQuery(query))
|
||||
{
|
||||
Error(_log, "Failed to create table: '%s' Error: %s", QSTRING_CSTR(_table), QSTRING_CSTR(idb.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -358,8 +389,8 @@ bool DBManager::createTable(QStringList& columns) const
|
||||
int err = 0;
|
||||
for(const auto& column : columns)
|
||||
{
|
||||
QStringList id = column.split(' ');
|
||||
if(rec.indexOf(id.at(0)) == -1)
|
||||
QStringList columName = column.split(' ');
|
||||
if(rec.indexOf(columName.at(0)) == -1)
|
||||
{
|
||||
if(!createColumn(column))
|
||||
{
|
||||
@ -367,79 +398,168 @@ bool DBManager::createTable(QStringList& columns) const
|
||||
}
|
||||
}
|
||||
}
|
||||
if(err)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return err == 0;
|
||||
}
|
||||
|
||||
bool DBManager::createColumn(const QString& column) const
|
||||
{
|
||||
if ( _readonlyMode )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QSqlDatabase idb = getDB();
|
||||
QSqlQuery query(idb);
|
||||
if(!query.exec(QString("ALTER TABLE %1 ADD COLUMN %2").arg(_table,column)))
|
||||
{
|
||||
Error(_log, "Failed to create column: '%s' in table: '%s' Error: %s", QSTRING_CSTR(column), QSTRING_CSTR(_table), QSTRING_CSTR(idb.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
query.prepare(QString("ALTER TABLE %1 ADD COLUMN %2").arg(_table,column));
|
||||
return executeQuery(query);
|
||||
}
|
||||
|
||||
bool DBManager::tableExists(const QString& table) const
|
||||
{
|
||||
QSqlDatabase idb = getDB();
|
||||
QStringList tables = idb.tables();
|
||||
if(tables.contains(table))
|
||||
return true;
|
||||
return false;
|
||||
return tables.contains(table);
|
||||
}
|
||||
|
||||
bool DBManager::deleteTable(const QString& table) const
|
||||
{
|
||||
if ( _readonlyMode )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(tableExists(table))
|
||||
{
|
||||
QSqlDatabase idb = getDB();
|
||||
QSqlQuery query(idb);
|
||||
if(!query.exec(QString("DROP TABLE %1").arg(table)))
|
||||
{
|
||||
Error(_log, "Failed to delete table: '%s' Error: %s", QSTRING_CSTR(table), QSTRING_CSTR(idb.lastError().text()));
|
||||
return false;
|
||||
}
|
||||
|
||||
query.prepare(QString("DROP TABLE %1").arg(table));
|
||||
return executeQuery(query);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DBManager::doAddBindValue(QSqlQuery& query, const QVariantList& variants) const
|
||||
void DBManager::addBindValues(QSqlQuery& query, const QVariantList& bindValues) const
|
||||
{
|
||||
for(const auto& variant : variants)
|
||||
if (!bindValues.isEmpty())
|
||||
{
|
||||
auto t = variant.userType();
|
||||
switch(t)
|
||||
for(const auto& value : bindValues)
|
||||
{
|
||||
case QMetaType::UInt:
|
||||
case QMetaType::Int:
|
||||
case QMetaType::Bool:
|
||||
query.addBindValue(variant.toInt());
|
||||
break;
|
||||
case QMetaType::Double:
|
||||
query.addBindValue(variant.toFloat());
|
||||
break;
|
||||
case QMetaType::QByteArray:
|
||||
query.addBindValue(variant.toByteArray());
|
||||
break;
|
||||
default:
|
||||
query.addBindValue(variant.toString());
|
||||
break;
|
||||
query.addBindValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString DBManager::constructExecutedQuery(const QSqlQuery& query) const
|
||||
{
|
||||
QString executedQuery = query.executedQuery();
|
||||
|
||||
// Check if the query uses positional placeholders
|
||||
if (executedQuery.contains('?')) {
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
|
||||
QVariantList boundValues = query.boundValues(); // Get bound values as a list
|
||||
#else
|
||||
QVariantMap boundValues = query.boundValues(); // Get bound values as a list
|
||||
#endif
|
||||
// Iterate through the bound values and replace placeholders
|
||||
for (const QVariant &value : boundValues) {
|
||||
// Replace the first occurrence of '?' with the actual value
|
||||
QString valueStr;
|
||||
if (value.canConvert<QString>())
|
||||
{
|
||||
valueStr = value.toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
valueStr = "Unkown";
|
||||
}
|
||||
executedQuery.replace(executedQuery.indexOf('?'), 1, valueStr);
|
||||
}
|
||||
}
|
||||
return executedQuery;
|
||||
}
|
||||
|
||||
bool DBManager::executeQuery(QSqlQuery& query) const
|
||||
{
|
||||
if( !query.exec())
|
||||
{
|
||||
QString finalQuery = constructExecutedQuery(query);
|
||||
QString errorText = query.lastError().text();
|
||||
|
||||
Debug(_log, "Database Error: '%s', SqlQuery: '%s'", QSTRING_CSTR(errorText), QSTRING_CSTR(finalQuery));
|
||||
Error(_log, "Database Error: '%s'", QSTRING_CSTR(errorText));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef SQLQUERY_LOGGING
|
||||
QString finalQuery = constructExecutedQuery(query);
|
||||
Debug(_log, "SqlQuery executed: '%s'", QSTRING_CSTR(finalQuery));
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBManager::startTransaction(QSqlDatabase& idb) const
|
||||
{
|
||||
if (!idb.transaction())
|
||||
{
|
||||
QString errorText = QString("Could not create a database transaction. Error: %1").arg(idb.lastError().text());
|
||||
Error(_log, "'%s'", QSTRING_CSTR(errorText));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBManager::startTransaction(QSqlDatabase& idb, QStringList& errorList)
|
||||
{
|
||||
if (!idb.transaction())
|
||||
{
|
||||
QString errorText = QString("Could not create a database transaction. Error: %1").arg(idb.lastError().text());
|
||||
logErrorAndAppend(errorText, errorList);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBManager::commiTransaction(QSqlDatabase& idb) const
|
||||
{
|
||||
if (!idb.commit())
|
||||
{
|
||||
QString errorText = QString("Could not finalize the database changes. Error: %1").arg(idb.lastError().text());
|
||||
Error(_log, "'%s'", QSTRING_CSTR(errorText));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBManager::commiTransaction(QSqlDatabase& idb, QStringList& errorList)
|
||||
{
|
||||
if (!idb.commit())
|
||||
{
|
||||
QString errorText = QString("Could not finalize the database changes. Error: %1").arg(idb.lastError().text());
|
||||
logErrorAndAppend(errorText, errorList);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBManager::rollbackTransaction(QSqlDatabase& idb) const
|
||||
{
|
||||
if (!idb.rollback())
|
||||
{
|
||||
QString errorText = QString("Could not rollback the database transaction. Error: %1").arg(idb.lastError().text());
|
||||
Error(_log, "'%s'", QSTRING_CSTR(errorText));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DBManager::rollbackTransaction(QSqlDatabase& idb, QStringList& errorList)
|
||||
{
|
||||
if (!idb.rollback())
|
||||
{
|
||||
QString errorText = QString("Could not rollback the database transaction. Error: %1").arg(idb.lastError().text());
|
||||
logErrorAndAppend(errorText, errorList);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Function to log error and append it to the error list
|
||||
void DBManager::logErrorAndAppend(const QString& errorText, QStringList& errorList)
|
||||
{
|
||||
Error(_log, "'%s'", QSTRING_CSTR(errorText));
|
||||
errorList.append(errorText);
|
||||
}
|
||||
|
767
libsrc/db/DBMigrationManager.cpp
Normal file
767
libsrc/db/DBMigrationManager.cpp
Normal file
@ -0,0 +1,767 @@
|
||||
#include <db/DBMigrationManager.h>
|
||||
|
||||
#include "db/SettingsTable.h"
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/QStringUtils.h>
|
||||
|
||||
#include <HyperionConfig.h>
|
||||
|
||||
#include <QJsonObject>
|
||||
|
||||
DBMigrationManager::DBMigrationManager(QObject *parent)
|
||||
: DBManager{parent}
|
||||
{
|
||||
}
|
||||
|
||||
bool DBMigrationManager::isMigrationRequired()
|
||||
{
|
||||
bool isNewRelease = false;
|
||||
|
||||
SettingsTable settingsTableGlobal;
|
||||
|
||||
if (settingsTableGlobal.resolveConfigVersion())
|
||||
{
|
||||
semver::version BUILD_VERSION(HYPERION_VERSION);
|
||||
|
||||
if (!BUILD_VERSION.isValid())
|
||||
{
|
||||
Error(_log, "Current Hyperion version [%s] is invalid. Exiting...", BUILD_VERSION.getVersion().c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
const semver::version& currentVersion = settingsTableGlobal.getConfigVersion();
|
||||
if (currentVersion > BUILD_VERSION)
|
||||
{
|
||||
Error(_log, "Database version [%s] is greater than current Hyperion version [%s]. Exiting...", currentVersion.getVersion().c_str(), BUILD_VERSION.getVersion().c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (currentVersion < BUILD_VERSION)
|
||||
{
|
||||
isNewRelease = true;
|
||||
}
|
||||
}
|
||||
return isNewRelease;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::migrateSettings(QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
semver::version BUILD_VERSION(HYPERION_VERSION);
|
||||
|
||||
SettingsTable settingsTableGlobal;
|
||||
QJsonObject generalConfig = config.value("global").toObject().value("settings").toObject().value("general").toObject();
|
||||
|
||||
if (settingsTableGlobal.resolveConfigVersion(generalConfig))
|
||||
{
|
||||
semver::version currentVersion = settingsTableGlobal.getConfigVersion();
|
||||
|
||||
if (currentVersion < BUILD_VERSION)
|
||||
{
|
||||
Info(_log, "Migration from current version [%s] to new version [%s] started", currentVersion.getVersion().c_str(), BUILD_VERSION.getVersion().c_str());
|
||||
|
||||
// Extract, modify, and reinsert the global settings
|
||||
QJsonObject globalSettings = config.value("global").toObject().value("settings").toObject();
|
||||
upgradeGlobalSettings(currentVersion, globalSettings);
|
||||
|
||||
QJsonObject globalConfig = config.value("global").toObject();
|
||||
globalConfig.insert("settings", globalSettings);
|
||||
config.insert("global", globalConfig);
|
||||
|
||||
// Update each instance directly within the config
|
||||
QJsonArray instancesConfig = config.value("instances").toArray();
|
||||
for (int i = 0; i < instancesConfig.size(); ++i)
|
||||
{
|
||||
QJsonObject instanceConfig = instancesConfig[i].toObject();
|
||||
QJsonObject instanceSettings = instanceConfig.value("settings").toObject();
|
||||
|
||||
upgradeInstanceSettings(currentVersion, static_cast<quint8>(i), instanceSettings);
|
||||
|
||||
// Reinsert the modified instance settings back into the instanceConfig
|
||||
instanceConfig.insert("settings", instanceSettings);
|
||||
instancesConfig.replace(i, instanceConfig);
|
||||
}
|
||||
config.insert("instances", instancesConfig);
|
||||
|
||||
Info(_log, "Migration from current version [%s] to new version [%s] finished", currentVersion.getVersion().c_str(), BUILD_VERSION.getVersion().c_str());
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::upgradeGlobalSettings(const semver::version& currentVersion, QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
|
||||
semver::version migratedVersion = currentVersion;
|
||||
|
||||
//Migration step for versions < alpha 9
|
||||
upgradeGlobalSettings_alpha_9(migratedVersion, config);
|
||||
//Migration step for versions < 2.0.12
|
||||
upgradeGlobalSettings_2_0_12(migratedVersion, config);
|
||||
//Migration step for versions < 2.0.16
|
||||
upgradeGlobalSettings_2_0_16(migratedVersion, config);
|
||||
//Migration step for versions < 2.0.17
|
||||
upgradeGlobalSettings_2_1_0(migratedVersion, config);
|
||||
|
||||
// Set the daqtabase version to the current build version
|
||||
QJsonObject generalConfig = config["general"].toObject();
|
||||
// Update the configVersion if necessary
|
||||
if (generalConfig["configVersion"].toString() != HYPERION_VERSION) {
|
||||
generalConfig["configVersion"] = HYPERION_VERSION;
|
||||
migrated = true;
|
||||
}
|
||||
// Re-insert the modified "general" object back into the config
|
||||
config["general"] = generalConfig;
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::upgradeInstanceSettings(const semver::version& currentVersion, quint8 instance, QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
semver::version migratedVersion = currentVersion;
|
||||
|
||||
//Migration step for versions < alpha 9
|
||||
upgradeInstanceSettings_alpha_9(migratedVersion, instance, config);
|
||||
//Migration step for versions < 2.0.12
|
||||
upgradeInstanceSettings_2_0_12(migratedVersion, instance, config);
|
||||
//Migration step for versions < 2.0.13
|
||||
upgradeInstanceSettings_2_0_13(migratedVersion, instance, config);
|
||||
//Migration step for versions < 2.0.16
|
||||
upgradeInstanceSettings_2_0_16(migratedVersion, instance, config);
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::upgradeGlobalSettings_alpha_9(semver::version& currentVersion, QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
const semver::version targetVersion{ "2.0.0-alpha.9" };
|
||||
|
||||
if (currentVersion < targetVersion)
|
||||
{
|
||||
Info(_log, "Global settings: Migrate from version [%s] to version [%s] or later", currentVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
currentVersion = targetVersion;
|
||||
|
||||
if (config.contains("grabberV4L2"))
|
||||
{
|
||||
QJsonObject newGrabberV4L2Config = config["grabberV4L2"].toObject();
|
||||
|
||||
if (newGrabberV4L2Config.contains("encoding_format"))
|
||||
{
|
||||
newGrabberV4L2Config.remove("encoding_format");
|
||||
newGrabberV4L2Config["grabberV4L2"] = newGrabberV4L2Config;
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
//Add new element enable
|
||||
if (!newGrabberV4L2Config.contains("enable"))
|
||||
{
|
||||
newGrabberV4L2Config["enable"] = false;
|
||||
migrated = true;
|
||||
}
|
||||
config["grabberV4L2"] = newGrabberV4L2Config;
|
||||
Debug(_log, "GrabberV4L2 records migrated");
|
||||
}
|
||||
|
||||
if (config.contains("grabberAudio"))
|
||||
{
|
||||
QJsonObject newGrabberAudioConfig = config["grabberAudio"].toObject();
|
||||
|
||||
//Add new element enable
|
||||
if (!newGrabberAudioConfig.contains("enable"))
|
||||
{
|
||||
newGrabberAudioConfig["enable"] = false;
|
||||
migrated = true;
|
||||
}
|
||||
config["grabberAudio"] = newGrabberAudioConfig;
|
||||
Debug(_log, "GrabberAudio records migrated");
|
||||
}
|
||||
|
||||
if (config.contains("framegrabber"))
|
||||
{
|
||||
QJsonObject newFramegrabberConfig = config["framegrabber"].toObject();
|
||||
|
||||
//Align element namings with grabberV4L2
|
||||
//Rename element type -> device
|
||||
if (newFramegrabberConfig.contains("type"))
|
||||
{
|
||||
newFramegrabberConfig["device"] = newFramegrabberConfig["type"].toString();
|
||||
newFramegrabberConfig.remove("type");
|
||||
migrated = true;
|
||||
}
|
||||
//Rename element frequency_Hz -> fps
|
||||
if (newFramegrabberConfig.contains("frequency_Hz"))
|
||||
{
|
||||
newFramegrabberConfig["fps"] = newFramegrabberConfig["frequency_Hz"].toInt(25);
|
||||
newFramegrabberConfig.remove("frequency_Hz");
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
//Rename element display -> input
|
||||
if (newFramegrabberConfig.contains("display"))
|
||||
{
|
||||
newFramegrabberConfig["input"] = newFramegrabberConfig["display"];
|
||||
newFramegrabberConfig.remove("display");
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
//Add new element enable
|
||||
if (!newFramegrabberConfig.contains("enable"))
|
||||
{
|
||||
newFramegrabberConfig["enable"] = false;
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
config["framegrabber"] = newFramegrabberConfig;
|
||||
Debug(_log, "Framegrabber records migrated");
|
||||
}
|
||||
}
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::upgradeGlobalSettings_2_0_12(semver::version& currentVersion, QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
const semver::version targetVersion{ "2.0.12" };
|
||||
|
||||
if (currentVersion < targetVersion)
|
||||
{
|
||||
Info(_log, "Global settings: Migrate from version [%s] to version [%s] or later", currentVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
currentVersion = targetVersion;
|
||||
|
||||
// Have Hostname/IP-address separate from port for Forwarder
|
||||
if (config.contains("forwarder"))
|
||||
{
|
||||
QJsonObject newForwarderConfig = config["forwarder"].toObject();
|
||||
|
||||
QJsonArray json;
|
||||
if (newForwarderConfig.contains("json"))
|
||||
{
|
||||
const QJsonArray oldJson = newForwarderConfig["json"].toArray();
|
||||
QJsonObject newJsonConfig;
|
||||
|
||||
for (const QJsonValue& value : oldJson)
|
||||
{
|
||||
if (value.isString())
|
||||
{
|
||||
QString oldHost = value.toString();
|
||||
// Resolve hostname and port
|
||||
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
QString host = addressparts[0];
|
||||
|
||||
if (host != "127.0.0.1")
|
||||
{
|
||||
newJsonConfig["host"] = host;
|
||||
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
newJsonConfig["port"] = addressparts[1].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
newJsonConfig["port"] = 19444;
|
||||
}
|
||||
newJsonConfig["name"] = host;
|
||||
|
||||
json.append(newJsonConfig);
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!json.isEmpty())
|
||||
{
|
||||
newForwarderConfig["jsonapi"] = json;
|
||||
}
|
||||
newForwarderConfig.remove("json");
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
QJsonArray flatbuffer;
|
||||
if (newForwarderConfig.contains("flat"))
|
||||
{
|
||||
const QJsonArray oldFlatbuffer = newForwarderConfig["flat"].toArray();
|
||||
QJsonObject newFlattbufferConfig;
|
||||
|
||||
for (const QJsonValue& value : oldFlatbuffer)
|
||||
{
|
||||
if (value.isString())
|
||||
{
|
||||
QString oldHost = value.toString();
|
||||
// Resolve hostname and port
|
||||
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
QString host = addressparts[0];
|
||||
|
||||
if (host != "127.0.0.1")
|
||||
{
|
||||
newFlattbufferConfig["host"] = host;
|
||||
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
newFlattbufferConfig["port"] = addressparts[1].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
newFlattbufferConfig["port"] = 19400;
|
||||
}
|
||||
newFlattbufferConfig["name"] = host;
|
||||
|
||||
flatbuffer.append(newFlattbufferConfig);
|
||||
}
|
||||
}
|
||||
|
||||
if (!flatbuffer.isEmpty())
|
||||
{
|
||||
newForwarderConfig["flatbuffer"] = flatbuffer;
|
||||
}
|
||||
newForwarderConfig.remove("flat");
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (json.isEmpty() && flatbuffer.isEmpty())
|
||||
{
|
||||
newForwarderConfig["enable"] = false;
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["forwarder"] = newForwarderConfig;
|
||||
Debug(_log, "Forwarder records migrated");
|
||||
currentVersion = targetVersion;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::upgradeGlobalSettings_2_0_16(semver::version& currentVersion, QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
const semver::version targetVersion{ "2.0.16" };
|
||||
|
||||
if (currentVersion < targetVersion)
|
||||
{
|
||||
Info(_log, "Global settings: Migrate from version [%s] to version [%s] or later", currentVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
currentVersion = targetVersion;
|
||||
|
||||
if (config.contains("cecEvents"))
|
||||
{
|
||||
bool isCECEnabled {false};
|
||||
if (config.contains("grabberV4L2"))
|
||||
{
|
||||
QJsonObject newGrabberV4L2Config = config["grabberV4L2"].toObject();
|
||||
if (newGrabberV4L2Config.contains("cecDetection"))
|
||||
{
|
||||
isCECEnabled = newGrabberV4L2Config.value("cecDetection").toBool(false);
|
||||
newGrabberV4L2Config.remove("cecDetection");
|
||||
config["grabberV4L2"] = newGrabberV4L2Config;
|
||||
|
||||
QJsonObject newGCecEventsConfig = config["cecEvents"].toObject();
|
||||
newGCecEventsConfig["enable"] = isCECEnabled;
|
||||
if (!newGCecEventsConfig.contains("actions"))
|
||||
{
|
||||
QJsonObject action1
|
||||
{
|
||||
{"action", "Suspend"},
|
||||
{"event", "standby"}
|
||||
};
|
||||
QJsonObject action2
|
||||
{
|
||||
{"action", "Resume"},
|
||||
{"event", "set stream path"}
|
||||
};
|
||||
|
||||
QJsonArray actions { action1, action2 };
|
||||
newGCecEventsConfig.insert("actions",actions);
|
||||
}
|
||||
config["cecEvents"] = newGCecEventsConfig;
|
||||
|
||||
migrated = true;
|
||||
Debug(_log, "CEC configuration records migrated");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::upgradeGlobalSettings_2_1_0(semver::version& currentVersion, QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
const semver::version targetVersion{ "2.0.17-beta.2" };
|
||||
|
||||
if (currentVersion < targetVersion)
|
||||
{
|
||||
Info(_log, "Global settings: Migrate from version [%s] to version [%s] or later", currentVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
currentVersion = targetVersion;
|
||||
|
||||
if (config.contains("general"))
|
||||
{
|
||||
QJsonObject newGeneralConfig = config["general"].toObject();
|
||||
newGeneralConfig.remove("previousVersion");
|
||||
config.insert("general", newGeneralConfig);
|
||||
|
||||
Debug(_log, "General settings migrated");
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
if (config.contains("network"))
|
||||
{
|
||||
QJsonObject newNetworkConfig = config["network"].toObject();
|
||||
newNetworkConfig.remove("apiAuth");
|
||||
newNetworkConfig.remove("localAdminAuth");
|
||||
config.insert("network", newNetworkConfig);
|
||||
|
||||
Debug(_log, "Network settings migrated");
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//Remove wrong instance 255 configuration records, created by the global instance #255
|
||||
SettingsTable globalSettingsTable(255);
|
||||
globalSettingsTable.deleteInstance();
|
||||
migrated = true;
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::upgradeInstanceSettings_alpha_9(semver::version& currentVersion, quint8 instance, QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
const semver::version targetVersion{ "2.0.0-alpha.9" };
|
||||
|
||||
if (currentVersion < targetVersion)
|
||||
{
|
||||
Info(_log, "Settings instance [%u]: Migrate from version [%s] to version [%s] or later", instance, currentVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
currentVersion = targetVersion;
|
||||
|
||||
// LED LAYOUT UPGRADE
|
||||
// from { hscan: { minimum: 0.2, maximum: 0.3 }, vscan: { minimum: 0.2, maximum: 0.3 } }
|
||||
// from { h: { min: 0.2, max: 0.3 }, v: { min: 0.2, max: 0.3 } }
|
||||
// to { hmin: 0.2, hmax: 0.3, vmin: 0.2, vmax: 0.3}
|
||||
if (config.contains("leds"))
|
||||
{
|
||||
const QJsonArray ledarr = config["leds"].toArray();
|
||||
const QJsonObject firstLed = ledarr[0].toObject();
|
||||
|
||||
if (firstLed.contains("hscan") || firstLed.contains("h"))
|
||||
{
|
||||
const bool whscan = firstLed.contains("hscan");
|
||||
QJsonArray newLedarr;
|
||||
|
||||
for (const auto& entry : ledarr)
|
||||
{
|
||||
const QJsonObject led = entry.toObject();
|
||||
QJsonObject hscan;
|
||||
QJsonObject vscan;
|
||||
QJsonValue hmin;
|
||||
QJsonValue hmax;
|
||||
QJsonValue vmin;
|
||||
QJsonValue vmax;
|
||||
QJsonObject nL;
|
||||
|
||||
if (whscan)
|
||||
{
|
||||
hscan = led["hscan"].toObject();
|
||||
vscan = led["vscan"].toObject();
|
||||
hmin = hscan["minimum"];
|
||||
hmax = hscan["maximum"];
|
||||
vmin = vscan["minimum"];
|
||||
vmax = vscan["maximum"];
|
||||
}
|
||||
else
|
||||
{
|
||||
hscan = led["h"].toObject();
|
||||
vscan = led["v"].toObject();
|
||||
hmin = hscan["min"];
|
||||
hmax = hscan["max"];
|
||||
vmin = vscan["min"];
|
||||
vmax = vscan["max"];
|
||||
}
|
||||
// append to led object
|
||||
nL["hmin"] = hmin;
|
||||
nL["hmax"] = hmax;
|
||||
nL["vmin"] = vmin;
|
||||
nL["vmax"] = vmax;
|
||||
newLedarr.append(nL);
|
||||
}
|
||||
// replace
|
||||
config["leds"] = newLedarr;
|
||||
migrated = true;
|
||||
Info(_log, "Instance [%u]: LED Layout migrated", instance);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.contains("ledConfig"))
|
||||
{
|
||||
QJsonObject oldLedConfig = config["ledConfig"].toObject();
|
||||
if (!oldLedConfig.contains("classic"))
|
||||
{
|
||||
QJsonObject newLedConfig;
|
||||
newLedConfig.insert("classic", oldLedConfig);
|
||||
QJsonObject defaultMatrixConfig{ {"ledshoriz", 1}
|
||||
,{"ledsvert", 1}
|
||||
,{"cabling","snake"}
|
||||
,{"start","top-left"}
|
||||
};
|
||||
newLedConfig.insert("matrix", defaultMatrixConfig);
|
||||
|
||||
config["ledConfig"] = newLedConfig;
|
||||
migrated = true;
|
||||
Info(_log, "Instance [%u]: LED-Config migrated", instance);
|
||||
}
|
||||
}
|
||||
|
||||
// LED Hardware count is leading for versions after alpha 9
|
||||
// Setting Hardware LED count to number of LEDs configured via layout, if layout number is greater than number of hardware LEDs
|
||||
if (config.contains("device"))
|
||||
{
|
||||
QJsonObject newDeviceConfig = config["device"].toObject();
|
||||
|
||||
if (newDeviceConfig.contains("hardwareLedCount"))
|
||||
{
|
||||
int hwLedcount = newDeviceConfig["hardwareLedCount"].toInt();
|
||||
if (config.contains("leds"))
|
||||
{
|
||||
const QJsonArray ledarr = config["leds"].toArray();
|
||||
int layoutLedCount = ledarr.size();
|
||||
|
||||
if (hwLedcount < layoutLedCount)
|
||||
{
|
||||
Warning(_log, "Instance [%u]: HwLedCount/Layout mismatch! Setting Hardware LED count to number of LEDs configured via layout", instance);
|
||||
hwLedcount = layoutLedCount;
|
||||
newDeviceConfig["hardwareLedCount"] = hwLedcount;
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newDeviceConfig.contains("type"))
|
||||
{
|
||||
QString type = newDeviceConfig["type"].toString();
|
||||
if (type == "atmoorb" || type == "fadecandy" || type == "philipshue")
|
||||
{
|
||||
if (newDeviceConfig.contains("output"))
|
||||
{
|
||||
newDeviceConfig["host"] = newDeviceConfig["output"].toString();
|
||||
newDeviceConfig.remove("output");
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["device"] = newDeviceConfig;
|
||||
Debug(_log, "LED-Device records migrated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::upgradeInstanceSettings_2_0_12(semver::version& currentVersion, quint8 instance, QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
const semver::version targetVersion{ "2.0.12" };
|
||||
|
||||
if (currentVersion < targetVersion)
|
||||
{
|
||||
Info(_log, "Settings instance [%u]: Migrate from version [%s] to version [%s] or later", instance, currentVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
currentVersion = targetVersion;
|
||||
|
||||
// Have Hostname/IP-address separate from port for LED-Devices
|
||||
if (config.contains("device"))
|
||||
{
|
||||
QJsonObject newDeviceConfig = config["device"].toObject();
|
||||
|
||||
if (newDeviceConfig.contains("host"))
|
||||
{
|
||||
QString oldHost = newDeviceConfig["host"].toString();
|
||||
|
||||
// Resolve hostname and port
|
||||
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
|
||||
newDeviceConfig["host"] = addressparts[0];
|
||||
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
if (!newDeviceConfig.contains("port"))
|
||||
{
|
||||
newDeviceConfig["port"] = addressparts[1].toInt();
|
||||
}
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (newDeviceConfig.contains("type"))
|
||||
{
|
||||
QString type = newDeviceConfig["type"].toString();
|
||||
if (type == "apa102")
|
||||
{
|
||||
if (newDeviceConfig.contains("colorOrder"))
|
||||
{
|
||||
QString colorOrder = newDeviceConfig["colorOrder"].toString();
|
||||
if (colorOrder == "bgr")
|
||||
{
|
||||
newDeviceConfig["colorOrder"] = "rgb";
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["device"] = newDeviceConfig;
|
||||
Debug(_log, "LED-Device records migrated");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::upgradeInstanceSettings_2_0_13(semver::version& currentVersion, quint8 instance, QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
const semver::version targetVersion{ "2.0.13" };
|
||||
|
||||
if (currentVersion < targetVersion)
|
||||
{
|
||||
Info(_log, "Settings instance [%u]: Migrate from version [%s] to version [%s] or later", instance, currentVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
currentVersion = targetVersion;
|
||||
|
||||
// Have Hostname/IP-address separate from port for LED-Devices
|
||||
if (config.contains("device"))
|
||||
{
|
||||
QJsonObject newDeviceConfig = config["device"].toObject();
|
||||
|
||||
if (newDeviceConfig.contains("type"))
|
||||
{
|
||||
QString type = newDeviceConfig["type"].toString();
|
||||
|
||||
const QStringList serialDevices{ "adalight", "dmx", "atmo", "sedu", "tpm2", "karate" };
|
||||
if (serialDevices.contains(type))
|
||||
{
|
||||
if (!newDeviceConfig.contains("rateList"))
|
||||
{
|
||||
newDeviceConfig["rateList"] = "CUSTOM";
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == "adalight")
|
||||
{
|
||||
if (newDeviceConfig.contains("lightberry_apa102_mode"))
|
||||
{
|
||||
bool lightberry_apa102_mode = newDeviceConfig["lightberry_apa102_mode"].toBool();
|
||||
if (lightberry_apa102_mode)
|
||||
{
|
||||
newDeviceConfig["streamProtocol"] = "1";
|
||||
}
|
||||
else
|
||||
{
|
||||
newDeviceConfig["streamProtocol"] = "0";
|
||||
}
|
||||
newDeviceConfig.remove("lightberry_apa102_mode");
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["device"] = newDeviceConfig;
|
||||
Debug(_log, "LED-Device records migrated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
||||
bool DBMigrationManager::upgradeInstanceSettings_2_0_16(semver::version& currentVersion, quint8 instance, QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
const semver::version targetVersion{ "2.0.16" };
|
||||
|
||||
if (currentVersion >= targetVersion) return migrated;
|
||||
|
||||
Info(_log, "Settings instance [%u]: Migrate from version [%s] to version [%s] or later", instance, currentVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
currentVersion = targetVersion;
|
||||
|
||||
if (config.contains("device"))
|
||||
{
|
||||
QJsonObject newDeviceConfig = config["device"].toObject();
|
||||
|
||||
auto convertIntToString = [&](const QString& key) {
|
||||
if (newDeviceConfig.contains(key) && newDeviceConfig[key].isDouble()) {
|
||||
int value = newDeviceConfig[key].toInt();
|
||||
newDeviceConfig[key] = QString::number(value);
|
||||
migrated = true;
|
||||
}
|
||||
};
|
||||
|
||||
if (newDeviceConfig.contains("type"))
|
||||
{
|
||||
QString type = newDeviceConfig["type"].toString();
|
||||
|
||||
if (type == "philipshue")
|
||||
{
|
||||
convertIntToString("groupId");
|
||||
|
||||
if (newDeviceConfig.contains("lightIds"))
|
||||
{
|
||||
QJsonArray lightIds = newDeviceConfig["lightIds"].toArray();
|
||||
for (int i = 0; i < lightIds.size(); ++i)
|
||||
{
|
||||
if (lightIds[i].isDouble())
|
||||
{
|
||||
lightIds[i] = QString::number(lightIds[i].toInt());
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
newDeviceConfig["lightIds"] = lightIds;
|
||||
}
|
||||
}
|
||||
else if (type == "nanoleaf")
|
||||
{
|
||||
const auto updatePanelOrder = [&](const QString& key, const QString& zeroStr, const QString& oneStr) {
|
||||
if (newDeviceConfig.contains(key))
|
||||
{
|
||||
int order = newDeviceConfig[key].isDouble() ? newDeviceConfig[key].toInt() : newDeviceConfig[key].toString().toInt();
|
||||
newDeviceConfig[key] = (order == 0) ? zeroStr : oneStr;
|
||||
migrated = true;
|
||||
}
|
||||
};
|
||||
|
||||
newDeviceConfig.remove("panelStartPos");
|
||||
migrated = true;
|
||||
|
||||
updatePanelOrder("panelOrderTopDown", "top2down", "bottom2up");
|
||||
updatePanelOrder("panelOrderLeftRight", "left2right", "right2left");
|
||||
}
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["device"] = newDeviceConfig;
|
||||
Debug(_log, "LED-Device records migrated");
|
||||
}
|
||||
}
|
||||
|
||||
return migrated;
|
||||
}
|
||||
|
142
libsrc/db/InstanceTable.cpp
Normal file
142
libsrc/db/InstanceTable.cpp
Normal file
@ -0,0 +1,142 @@
|
||||
|
||||
// db
|
||||
#include <db/InstanceTable.h>
|
||||
#include <db/SettingsTable.h>
|
||||
|
||||
// qt
|
||||
#include <QDateTime>
|
||||
|
||||
InstanceTable::InstanceTable(QObject* parent)
|
||||
: DBManager(parent)
|
||||
{
|
||||
// Init instance table
|
||||
setTable("instances");
|
||||
createTable(QStringList()<<"instance INTEGER"<<"friendly_name TEXT"<<"enabled INTEGER DEFAULT 0"<<"last_use TEXT");
|
||||
}
|
||||
|
||||
bool InstanceTable::createInstance(const QString& name, quint8& inst)
|
||||
{
|
||||
// check duplicate
|
||||
if(!recordExists({{"friendly_name", name}}))
|
||||
{
|
||||
QList<quint8> instanceList = getAllInstanceIDs(false);
|
||||
|
||||
inst = 0;
|
||||
while (instanceList.contains(inst))
|
||||
{
|
||||
++inst;
|
||||
}
|
||||
|
||||
// create
|
||||
QVariantMap data;
|
||||
data["friendly_name"] = name;
|
||||
data["instance"] = inst;
|
||||
return createRecord({}, data);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InstanceTable::deleteInstance(quint8 inst)
|
||||
{
|
||||
Debug(_log,"");
|
||||
if(deleteRecord({{"instance",inst}}))
|
||||
{
|
||||
// delete settings entries
|
||||
SettingsTable settingsTable(inst);
|
||||
settingsTable.deleteInstance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InstanceTable::saveName(quint8 inst, const QString& name)
|
||||
{
|
||||
// check duplicate
|
||||
if(!recordExists({{"friendly_name", name}}))
|
||||
{
|
||||
if(instanceExist(inst))
|
||||
{
|
||||
return updateRecord({{"instance",inst}}, {{"friendly_name", name}});
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QVector<QVariantMap> InstanceTable::getAllInstances(bool onlyEnabled)
|
||||
{
|
||||
QVector<QVariantMap> results;
|
||||
|
||||
VectorPair onlyEnabledCondition {};
|
||||
if (onlyEnabled)
|
||||
{
|
||||
onlyEnabledCondition = {{"enabled", true}};
|
||||
}
|
||||
getRecords(onlyEnabledCondition, results, {}, {"instance ASC"});
|
||||
return results;
|
||||
}
|
||||
|
||||
QList<quint8> InstanceTable::getAllInstanceIDs (bool onlyEnabled)
|
||||
{
|
||||
QVector<QVariantMap> instanceList = getAllInstances(onlyEnabled);
|
||||
QList<quint8> instanceIds;
|
||||
for (const QVariantMap &idx : std::as_const(instanceList))
|
||||
{
|
||||
instanceIds.append(static_cast<quint8>(idx.value("instance").toInt()));
|
||||
}
|
||||
|
||||
return instanceIds;
|
||||
}
|
||||
|
||||
bool InstanceTable::instanceExist(quint8 inst)
|
||||
{
|
||||
return recordExists({{"instance",inst}});
|
||||
}
|
||||
|
||||
QString InstanceTable::getNamebyIndex(quint8 index)
|
||||
{
|
||||
QVariantMap results;
|
||||
getRecord({{"instance", index}}, results, {"friendly_name"});
|
||||
|
||||
QString name = results["friendly_name"].toString();
|
||||
return name.isEmpty() ? "NOT FOUND" : name;
|
||||
}
|
||||
|
||||
bool InstanceTable::setLastUse(quint8 inst)
|
||||
{
|
||||
return updateRecord({{"instance", inst}}, {{"last_use", QDateTime::currentDateTimeUtc().toString(Qt::ISODate)}});
|
||||
}
|
||||
|
||||
bool InstanceTable::setEnable(quint8 inst, bool newState)
|
||||
{
|
||||
return updateRecord({{"instance", inst}}, {{"enabled", newState}});
|
||||
}
|
||||
|
||||
bool InstanceTable::isEnabled(quint8 inst)
|
||||
{
|
||||
QVariantMap results;
|
||||
getRecord({{"instance", inst}}, results);
|
||||
|
||||
return results["enabled"].toBool();
|
||||
}
|
||||
|
||||
void InstanceTable::createDefaultInstance()
|
||||
{
|
||||
if(instanceExist(0))
|
||||
{
|
||||
setEnable(0, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(createRecord({{"instance", 0}}, {{"friendly_name", "First LED Hardware instance"}}))
|
||||
{
|
||||
setEnable(0, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Failed to create Hyperion root instance in db! This should never be the case...");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
47
libsrc/db/MetaTable.cpp
Normal file
47
libsrc/db/MetaTable.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
|
||||
#include <db/MetaTable.h>
|
||||
|
||||
// qt
|
||||
#include <QDateTime>
|
||||
#include <QUuid>
|
||||
#include <QNetworkInterface>
|
||||
#include <QCryptographicHash>
|
||||
|
||||
MetaTable::MetaTable(QObject* parent)
|
||||
: DBManager(parent)
|
||||
{
|
||||
setTable("meta");
|
||||
createTable(QStringList()<<"uuid TEXT"<<"created_at TEXT");
|
||||
};
|
||||
|
||||
QString MetaTable::getUUID() const
|
||||
{
|
||||
QVector<QVariantMap> results;
|
||||
getRecords(results, QStringList() << "uuid");
|
||||
|
||||
for(const auto & entry : std::as_const(results))
|
||||
{
|
||||
if(!entry["uuid"].toString().isEmpty())
|
||||
{
|
||||
return entry["uuid"].toString();
|
||||
}
|
||||
}
|
||||
|
||||
// create new uuidv5 based on net adapter MAC, save to db and return
|
||||
QString hash;
|
||||
foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces())
|
||||
{
|
||||
if (!(interface.flags() & QNetworkInterface::IsLoopBack))
|
||||
{
|
||||
hash = QCryptographicHash::hash(interface.hardwareAddress().toLocal8Bit(),QCryptographicHash::Sha1).toHex();
|
||||
break;
|
||||
}
|
||||
}
|
||||
const QString newUuid = QUuid::createUuidV5(QUuid(), hash).toString().mid(1, 36);
|
||||
QVariantMap map;
|
||||
map["created_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
createRecord({{"uuid",newUuid}}, map);
|
||||
|
||||
return newUuid;
|
||||
}
|
389
libsrc/db/SettingsTable.cpp
Normal file
389
libsrc/db/SettingsTable.cpp
Normal file
@ -0,0 +1,389 @@
|
||||
#include <db/SettingsTable.h>
|
||||
|
||||
#include <utils/jsonschema/QJsonFactory.h>
|
||||
#include <utils/JsonUtils.h>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QSqlDatabase>
|
||||
#include <QSqlError>
|
||||
|
||||
namespace {
|
||||
const char DEFAULT_INSTANCE_SETTINGS_SCHEMA_FILE[] = ":/schema-settings-instance.json";
|
||||
const char GLOBAL_SETTINGS_SCHEMA_FILE[] = ":/schema-settings-global.json";
|
||||
const char DEFAULT_SETTINGS_SCHEMA_FILE[] = ":/schema-settings-default.json";
|
||||
const char DEFAULT_SETTINGS_CONFIGURATION_FILE[] = ":/hyperion_default.settings";
|
||||
}
|
||||
|
||||
QVector<QString> SettingsTable::globalSettingTypes;
|
||||
bool SettingsTable::areGlobalSettingTypesInitialised = false;
|
||||
|
||||
QVector<QString> SettingsTable::instanceSettingTypes;
|
||||
bool SettingsTable::areInstanceSettingTypesInitialised = false;
|
||||
|
||||
QJsonObject SettingsTable::defaultSettings;
|
||||
bool SettingsTable::areDefaultSettingsInitialised = false;
|
||||
|
||||
|
||||
SettingsTable::SettingsTable(quint8 instance, QObject* parent)
|
||||
: DBManager(parent)
|
||||
, _instance(instance)
|
||||
, _configVersion(DEFAULT_CONFIG_VERSION)
|
||||
{
|
||||
setTable("settings");
|
||||
// create table columns
|
||||
createTable(QStringList()<<"type TEXT"<<"config TEXT"<<"hyperion_inst INTEGER"<<"updated_at TEXT");
|
||||
}
|
||||
|
||||
const QVector<QString>& SettingsTable::getGlobalSettingTypes() const
|
||||
{
|
||||
if (!areGlobalSettingTypesInitialised) {
|
||||
globalSettingTypes = initializeGlobalSettingTypes();
|
||||
areGlobalSettingTypesInitialised = true;
|
||||
}
|
||||
return globalSettingTypes;
|
||||
}
|
||||
|
||||
QVector<QString> SettingsTable::initializeGlobalSettingTypes() const
|
||||
{
|
||||
QJsonObject schemaJson;
|
||||
try
|
||||
{
|
||||
schemaJson = QJsonFactory::readSchema(GLOBAL_SETTINGS_SCHEMA_FILE);
|
||||
}
|
||||
catch (const std::runtime_error& error)
|
||||
{
|
||||
throw std::runtime_error(error.what());
|
||||
}
|
||||
|
||||
const QVector<QString> types = schemaJson.value("properties").toObject().keys().toVector();
|
||||
return types;
|
||||
}
|
||||
|
||||
bool SettingsTable::isGlobalSettingType(const QString& type) const {
|
||||
return getGlobalSettingTypes().contains(type);
|
||||
}
|
||||
|
||||
bool SettingsTable::isInstanceSettingType(const QString& type) const {
|
||||
return getInstanceSettingTypes().contains(type);
|
||||
}
|
||||
|
||||
const QVector<QString>& SettingsTable::getInstanceSettingTypes() const
|
||||
{
|
||||
if (!areInstanceSettingTypesInitialised) {
|
||||
instanceSettingTypes = initializeInstanceSettingTypes();
|
||||
areInstanceSettingTypesInitialised = true;
|
||||
}
|
||||
return instanceSettingTypes;
|
||||
}
|
||||
|
||||
QVector<QString> SettingsTable::initializeInstanceSettingTypes() const
|
||||
{
|
||||
QJsonObject schemaJson;
|
||||
try
|
||||
{
|
||||
schemaJson = QJsonFactory::readSchema(DEFAULT_INSTANCE_SETTINGS_SCHEMA_FILE);
|
||||
}
|
||||
catch (const std::runtime_error& error)
|
||||
{
|
||||
throw std::runtime_error(error.what());
|
||||
}
|
||||
|
||||
const QVector<QString> types = schemaJson.value("properties").toObject().keys().toVector();
|
||||
return types;
|
||||
}
|
||||
|
||||
const QJsonObject& SettingsTable::getDefaultSettings() const
|
||||
{
|
||||
if (!areDefaultSettingsInitialised) {
|
||||
defaultSettings = initializeDefaultSettings();
|
||||
areDefaultSettingsInitialised = true;
|
||||
}
|
||||
return defaultSettings;
|
||||
}
|
||||
|
||||
QJsonObject SettingsTable::initializeDefaultSettings() const
|
||||
{
|
||||
QJsonObject defaultConfig;
|
||||
if ( QJsonFactory::load(DEFAULT_SETTINGS_SCHEMA_FILE, DEFAULT_SETTINGS_CONFIGURATION_FILE, defaultConfig) < 0)
|
||||
{
|
||||
Error(_log,"Failed to read default config");
|
||||
}
|
||||
|
||||
return defaultConfig;
|
||||
}
|
||||
|
||||
bool SettingsTable::createSettingsRecord(const QString& type, const QString& config) const
|
||||
{
|
||||
QVariantMap map;
|
||||
map["config"] = config;
|
||||
map["updated_at"] = QDateTime::currentDateTimeUtc().toString(Qt::ISODate);
|
||||
|
||||
VectorPair cond;
|
||||
cond.append(CPair("type",type));
|
||||
// when a setting is not global we are searching also for the instance
|
||||
if(!isGlobalSettingType(type))
|
||||
{
|
||||
cond.append(CPair("AND hyperion_inst",_instance));
|
||||
}
|
||||
return createRecord(cond, map);
|
||||
}
|
||||
|
||||
bool SettingsTable::recordExist(const QString& type) const
|
||||
{
|
||||
VectorPair cond;
|
||||
cond.append(CPair("type",type));
|
||||
// when a setting is not global we are searching also for the instance
|
||||
if(!isGlobalSettingType(type))
|
||||
{
|
||||
cond.append(CPair("AND hyperion_inst",_instance));
|
||||
}
|
||||
return recordExists(cond);
|
||||
}
|
||||
|
||||
QJsonDocument SettingsTable::getSettingsRecord(const QString& type) const
|
||||
{
|
||||
QVariantMap results;
|
||||
VectorPair cond;
|
||||
cond.append(CPair("type",type));
|
||||
// when a setting is not global we are searching also for the instance
|
||||
if(!isGlobalSettingType(type))
|
||||
{
|
||||
cond.append(CPair("AND hyperion_inst",_instance));
|
||||
}
|
||||
getRecord(cond, results, QStringList("config"));
|
||||
return QJsonDocument::fromJson(results["config"].toByteArray());
|
||||
}
|
||||
|
||||
QString SettingsTable::getSettingsRecordString(const QString& type) const
|
||||
{
|
||||
QVariantMap results;
|
||||
VectorPair cond;
|
||||
cond.append(CPair("type",type));
|
||||
// when a setting is not global we are searching also for the instance
|
||||
if(!isGlobalSettingType(type))
|
||||
{
|
||||
cond.append(CPair("AND hyperion_inst",_instance));
|
||||
}
|
||||
getRecord(cond, results, QStringList("config"));
|
||||
return results["config"].toString();
|
||||
}
|
||||
|
||||
QJsonObject SettingsTable::getSettings(const QStringList& filteredTypes ) const
|
||||
{
|
||||
return getSettings(_instance, filteredTypes);
|
||||
}
|
||||
|
||||
QJsonObject SettingsTable::getSettings(const QVariant& instance, const QStringList& filteredTypes ) const
|
||||
{
|
||||
QJsonObject settingsObject;
|
||||
QStringList settingsKeys({ "type", "config" });
|
||||
QString settingsCondition;
|
||||
QVariantList conditionValues;
|
||||
|
||||
if (instance.isNull() || instance == GLOABL_INSTANCE_ID )
|
||||
{
|
||||
settingsCondition = "hyperion_inst IS NULL";
|
||||
}
|
||||
else
|
||||
{
|
||||
settingsCondition = "hyperion_inst = ?";
|
||||
conditionValues.append(instance);
|
||||
}
|
||||
|
||||
if (!filteredTypes.isEmpty())
|
||||
{
|
||||
QStringList seletedSettingTypes;
|
||||
for (const auto &type : filteredTypes) {
|
||||
seletedSettingTypes << QString("%1=?").arg("type");
|
||||
conditionValues.append(type);
|
||||
}
|
||||
settingsCondition += QString (" AND (%1)").arg(seletedSettingTypes.join(" OR "));
|
||||
}
|
||||
|
||||
QVector<QVariantMap> settingsList;
|
||||
if (getRecords(settingsCondition, conditionValues, settingsList, settingsKeys))
|
||||
{
|
||||
for (const QVariantMap &setting : std::as_const(settingsList))
|
||||
{
|
||||
QString type = setting.value("type").toString();
|
||||
QByteArray configObject = setting.value("config").toByteArray();
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(configObject);
|
||||
|
||||
if (!jsonDoc.isNull())
|
||||
{
|
||||
QJsonValue config;
|
||||
|
||||
if (jsonDoc.isArray())
|
||||
{
|
||||
config = jsonDoc.array();
|
||||
}
|
||||
else if (jsonDoc.isObject())
|
||||
{
|
||||
config = jsonDoc.object();
|
||||
}
|
||||
settingsObject.insert(type, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
return settingsObject;
|
||||
}
|
||||
|
||||
QStringList SettingsTable::nonExtingTypes() const
|
||||
{
|
||||
QStringList testTypes;
|
||||
QString condition {"hyperion_inst"};
|
||||
if(_instance == GLOABL_INSTANCE_ID)
|
||||
{
|
||||
condition += " IS NULL";
|
||||
testTypes = getGlobalSettingTypes().toList();
|
||||
}
|
||||
else
|
||||
{
|
||||
condition += QString(" = %1").arg(_instance);
|
||||
testTypes = getInstanceSettingTypes().toList();
|
||||
}
|
||||
|
||||
QVariantList testTypesList;
|
||||
testTypesList.reserve(testTypes.size());
|
||||
|
||||
for (const QString &str : std::as_const(testTypes)) {
|
||||
testTypesList.append(QVariant(str));
|
||||
}
|
||||
|
||||
QStringList nonExistingRecs;
|
||||
recordsNotExisting(testTypesList, "type", nonExistingRecs, condition );
|
||||
|
||||
return nonExistingRecs;
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> SettingsTable::addMissingDefaults()
|
||||
{
|
||||
QStringList errorList;
|
||||
|
||||
QJsonObject defaultSettings;
|
||||
if (_instance == GLOABL_INSTANCE_ID)
|
||||
{
|
||||
defaultSettings = getDefaultSettings().value("global").toObject();
|
||||
}
|
||||
else
|
||||
{
|
||||
defaultSettings = getDefaultSettings().value("instance").toObject();
|
||||
}
|
||||
|
||||
const QStringList missingTypes = nonExtingTypes();
|
||||
if (missingTypes.empty())
|
||||
{
|
||||
Debug(_log, "Instance [%u]: No missing configuration items identified", _instance);
|
||||
return qMakePair (true, errorList );
|
||||
}
|
||||
|
||||
QSqlDatabase idb = getDB();
|
||||
if (!startTransaction(idb, errorList))
|
||||
{
|
||||
return qMakePair(false, errorList);
|
||||
}
|
||||
|
||||
|
||||
bool errorOccured {false};
|
||||
|
||||
Info(_log, "Instance [%u]: Add default settings for %d missing configuration items",_instance, missingTypes.size());
|
||||
for (const auto &missingType: missingTypes)
|
||||
{
|
||||
if (!createSettingsRecord(missingType, JsonUtils::jsonValueToQString(defaultSettings.value(missingType))))
|
||||
{
|
||||
errorOccured = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (errorOccured)
|
||||
{
|
||||
QString errorText = "Errors occured while adding missing settings to instance configuration items";
|
||||
Error(_log, "'%s'", QSTRING_CSTR(errorText));
|
||||
errorList.append(errorText);
|
||||
|
||||
if (!idb.rollback())
|
||||
{
|
||||
errorText = QString("Could not create a database transaction. Error: %1").arg(idb.lastError().text());
|
||||
Error(_log, "'%s'", QSTRING_CSTR(errorText));
|
||||
errorList.append(errorText);
|
||||
}
|
||||
}
|
||||
|
||||
commiTransaction(idb, errorList);
|
||||
|
||||
if(errorList.isEmpty())
|
||||
{
|
||||
Debug(_log, "Instance [%u]: Successfully defaulted settings for %d missing configuration items", _instance, missingTypes.size());
|
||||
}
|
||||
|
||||
return qMakePair (errorList.isEmpty(), errorList );
|
||||
}
|
||||
|
||||
void SettingsTable::deleteInstance() const
|
||||
{
|
||||
deleteRecord({{"hyperion_inst",_instance}});
|
||||
}
|
||||
|
||||
QString SettingsTable::fixVersion(const QString& version)
|
||||
{
|
||||
QString newVersion;
|
||||
|
||||
// Use a static QRegularExpression to avoid re-creating it every time
|
||||
static const QRegularExpression regEx(
|
||||
"(\\d+\\.\\d+\\.\\d+-?[a-zA-Z-\\d]*\\.?[\\d]*)",
|
||||
QRegularExpression::CaseInsensitiveOption | QRegularExpression::MultilineOption
|
||||
);
|
||||
|
||||
// Try fixing version number, remove dot-separated pre-release identifiers not supported
|
||||
QRegularExpressionMatch match = regEx.match(version);
|
||||
|
||||
if (match.hasMatch())
|
||||
{
|
||||
newVersion = match.captured(1);
|
||||
}
|
||||
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
bool SettingsTable::resolveConfigVersion()
|
||||
{
|
||||
QJsonObject generalConfig = getSettingsRecord({"general"}).object();
|
||||
return resolveConfigVersion(generalConfig);
|
||||
}
|
||||
|
||||
bool SettingsTable::resolveConfigVersion(QJsonObject generalConfig)
|
||||
{
|
||||
bool isValid = false;
|
||||
|
||||
QString configVersion = generalConfig["configVersion"].toString();
|
||||
if (!configVersion.isEmpty())
|
||||
{
|
||||
isValid = _configVersion.setVersion(configVersion.toStdString());
|
||||
if (!isValid)
|
||||
{
|
||||
isValid = _configVersion.setVersion(fixVersion(configVersion).toStdString());
|
||||
if (isValid)
|
||||
{
|
||||
Info(_log, "Invalid config version [%s] fixed. Updated to [%s]", QSTRING_CSTR(configVersion), _configVersion.getVersion().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
QString SettingsTable::getConfigVersionString()
|
||||
{
|
||||
return _configVersion.getVersion().data();
|
||||
}
|
||||
|
||||
semver::version SettingsTable::getConfigVersion()
|
||||
{
|
||||
return _configVersion;
|
||||
}
|
@ -103,7 +103,7 @@ QString EffectFileHandler::saveEffect(const QJsonObject& message)
|
||||
|
||||
if (it != effectsSchemas.end())
|
||||
{
|
||||
if (!JsonUtils::validate("EffectFileHandler", message["args"].toObject(), it->schemaFile, _log).first)
|
||||
if (!JsonUtils::validate("EffectFileHandler", message["args"], it->schemaFile, _log).first)
|
||||
{
|
||||
return "Error during arg validation against schema, please consult the Hyperion Log";
|
||||
}
|
||||
|
@ -7,14 +7,15 @@
|
||||
// qt
|
||||
#include <QJsonObject>
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
#include <QUuid>
|
||||
|
||||
AuthManager *AuthManager::manager = nullptr;
|
||||
|
||||
AuthManager::AuthManager(QObject *parent, bool readonlyMode)
|
||||
AuthManager::AuthManager(QObject *parent)
|
||||
: QObject(parent)
|
||||
, _authTable(new AuthTable("", this, readonlyMode))
|
||||
, _metaTable(new MetaTable(this, readonlyMode))
|
||||
, _pendingRequests()
|
||||
, _authTable(new AuthTable(this))
|
||||
, _metaTable(new MetaTable(this))
|
||||
, _timer(new QTimer(this))
|
||||
, _authBlockTimer(new QTimer(this))
|
||||
{
|
||||
@ -209,7 +210,7 @@ QVector<AuthManager::AuthDefinition> AuthManager::getPendingRequests() const
|
||||
|
||||
bool AuthManager::renameToken(const QString &id, const QString &comment)
|
||||
{
|
||||
if (_authTable->idExist(id))
|
||||
if (_authTable->identifierExist(id))
|
||||
{
|
||||
if (_authTable->renameToken(id, comment))
|
||||
{
|
||||
@ -222,7 +223,7 @@ bool AuthManager::renameToken(const QString &id, const QString &comment)
|
||||
|
||||
bool AuthManager::deleteToken(const QString &id)
|
||||
{
|
||||
if (_authTable->idExist(id))
|
||||
if (_authTable->identifierExist(id))
|
||||
{
|
||||
if (_authTable->deleteToken(id))
|
||||
{
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QThread>
|
||||
#include <QVariantMap>
|
||||
|
||||
// hyperion include
|
||||
#include <hyperion/Hyperion.h>
|
||||
@ -21,6 +22,7 @@
|
||||
#include <utils/hyperion.h>
|
||||
#include <utils/GlobalSignals.h>
|
||||
#include <utils/Logger.h>
|
||||
#include <utils/JsonUtils.h>
|
||||
|
||||
// LedDevice includes
|
||||
#include <leddevice/LedDeviceWrapper.h>
|
||||
@ -47,10 +49,10 @@
|
||||
#include <boblightserver/BoblightServer.h>
|
||||
#endif
|
||||
|
||||
Hyperion::Hyperion(quint8 instance, bool readonlyMode)
|
||||
Hyperion::Hyperion(quint8 instance)
|
||||
: QObject()
|
||||
, _instIndex(instance)
|
||||
, _settingsManager(new SettingsManager(instance, this, readonlyMode))
|
||||
, _settingsManager(new SettingsManager(instance, this))
|
||||
, _componentRegister(nullptr)
|
||||
, _ledString(LedString::createLedString(getSetting(settings::LEDS).array(), hyperion::createColorOrder(getSetting(settings::DEVICE).object())))
|
||||
, _imageProcessor(nullptr)
|
||||
@ -73,7 +75,6 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode)
|
||||
#if defined(ENABLE_BOBLIGHT_SERVER)
|
||||
, _boblightServer(nullptr)
|
||||
#endif
|
||||
, _readOnlyMode(readonlyMode)
|
||||
{
|
||||
qRegisterMetaType<ComponentList>("ComponentList");
|
||||
|
||||
@ -320,14 +321,17 @@ QJsonDocument Hyperion::getSetting(settings::type type) const
|
||||
return _settingsManager->getSetting(type);
|
||||
}
|
||||
|
||||
bool Hyperion::saveSettings(const QJsonObject& config, bool correct)
|
||||
// TODO: Remove function, if UI is able to handle full configuration
|
||||
QJsonObject Hyperion::getQJsonConfig() const
|
||||
{
|
||||
return _settingsManager->saveSettings(config, correct);
|
||||
const QJsonObject instanceConfig = _settingsManager->getSettings();
|
||||
const QJsonObject globalConfig = _settingsManager->getSettings({},QStringList());
|
||||
return JsonUtils::mergeJsonObjects(instanceConfig, globalConfig);
|
||||
}
|
||||
|
||||
bool Hyperion::restoreSettings(const QJsonObject& config, bool correct)
|
||||
QPair<bool, QStringList> Hyperion::saveSettings(const QJsonObject& config)
|
||||
{
|
||||
return _settingsManager->restoreSettings(config, correct);
|
||||
return _settingsManager->saveSettings(config);
|
||||
}
|
||||
|
||||
int Hyperion::getLatchTime() const
|
||||
@ -597,11 +601,6 @@ int Hyperion::setEffect(const QString &effectName, const QJsonObject &args, int
|
||||
}
|
||||
#endif
|
||||
|
||||
QJsonObject Hyperion::getQJsonConfig() const
|
||||
{
|
||||
return _settingsManager->getSettings();
|
||||
}
|
||||
|
||||
void Hyperion::setLedMappingType(int mappingType)
|
||||
{
|
||||
if(mappingType != _imageProcessor->getUserLedMappingType())
|
||||
|
@ -9,15 +9,14 @@
|
||||
|
||||
HyperionIManager* HyperionIManager::HIMinstance;
|
||||
|
||||
HyperionIManager::HyperionIManager(const QString& rootPath, QObject* parent, bool readonlyMode)
|
||||
HyperionIManager::HyperionIManager(QObject* parent)
|
||||
: QObject(parent)
|
||||
, _log(Logger::getInstance("HYPERION-INSTMGR"))
|
||||
, _instanceTable( new InstanceTable(rootPath, this, readonlyMode) )
|
||||
, _rootPath( rootPath )
|
||||
, _readonlyMode(readonlyMode)
|
||||
, _instanceTable( new InstanceTable())
|
||||
{
|
||||
HIMinstance = this;
|
||||
qRegisterMetaType<InstanceState>("InstanceState");
|
||||
_instanceTable->createDefaultInstance();
|
||||
}
|
||||
|
||||
Hyperion* HyperionIManager::getHyperionInstance(quint8 instance)
|
||||
@ -45,14 +44,32 @@ QVector<QVariantMap> HyperionIManager::getInstanceData() const
|
||||
return instances;
|
||||
}
|
||||
|
||||
QString HyperionIManager::getInstanceName(quint8 inst)
|
||||
{
|
||||
return _instanceTable->getNamebyIndex(inst);
|
||||
}
|
||||
|
||||
QList<quint8> HyperionIManager::getRunningInstanceIdx() const
|
||||
{
|
||||
return _runningInstances.keys();
|
||||
}
|
||||
|
||||
QList<quint8> HyperionIManager::getInstanceIds() const
|
||||
{
|
||||
return _instanceTable->getAllInstanceIDs();
|
||||
}
|
||||
|
||||
|
||||
void HyperionIManager::startAll()
|
||||
{
|
||||
for(const auto & entry : _instanceTable->getAllInstances(true))
|
||||
const QVector<QVariantMap> instances = _instanceTable->getAllInstances(true);
|
||||
if (instances.isEmpty())
|
||||
{
|
||||
Error(_log, "No enabled instances found to be started");
|
||||
return;
|
||||
}
|
||||
|
||||
for(const auto & entry : instances)
|
||||
{
|
||||
startInstance(entry["instance"].toInt());
|
||||
}
|
||||
@ -62,7 +79,7 @@ void HyperionIManager::stopAll()
|
||||
{
|
||||
// copy the instances due to loop corruption, even with .erase() return next iter
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
for(auto *const instance : instCopy)
|
||||
{
|
||||
instance->stop();
|
||||
}
|
||||
@ -131,7 +148,7 @@ bool HyperionIManager::startInstance(quint8 inst, bool block, QObject* caller, i
|
||||
{
|
||||
QThread* hyperionThread = new QThread();
|
||||
hyperionThread->setObjectName("HyperionThread");
|
||||
Hyperion* hyperion = new Hyperion(inst, _readonlyMode);
|
||||
Hyperion* hyperion = new Hyperion(inst);
|
||||
hyperion->moveToThread(hyperionThread);
|
||||
// setup thread management
|
||||
connect(hyperionThread, &QThread::started, hyperion, &Hyperion::start);
|
||||
@ -156,7 +173,7 @@ bool HyperionIManager::startInstance(quint8 inst, bool block, QObject* caller, i
|
||||
|
||||
if(block)
|
||||
{
|
||||
while(!hyperionThread->isRunning()){};
|
||||
while(!hyperionThread->isRunning()){}
|
||||
}
|
||||
|
||||
if (!_pendingRequests.contains(inst) && caller != nullptr)
|
||||
@ -203,10 +220,10 @@ bool HyperionIManager::stopInstance(quint8 inst)
|
||||
|
||||
bool HyperionIManager::createInstance(const QString& name, bool start)
|
||||
{
|
||||
quint8 inst;
|
||||
quint8 inst = 0;
|
||||
if(_instanceTable->createInstance(name, inst))
|
||||
{
|
||||
Info(_log,"New Hyperion instance created with name '%s'",QSTRING_CSTR(name));
|
||||
Info(_log,"New Hyperion instance [%d] created with name '%s'", inst, QSTRING_CSTR(name));
|
||||
emit instanceStateChanged(InstanceState::H_CREATED, inst, name);
|
||||
emit change();
|
||||
|
||||
@ -221,7 +238,9 @@ bool HyperionIManager::deleteInstance(quint8 inst)
|
||||
{
|
||||
// inst 0 can't be deleted
|
||||
if(!isInstAllowed(inst))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// stop it if required as blocking and wait
|
||||
stopInstance(inst);
|
||||
|
@ -1,939 +1,59 @@
|
||||
// proj
|
||||
#include <hyperion/SettingsManager.h>
|
||||
|
||||
// util
|
||||
#include <utils/JsonUtils.h>
|
||||
#include <utils/QStringUtils.h>
|
||||
|
||||
#include <db/SettingsTable.h>
|
||||
#include "HyperionConfig.h"
|
||||
|
||||
// json schema process
|
||||
#include <utils/jsonschema/QJsonFactory.h>
|
||||
#include <utils/jsonschema/QJsonSchemaChecker.h>
|
||||
|
||||
// write config to filesystem
|
||||
#include <utils/JsonUtils.h>
|
||||
#include <utils/jsonschema/QJsonFactory.h>
|
||||
|
||||
#include <utils/version.hpp>
|
||||
#include <QPair>
|
||||
|
||||
using namespace semver;
|
||||
|
||||
// Constants
|
||||
namespace {
|
||||
const char DEFAULT_VERSION[] = "2.0.0-alpha.8";
|
||||
} //End of constants
|
||||
|
||||
QJsonObject SettingsManager::schemaJson;
|
||||
|
||||
SettingsManager::SettingsManager(quint8 instance, QObject* parent, bool readonlyMode)
|
||||
SettingsManager::SettingsManager(quint8 instance, QObject* parent)
|
||||
: QObject(parent)
|
||||
, _log(Logger::getInstance("SETTINGSMGR", "I" + QString::number(instance)))
|
||||
, _instance(instance)
|
||||
, _sTable(new SettingsTable(instance, this))
|
||||
, _configVersion(DEFAULT_VERSION)
|
||||
, _previousVersion(DEFAULT_VERSION)
|
||||
, _readonlyMode(readonlyMode)
|
||||
{
|
||||
_sTable->setReadonlyMode(_readonlyMode);
|
||||
// get schema
|
||||
if (schemaJson.isEmpty())
|
||||
{
|
||||
Q_INIT_RESOURCE(resource);
|
||||
try
|
||||
{
|
||||
schemaJson = QJsonFactory::readSchema(":/hyperion-schema");
|
||||
}
|
||||
catch (const std::runtime_error& error)
|
||||
{
|
||||
throw std::runtime_error(error.what());
|
||||
}
|
||||
}
|
||||
|
||||
// get default config
|
||||
QJsonObject defaultConfig;
|
||||
if (!JsonUtils::readFile(":/hyperion_default.config", defaultConfig, _log).first)
|
||||
{
|
||||
throw std::runtime_error("Failed to read default config");
|
||||
}
|
||||
|
||||
// transform json to string lists
|
||||
const QStringList keyList = defaultConfig.keys();
|
||||
QStringList defValueList;
|
||||
for (const auto& key : keyList)
|
||||
{
|
||||
if (defaultConfig[key].isObject())
|
||||
{
|
||||
defValueList << QString(QJsonDocument(defaultConfig[key].toObject()).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
else if (defaultConfig[key].isArray())
|
||||
{
|
||||
defValueList << QString(QJsonDocument(defaultConfig[key].toArray()).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
}
|
||||
|
||||
// fill database with default data if required
|
||||
for (const auto& key : keyList)
|
||||
{
|
||||
QString val = defValueList.takeFirst();
|
||||
// prevent overwrite
|
||||
if (!_sTable->recordExist(key))
|
||||
{
|
||||
_sTable->createSettingsRecord(key, val);
|
||||
}
|
||||
}
|
||||
|
||||
// need to validate all data in database construct the entire data object
|
||||
// TODO refactor schemaChecker to accept QJsonArray in validate(); QJsonDocument container? To validate them per entry...
|
||||
QJsonObject dbConfig;
|
||||
for (const auto& key : keyList)
|
||||
{
|
||||
QJsonDocument doc = _sTable->getSettingsRecord(key);
|
||||
if (doc.isArray())
|
||||
{
|
||||
dbConfig[key] = doc.array();
|
||||
}
|
||||
else
|
||||
{
|
||||
dbConfig[key] = doc.object();
|
||||
}
|
||||
}
|
||||
|
||||
//Check, if database requires migration
|
||||
bool isNewRelease = false;
|
||||
// Use instance independent SettingsManager to track migration status
|
||||
if (_instance == GLOABL_INSTANCE_ID)
|
||||
{
|
||||
if (resolveConfigVersion(dbConfig))
|
||||
{
|
||||
QJsonObject newGeneralConfig = dbConfig["general"].toObject();
|
||||
|
||||
semver::version BUILD_VERSION(HYPERION_VERSION);
|
||||
|
||||
if (!BUILD_VERSION.isValid())
|
||||
{
|
||||
Error(_log, "Current Hyperion version [%s] is invalid. Exiting...", BUILD_VERSION.getVersion().c_str());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (_configVersion > BUILD_VERSION)
|
||||
{
|
||||
Error(_log, "Database version [%s] is greater than current Hyperion version [%s]", _configVersion.getVersion().c_str(), BUILD_VERSION.getVersion().c_str());
|
||||
// TODO: Remove version checking and Settingsmanager from components' constructor to be able to stop hyperion.
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_previousVersion < BUILD_VERSION)
|
||||
{
|
||||
if (_configVersion == BUILD_VERSION)
|
||||
{
|
||||
newGeneralConfig["previousVersion"] = BUILD_VERSION.getVersion().c_str();
|
||||
dbConfig["general"] = newGeneralConfig;
|
||||
isNewRelease = true;
|
||||
Info(_log, "Migration completed to version [%s]", BUILD_VERSION.getVersion().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Info(_log, "Migration from current version [%s] to new version [%s] started", _previousVersion.getVersion().c_str(), BUILD_VERSION.getVersion().c_str());
|
||||
|
||||
newGeneralConfig["previousVersion"] = _configVersion.getVersion().c_str();
|
||||
newGeneralConfig["configVersion"] = BUILD_VERSION.getVersion().c_str();
|
||||
dbConfig["general"] = newGeneralConfig;
|
||||
isNewRelease = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// possible data upgrade steps to prevent data loss
|
||||
bool migrated = handleConfigUpgrade(dbConfig);
|
||||
if (isNewRelease || migrated)
|
||||
{
|
||||
saveSettings(dbConfig, true);
|
||||
}
|
||||
|
||||
// validate full dbconfig against schema, on error we need to rewrite entire table
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
schemaChecker.setSchema(schemaJson);
|
||||
QPair<bool, bool> valid = schemaChecker.validate(dbConfig);
|
||||
// check if our main schema syntax is IO
|
||||
if (!valid.second)
|
||||
{
|
||||
for (auto& schemaError : schemaChecker.getMessages())
|
||||
{
|
||||
Error(_log, "Schema Syntax Error: %s", QSTRING_CSTR(schemaError));
|
||||
}
|
||||
throw std::runtime_error("The config schema has invalid syntax. This should never happen! Go fix it!");
|
||||
}
|
||||
if (!valid.first)
|
||||
{
|
||||
Info(_log, "Table upgrade required...");
|
||||
dbConfig = schemaChecker.getAutoCorrectedConfig(dbConfig);
|
||||
|
||||
for (auto& schemaError : schemaChecker.getMessages())
|
||||
{
|
||||
Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError));
|
||||
}
|
||||
|
||||
saveSettings(dbConfig, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_qconfig = dbConfig;
|
||||
}
|
||||
|
||||
Debug(_log, "Settings database initialized");
|
||||
_sTable->addMissingDefaults();
|
||||
}
|
||||
|
||||
QJsonDocument SettingsManager::getSetting(settings::type type) const
|
||||
{
|
||||
return _sTable->getSettingsRecord(settings::typeToString(type));
|
||||
return getSetting(settings::typeToString(type));
|
||||
}
|
||||
|
||||
QJsonObject SettingsManager::getSettings() const
|
||||
QJsonDocument SettingsManager::getSetting(const QString& type) const
|
||||
{
|
||||
QJsonObject config;
|
||||
for (const auto& key : _qconfig.keys())
|
||||
{
|
||||
//Read all records from database to ensure that global settings are read across instances
|
||||
QJsonDocument doc = _sTable->getSettingsRecord(key);
|
||||
if (doc.isArray())
|
||||
{
|
||||
config.insert(key, doc.array());
|
||||
}
|
||||
else
|
||||
{
|
||||
config.insert(key, doc.object());
|
||||
}
|
||||
}
|
||||
return config;
|
||||
return _sTable->getSettingsRecord(type);
|
||||
}
|
||||
|
||||
bool SettingsManager::restoreSettings(QJsonObject config, bool correct)
|
||||
QJsonObject SettingsManager::getSettings(const QStringList& filteredTypes ) const
|
||||
{
|
||||
// optional data upgrades e.g. imported legacy/older configs
|
||||
handleConfigUpgrade(config);
|
||||
return saveSettings(config, correct);
|
||||
return _sTable->getSettings(filteredTypes);
|
||||
}
|
||||
|
||||
bool SettingsManager::saveSettings(QJsonObject config, bool correct)
|
||||
QJsonObject SettingsManager::getSettings(const QVariant& instance, const QStringList& filteredTypes ) const
|
||||
{
|
||||
// we need to validate data against schema
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
schemaChecker.setSchema(schemaJson);
|
||||
if (!schemaChecker.validate(config).first)
|
||||
{
|
||||
if (!correct)
|
||||
{
|
||||
Error(_log, "Failed to save configuration, errors during validation");
|
||||
return false;
|
||||
}
|
||||
Warning(_log, "Fixing json data!");
|
||||
config = schemaChecker.getAutoCorrectedConfig(config);
|
||||
|
||||
for (const auto& schemaError : schemaChecker.getMessages())
|
||||
{
|
||||
Warning(_log, "Config Fix: %s", QSTRING_CSTR(schemaError));
|
||||
}
|
||||
return _sTable->getSettings(instance, filteredTypes);
|
||||
}
|
||||
|
||||
// store the new config
|
||||
_qconfig = config;
|
||||
|
||||
// extract keys and data
|
||||
const QStringList keyList = config.keys();
|
||||
QStringList newValueList;
|
||||
for (const auto& key : keyList)
|
||||
QPair<bool, QStringList> SettingsManager::saveSettings(const QJsonObject& config)
|
||||
{
|
||||
if (config[key].isObject())
|
||||
QStringList errorList;
|
||||
for (auto &key : config.keys())
|
||||
{
|
||||
newValueList << QString(QJsonDocument(config[key].toObject()).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
else if (config[key].isArray())
|
||||
{
|
||||
newValueList << QString(QJsonDocument(config[key].toArray()).toJson(QJsonDocument::Compact));
|
||||
}
|
||||
}
|
||||
|
||||
bool rc = true;
|
||||
// compare database data with new data to emit/save changes accordingly
|
||||
for (const auto& key : keyList)
|
||||
{
|
||||
QString data = newValueList.takeFirst();
|
||||
const QJsonValue configItem = config.value(key);
|
||||
const QString data = JsonUtils::jsonValueToQString(configItem);
|
||||
if (_sTable->getSettingsRecordString(key) != data)
|
||||
{
|
||||
if (!_sTable->createSettingsRecord(key, data))
|
||||
{
|
||||
rc = false;
|
||||
errorList.append(QString("Failed to save configuration item: %1").arg(key));
|
||||
return qMakePair (false, errorList);
|
||||
}
|
||||
else
|
||||
{
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(data.toUtf8(), &error);
|
||||
if (error.error != QJsonParseError::NoError) {
|
||||
Error(_log, "Error parsing JSON: %s", QSTRING_CSTR(error.errorString()));
|
||||
rc = false;
|
||||
emit settingsChanged(settings::stringToType(key), QJsonDocument::fromVariant(configItem.toVariant()));
|
||||
}
|
||||
else {
|
||||
emit settingsChanged(settings::stringToType(key), jsonDocument);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
inline QString fixVersion(const QString& version)
|
||||
{
|
||||
QString newVersion;
|
||||
//Try fixing version number, remove dot separated pre-release identifiers not supported
|
||||
QRegularExpression regEx("(\\d+\\.\\d+\\.\\d+-?[a-zA-Z-\\d]*\\.?[\\d]*)", QRegularExpression::CaseInsensitiveOption | QRegularExpression::MultilineOption);
|
||||
QRegularExpressionMatch match;
|
||||
|
||||
match = regEx.match(version);
|
||||
if (match.hasMatch())
|
||||
{
|
||||
newVersion = match.captured(1);
|
||||
}
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
bool SettingsManager::resolveConfigVersion(QJsonObject& config)
|
||||
{
|
||||
bool isValid = false;
|
||||
if (config.contains("general"))
|
||||
{
|
||||
QJsonObject generalConfig = config["general"].toObject();
|
||||
QString configVersion = generalConfig["configVersion"].toString();
|
||||
QString previousVersion = generalConfig["previousVersion"].toString();
|
||||
|
||||
if (!configVersion.isEmpty())
|
||||
{
|
||||
isValid = _configVersion.setVersion(configVersion.toStdString());
|
||||
if (!isValid)
|
||||
{
|
||||
isValid = _configVersion.setVersion(fixVersion(configVersion).toStdString());
|
||||
if (isValid)
|
||||
{
|
||||
Info(_log, "Invalid config version [%s] fixed. Updated to [%s]", QSTRING_CSTR(configVersion), _configVersion.getVersion().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
isValid = true;
|
||||
}
|
||||
|
||||
if (!previousVersion.isEmpty() && isValid)
|
||||
{
|
||||
isValid = _previousVersion.setVersion(previousVersion.toStdString());
|
||||
if (!isValid)
|
||||
{
|
||||
isValid = _previousVersion.setVersion(fixVersion(previousVersion).toStdString());
|
||||
if (isValid)
|
||||
{
|
||||
Info(_log, "Invalid previous version [%s] fixed. Updated to [%s]", QSTRING_CSTR(previousVersion), _previousVersion.getVersion().c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_previousVersion.setVersion(DEFAULT_VERSION);
|
||||
isValid = true;
|
||||
}
|
||||
}
|
||||
return isValid;
|
||||
}
|
||||
|
||||
bool SettingsManager::handleConfigUpgrade(QJsonObject& config)
|
||||
{
|
||||
bool migrated = false;
|
||||
|
||||
//Only migrate, if valid versions are available
|
||||
if (!resolveConfigVersion(config))
|
||||
{
|
||||
Warning(_log, "Invalid version information found in configuration. No database migration executed.");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Do only migrate, if configuration is not up to date
|
||||
if (_previousVersion < _configVersion)
|
||||
{
|
||||
//Migration steps for versions <= alpha 9
|
||||
semver::version targetVersion{ "2.0.0-alpha.9" };
|
||||
if (_previousVersion <= targetVersion)
|
||||
{
|
||||
Info(_log, "Instance [%u]: Migrate from version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
|
||||
// LED LAYOUT UPGRADE
|
||||
// from { hscan: { minimum: 0.2, maximum: 0.3 }, vscan: { minimum: 0.2, maximum: 0.3 } }
|
||||
// from { h: { min: 0.2, max: 0.3 }, v: { min: 0.2, max: 0.3 } }
|
||||
// to { hmin: 0.2, hmax: 0.3, vmin: 0.2, vmax: 0.3}
|
||||
if (config.contains("leds"))
|
||||
{
|
||||
const QJsonArray ledarr = config["leds"].toArray();
|
||||
const QJsonObject led = ledarr[0].toObject();
|
||||
|
||||
if (led.contains("hscan") || led.contains("h"))
|
||||
{
|
||||
const bool whscan = led.contains("hscan");
|
||||
QJsonArray newLedarr;
|
||||
|
||||
for (const auto& entry : ledarr)
|
||||
{
|
||||
const QJsonObject led = entry.toObject();
|
||||
QJsonObject hscan;
|
||||
QJsonObject vscan;
|
||||
QJsonValue hmin;
|
||||
QJsonValue hmax;
|
||||
QJsonValue vmin;
|
||||
QJsonValue vmax;
|
||||
QJsonObject nL;
|
||||
|
||||
if (whscan)
|
||||
{
|
||||
hscan = led["hscan"].toObject();
|
||||
vscan = led["vscan"].toObject();
|
||||
hmin = hscan["minimum"];
|
||||
hmax = hscan["maximum"];
|
||||
vmin = vscan["minimum"];
|
||||
vmax = vscan["maximum"];
|
||||
}
|
||||
else
|
||||
{
|
||||
hscan = led["h"].toObject();
|
||||
vscan = led["v"].toObject();
|
||||
hmin = hscan["min"];
|
||||
hmax = hscan["max"];
|
||||
vmin = vscan["min"];
|
||||
vmax = vscan["max"];
|
||||
}
|
||||
// append to led object
|
||||
nL["hmin"] = hmin;
|
||||
nL["hmax"] = hmax;
|
||||
nL["vmin"] = vmin;
|
||||
nL["vmax"] = vmax;
|
||||
newLedarr.append(nL);
|
||||
}
|
||||
// replace
|
||||
config["leds"] = newLedarr;
|
||||
migrated = true;
|
||||
Info(_log, "Instance [%u]: LED Layout migrated", _instance);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.contains("ledConfig"))
|
||||
{
|
||||
QJsonObject oldLedConfig = config["ledConfig"].toObject();
|
||||
if (!oldLedConfig.contains("classic"))
|
||||
{
|
||||
QJsonObject newLedConfig;
|
||||
newLedConfig.insert("classic", oldLedConfig);
|
||||
QJsonObject defaultMatrixConfig{ {"ledshoriz", 1}
|
||||
,{"ledsvert", 1}
|
||||
,{"cabling","snake"}
|
||||
,{"start","top-left"}
|
||||
};
|
||||
newLedConfig.insert("matrix", defaultMatrixConfig);
|
||||
|
||||
config["ledConfig"] = newLedConfig;
|
||||
migrated = true;
|
||||
Info(_log, "Instance [%u]: LED-Config migrated", _instance);
|
||||
}
|
||||
}
|
||||
|
||||
// LED Hardware count is leading for versions after alpha 9
|
||||
// Setting Hardware LED count to number of LEDs configured via layout, if layout number is greater than number of hardware LEDs
|
||||
if (config.contains("device"))
|
||||
{
|
||||
QJsonObject newDeviceConfig = config["device"].toObject();
|
||||
|
||||
if (newDeviceConfig.contains("hardwareLedCount"))
|
||||
{
|
||||
int hwLedcount = newDeviceConfig["hardwareLedCount"].toInt();
|
||||
if (config.contains("leds"))
|
||||
{
|
||||
const QJsonArray ledarr = config["leds"].toArray();
|
||||
int layoutLedCount = ledarr.size();
|
||||
|
||||
if (hwLedcount < layoutLedCount)
|
||||
{
|
||||
Warning(_log, "Instance [%u]: HwLedCount/Layout mismatch! Setting Hardware LED count to number of LEDs configured via layout", _instance);
|
||||
hwLedcount = layoutLedCount;
|
||||
newDeviceConfig["hardwareLedCount"] = hwLedcount;
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newDeviceConfig.contains("type"))
|
||||
{
|
||||
QString type = newDeviceConfig["type"].toString();
|
||||
if (type == "atmoorb" || type == "fadecandy" || type == "philipshue")
|
||||
{
|
||||
if (newDeviceConfig.contains("output"))
|
||||
{
|
||||
newDeviceConfig["host"] = newDeviceConfig["output"].toString();
|
||||
newDeviceConfig.remove("output");
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["device"] = newDeviceConfig;
|
||||
Debug(_log, "LED-Device records migrated");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.contains("grabberV4L2"))
|
||||
{
|
||||
QJsonObject newGrabberV4L2Config = config["grabberV4L2"].toObject();
|
||||
|
||||
if (newGrabberV4L2Config.contains("encoding_format"))
|
||||
{
|
||||
newGrabberV4L2Config.remove("encoding_format");
|
||||
newGrabberV4L2Config["grabberV4L2"] = newGrabberV4L2Config;
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
//Add new element enable
|
||||
if (!newGrabberV4L2Config.contains("enable"))
|
||||
{
|
||||
newGrabberV4L2Config["enable"] = false;
|
||||
migrated = true;
|
||||
}
|
||||
config["grabberV4L2"] = newGrabberV4L2Config;
|
||||
Debug(_log, "GrabberV4L2 records migrated");
|
||||
}
|
||||
|
||||
if (config.contains("grabberAudio"))
|
||||
{
|
||||
QJsonObject newGrabberAudioConfig = config["grabberAudio"].toObject();
|
||||
|
||||
//Add new element enable
|
||||
if (!newGrabberAudioConfig.contains("enable"))
|
||||
{
|
||||
newGrabberAudioConfig["enable"] = false;
|
||||
migrated = true;
|
||||
}
|
||||
config["grabberAudio"] = newGrabberAudioConfig;
|
||||
Debug(_log, "GrabberAudio records migrated");
|
||||
}
|
||||
|
||||
if (config.contains("framegrabber"))
|
||||
{
|
||||
QJsonObject newFramegrabberConfig = config["framegrabber"].toObject();
|
||||
|
||||
//Align element namings with grabberV4L2
|
||||
//Rename element type -> device
|
||||
if (newFramegrabberConfig.contains("type"))
|
||||
{
|
||||
newFramegrabberConfig["device"] = newFramegrabberConfig["type"].toString();
|
||||
newFramegrabberConfig.remove("type");
|
||||
migrated = true;
|
||||
}
|
||||
//Rename element frequency_Hz -> fps
|
||||
if (newFramegrabberConfig.contains("frequency_Hz"))
|
||||
{
|
||||
newFramegrabberConfig["fps"] = newFramegrabberConfig["frequency_Hz"].toInt(25);
|
||||
newFramegrabberConfig.remove("frequency_Hz");
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
//Rename element display -> input
|
||||
if (newFramegrabberConfig.contains("display"))
|
||||
{
|
||||
newFramegrabberConfig["input"] = newFramegrabberConfig["display"];
|
||||
newFramegrabberConfig.remove("display");
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
//Add new element enable
|
||||
if (!newFramegrabberConfig.contains("enable"))
|
||||
{
|
||||
newFramegrabberConfig["enable"] = false;
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
config["framegrabber"] = newFramegrabberConfig;
|
||||
Debug(_log, "Framegrabber records migrated");
|
||||
}
|
||||
}
|
||||
|
||||
//Migration steps for versions <= 2.0.12
|
||||
_previousVersion = targetVersion;
|
||||
targetVersion.setVersion("2.0.12");
|
||||
if (_previousVersion <= targetVersion)
|
||||
{
|
||||
Info(_log, "Instance [%u]: Migrate from version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
|
||||
// Have Hostname/IP-address separate from port for LED-Devices
|
||||
if (config.contains("device"))
|
||||
{
|
||||
QJsonObject newDeviceConfig = config["device"].toObject();
|
||||
|
||||
if (newDeviceConfig.contains("host"))
|
||||
{
|
||||
QString oldHost = newDeviceConfig["host"].toString();
|
||||
|
||||
// Resolve hostname and port
|
||||
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
|
||||
newDeviceConfig["host"] = addressparts[0];
|
||||
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
if (!newDeviceConfig.contains("port"))
|
||||
{
|
||||
newDeviceConfig["port"] = addressparts[1].toInt();
|
||||
}
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (newDeviceConfig.contains("type"))
|
||||
{
|
||||
QString type = newDeviceConfig["type"].toString();
|
||||
if (type == "apa102")
|
||||
{
|
||||
if (newDeviceConfig.contains("colorOrder"))
|
||||
{
|
||||
QString colorOrder = newDeviceConfig["colorOrder"].toString();
|
||||
if (colorOrder == "bgr")
|
||||
{
|
||||
newDeviceConfig["colorOrder"] = "rgb";
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["device"] = newDeviceConfig;
|
||||
Debug(_log, "LED-Device records migrated");
|
||||
}
|
||||
}
|
||||
|
||||
// Have Hostname/IP-address separate from port for Forwarder
|
||||
if (config.contains("forwarder"))
|
||||
{
|
||||
QJsonObject newForwarderConfig = config["forwarder"].toObject();
|
||||
|
||||
QJsonArray json;
|
||||
if (newForwarderConfig.contains("json"))
|
||||
{
|
||||
const QJsonArray oldJson = newForwarderConfig["json"].toArray();
|
||||
QJsonObject newJsonConfig;
|
||||
|
||||
for (const QJsonValue& value : oldJson)
|
||||
{
|
||||
if (value.isString())
|
||||
{
|
||||
QString oldHost = value.toString();
|
||||
// Resolve hostname and port
|
||||
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
QString host = addressparts[0];
|
||||
|
||||
if (host != "127.0.0.1")
|
||||
{
|
||||
newJsonConfig["host"] = host;
|
||||
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
newJsonConfig["port"] = addressparts[1].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
newJsonConfig["port"] = 19444;
|
||||
}
|
||||
newJsonConfig["name"] = host;
|
||||
|
||||
json.append(newJsonConfig);
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!json.isEmpty())
|
||||
{
|
||||
newForwarderConfig["jsonapi"] = json;
|
||||
}
|
||||
newForwarderConfig.remove("json");
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
QJsonArray flatbuffer;
|
||||
if (newForwarderConfig.contains("flat"))
|
||||
{
|
||||
const QJsonArray oldFlatbuffer = newForwarderConfig["flat"].toArray();
|
||||
QJsonObject newFlattbufferConfig;
|
||||
|
||||
for (const QJsonValue& value : oldFlatbuffer)
|
||||
{
|
||||
if (value.isString())
|
||||
{
|
||||
QString oldHost = value.toString();
|
||||
// Resolve hostname and port
|
||||
QStringList addressparts = QStringUtils::split(oldHost, ":", QStringUtils::SplitBehavior::SkipEmptyParts);
|
||||
QString host = addressparts[0];
|
||||
|
||||
if (host != "127.0.0.1")
|
||||
{
|
||||
newFlattbufferConfig["host"] = host;
|
||||
|
||||
if (addressparts.size() > 1)
|
||||
{
|
||||
newFlattbufferConfig["port"] = addressparts[1].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
newFlattbufferConfig["port"] = 19400;
|
||||
}
|
||||
newFlattbufferConfig["name"] = host;
|
||||
|
||||
flatbuffer.append(newFlattbufferConfig);
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flatbuffer.isEmpty())
|
||||
{
|
||||
newForwarderConfig["flatbuffer"] = flatbuffer;
|
||||
}
|
||||
newForwarderConfig.remove("flat");
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (json.isEmpty() && flatbuffer.isEmpty())
|
||||
{
|
||||
newForwarderConfig["enable"] = false;
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["forwarder"] = newForwarderConfig;
|
||||
Debug(_log, "Forwarder records migrated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Migration steps for versions <= 2.0.13
|
||||
_previousVersion = targetVersion;
|
||||
targetVersion.setVersion("2.0.13");
|
||||
if (_previousVersion <= targetVersion)
|
||||
{
|
||||
Info(_log, "Instance [%u]: Migrate from version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
|
||||
|
||||
// Have Hostname/IP-address separate from port for LED-Devices
|
||||
if (config.contains("device"))
|
||||
{
|
||||
QJsonObject newDeviceConfig = config["device"].toObject();
|
||||
|
||||
if (newDeviceConfig.contains("type"))
|
||||
{
|
||||
QString type = newDeviceConfig["type"].toString();
|
||||
|
||||
const QStringList serialDevices{ "adalight", "dmx", "atmo", "sedu", "tpm2", "karate" };
|
||||
if (serialDevices.contains(type))
|
||||
{
|
||||
if (!newDeviceConfig.contains("rateList"))
|
||||
{
|
||||
newDeviceConfig["rateList"] = "CUSTOM";
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (type == "adalight")
|
||||
{
|
||||
if (newDeviceConfig.contains("lightberry_apa102_mode"))
|
||||
{
|
||||
bool lightberry_apa102_mode = newDeviceConfig["lightberry_apa102_mode"].toBool();
|
||||
if (lightberry_apa102_mode)
|
||||
{
|
||||
newDeviceConfig["streamProtocol"] = "1";
|
||||
}
|
||||
else
|
||||
{
|
||||
newDeviceConfig["streamProtocol"] = "0";
|
||||
}
|
||||
newDeviceConfig.remove("lightberry_apa102_mode");
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["device"] = newDeviceConfig;
|
||||
Debug(_log, "LED-Device records migrated");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Migration steps for versions <= 2.0.16
|
||||
_previousVersion = targetVersion;
|
||||
targetVersion.setVersion("2.0.16");
|
||||
if (_previousVersion <= targetVersion)
|
||||
{
|
||||
Info(_log, "Instance [%u]: Migrate from version [%s] to version [%s] or later", _instance, _previousVersion.getVersion().c_str(), targetVersion.getVersion().c_str());
|
||||
|
||||
// Have Hostname/IP-address separate from port for LED-Devices
|
||||
if (config.contains("device"))
|
||||
{
|
||||
QJsonObject newDeviceConfig = config["device"].toObject();
|
||||
|
||||
if (newDeviceConfig.contains("type"))
|
||||
{
|
||||
QString type = newDeviceConfig["type"].toString();
|
||||
|
||||
if (type == "philipshue")
|
||||
{
|
||||
if (newDeviceConfig.contains("groupId"))
|
||||
{
|
||||
if (newDeviceConfig["groupId"].isDouble())
|
||||
{
|
||||
int groupID = newDeviceConfig["groupId"].toInt();
|
||||
newDeviceConfig["groupId"] = QString::number(groupID);
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (newDeviceConfig.contains("lightIds"))
|
||||
{
|
||||
QJsonArray lightIds = newDeviceConfig.value("lightIds").toArray();
|
||||
// Iterate through the JSON array and update integer values to strings
|
||||
for (int i = 0; i < lightIds.size(); ++i) {
|
||||
QJsonValue value = lightIds.at(i);
|
||||
if (value.isDouble())
|
||||
{
|
||||
int lightId = value.toInt();
|
||||
lightIds.replace(i, QString::number(lightId));
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
newDeviceConfig["lightIds"] = lightIds;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (type == "nanoleaf")
|
||||
{
|
||||
if (newDeviceConfig.contains("panelStartPos"))
|
||||
{
|
||||
newDeviceConfig.remove("panelStartPos");
|
||||
migrated = true;
|
||||
}
|
||||
|
||||
if (newDeviceConfig.contains("panelOrderTopDown"))
|
||||
{
|
||||
int panelOrderTopDown;
|
||||
if (newDeviceConfig["panelOrderTopDown"].isDouble())
|
||||
{
|
||||
panelOrderTopDown = newDeviceConfig["panelOrderTopDown"].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
panelOrderTopDown = newDeviceConfig["panelOrderTopDown"].toString().toInt();
|
||||
}
|
||||
|
||||
newDeviceConfig.remove("panelOrderTopDown");
|
||||
if (panelOrderTopDown == 0)
|
||||
{
|
||||
newDeviceConfig["panelOrderTopDown"] = "top2down";
|
||||
migrated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (panelOrderTopDown == 1)
|
||||
{
|
||||
newDeviceConfig["panelOrderTopDown"] = "bottom2up";
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newDeviceConfig.contains("panelOrderLeftRight"))
|
||||
{
|
||||
int panelOrderLeftRight;
|
||||
if (newDeviceConfig["panelOrderLeftRight"].isDouble())
|
||||
{
|
||||
panelOrderLeftRight = newDeviceConfig["panelOrderLeftRight"].toInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
panelOrderLeftRight = newDeviceConfig["panelOrderLeftRight"].toString().toInt();
|
||||
}
|
||||
|
||||
newDeviceConfig.remove("panelOrderLeftRight");
|
||||
if (panelOrderLeftRight == 0)
|
||||
{
|
||||
newDeviceConfig["panelOrderLeftRight"] = "left2right";
|
||||
migrated = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (panelOrderLeftRight == 1)
|
||||
{
|
||||
newDeviceConfig["panelOrderLeftRight"] = "right2left";
|
||||
migrated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (migrated)
|
||||
{
|
||||
config["device"] = newDeviceConfig;
|
||||
Debug(_log, "LED-Device records migrated");
|
||||
}
|
||||
}
|
||||
|
||||
if (config.contains("cecEvents"))
|
||||
{
|
||||
bool isCECEnabled {false};
|
||||
if (config.contains("grabberV4L2"))
|
||||
{
|
||||
QJsonObject newGrabberV4L2Config = config["grabberV4L2"].toObject();
|
||||
if (newGrabberV4L2Config.contains("cecDetection"))
|
||||
{
|
||||
isCECEnabled = newGrabberV4L2Config.value("cecDetection").toBool(false);
|
||||
newGrabberV4L2Config.remove("cecDetection");
|
||||
config["grabberV4L2"] = newGrabberV4L2Config;
|
||||
|
||||
QJsonObject newGCecEventsConfig = config["cecEvents"].toObject();
|
||||
newGCecEventsConfig["enable"] = isCECEnabled;
|
||||
if (!newGCecEventsConfig.contains("actions"))
|
||||
{
|
||||
QJsonObject action1
|
||||
{
|
||||
{"action", "Suspend"},
|
||||
{"event", "standby"}
|
||||
};
|
||||
QJsonObject action2
|
||||
{
|
||||
{"action", "Resume"},
|
||||
{"event", "set stream path"}
|
||||
};
|
||||
|
||||
QJsonArray actions { action1, action2 };
|
||||
newGCecEventsConfig.insert("actions",actions);
|
||||
}
|
||||
config["cecEvents"] = newGCecEventsConfig;
|
||||
|
||||
migrated = true;
|
||||
Debug(_log, "CEC configuration records migrated");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return migrated;
|
||||
return qMakePair (true, errorList );
|
||||
}
|
||||
|
@ -1,108 +0,0 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"required" : true,
|
||||
"properties" :
|
||||
{
|
||||
"general" :
|
||||
{
|
||||
"$ref": "schema-general.json"
|
||||
},
|
||||
"logger" :
|
||||
{
|
||||
"$ref": "schema-logger.json"
|
||||
},
|
||||
"device" :
|
||||
{
|
||||
"$ref": "schema-device.json"
|
||||
},
|
||||
"color" :
|
||||
{
|
||||
"$ref": "schema-color.json"
|
||||
},
|
||||
"smoothing":
|
||||
{
|
||||
"$ref": "schema-smoothing.json"
|
||||
},
|
||||
"grabberV4L2" :
|
||||
{
|
||||
"$ref": "schema-grabberV4L2.json"
|
||||
},
|
||||
"grabberAudio" :
|
||||
{
|
||||
"$ref": "schema-grabberAudio.json"
|
||||
},
|
||||
"framegrabber" :
|
||||
{
|
||||
"$ref": "schema-framegrabber.json"
|
||||
},
|
||||
"blackborderdetector" :
|
||||
{
|
||||
"$ref": "schema-blackborderdetector.json"
|
||||
},
|
||||
"foregroundEffect" :
|
||||
{
|
||||
"$ref": "schema-foregroundEffect.json"
|
||||
},
|
||||
"backgroundEffect" :
|
||||
{
|
||||
"$ref": "schema-backgroundEffect.json"
|
||||
},
|
||||
"forwarder" :
|
||||
{
|
||||
"$ref": "schema-forwarder.json"
|
||||
},
|
||||
"jsonServer" :
|
||||
{
|
||||
"$ref": "schema-jsonServer.json"
|
||||
},
|
||||
"flatbufServer":
|
||||
{
|
||||
"$ref": "schema-flatbufServer.json"
|
||||
},
|
||||
"protoServer" :
|
||||
{
|
||||
"$ref": "schema-protoServer.json"
|
||||
},
|
||||
"boblightServer" :
|
||||
{
|
||||
"$ref": "schema-boblightServer.json"
|
||||
},
|
||||
"webConfig" :
|
||||
{
|
||||
"$ref": "schema-webConfig.json"
|
||||
},
|
||||
"effects" :
|
||||
{
|
||||
"$ref": "schema-effects.json"
|
||||
},
|
||||
"instCapture":
|
||||
{
|
||||
"$ref": "schema-instCapture.json"
|
||||
},
|
||||
"network":
|
||||
{
|
||||
"$ref": "schema-network.json"
|
||||
},
|
||||
"ledConfig":
|
||||
{
|
||||
"$ref": "schema-ledConfig.json"
|
||||
},
|
||||
"leds":
|
||||
{
|
||||
"$ref": "schema-leds.json"
|
||||
},
|
||||
"osEvents":
|
||||
{
|
||||
"$ref": "schema-osEvents.json"
|
||||
},
|
||||
"cecEvents":
|
||||
{
|
||||
"$ref": "schema-cecEvents.json"
|
||||
},
|
||||
"schedEvents":
|
||||
{
|
||||
"$ref": "schema-schedEvents.json"
|
||||
}
|
||||
},
|
||||
"additionalProperties" : false
|
||||
}
|
@ -1,31 +1,39 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file alias="hyperion-schema">hyperion.schema.json</file>
|
||||
<file alias="schema-general.json">schema/schema-general.json</file>
|
||||
<file alias="schema-logger.json">schema/schema-logger.json</file>
|
||||
<file alias="schema-device.json">schema/schema-device.json</file>
|
||||
<file alias="schema-color.json">schema/schema-color.json</file>
|
||||
<file alias="schema-smoothing.json">schema/schema-smoothing.json</file>
|
||||
<file alias="schema-grabberV4L2.json">schema/schema-grabberV4L2.json</file>
|
||||
<file alias="schema-grabberAudio.json">schema/schema-grabberAudio.json</file>
|
||||
<file alias="schema-framegrabber.json">schema/schema-framegrabber.json</file>
|
||||
<file alias="schema-blackborderdetector.json">schema/schema-blackborderdetector.json</file>
|
||||
<file alias="schema-foregroundEffect.json">schema/schema-foregroundEffect.json</file>
|
||||
<file alias="schema-backgroundEffect.json">schema/schema-backgroundEffect.json</file>
|
||||
<file alias="schema-forwarder.json">schema/schema-forwarder.json</file>
|
||||
<file alias="schema-jsonServer.json">schema/schema-jsonServer.json</file>
|
||||
<file alias="schema-flatbufServer.json">schema/schema-flatbufServer.json</file>
|
||||
<file alias="schema-protoServer.json">schema/schema-protoServer.json</file>
|
||||
<file alias="schema-blackborderdetector.json">schema/schema-blackborderdetector.json</file>
|
||||
<file alias="schema-boblightServer.json">schema/schema-boblightServer.json</file>
|
||||
<file alias="schema-webConfig.json">schema/schema-webConfig.json</file>
|
||||
<file alias="schema-cecEvents.json">schema/schema-cecEvents.json</file>
|
||||
<file alias="schema-color.json">schema/schema-color.json</file>
|
||||
<file alias="schema-device.json">schema/schema-device.json</file>
|
||||
<file alias="schema-effects.json">schema/schema-effects.json</file>
|
||||
<file alias="schema-eventActions.json">schema/schema-eventActions.json</file>
|
||||
<file alias="schema-flatbufServer.json">schema/schema-flatbufServer.json</file>
|
||||
<file alias="schema-forwarder.json">schema/schema-forwarder.json</file>
|
||||
<file alias="schema-framegrabber.json">schema/schema-framegrabber.json</file>
|
||||
<file alias="schema-foregroundEffect.json">schema/schema-foregroundEffect.json</file>
|
||||
<file alias="schema-general.json">schema/schema-general.json</file>
|
||||
<file alias="schema-grabberAudio.json">schema/schema-grabberAudio.json</file>
|
||||
<file alias="schema-grabberV4L2.json">schema/schema-grabberV4L2.json</file>
|
||||
<file alias="schema-instCapture.json">schema/schema-instCapture.json</file>
|
||||
<file alias="schema-jsonServer.json">schema/schema-jsonServer.json</file>
|
||||
<file alias="schema-ledConfig.json">schema/schema-ledConfig.json</file>
|
||||
<file alias="schema-leds.json">schema/schema-leds.json</file>
|
||||
<file alias="schema-instCapture.json">schema/schema-instCapture.json</file>
|
||||
<file alias="schema-logger.json">schema/schema-logger.json</file>
|
||||
<file alias="schema-network.json">schema/schema-network.json</file>
|
||||
<file alias="schema-eventActions.json">schema/schema-eventActions.json</file>
|
||||
<file alias="schema-schedEvents.json">schema/schema-schedEvents.json</file>
|
||||
<file alias="schema-osEvents.json">schema/schema-osEvents.json</file>
|
||||
<file alias="schema-cecEvents.json">schema/schema-cecEvents.json</file>
|
||||
<file alias="schema-protoServer.json">schema/schema-protoServer.json</file>
|
||||
<file alias="schema-schedEvents.json">schema/schema-schedEvents.json</file>
|
||||
<file alias="schema-smoothing.json">schema/schema-smoothing.json</file>
|
||||
<file alias="schema-webConfig.json">schema/schema-webConfig.json</file>
|
||||
|
||||
<file alias="schema-settings-default.json">schema/schema-settings-default.json</file>
|
||||
<file alias="schema-settings-full.json">schema/schema-settings-full.json</file>
|
||||
<file alias="schema-settings-full-relaxed.json">schema/schema-settings-full-relaxed.json</file>
|
||||
<file alias="schema-settings-global.json">schema/schema-settings-global.json</file>
|
||||
<file alias="schema-settings-global-relaxed.json">schema/schema-settings-global-relaxed.json</file>
|
||||
<file alias="schema-settings-instance.json">schema/schema-settings-instance.json</file>
|
||||
<file alias="schema-settings-instance-relaxed.json">schema/schema-settings-instance-relaxed.json</file>
|
||||
<file alias="schema-settings-ui.json">schema/schema-settings-ui.json</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"type": "object",
|
||||
"required": true,
|
||||
"properties": {
|
||||
"enable": {
|
||||
"type": "boolean",
|
||||
|
@ -1,7 +1,6 @@
|
||||
{
|
||||
"type":"object",
|
||||
"title" : "edt_conf_color_heading_title",
|
||||
"required" : true,
|
||||
"properties":
|
||||
{
|
||||
"imageToLedMappingType" :
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"required" : true,
|
||||
"title" : "edt_conf_fbs_heading_title",
|
||||
"properties" :
|
||||
{
|
||||
|
@ -7,6 +7,7 @@
|
||||
{
|
||||
"type" : "boolean",
|
||||
"title" : "edt_conf_general_enable_title",
|
||||
"required" : true,
|
||||
"default" : true,
|
||||
"propertyOrder" : 1
|
||||
},
|
||||
|
@ -1,7 +1,6 @@
|
||||
{
|
||||
"type": "object",
|
||||
"title": "edt_conf_fw_heading_title",
|
||||
"required": true,
|
||||
"properties": {
|
||||
"enable": {
|
||||
"type": "boolean",
|
||||
|
@ -1,7 +1,6 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"title" : "edt_conf_gen_heading_title",
|
||||
"required" : true,
|
||||
"properties" :
|
||||
{
|
||||
"name" :
|
||||
@ -44,15 +43,6 @@
|
||||
},
|
||||
"access" : "expert",
|
||||
"propertyOrder" : 4
|
||||
},
|
||||
"previousVersion" :
|
||||
{
|
||||
"type" : "string",
|
||||
"options" : {
|
||||
"hidden":true
|
||||
},
|
||||
"access" : "expert",
|
||||
"propertyOrder" : 5
|
||||
}
|
||||
},
|
||||
"additionalProperties" : false
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"type": "object",
|
||||
"required": true,
|
||||
"title": "edt_conf_audio_heading_title",
|
||||
"properties": {
|
||||
"enable": {
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"required" : true,
|
||||
"title" : "edt_conf_v4l2_heading_title",
|
||||
"properties":
|
||||
{
|
||||
@ -24,6 +23,7 @@
|
||||
"device": {
|
||||
"type": "string",
|
||||
"title": "edt_conf_enum_custom",
|
||||
"default": "none",
|
||||
"options": {
|
||||
"hidden": true
|
||||
},
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"required" : true,
|
||||
"title" : "edt_conf_instC_heading_title",
|
||||
"properties": {
|
||||
"systemEnable": {
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"required" : true,
|
||||
"title" : "edt_conf_js_heading_title",
|
||||
"properties" :
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"type": "array",
|
||||
"required": true,
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "object",
|
||||
|
@ -6,6 +6,7 @@
|
||||
"level" :
|
||||
{
|
||||
"type" : "string",
|
||||
"required" : true,
|
||||
"enum" : ["silent", "warn", "verbose", "debug"],
|
||||
"title" : "edt_conf_log_level_title",
|
||||
"options" : {
|
||||
|
@ -1,7 +1,6 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"title" : "edt_conf_net_heading_title",
|
||||
"required" : true,
|
||||
"properties" :
|
||||
{
|
||||
"internetAccessAPI" :
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"required" : true,
|
||||
"title" : "edt_conf_os_events_heading_title",
|
||||
"properties": {
|
||||
"suspendEnable": {
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"type" : "object",
|
||||
"required" : true,
|
||||
"title" : "edt_conf_pbs_heading_title",
|
||||
"properties" :
|
||||
{
|
||||
|
@ -1,6 +1,5 @@
|
||||
{
|
||||
"type": "object",
|
||||
"required": true,
|
||||
"properties": {
|
||||
"enable": {
|
||||
"type": "boolean",
|
||||
|
17
libsrc/hyperion/schema/schema-settings-default.json
Normal file
17
libsrc/hyperion/schema/schema-settings-default.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"global":{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"$ref":"schema-settings-global.json"
|
||||
},
|
||||
"instance":{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"$ref":"schema-settings-instance.json"
|
||||
}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}
|
59
libsrc/hyperion/schema/schema-settings-full-relaxed.json
Normal file
59
libsrc/hyperion/schema/schema-settings-full-relaxed.json
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"global":{
|
||||
"type":"object",
|
||||
"required":false,
|
||||
"properties":{
|
||||
"settings":{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"$ref":"schema-settings-global-relaxed.json"
|
||||
},
|
||||
"uuid":{
|
||||
"type":"string",
|
||||
"format":"uuid",
|
||||
"required":false
|
||||
}
|
||||
},
|
||||
"additionalProperties":false
|
||||
},
|
||||
"instanceIds":{
|
||||
"type":"array",
|
||||
"required":false,
|
||||
"items":{
|
||||
"type":"integer"
|
||||
},
|
||||
"minItems":1
|
||||
},
|
||||
"instances":{
|
||||
"type":"array",
|
||||
"required":false,
|
||||
"items":{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"enabled":{
|
||||
"type":"boolean"
|
||||
},
|
||||
"id":{
|
||||
"type":"integer",
|
||||
"minimum":0,
|
||||
"maximum":255
|
||||
},
|
||||
"name":{
|
||||
"type":"string",
|
||||
"minLength":5
|
||||
},
|
||||
"settings":{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"$ref":"schema-settings-instance-relaxed.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties":true
|
||||
},
|
||||
"additionalProperties":false
|
||||
}
|
59
libsrc/hyperion/schema/schema-settings-full.json
Normal file
59
libsrc/hyperion/schema/schema-settings-full.json
Normal file
@ -0,0 +1,59 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"global":{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"settings":{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"$ref":"schema-settings-global.json"
|
||||
},
|
||||
"uuid":{
|
||||
"type":"string",
|
||||
"format":"uuid",
|
||||
"required":false
|
||||
}
|
||||
},
|
||||
"additionalProperties":true
|
||||
},
|
||||
"instanceIds":{
|
||||
"type":"array",
|
||||
"required":false,
|
||||
"items":{
|
||||
"type":"integer"
|
||||
},
|
||||
"minItems":1
|
||||
},
|
||||
"instances":{
|
||||
"type":"array",
|
||||
"required":true,
|
||||
"items":{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"enabled":{
|
||||
"type":"boolean"
|
||||
},
|
||||
"id":{
|
||||
"type":"integer",
|
||||
"minimum":0,
|
||||
"maximum":255
|
||||
},
|
||||
"name":{
|
||||
"type":"string",
|
||||
"minLength":5
|
||||
},
|
||||
"settings":{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"$ref":"schema-settings-instance.json"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"additionalProperties":true
|
||||
},
|
||||
"additionalProperties":false
|
||||
}
|
62
libsrc/hyperion/schema/schema-settings-global-relaxed.json
Normal file
62
libsrc/hyperion/schema/schema-settings-global-relaxed.json
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"cecEvents":{
|
||||
"required":false,
|
||||
"$ref":"schema-cecEvents.json"
|
||||
},
|
||||
"flatbufServer":{
|
||||
"required":false,
|
||||
"$ref":"schema-flatbufServer.json"
|
||||
},
|
||||
"forwarder":{
|
||||
"required":false,
|
||||
"$ref":"schema-forwarder.json"
|
||||
},
|
||||
"framegrabber":{
|
||||
"required":false,
|
||||
"$ref":"schema-framegrabber.json"
|
||||
},
|
||||
"general":{
|
||||
"required":false,
|
||||
"$ref":"schema-general.json"
|
||||
},
|
||||
"grabberAudio":{
|
||||
"required":false,
|
||||
"$ref":"schema-grabberAudio.json"
|
||||
},
|
||||
"grabberV4L2":{
|
||||
"required":false,
|
||||
"$ref":"schema-grabberV4L2.json"
|
||||
},
|
||||
"jsonServer":{
|
||||
"required":false,
|
||||
"$ref":"schema-jsonServer.json"
|
||||
},
|
||||
"logger":{
|
||||
"required":false,
|
||||
"$ref":"schema-logger.json"
|
||||
},
|
||||
"network":{
|
||||
"required":false,
|
||||
"$ref":"schema-network.json"
|
||||
},
|
||||
"osEvents":{
|
||||
"required":false,
|
||||
"$ref":"schema-osEvents.json"
|
||||
},
|
||||
"protoServer":{
|
||||
"required":false,
|
||||
"$ref":"schema-protoServer.json"
|
||||
},
|
||||
"schedEvents":{
|
||||
"required":false,
|
||||
"$ref":"schema-schedEvents.json"
|
||||
},
|
||||
"webConfig":{
|
||||
"required":false,
|
||||
"$ref":"schema-webConfig.json"
|
||||
}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}
|
62
libsrc/hyperion/schema/schema-settings-global.json
Normal file
62
libsrc/hyperion/schema/schema-settings-global.json
Normal file
@ -0,0 +1,62 @@
|
||||
{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"cecEvents":{
|
||||
"required":true,
|
||||
"$ref":"schema-cecEvents.json"
|
||||
},
|
||||
"flatbufServer":{
|
||||
"required":true,
|
||||
"$ref":"schema-flatbufServer.json"
|
||||
},
|
||||
"forwarder":{
|
||||
"required":true,
|
||||
"$ref":"schema-forwarder.json"
|
||||
},
|
||||
"framegrabber":{
|
||||
"required":true,
|
||||
"$ref":"schema-framegrabber.json"
|
||||
},
|
||||
"general":{
|
||||
"required":true,
|
||||
"$ref":"schema-general.json"
|
||||
},
|
||||
"grabberAudio":{
|
||||
"required":true,
|
||||
"$ref":"schema-grabberAudio.json"
|
||||
},
|
||||
"grabberV4L2":{
|
||||
"required":true,
|
||||
"$ref":"schema-grabberV4L2.json"
|
||||
},
|
||||
"jsonServer":{
|
||||
"required":true,
|
||||
"$ref":"schema-jsonServer.json"
|
||||
},
|
||||
"logger":{
|
||||
"required":true,
|
||||
"$ref":"schema-logger.json"
|
||||
},
|
||||
"network":{
|
||||
"required":true,
|
||||
"$ref":"schema-network.json"
|
||||
},
|
||||
"osEvents":{
|
||||
"required":true,
|
||||
"$ref":"schema-osEvents.json"
|
||||
},
|
||||
"protoServer":{
|
||||
"required":true,
|
||||
"$ref":"schema-protoServer.json"
|
||||
},
|
||||
"schedEvents":{
|
||||
"required":true,
|
||||
"$ref":"schema-schedEvents.json"
|
||||
},
|
||||
"webConfig":{
|
||||
"required":true,
|
||||
"$ref":"schema-webConfig.json"
|
||||
}
|
||||
},
|
||||
"additionalProperties":true
|
||||
}
|
50
libsrc/hyperion/schema/schema-settings-instance-relaxed.json
Normal file
50
libsrc/hyperion/schema/schema-settings-instance-relaxed.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"backgroundEffect":{
|
||||
"required":false,
|
||||
"$ref":"schema-backgroundEffect.json"
|
||||
},
|
||||
"blackborderdetector":{
|
||||
"required":false,
|
||||
"$ref":"schema-blackborderdetector.json"
|
||||
},
|
||||
"boblightServer":{
|
||||
"required":false,
|
||||
"$ref":"schema-boblightServer.json"
|
||||
},
|
||||
"color":{
|
||||
"required":false,
|
||||
"$ref":"schema-color.json"
|
||||
},
|
||||
"device":{
|
||||
"required":false,
|
||||
"$ref":"schema-device.json"
|
||||
},
|
||||
"effects":{
|
||||
"required":false,
|
||||
"$ref":"schema-effects.json"
|
||||
},
|
||||
"foregroundEffect":{
|
||||
"required":false,
|
||||
"$ref":"schema-foregroundEffect.json"
|
||||
},
|
||||
"instCapture":{
|
||||
"required":false,
|
||||
"$ref":"schema-instCapture.json"
|
||||
},
|
||||
"ledConfig":{
|
||||
"required":false,
|
||||
"$ref":"schema-ledConfig.json"
|
||||
},
|
||||
"leds":{
|
||||
"required":false,
|
||||
"$ref":"schema-leds.json"
|
||||
},
|
||||
"smoothing":{
|
||||
"required":false,
|
||||
"$ref":"schema-smoothing.json"
|
||||
}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}
|
50
libsrc/hyperion/schema/schema-settings-instance.json
Normal file
50
libsrc/hyperion/schema/schema-settings-instance.json
Normal file
@ -0,0 +1,50 @@
|
||||
{
|
||||
"type":"object",
|
||||
"properties":{
|
||||
"backgroundEffect":{
|
||||
"required":true,
|
||||
"$ref":"schema-backgroundEffect.json"
|
||||
},
|
||||
"blackborderdetector":{
|
||||
"required":true,
|
||||
"$ref":"schema-blackborderdetector.json"
|
||||
},
|
||||
"boblightServer":{
|
||||
"required":true,
|
||||
"$ref":"schema-boblightServer.json"
|
||||
},
|
||||
"color":{
|
||||
"required":true,
|
||||
"$ref":"schema-color.json"
|
||||
},
|
||||
"device":{
|
||||
"required":true,
|
||||
"$ref":"schema-device.json"
|
||||
},
|
||||
"effects":{
|
||||
"required":true,
|
||||
"$ref":"schema-effects.json"
|
||||
},
|
||||
"foregroundEffect":{
|
||||
"required":true,
|
||||
"$ref":"schema-foregroundEffect.json"
|
||||
},
|
||||
"instCapture":{
|
||||
"required":true,
|
||||
"$ref":"schema-instCapture.json"
|
||||
},
|
||||
"ledConfig":{
|
||||
"required":true,
|
||||
"$ref":"schema-ledConfig.json"
|
||||
},
|
||||
"leds":{
|
||||
"required":true,
|
||||
"$ref":"schema-leds.json"
|
||||
},
|
||||
"smoothing":{
|
||||
"required":true,
|
||||
"$ref":"schema-smoothing.json"
|
||||
}
|
||||
},
|
||||
"additionalProperties":true
|
||||
}
|
107
libsrc/hyperion/schema/schema-settings-ui.json
Normal file
107
libsrc/hyperion/schema/schema-settings-ui.json
Normal file
@ -0,0 +1,107 @@
|
||||
{
|
||||
"type":"object",
|
||||
"required":true,
|
||||
"properties":{
|
||||
"cecEvents":{
|
||||
"required":true,
|
||||
"$ref":"schema-cecEvents.json"
|
||||
},
|
||||
"flatbufServer":{
|
||||
"required":true,
|
||||
"$ref":"schema-flatbufServer.json"
|
||||
},
|
||||
"forwarder":{
|
||||
"required":true,
|
||||
"$ref":"schema-forwarder.json"
|
||||
},
|
||||
"framegrabber":{
|
||||
"required":true,
|
||||
"$ref":"schema-framegrabber.json"
|
||||
},
|
||||
"general":{
|
||||
"required":true,
|
||||
"$ref":"schema-general.json"
|
||||
},
|
||||
"grabberAudio":{
|
||||
"required":true,
|
||||
"$ref":"schema-grabberAudio.json"
|
||||
},
|
||||
"grabberV4L2":{
|
||||
"required":true,
|
||||
"$ref":"schema-grabberV4L2.json"
|
||||
},
|
||||
"jsonServer":{
|
||||
"required":true,
|
||||
"$ref":"schema-jsonServer.json"
|
||||
},
|
||||
"logger":{
|
||||
"required":true,
|
||||
"$ref":"schema-logger.json"
|
||||
},
|
||||
"network":{
|
||||
"required":true,
|
||||
"$ref":"schema-network.json"
|
||||
},
|
||||
"osEvents":{
|
||||
"required":true,
|
||||
"$ref":"schema-osEvents.json"
|
||||
},
|
||||
"protoServer":{
|
||||
"required":true,
|
||||
"$ref":"schema-protoServer.json"
|
||||
},
|
||||
"schedEvents":{
|
||||
"required":true,
|
||||
"$ref":"schema-schedEvents.json"
|
||||
},
|
||||
"webConfig":{
|
||||
"required":true,
|
||||
"$ref":"schema-webConfig.json"
|
||||
},
|
||||
"backgroundEffect":{
|
||||
"required":true,
|
||||
"$ref":"schema-backgroundEffect.json"
|
||||
},
|
||||
"blackborderdetector":{
|
||||
"required":true,
|
||||
"$ref":"schema-blackborderdetector.json"
|
||||
},
|
||||
"boblightServer":{
|
||||
"required":true,
|
||||
"$ref":"schema-boblightServer.json"
|
||||
},
|
||||
"color":{
|
||||
"required":true,
|
||||
"$ref":"schema-color.json"
|
||||
},
|
||||
"device":{
|
||||
"required":true,
|
||||
"$ref":"schema-device.json"
|
||||
},
|
||||
"effects":{
|
||||
"required":true,
|
||||
"$ref":"schema-effects.json"
|
||||
},
|
||||
"foregroundEffect":{
|
||||
"required":true,
|
||||
"$ref":"schema-foregroundEffect.json"
|
||||
},
|
||||
"instCapture":{
|
||||
"required":true,
|
||||
"$ref":"schema-instCapture.json"
|
||||
},
|
||||
"ledConfig":{
|
||||
"required":true,
|
||||
"$ref":"schema-ledConfig.json"
|
||||
},
|
||||
"leds":{
|
||||
"required":true,
|
||||
"$ref":"schema-leds.json"
|
||||
},
|
||||
"smoothing":{
|
||||
"required":true,
|
||||
"$ref":"schema-smoothing.json"
|
||||
}
|
||||
},
|
||||
"additionalProperties":false
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
#include "SSDPDescription.h"
|
||||
#include <hyperion/Hyperion.h>
|
||||
#include <HyperionConfig.h>
|
||||
#include <hyperion/AuthManager.h>
|
||||
#include <db/MetaTable.h>
|
||||
|
||||
#include <QNetworkInterface>
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
|
||||
@ -40,7 +40,8 @@ SSDPHandler::~SSDPHandler()
|
||||
|
||||
void SSDPHandler::initServer()
|
||||
{
|
||||
_uuid = AuthManager::getInstance()->getID();
|
||||
MetaTable metaTable;
|
||||
_uuid = metaTable.getUUID();
|
||||
SSDPServer::setUuid(_uuid);
|
||||
|
||||
// announce targets
|
||||
|
@ -7,12 +7,23 @@
|
||||
//qt includes
|
||||
#include <QRegularExpression>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonParseError>
|
||||
#include <QStringList>
|
||||
|
||||
namespace JsonUtils {
|
||||
|
||||
QPair<bool, QStringList> readFile(const QString& path, QJsonObject& obj, Logger* log, bool ignError)
|
||||
{
|
||||
QJsonValue value(obj);
|
||||
|
||||
QPair<bool, QStringList> result = readFile(path, value,log, ignError);
|
||||
obj = value.toObject();
|
||||
return result;
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> readFile(const QString& path, QJsonValue& obj, Logger* log, bool ignError)
|
||||
{
|
||||
QString data;
|
||||
if(!FileUtils::readFile(path, data, log, ignError))
|
||||
@ -24,32 +35,46 @@ namespace JsonUtils {
|
||||
return parsingResult;
|
||||
}
|
||||
|
||||
|
||||
bool readSchema(const QString& path, QJsonObject& obj, Logger* log)
|
||||
{
|
||||
QJsonObject schema;
|
||||
if(!readFile(path, schema, log).first)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!resolveRefs(schema, obj, log))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonObject& obj, Logger* log)
|
||||
{
|
||||
QJsonDocument doc;
|
||||
QPair<bool, QStringList> parsingResult = JsonUtils::parse(path, data, doc, log);
|
||||
obj = doc.object();
|
||||
return parsingResult;
|
||||
QJsonValue value(obj);
|
||||
|
||||
QPair<bool, QStringList> result = JsonUtils::parse(path, data, value, log);
|
||||
obj = value.toObject();
|
||||
return result;
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonArray& arr, Logger* log)
|
||||
{
|
||||
QJsonDocument doc;
|
||||
QJsonValue value(arr);
|
||||
|
||||
QPair<bool, QStringList> result = JsonUtils::parse(path, data, value, log);
|
||||
arr = value.toArray();
|
||||
return result;
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> parse(const QString& path, const QString& data, QJsonValue& value, Logger* log)
|
||||
{
|
||||
QJsonDocument doc;
|
||||
QPair<bool, QStringList> parsingResult = JsonUtils::parse(path, data, doc, log);
|
||||
arr = doc.array();
|
||||
value = doc.object();
|
||||
return parsingResult;
|
||||
}
|
||||
|
||||
@ -72,7 +97,8 @@ namespace JsonUtils {
|
||||
}
|
||||
errorLine += data.left(error.offset).count('\n');
|
||||
|
||||
const QString errorMessage = QString("JSON parse error: %1, line: %2, column: %3, Data: '%4'")
|
||||
const QString errorMessage = QString("JSON parse error @(%1): %2, line: %3, column: %4, Data: '%5'")
|
||||
.arg(path)
|
||||
.arg(error.errorString())
|
||||
.arg(errorLine)
|
||||
.arg(errorColumn)
|
||||
@ -85,7 +111,7 @@ namespace JsonUtils {
|
||||
return qMakePair(true, errorList);
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonObject& json, const QString& schemaPath, Logger* log)
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonValue& json, const QString& schemaPath, Logger* log)
|
||||
{
|
||||
// get the schema data
|
||||
QJsonObject schema;
|
||||
@ -100,7 +126,7 @@ namespace JsonUtils {
|
||||
return validationResult;
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonObject& json, const QJsonObject& schema, Logger* log)
|
||||
QPair<bool, QStringList> validate(const QString& file, const QJsonValue& json, const QJsonObject& schema, Logger* log)
|
||||
{
|
||||
QStringList errorList;
|
||||
|
||||
@ -111,8 +137,8 @@ namespace JsonUtils {
|
||||
const QStringList &errors = schemaChecker.getMessages();
|
||||
for (const auto& error : errors)
|
||||
{
|
||||
QString errorMessage = QString("JSON parse error: %1")
|
||||
.arg(error);
|
||||
QString errorMessage = QString("JSON parse error @(%1) - %2")
|
||||
.arg(file, error);
|
||||
errorList.push_back(errorMessage);
|
||||
Error(log, "%s", QSTRING_CSTR(errorMessage));
|
||||
}
|
||||
@ -121,6 +147,32 @@ namespace JsonUtils {
|
||||
return qMakePair(true, errorList);
|
||||
}
|
||||
|
||||
QPair<bool, QStringList> correct(const QString& file, QJsonValue& json, const QJsonObject& schema, Logger* log)
|
||||
{
|
||||
bool wasCorrected {false};
|
||||
QStringList corrections;
|
||||
QJsonValue correctJson;
|
||||
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
schemaChecker.setSchema(schema);
|
||||
if (!schemaChecker.validate(json).first)
|
||||
{
|
||||
Warning(log, "Fixing JSON data!");
|
||||
json = schemaChecker.getAutoCorrectedConfig(json);
|
||||
wasCorrected = true;
|
||||
|
||||
const QStringList &correctionMessages = schemaChecker.getMessages();
|
||||
for (const auto& correction : correctionMessages)
|
||||
{
|
||||
QString message = QString("JSON fix @(%1) - %2")
|
||||
.arg(file, correction);
|
||||
corrections.push_back(message);
|
||||
Warning(log, "%s", QSTRING_CSTR(message));
|
||||
}
|
||||
}
|
||||
return qMakePair(wasCorrected, corrections);
|
||||
}
|
||||
|
||||
bool write(const QString& filename, const QJsonObject& json, Logger* log)
|
||||
{
|
||||
QJsonDocument doc;
|
||||
@ -128,10 +180,7 @@ namespace JsonUtils {
|
||||
doc.setObject(json);
|
||||
QByteArray data = doc.toJson(QJsonDocument::Indented);
|
||||
|
||||
if(!FileUtils::writeFile(filename, data, log))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
return FileUtils::writeFile(filename, data, log);
|
||||
}
|
||||
|
||||
bool resolveRefs(const QJsonObject& schema, QJsonObject& obj, Logger* log)
|
||||
@ -150,7 +199,9 @@ namespace JsonUtils {
|
||||
}
|
||||
}
|
||||
else if (attributeValue.isObject())
|
||||
{
|
||||
obj.insert(attribute, resolveRefs(attributeValue.toObject(), obj, log));
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.insert(attribute, attributeValue);
|
||||
@ -158,4 +209,49 @@ namespace JsonUtils {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QString jsonValueToQString(const QJsonValue &value, QJsonDocument::JsonFormat format)
|
||||
{
|
||||
switch (value.type()) {
|
||||
case QJsonValue::Object:
|
||||
{
|
||||
return QJsonDocument(value.toObject()).toJson(format);
|
||||
}
|
||||
case QJsonValue::Array:
|
||||
{
|
||||
return QJsonDocument(value.toArray()).toJson(format);
|
||||
}
|
||||
case QJsonValue::String:
|
||||
case QJsonValue::Double:
|
||||
case QJsonValue::Bool:
|
||||
{
|
||||
return value.toString();
|
||||
}
|
||||
case QJsonValue::Null:
|
||||
{
|
||||
return "Null";
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QJsonObject mergeJsonObjects(const QJsonObject &obj1, const QJsonObject &obj2, bool overrideObj1)
|
||||
{
|
||||
QJsonObject result = obj1;
|
||||
|
||||
for (auto it = obj2.begin(); it != obj2.end(); ++it) {
|
||||
if (result.contains(it.key())) {
|
||||
if (overrideObj1)
|
||||
{
|
||||
result[it.key()] = it.value();
|
||||
}
|
||||
} else {
|
||||
result[it.key()] = it.value();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
@ -40,7 +40,7 @@ QStringList QJsonSchemaChecker::getMessages() const
|
||||
return _messages;
|
||||
}
|
||||
|
||||
QPair<bool, bool> QJsonSchemaChecker::validate(const QJsonObject& value, bool ignoreRequired)
|
||||
QPair<bool, bool> QJsonSchemaChecker::validate(const QJsonValue& value, bool ignoreRequired)
|
||||
{
|
||||
// initialize state
|
||||
_ignoreRequired = ignoreRequired;
|
||||
@ -56,7 +56,7 @@ QPair<bool, bool> QJsonSchemaChecker::validate(const QJsonObject& value, bool ig
|
||||
return QPair<bool, bool>(!_error, !_schemaError);
|
||||
}
|
||||
|
||||
QJsonObject QJsonSchemaChecker::getAutoCorrectedConfig(const QJsonObject& value, bool ignoreRequired)
|
||||
QJsonValue QJsonSchemaChecker::getAutoCorrectedConfig(const QJsonValue& value, bool ignoreRequired)
|
||||
{
|
||||
_ignoreRequired = ignoreRequired;
|
||||
const QStringList sequence = QStringList() << "remove" << "modify" << "create";
|
||||
|
@ -1,6 +1,6 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
<file alias="hyperion_default.config">${CMAKE_BINARY_DIR}/config/hyperion.config.json.default</file>
|
||||
<file alias="hyperion_default.settings">${CMAKE_BINARY_DIR}/settings/hyperion.settings.json.default</file>
|
||||
${HYPERION_RES}
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
0
config/.gitignore → settings/.gitignore
vendored
0
config/.gitignore → settings/.gitignore
vendored
309
settings/hyperion.settings.json.default
Normal file
309
settings/hyperion.settings.json.default
Normal file
@ -0,0 +1,309 @@
|
||||
{
|
||||
"global":{
|
||||
"cecEvents":{
|
||||
"actions":[
|
||||
{
|
||||
"action":"Suspend",
|
||||
"event":"standby"
|
||||
},
|
||||
{
|
||||
"action":"Resume",
|
||||
"event":"set stream path"
|
||||
}
|
||||
],
|
||||
"enable":false
|
||||
},
|
||||
"flatbufServer":{
|
||||
"enable":true,
|
||||
"port":19400,
|
||||
"timeout":5
|
||||
},
|
||||
"forwarder":{
|
||||
"enable":false,
|
||||
"jsonapi":[
|
||||
|
||||
],
|
||||
"flatbuffer":[
|
||||
|
||||
]
|
||||
},
|
||||
"framegrabber":{
|
||||
"enable":false,
|
||||
"device":"auto",
|
||||
"input":0,
|
||||
"width":80,
|
||||
"height":45,
|
||||
"fps":10,
|
||||
"pixelDecimation":8,
|
||||
"cropLeft":0,
|
||||
"cropRight":0,
|
||||
"cropTop":0,
|
||||
"cropBottom":0
|
||||
},
|
||||
"general":{
|
||||
"name":"My Hyperion Config",
|
||||
"configVersion":"configVersionValue",
|
||||
"watchedVersionBranch":"Stable",
|
||||
"showOptHelp":true
|
||||
},
|
||||
"grabberAudio":{
|
||||
"enable":false,
|
||||
"device":"auto",
|
||||
"audioEffect":"vuMeter",
|
||||
"vuMeter":{
|
||||
"flip":"NO_CHANGE",
|
||||
"hotColor":[
|
||||
255,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"multiplier":1,
|
||||
"safeColor":[
|
||||
0,
|
||||
255,
|
||||
0
|
||||
],
|
||||
"safeValue":45,
|
||||
"tolerance":5,
|
||||
"warnColor":[
|
||||
255,
|
||||
255,
|
||||
0
|
||||
],
|
||||
"warnValue":80
|
||||
}
|
||||
},
|
||||
"grabberV4L2":{
|
||||
"enable":false,
|
||||
"device":"none",
|
||||
"input":0,
|
||||
"encoding":"NO_CHANGE",
|
||||
"width":0,
|
||||
"height":0,
|
||||
"fps":15,
|
||||
"flip":"NO_CHANGE",
|
||||
"fpsSoftwareDecimation":0,
|
||||
"sizeDecimation":8,
|
||||
"cropLeft":0,
|
||||
"cropRight":0,
|
||||
"cropTop":0,
|
||||
"cropBottom":0,
|
||||
"redSignalThreshold":0,
|
||||
"greenSignalThreshold":100,
|
||||
"blueSignalThreshold":0,
|
||||
"signalDetection":false,
|
||||
"noSignalCounterThreshold":200,
|
||||
"sDVOffsetMin":0.1,
|
||||
"sDVOffsetMax":0.9,
|
||||
"sDHOffsetMin":0.4,
|
||||
"sDHOffsetMax":0.46,
|
||||
"hardware_brightness":0,
|
||||
"hardware_contrast":0,
|
||||
"hardware_saturation":0,
|
||||
"hardware_hue":0
|
||||
},
|
||||
"jsonServer":{
|
||||
"port":19444
|
||||
},
|
||||
"logger":{
|
||||
"level":"warn"
|
||||
},
|
||||
"network":{
|
||||
"internetAccessAPI":false,
|
||||
"restirctedInternetAccessAPI":false,
|
||||
"ipWhitelist":[
|
||||
|
||||
],
|
||||
"localApiAuth":false
|
||||
},
|
||||
"osEvents":{
|
||||
"suspendEnable":true,
|
||||
"lockEnable":true
|
||||
},
|
||||
"protoServer":{
|
||||
"enable":true,
|
||||
"port":19445,
|
||||
"timeout":5
|
||||
},
|
||||
"schedEvents":{
|
||||
"enable":false
|
||||
},
|
||||
"webConfig":{
|
||||
"document_root":"",
|
||||
"port":8090,
|
||||
"sslPort":8092,
|
||||
"crtPath":"",
|
||||
"keyPath":"",
|
||||
"keyPassPhrase":""
|
||||
}
|
||||
},
|
||||
"instance":{
|
||||
"backgroundEffect":{
|
||||
"enable":false,
|
||||
"type":"effect",
|
||||
"color":[
|
||||
255,
|
||||
138,
|
||||
0
|
||||
],
|
||||
"effect":"Warm mood blobs"
|
||||
},
|
||||
"blackborderdetector":{
|
||||
"enable":true,
|
||||
"threshold":5,
|
||||
"unknownFrameCnt":600,
|
||||
"borderFrameCnt":50,
|
||||
"maxInconsistentCnt":10,
|
||||
"blurRemoveCnt":1,
|
||||
"mode":"default"
|
||||
},
|
||||
"boblightServer":{
|
||||
"enable":false,
|
||||
"port":19333,
|
||||
"priority":128
|
||||
},
|
||||
"color":{
|
||||
"imageToLedMappingType":"multicolor_mean",
|
||||
"channelAdjustment":[
|
||||
{
|
||||
"id":"default",
|
||||
"leds":"*",
|
||||
"white":[
|
||||
255,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"red":[
|
||||
255,
|
||||
0,
|
||||
0
|
||||
],
|
||||
"green":[
|
||||
0,
|
||||
255,
|
||||
0
|
||||
],
|
||||
"blue":[
|
||||
0,
|
||||
0,
|
||||
255
|
||||
],
|
||||
"cyan":[
|
||||
0,
|
||||
255,
|
||||
255
|
||||
],
|
||||
"magenta":[
|
||||
255,
|
||||
0,
|
||||
255
|
||||
],
|
||||
"yellow":[
|
||||
255,
|
||||
255,
|
||||
0
|
||||
],
|
||||
"gammaRed":2.2,
|
||||
"gammaGreen":2.2,
|
||||
"gammaBlue":2.2,
|
||||
"backlightThreshold":0,
|
||||
"backlightColored":false,
|
||||
"brightness":100,
|
||||
"brightnessCompensation":100,
|
||||
"saturationGain":1.0,
|
||||
"brightnessGain":1.0
|
||||
}
|
||||
]
|
||||
},
|
||||
"device":{
|
||||
"type":"file",
|
||||
"hardwareLedCount":1,
|
||||
"autoStart":true,
|
||||
"output":"/dev/null",
|
||||
"colorOrder":"rgb",
|
||||
"latchTime":0,
|
||||
"rewriteTime":0,
|
||||
"enableAttempts":6,
|
||||
"enableAttemptsInterval":15
|
||||
},
|
||||
"effects":{
|
||||
"paths":[
|
||||
"$ROOT/custom-effects"
|
||||
],
|
||||
"disable":[
|
||||
""
|
||||
]
|
||||
},
|
||||
"foregroundEffect":{
|
||||
"enable":true,
|
||||
"type":"effect",
|
||||
"color":[
|
||||
0,
|
||||
0,
|
||||
255
|
||||
],
|
||||
"effect":"Rainbow swirl fast",
|
||||
"duration_ms":3000
|
||||
},
|
||||
"instCapture":{
|
||||
"systemEnable":false,
|
||||
"systemGrabberDevice":"NONE",
|
||||
"systemPriority":250,
|
||||
"v4lEnable":false,
|
||||
"v4lGrabberDevice":"NONE",
|
||||
"v4lPriority":240,
|
||||
"audioEnable":false,
|
||||
"audioGrabberDevice":"NONE",
|
||||
"audioPriority":230
|
||||
},
|
||||
"ledConfig":{
|
||||
"classic":{
|
||||
"top":1,
|
||||
"bottom":0,
|
||||
"left":0,
|
||||
"right":0,
|
||||
"glength":0,
|
||||
"gpos":0,
|
||||
"position":0,
|
||||
"reverse":false,
|
||||
"hdepth":8,
|
||||
"vdepth":5,
|
||||
"overlap":0,
|
||||
"edgegap":0,
|
||||
"ptlh":0,
|
||||
"ptlv":0,
|
||||
"ptrh":100,
|
||||
"ptrv":0,
|
||||
"pblh":0,
|
||||
"pblv":100,
|
||||
"pbrh":100,
|
||||
"pbrv":100
|
||||
},
|
||||
"matrix":{
|
||||
"ledshoriz":1,
|
||||
"ledsvert":1,
|
||||
"cabling":"snake",
|
||||
"direction":"horizontal",
|
||||
"start":"top-left"
|
||||
}
|
||||
},
|
||||
"leds":[
|
||||
{
|
||||
"hmax":1,
|
||||
"hmin":0,
|
||||
"vmax":0.08,
|
||||
"vmin":0
|
||||
}
|
||||
],
|
||||
"smoothing":{
|
||||
"enable":true,
|
||||
"type":"linear",
|
||||
"time_ms":150,
|
||||
"updateFrequency":25.0000,
|
||||
"interpolationRate":25.0000,
|
||||
"decay":1,
|
||||
"dithering":false,
|
||||
"updateDelay":0
|
||||
}
|
||||
}
|
||||
}
|
@ -65,14 +65,14 @@
|
||||
|
||||
HyperionDaemon* HyperionDaemon::daemon = nullptr;
|
||||
|
||||
HyperionDaemon::HyperionDaemon(const QString& rootPath, QObject* parent, bool logLvlOverwrite, bool readonlyMode)
|
||||
HyperionDaemon::HyperionDaemon(const QString& rootPath, QObject* parent, bool logLvlOverwrite)
|
||||
: QObject(parent), _log(Logger::getInstance("DAEMON"))
|
||||
, _instanceManager(new HyperionIManager(rootPath, this, readonlyMode))
|
||||
, _settingsManager(new SettingsManager(GLOABL_INSTANCE_ID, this, readonlyMode)) // init settings, this settingsManager accesses global settings which are independent from instances
|
||||
, _instanceManager(new HyperionIManager(this))
|
||||
, _settingsManager(new SettingsManager(GLOABL_INSTANCE_ID, this)) // init settings, this settingsManager accesses global settings which are independent from instances
|
||||
#if defined(ENABLE_EFFECTENGINE)
|
||||
, _pyInit(new PythonInit())
|
||||
#endif
|
||||
, _authManager(new AuthManager(this, readonlyMode))
|
||||
, _authManager(new AuthManager(this))
|
||||
, _netOrigin(new NetOrigin(this))
|
||||
, _currVideoMode(VideoMode::VIDEO_2D)
|
||||
{
|
||||
|
@ -114,7 +114,7 @@ class HyperionDaemon : public QObject
|
||||
friend SysTray;
|
||||
|
||||
public:
|
||||
HyperionDaemon(const QString& rootPath, QObject *parent, bool logLvlOverwrite, bool readonlyMode = false);
|
||||
HyperionDaemon(const QString& rootPath, QObject *parent, bool logLvlOverwrite);
|
||||
~HyperionDaemon() override;
|
||||
|
||||
///
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -35,6 +36,7 @@
|
||||
#include <commandline/Parser.h>
|
||||
#include <commandline/IntOption.h>
|
||||
#include <utils/DefaultSignalHandler.h>
|
||||
#include <db/DBConfigManager.h>
|
||||
#include <../../include/db/AuthTable.h>
|
||||
|
||||
#include "detectProcess.h"
|
||||
@ -131,7 +133,10 @@ int main(int argc, char** argv)
|
||||
BooleanOption & versionOption = parser.add<BooleanOption> (0x0, "version", "Show version information");
|
||||
Option & userDataOption = parser.add<Option> ('u', "userdata", "Overwrite user data path, defaults to home directory of current user (%1)", QDir::homePath() + "/.hyperion");
|
||||
BooleanOption & resetPassword = parser.add<BooleanOption> (0x0, "resetPassword", "Lost your password? Reset it with this option back to 'hyperion'");
|
||||
BooleanOption & readOnlyModeOption = parser.add<BooleanOption> (0x0, "readonlyMode", "Start in read-only mode. No updates will be written to the database");
|
||||
BooleanOption & deleteDB = parser.add<BooleanOption> (0x0, "deleteDatabase", "Start all over? This Option will delete the database");
|
||||
Option & importConfig = parser.add<Option> (0x0, "importConfig", "Replace the current configuration database by a new configuration");
|
||||
Option & exportConfigPath = parser.add<Option> (0x0, "exportConfig", "Export the current configuration database, defaults to home directory of current user (%1)", QDir::homePath() + "/.hyperion//archive");
|
||||
BooleanOption & silentOption = parser.add<BooleanOption> ('s', "silent", "Do not print any outputs");
|
||||
BooleanOption & verboseOption = parser.add<BooleanOption> ('v', "verbose", "Increase verbosity");
|
||||
BooleanOption & debugOption = parser.add<BooleanOption> ('d', "debug", "Show debug messages");
|
||||
@ -264,16 +269,30 @@ int main(int argc, char** argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
Info(log,"Hyperion %s, %s, built: %s:%s", HYPERION_VERSION, HYPERION_BUILD_ID, __DATE__, __TIME__);
|
||||
Debug(log,"QtVersion [%s]", QT_VERSION_STR);
|
||||
|
||||
int rc = 1;
|
||||
bool readonlyMode = false;
|
||||
|
||||
QString userDataPath(userDataOption.value(parser));
|
||||
|
||||
QDir userDataDirectory(userDataPath);
|
||||
QFileInfo dbFile(userDataDirectory.absolutePath() +"/db/hyperion.db");
|
||||
|
||||
|
||||
if (parser.isSet(readOnlyModeOption))
|
||||
{
|
||||
readonlyMode = true;
|
||||
Debug(log,"Force readonlyMode");
|
||||
}
|
||||
DBManager::initializeDatabase(userDataDirectory, readonlyMode);
|
||||
|
||||
Info(log, "Hyperion configuration and user data location: '%s'", QSTRING_CSTR(userDataDirectory.absolutePath()));
|
||||
|
||||
QFileInfo dbFile(DBManager::getFileInfo());
|
||||
|
||||
try
|
||||
{
|
||||
DBConfigManager configManager;
|
||||
if (dbFile.exists())
|
||||
{
|
||||
if (!dbFile.isReadable())
|
||||
@ -285,9 +304,30 @@ int main(int argc, char** argv)
|
||||
{
|
||||
readonlyMode = true;
|
||||
}
|
||||
|
||||
if(parser.isSet(exportConfigPath))
|
||||
{
|
||||
QString path = exportConfigPath.value(parser);
|
||||
if (path.isEmpty())
|
||||
{
|
||||
path = userDataDirectory.absolutePath() + "/archive";
|
||||
}
|
||||
|
||||
if (!configManager.exportJson(path))
|
||||
{
|
||||
throw std::runtime_error("Configuration export failed'");
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(parser.isSet(exportConfigPath))
|
||||
{
|
||||
throw std::runtime_error("The configuration cannot be exported. The database file '" + dbFile.absoluteFilePath().toStdString() + "' does not exist.'");
|
||||
}
|
||||
|
||||
if (!userDataDirectory.mkpath(dbFile.absolutePath()))
|
||||
{
|
||||
if (!userDataDirectory.isReadable() || !dbFile.isWritable())
|
||||
@ -302,11 +342,11 @@ int main(int argc, char** argv)
|
||||
{
|
||||
if ( readonlyMode )
|
||||
{
|
||||
Error(log,"Password reset is not possible. The user data path '%s' is not writeable.", QSTRING_CSTR(userDataDirectory.absolutePath()));
|
||||
Error(log,"Password reset is not possible. Hyperion's database '%s' is not writeable.", QSTRING_CSTR(dbFile.absolutePath()));
|
||||
throw std::runtime_error("Password reset failed");
|
||||
}
|
||||
|
||||
AuthTable* table = new AuthTable(userDataDirectory.absolutePath());
|
||||
AuthTable* table = new AuthTable();
|
||||
if(table->resetHyperionUser()){
|
||||
Info(log,"Password reset successful");
|
||||
delete table;
|
||||
@ -323,7 +363,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
if ( readonlyMode )
|
||||
{
|
||||
Error(log,"Deleting the configuration database is not possible. The user data path '%s' is not writeable.", QSTRING_CSTR(dbFile.absolutePath()));
|
||||
Error(log,"Deleting the configuration database is not possible. Hyperion's database '%s' is not writeable.", QSTRING_CSTR(dbFile.absolutePath()));
|
||||
throw std::runtime_error("Deleting the configuration database failed");
|
||||
}
|
||||
|
||||
@ -331,7 +371,7 @@ int main(int argc, char** argv)
|
||||
{
|
||||
if (!QFile::remove(dbFile.absoluteFilePath()))
|
||||
{
|
||||
Info(log,"Failed to delete Database!");
|
||||
Error(log,"Failed to delete Database!");
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
@ -341,26 +381,60 @@ int main(int argc, char** argv)
|
||||
}
|
||||
else
|
||||
{
|
||||
Warning(log,"Configuration database [%s] does not exist!", QSTRING_CSTR(dbFile.absoluteFilePath()));
|
||||
Warning(log,"Configuration database '%s' does not exist!", QSTRING_CSTR(dbFile.absoluteFilePath()));
|
||||
}
|
||||
}
|
||||
|
||||
Info(log,"Starting Hyperion [%sGUI mode] - %s, %s, built: %s:%s", isGuiApp ? "": "non-", HYPERION_VERSION, HYPERION_BUILD_ID, __DATE__, __TIME__);
|
||||
Debug(log,"QtVersion [%s]", QT_VERSION_STR);
|
||||
|
||||
if ( !readonlyMode )
|
||||
QString configFile(importConfig.value(parser));
|
||||
if (!configFile.isEmpty())
|
||||
{
|
||||
Info(log, "Set user data path to '%s'", QSTRING_CSTR(userDataDirectory.absolutePath()));
|
||||
if ( readonlyMode )
|
||||
{
|
||||
Error(log,"Configuration import is not possible. Hyperion's database '%s' is not writeable.", QSTRING_CSTR(dbFile.absolutePath()));
|
||||
throw std::runtime_error("Configuration import failed");
|
||||
}
|
||||
else
|
||||
|
||||
if (!configManager.importJson(configFile).first)
|
||||
{
|
||||
Warning(log,"The user data path '%s' is not writeable. Hyperion starts in read-only mode. Configuration updates will not be persisted!", QSTRING_CSTR(userDataDirectory.absolutePath()));
|
||||
throw std::runtime_error("Configuration import failed");
|
||||
}
|
||||
}
|
||||
|
||||
if (!configManager.addMissingDefaults().first)
|
||||
{
|
||||
throw std::runtime_error("Updating configuration database with missing defaults failed");
|
||||
}
|
||||
|
||||
if (!configManager.migrateConfiguration().first)
|
||||
{
|
||||
throw std::runtime_error("Migrating the configuration database failed");
|
||||
}
|
||||
|
||||
if (!configManager.validateConfiguration().first)
|
||||
{
|
||||
if (!configManager.updateConfiguration().first)
|
||||
{
|
||||
throw std::runtime_error("Invalid configuration database. Correcting the configuration database failed");
|
||||
}
|
||||
}
|
||||
|
||||
if (!configFile.isEmpty())
|
||||
{
|
||||
Info(log,"Configuration imported sucessfully. You can start Hyperion now.");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Info(log,"Starting Hyperion in %sGUI mode, DB is %s", isGuiApp ? "": "non-", readonlyMode ? "read-only" : "read/write");
|
||||
|
||||
if ( readonlyMode )
|
||||
{
|
||||
Warning(log,"The database file '%s' is set not writeable. Hyperion starts in read-only mode. Configuration updates will not be persisted!", QSTRING_CSTR(dbFile.absoluteFilePath()));
|
||||
}
|
||||
|
||||
HyperionDaemon* hyperiond = nullptr;
|
||||
try
|
||||
{
|
||||
hyperiond = new HyperionDaemon(userDataDirectory.absolutePath(), qApp, bool(logLevelCheck), readonlyMode);
|
||||
hyperiond = new HyperionDaemon(userDataDirectory.absolutePath(), qApp, bool(logLevelCheck));
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
|
@ -22,7 +22,7 @@ bool loadConfig(const QString & configFile, bool correct, bool ignore)
|
||||
|
||||
try
|
||||
{
|
||||
schemaJson = QJsonFactory::readSchema(":/hyperion-schema");
|
||||
schemaJson = QJsonFactory::readSchema(":/schema-settings-default.json");
|
||||
}
|
||||
catch(const std::runtime_error& error)
|
||||
{
|
||||
@ -36,7 +36,7 @@ bool loadConfig(const QString & configFile, bool correct, bool ignore)
|
||||
// read and validate the configuration file from the command line
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
QJsonObject jsonConfig = QJsonFactory::readConfig(configFile);
|
||||
QJsonValue jsonConfig = QJsonFactory::readConfig(configFile);
|
||||
|
||||
if (!correct)
|
||||
{
|
||||
@ -56,7 +56,8 @@ bool loadConfig(const QString & configFile, bool correct, bool ignore)
|
||||
else
|
||||
{
|
||||
jsonConfig = schemaChecker.getAutoCorrectedConfig(jsonConfig, ignore); // The second parameter is to ignore the "required" keyword in hyperion schema
|
||||
QJsonFactory::writeJson(configFile, jsonConfig);
|
||||
QJsonObject jsonObject = jsonConfig.toObject();
|
||||
QJsonFactory::writeJson(configFile, jsonObject);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -18,7 +18,7 @@ try:
|
||||
with open(schemaFileName) as schemaFile:
|
||||
with open(jsonFileName) as jsonFile:
|
||||
schema = json.load(schemaFile)
|
||||
uri = path2url('%s/schema/' % path.abspath(path.dirname(schemaFileName)))
|
||||
uri = path2url('%s/' % path.abspath(path.dirname(schemaFileName)))
|
||||
resolver = RefResolver(uri, referrer = schema)
|
||||
instance = json.load(jsonFile)
|
||||
Draft3Validator(schema, resolver=resolver).validate(instance)
|
||||
|
@ -44,7 +44,7 @@ echo "Hyperion test execution"
|
||||
echo
|
||||
exec_test "hyperiond is executable and show version" bin/hyperiond --version
|
||||
|
||||
for cfg in ../config/*json.default
|
||||
for cfg in ../settings/*json.default
|
||||
do
|
||||
exec_test "test $(basename $cfg)" bin/test_configfile $cfg
|
||||
done
|
||||
|
Loading…
x
Reference in New Issue
Block a user