优化后端结构

This commit is contained in:
2024-05-22 16:47:14 +08:00
parent 323cc25cf7
commit e867d2d251
52 changed files with 653 additions and 5117 deletions
@@ -1,12 +1,11 @@
#include <threadPoolManager.h>
#include "camera_thread.h"
#include "myiothread.h"
#include <FrontendBackendBridge.h>
#include <algorithmThread.h>
/// <summary>
/// 检查目标文件夹是否存在,不存在则创建
/// </summary>
/// <param name="path"></param>
using namespace std;
void createDirectoryIfNotExists_2(const std::string& path) {
// 检查路径是否存在
if (!std::filesystem::exists(path)) {
@@ -59,48 +58,9 @@ threadManager::threadManager(QObject* parent) : QThread(parent)
void threadManager::run()
{
return;
while (1)
{
while (insertQueue.size() > 0)
{
insertQueueMutex.lock();
while (insertQueue.size() > 0)
{
imgWaitList.push_back(insertQueue.dequeue());
}
insertQueueMutex.unlock();
}
if (imgWaitList.size() > 0)
{
for (int i = 0; i < imgWaitList.size(); i++)
{
int imgSize = imgWaitList[i]->imgs.size();
int imgAmountMin = imgWaitList[i]->imgAmountMin;
if (imgSize >= imgAmountMin)
{
int threadId = imgWaitList[i]->algoThreadIndex;
if (threadId == -1)
{
cout << "threadId return -1 ,algoName " << imgWaitList[i]->algoThreadName.toStdString() << endl;
imgWaitList.removeAt(i);
return;
}
algoThreadList[threadId]->addDetTask(imgWaitList[i]);
cout << "Size " << imgWaitList.size() << " delete " << i << endl;
imgWaitList.erase(imgWaitList.begin() + i);
for (auto& data : imgWaitList)
{
cout << "remain " << data->cameraKeyName.toStdString() << " " << data->algoThreadName.toStdString() << " " << data->cameraNameStr << endl;
}
break;
}
}
}
QThread::msleep(10);
}
}
void threadManager::addTask(detData* data)
void threadManager::addTask(std::shared_ptr <detData> data)
{
//cout << __LINE__ << "insert Data " << data ->timeCode<< endl;
{
@@ -125,29 +85,7 @@ void threadManager::addTask(detData* data)
insertQueueMutex.unlock();
//this->start();
}
bool threadManager::getFreeThread()
{
#if 0
int index = 0;
for (index = 0; index < threadPoolList.size(); index++)
{
if (threadPoolList[index]->isRunning() == false)
{
return true;
}
}
for (index = 0; index < threadPoolList.size(); index++)
{
if (threadPoolList[index]->nextObj.isEmpty() == true)
{
return true;
}
}
#endif
return false;
}
bool threadManager::addTaskFreeThread(detData* data)
bool threadManager::addTaskFreeThread(std::shared_ptr <detData> data)
{
#if 0
int index = 0;
@@ -177,13 +115,14 @@ threadManager::~threadManager()
for (auto thread : algoThreadList)
{
thread->m_runFlag = false;
while (thread->isRunning() == false);
thread->terminate();
while (thread->isRunning() == true);
}
for (auto thread : algoThreadList)
{
delete thread;
}
}
}
////////////////DET//DATA//////////////////
sncodeCls::sncodeCls()
{
@@ -221,6 +160,8 @@ void sncodeCls::checkSnFromWaittingVec(QByteArray byte)
}
}
}
//FINSEDIT
string sncodeCls::readSnFromQByteArray(QByteArray byte, int dmPos,
bool highLowConversion, bool clearAfterRead, long long timeCode, int Size)
{
@@ -251,10 +192,10 @@ string sncodeCls::readSnFromQByteArray(QByteArray byte, int dmPos,
}
if (str.size() < Size && Size != -1)
return snErrorsnError;
if (clearAfterRead == true)
//for(int i=0;i< snCount;i++)
bridge.back.sendFinsMsg(
QString::fromStdString("writeALL_DM" + to_string(dmPos) + "_" + to_string(snCount) + "_0"));
//if (clearAfterRead == true)
// //for(int i=0;i< snCount;i++)
// bridge.back.sendFinsMsg(
//QString::fromStdString("writeALL_DM" + to_string(dmPos) + "_" + to_string(snCount) + "_0"));
return str.toStdString();
}
QString sncodeCls::snHex(QString sn)