77 lines
2.7 KiB
C++
77 lines
2.7 KiB
C++
#include "ConfigManager.h"
|
||
#include "VrLog.h"
|
||
#include "VrError.h"
|
||
#include "PathManager.h"
|
||
|
||
// BagThreadPosition 应用的 ConfigManager 实现
|
||
// 所有通用功能都在 BaseConfigManager 中实现
|
||
// 这里只实现 BagThreadPosition 特定的功能
|
||
|
||
// 重写 Initialize 以禁用共享内存监控(BagThreadPositionApp 不需要)
|
||
bool ConfigManager::Initialize(const std::string& configFilePath)
|
||
{
|
||
LOG_INFO("ConfigManager initializing for BagThreadPositionApp...\n");
|
||
|
||
// 保存配置文件路径
|
||
if (configFilePath.empty()) {
|
||
QString defaultPath = PathManager::GetInstance().GetConfigFilePath();
|
||
m_configFilePath = defaultPath.toStdString();
|
||
} else {
|
||
m_configFilePath = configFilePath;
|
||
}
|
||
|
||
// 创建VrConfig实例
|
||
if (!IVrConfig::CreateInstance(&m_pVrConfig) || !m_pVrConfig) {
|
||
LOG_ERROR("Failed to create VrConfig instance\n");
|
||
return false;
|
||
}
|
||
|
||
// 加载配置文件
|
||
if (!LoadConfigFromFile(m_configFilePath)) {
|
||
LOG_WARNING("Failed to load config file, using default config\n");
|
||
_InitializeDefaultConfig();
|
||
}
|
||
|
||
// BagThreadPositionApp 不需要共享内存监控,跳过 ConfigMonitor 启动
|
||
LOG_INFO("ConfigManager initialized successfully for BagThreadPositionApp (shared memory disabled)\n");
|
||
return true;
|
||
}
|
||
|
||
// 实现 LoadConfigFromFile 以适配 BagThreadPosition 的 IVrConfig API
|
||
// BagThreadPosition 使用引用参数方式:int LoadConfig(const std::string& filePath, ConfigResult& configResult)
|
||
bool ConfigManager::LoadConfigFromFile(const std::string& filePath)
|
||
{
|
||
if (!m_pVrConfig) {
|
||
LOG_ERROR("VrConfig instance not available\n");
|
||
return false;
|
||
}
|
||
|
||
try {
|
||
ConfigResult configResult;
|
||
|
||
// BagThreadPosition 使用引用参数方式
|
||
int ret = m_pVrConfig->LoadConfig(filePath, configResult);
|
||
if (ret != SUCCESS) {
|
||
LOG_ERROR("Failed to load config from file: %s, error: %d\n", filePath.c_str(), ret);
|
||
return false;
|
||
}
|
||
|
||
// 使用基类的公共逻辑应用配置
|
||
return _ApplyLoadedConfig(configResult, filePath);
|
||
|
||
} catch (const std::exception& e) {
|
||
LOG_ERROR("Failed to load configuration from file %s: %s\n", filePath.c_str(), e.what());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
bool ConfigManager::OnSwitchWorkPositionCommand(const SwitchWorkPositionParam& param)
|
||
{
|
||
LOG_INFO("BagThreadPosition: Received switch work position command: workPositionId=%s\n", param.workPositionId);
|
||
|
||
// BagThreadPosition 应用特有的工作点切换逻辑
|
||
// 这里需要根据实际需求实现工作点切换
|
||
|
||
return true;
|
||
}
|