158 lines
4.9 KiB
C++
158 lines
4.9 KiB
C++
#ifndef CONFIGMANAGER_H
|
|
#define CONFIGMANAGER_H
|
|
|
|
#include "IVrConfig.h"
|
|
#include "VrConfigCmd.h"
|
|
#include "IVrShareMem.h"
|
|
#include <thread>
|
|
#include <atomic>
|
|
#include <mutex>
|
|
#include <vector>
|
|
#include <functional>
|
|
#include <memory>
|
|
|
|
/**
|
|
* @brief 扩展的相机UI参数
|
|
*/
|
|
struct CameraUIParam
|
|
{
|
|
int cameraIndex = 1; // 相机索引
|
|
double exposeTime = 100.0; // 曝光时间 (微秒)
|
|
double gain = 1.0; // 增益值
|
|
double frameRate = 30.0; // 帧率
|
|
double swingSpeed = 10.0; // 摆动速度
|
|
double swingStartAngle = 0.0; // 开始角度
|
|
double swingStopAngle = 180.0; // 结束角度
|
|
};
|
|
|
|
/**
|
|
* @brief 完整的系统配置数据
|
|
*/
|
|
struct SystemConfig
|
|
{
|
|
ConfigResult configResult; // VrConfig配置结果
|
|
std::vector<CameraUIParam> cameraUIParams; // 相机UI参数
|
|
|
|
// 获取指定相机的UI参数
|
|
CameraUIParam* GetCameraUIParam(int cameraIndex);
|
|
const CameraUIParam* GetCameraUIParam(int cameraIndex) const;
|
|
|
|
// 设置或更新指定相机的UI参数
|
|
void SetCameraUIParam(const CameraUIParam& param);
|
|
|
|
// 确保指定相机的参数存在
|
|
void EnsureCameraUIParam(int cameraIndex);
|
|
};
|
|
|
|
/**
|
|
* @brief 配置变化监听器接口
|
|
*/
|
|
class IConfigChangeListener
|
|
{
|
|
public:
|
|
virtual ~IConfigChangeListener() = default;
|
|
|
|
/**
|
|
* @brief 配置变化通知
|
|
* @param config 新的配置数据
|
|
*/
|
|
virtual void OnSystemConfigChanged(const SystemConfig& config) = 0;
|
|
|
|
/**
|
|
* @brief 相机参数变化通知
|
|
* @param cameraIndex 相机索引
|
|
* @param cameraParam 相机参数
|
|
*/
|
|
virtual void OnCameraParamChanged(int cameraIndex, const CameraUIParam& cameraParam) = 0;
|
|
|
|
/**
|
|
* @brief 算法参数变化通知
|
|
* @param algorithmParams 算法参数
|
|
*/
|
|
virtual void OnAlgorithmParamChanged(const VrAlgorithmParams& algorithmParams) = 0;
|
|
};
|
|
|
|
/**
|
|
* @brief 配置管理器类
|
|
* 负责管理系统配置、监听共享内存变化、提供配置变化通知
|
|
*/
|
|
class ConfigManager
|
|
{
|
|
public:
|
|
ConfigManager();
|
|
~ConfigManager();
|
|
|
|
// 基本配置管理
|
|
bool Initialize(const std::string& configFilePath = "");
|
|
void Shutdown();
|
|
|
|
// 配置访问(线程安全)
|
|
SystemConfig GetConfig() const;
|
|
CameraUIParam GetCameraUIParam(int cameraIndex) const;
|
|
VrAlgorithmParams GetAlgorithmParams() const;
|
|
ConfigResult GetConfigResult() const;
|
|
IVrConfig* GetVrConfigInstance() const { return m_pVrConfig; } // 获取 IVrConfig 实例
|
|
|
|
// 配置更新
|
|
bool UpdateCameraUIParam(int cameraIndex, const CameraUIParam& param);
|
|
bool UpdateAlgorithmParams(const VrAlgorithmParams& params);
|
|
bool UpdateFullConfig(const SystemConfig& config);
|
|
|
|
// 配置文件操作
|
|
bool LoadConfigFromFile(const std::string& filePath);
|
|
bool SaveConfigToFile(const std::string& filePath);
|
|
|
|
// 监听器管理
|
|
void AddConfigChangeListener(std::shared_ptr<IConfigChangeListener> listener);
|
|
void RemoveConfigChangeListener(std::shared_ptr<IConfigChangeListener> listener);
|
|
|
|
// 共享内存监听控制
|
|
bool StartSharedMemoryMonitor();
|
|
void StopSharedMemoryMonitor();
|
|
|
|
private:
|
|
// 配置数据
|
|
mutable std::mutex m_configMutex;
|
|
SystemConfig m_systemConfig;
|
|
std::string m_configFilePath;
|
|
|
|
// VrConfig实例
|
|
IVrConfig* m_pVrConfig;
|
|
|
|
// 共享内存监听
|
|
IVrShareMem* m_pConfigCmdShareMem;
|
|
std::thread m_sharedMemMonitorThread;
|
|
std::atomic<bool> m_bSharedMemMonitorRunning;
|
|
|
|
// 监听器管理
|
|
mutable std::mutex m_listenersMutex;
|
|
std::vector<std::weak_ptr<IConfigChangeListener>> m_listeners;
|
|
|
|
// 内部方法
|
|
void _SharedMemoryMonitorThread();
|
|
bool _ApplyConfigCommand(const ConfigCmdData& configData);
|
|
bool _ApplyCameraExpose(const CameraConfigParam& param);
|
|
bool _ApplyCameraGain(const CameraConfigParam& param);
|
|
bool _ApplyCameraFrameRate(const CameraConfigParam& param);
|
|
bool _ApplyCameraSwing(const SwingConfigParam& param);
|
|
bool _ApplyAlgoParam(const AlgoConfigParam& param);
|
|
bool _ApplyCalibParam(const CalibConfigParam& param);
|
|
bool _ApplyFullConfig(const FullConfigParam& param);
|
|
|
|
// 通知相关
|
|
void _NotifyConfigChanged();
|
|
void _NotifyCameraParamChanged(int cameraIndex);
|
|
void _NotifyAlgorithmParamChanged();
|
|
void _CleanupExpiredListeners();
|
|
|
|
// 初始化相关
|
|
bool _InitializeSharedMemory();
|
|
void _CleanupSharedMemory();
|
|
bool _InitializeDefaultConfig();
|
|
|
|
// JSON序列化/反序列化
|
|
std::string _SerializeConfigToJson(const SystemConfig& config);
|
|
bool _DeserializeConfigFromJson(const std::string& json, SystemConfig& config);
|
|
};
|
|
|
|
#endif // CONFIGMANAGER_H
|