61 lines
2.1 KiB
C++
61 lines
2.1 KiB
C++
#ifndef DEBUG_DATA_SAVER_H
|
||
#define DEBUG_DATA_SAVER_H
|
||
|
||
#include <string>
|
||
#include <vector>
|
||
#include <thread>
|
||
#include <mutex>
|
||
#include <condition_variable>
|
||
#include <queue>
|
||
#include <atomic>
|
||
#include "VZNL_Types.h"
|
||
|
||
class DebugDataSaver
|
||
{
|
||
public:
|
||
explicit DebugDataSaver(int maxThreads = 4);
|
||
~DebugDataSaver();
|
||
|
||
// 异步保存点云数据(内部深拷贝数据,不阻塞调用线程)
|
||
// timestamp: 检测时刻的时间戳,格式 YYYYMMDD_HHmmss
|
||
// 调用方需在持有数据锁时调用,DeepCopyData 会在调用线程完成深拷贝
|
||
void SaveAsync(const std::string& basePath,
|
||
const std::string& timestamp,
|
||
const std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& data,
|
||
const std::string& deviceName = "");
|
||
|
||
// 停止所有工作线程(等待队列中任务完成后退出)
|
||
void Stop();
|
||
|
||
private:
|
||
struct SaveTask {
|
||
std::string filePath;
|
||
std::string deviceName;
|
||
std::vector<std::pair<EVzResultDataType, SVzLaserLineData>> data;
|
||
};
|
||
|
||
void WorkerThread();
|
||
|
||
// 深拷贝检测数据(含原始指针数组的完整拷贝)
|
||
static std::vector<std::pair<EVzResultDataType, SVzLaserLineData>> DeepCopyData(
|
||
const std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& src);
|
||
|
||
// 释放深拷贝的数据
|
||
static void FreeData(std::vector<std::pair<EVzResultDataType, SVzLaserLineData>>& data);
|
||
|
||
// 生成带日期目录的完整保存路径: basePath/YYYYMMDD/pointcloud[_deviceName]_YYYYMMDD_HHmmss_NNN.txt
|
||
// timestamp: 检测时刻的时间戳,格式 YYYYMMDD_HHmmss
|
||
// deviceName: 设备名称(为空时不包含在文件名中)
|
||
std::string GenerateSavePath(const std::string& basePath, const std::string& timestamp, const std::string& deviceName = "");
|
||
|
||
int m_maxThreads;
|
||
std::vector<std::thread> m_workers;
|
||
std::queue<SaveTask> m_taskQueue;
|
||
std::mutex m_queueMutex;
|
||
std::condition_variable m_queueCondition;
|
||
std::atomic<bool> m_running;
|
||
std::atomic<int> m_taskCounter{0};
|
||
};
|
||
|
||
#endif // DEBUG_DATA_SAVER_H
|