2025-12-29 01:16:58 +08:00
|
|
|
|
#include "ConfigManager.h"
|
|
|
|
|
|
#include "VrLog.h"
|
|
|
|
|
|
#include "VrFileUtils.h"
|
2026-01-07 00:34:37 +08:00
|
|
|
|
#include "PathManager.h"
|
2025-12-29 01:16:58 +08:00
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
|
|
|
|
|
|
|
bool ConfigManager::Initialize(const std::string& configFilePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
// TunnelChannel 应用不需要共享内存监控
|
|
|
|
|
|
// 直接加载配置文件
|
|
|
|
|
|
|
|
|
|
|
|
std::string actualConfigPath = configFilePath;
|
|
|
|
|
|
|
2026-01-07 00:34:37 +08:00
|
|
|
|
// 如果没有指定配置文件路径,使用PathManager获取路径
|
2025-12-29 01:16:58 +08:00
|
|
|
|
if (actualConfigPath.empty()) {
|
2026-01-07 00:34:37 +08:00
|
|
|
|
QString configPath = PathManager::GetInstance().GetConfigFilePath();
|
|
|
|
|
|
actualConfigPath = configPath.toStdString();
|
2025-12-29 01:16:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-07 00:34:37 +08:00
|
|
|
|
// 保存配置文件路径到成员变量(用于后续保存)
|
|
|
|
|
|
m_configFilePath = actualConfigPath;
|
|
|
|
|
|
|
2025-12-29 01:16:58 +08:00
|
|
|
|
LOG_INFO("TunnelChannel ConfigManager: Loading config from %s\n", actualConfigPath.c_str());
|
|
|
|
|
|
|
2026-01-07 00:34:37 +08:00
|
|
|
|
// 创建VrConfig实例(用于后续保存配置)
|
|
|
|
|
|
if (!IVrConfig::CreateInstance(&m_pVrConfig) || !m_pVrConfig) {
|
|
|
|
|
|
LOG_ERR("Failed to create VrConfig instance\n");
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-29 01:16:58 +08:00
|
|
|
|
// 检查配置文件是否存在
|
|
|
|
|
|
if (!CVrFileUtils::IsFileExist(actualConfigPath.c_str())) {
|
|
|
|
|
|
LOG_WARN("Config file not found: %s, using default config\n", actualConfigPath.c_str());
|
|
|
|
|
|
return _InitializeDefaultConfig();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 加载配置文件
|
|
|
|
|
|
if (!LoadConfigFromFile(actualConfigPath)) {
|
|
|
|
|
|
LOG_WARN("Failed to load config file, using default config\n");
|
|
|
|
|
|
return _InitializeDefaultConfig();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ConfigManager::LoadConfigFromFile(const std::string& filePath)
|
|
|
|
|
|
{
|
2026-01-07 00:34:37 +08:00
|
|
|
|
// 使用已创建的 m_pVrConfig 实例加载配置
|
|
|
|
|
|
if (!m_pVrConfig) {
|
|
|
|
|
|
LOG_ERR("VrConfig instance not available\n");
|
2025-12-29 01:16:58 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 加载配置到临时结果
|
|
|
|
|
|
ConfigResult tempResult;
|
2026-01-07 00:34:37 +08:00
|
|
|
|
int loadResult = m_pVrConfig->LoadConfig(filePath, tempResult);
|
2025-12-29 01:16:58 +08:00
|
|
|
|
|
|
|
|
|
|
if (loadResult != LOAD_CONFIG_SUCCESS) {
|
|
|
|
|
|
LOG_ERR("Failed to load config file: %s, error code: %d\n", filePath.c_str(), loadResult);
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 将加载的配置存储到成员变量
|
|
|
|
|
|
{
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_configMutex);
|
|
|
|
|
|
m_systemConfig.configResult = tempResult;
|
|
|
|
|
|
m_configFilePath = filePath;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LOG_INFO("Config loaded successfully from: %s\n", filePath.c_str());
|
|
|
|
|
|
LOG_INFO(" - 3D Cameras: %zu\n", tempResult.cameraList.size());
|
|
|
|
|
|
LOG_INFO(" - Hik Cameras: %zu\n", tempResult.hikCameraList.size());
|
|
|
|
|
|
|
|
|
|
|
|
// 通知配置变化
|
|
|
|
|
|
_NotifyConfigChanged();
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<HikCameraConfig> ConfigManager::GetHikCameraList() const
|
|
|
|
|
|
{
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_configMutex);
|
|
|
|
|
|
return m_systemConfig.configResult.hikCameraList;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool ConfigManager::_InitializeDefaultConfig()
|
|
|
|
|
|
{
|
|
|
|
|
|
LOG_INFO("TunnelChannel ConfigManager: Initializing default config\n");
|
|
|
|
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> lock(m_configMutex);
|
|
|
|
|
|
|
|
|
|
|
|
// 初始化默认 ConfigResult
|
|
|
|
|
|
m_systemConfig.configResult = ConfigResult();
|
|
|
|
|
|
|
|
|
|
|
|
// 3D相机不设置默认配置,由 Presenter 自动搜索打开第一个相机
|
|
|
|
|
|
// 海康相机不设置默认配置,需要在配置文件中指定
|
|
|
|
|
|
|
|
|
|
|
|
LOG_INFO("TunnelChannel default configuration initialized\n");
|
|
|
|
|
|
LOG_INFO(" - 3D Cameras: auto search\n");
|
|
|
|
|
|
LOG_INFO(" - Hik Cameras: not configured\n");
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|