65 lines
1.2 KiB
C++
65 lines
1.2 KiB
C++
#include <unordered_map>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <triggerManager.h>
|
|
#include <mutex>
|
|
//typedef std::vector<std::string> cmdVec;
|
|
struct cmdData
|
|
{
|
|
bool _2dOK = false, _3dOk = false;
|
|
std::vector<QString> cmds;
|
|
};
|
|
class summaryData
|
|
{
|
|
public:
|
|
summaryData(triggerManager* triggerPtr):
|
|
_trigger(triggerPtr)
|
|
{
|
|
|
|
}
|
|
enum type
|
|
{
|
|
_2d,
|
|
_3d
|
|
};
|
|
std::unordered_map<std::string, cmdData> map;
|
|
void cleanAbove(int num)
|
|
{
|
|
for (auto it = map.end(); map.size() > num ; it--)
|
|
{
|
|
map.erase(it);
|
|
}
|
|
|
|
}
|
|
void add(std::string sn, std::vector<QString> cmds,type _type)
|
|
{
|
|
_mutex.lock();
|
|
cleanAbove(100);
|
|
if (map.find(sn) == map.end())//Êý¾Ý²»´æÔÚ
|
|
map.insert(std::make_pair(sn, cmdData()));//ÐÂÔö
|
|
|
|
auto it = map.find(sn);
|
|
it->second.cmds.insert(it->second.cmds.end(),cmds.begin(), cmds.end());
|
|
switch (_type)
|
|
{
|
|
case _2d:
|
|
it->second._2dOK = true;
|
|
break;
|
|
case _3d :
|
|
it->second._3dOk = true;
|
|
break;
|
|
}
|
|
if (it->second._2dOK == true && it->second._3dOk == true)
|
|
{
|
|
qDebug() << QString::fromStdString(sn) << "send sum data";
|
|
for (auto& cmd : it->second.cmds)
|
|
_trigger->sendFinsMsg(cmd);
|
|
map.erase(it);
|
|
}
|
|
_mutex.unlock();
|
|
}
|
|
private:
|
|
std::mutex _mutex;
|
|
triggerManager* _trigger;
|
|
};
|
|
#pragma once |