//#include "FaceDetectionParkingPush.h"


//FaceDetectionParkingPush::FaceDetectionParkingPush(){}

//FaceDetectionParkingPush::FaceDetectionParkingPush(QString &url, QString &httpUrl, QString &sSn, QTimer* devSnapSynTimer, int &channel)
//    : hDevice(-1),
//      currentConStatus(false),
//      loginParam(new SXSDKLoginParam()),
//      sxMediaFaceImageReq(new SXMediaFaceImageReq()),
//      channel(channel),
//      dev_snap_syn_timer(new QTimer(this)) {
//}

//FaceDetectionParkingPush::~FaceDetectionParkingPush() {
//    Common & instace= Common::getInstance();
//    instace.deleteObj(dev_snap_syn_timer);
//    instace.deleteObj(loginParam);
//    instace.deleteObj(sxMediaFaceImageReq);

//    QThreadPool::globalInstance()->waitForDone();

//}

//int FaceDetectionParkingPush::SdkDevLoginSyn(QString sDevId, int nDevPort, QString sUserName, QString sPassword, int nTimeout) {
//    QByteArray byteArray = sDevId.toUtf8();
//    char* cDevid=byteArray.data();

//    strcpy(loginParam->sDevId, cDevid);

//    loginParam->nDevPort=nDevPort;

//    QByteArray byteName = sUserName.toUtf8();
//    char* cName=byteName.data();

//    strcpy(loginParam->sUserName, cName);

//    if(sPassword.length()>0){
//        QByteArray bytePassword = sPassword.toUtf8();
//        strcpy(loginParam->sPassword, bytePassword.constData());
//    }else{
//        strcpy(loginParam->sPassword, "");
//    }
//    loginParam->nCnnType=EDEV_CNN_TYPE_AUTO;
//    int loginResult =XSDK_DevLoginSyn(loginParam,nTimeout);
//    if(loginResult<0){
//        qInfo() << "登录设备失败";
//        return loginResult;
//    }
//    return loginResult;
//}

//int FaceDetectionParkingPush::SdkDevSetAlarmListener(XSDK_HANDLE hDevice, int bListener) {
//    return XSDK_DevSetAlarmListener(hDevice,bListener);
//}

//int FaceDetectionParkingPush::getChannel(){
//    return channel;
//}
//int FaceDetectionParkingPush::getHdevice() {
//    return hDevice;
//}

//bool FaceDetectionParkingPush::getConnectionStatus() {
//    return currentConStatus;
//}

//void FaceDetectionParkingPush::initSdkRealTimeDevSnapSyn(int hDevice) {
//    connect(dev_snap_syn_timer, &QTimer::timeout, this, [this,hDevice]() {
//        this->SdkRealTimeDevSnapSyn(hDevice);
//    }, Qt::QueuedConnection);
//    dev_snap_syn_timer->start(2000);
//}

//void FaceDetectionParkingPush::SdkRealTimeDevSnapSyn(int hDevice) {
//    QThreadPool* threadPool = QThreadPool::globalInstance();
//    threadPool->setMaxThreadCount(6);
//    if (!task) { // 检查是否已经创建了TaskRunnable
//        task = new TaskRunnable(this, hDevice, this->channel,TaskRunnable::SdkDevSnapSyn);
//        task->setAutoDelete(false); // 确保task不会在执行后被自动删除
//    }else {
//        task->setHdevice(hDevice);
//        task->setChannel(this->channel);
//        task->setCallbackFunction(TaskRunnable::SdkDevSnapSyn);
//    }

//    if (!threadPool->tryStart(task)) { // 尝试启动任务，如果线程池满了则不会启动
//        qDebug() << "线程池已满，无法启动TaskRunnable";
//    }
//}
//TaskRunnable*FaceDetectionParkingPush::getTask(){
//    return task;
//}
//void FaceDetectionParkingPush::setTask(TaskRunnable* newTask){
//    this->task=newTask;
//}

//int FaceDetectionParkingPush::CallbackFunction(XSDK_HANDLE hObject, QString &szString) {
//    QByteArray && byJson = szString.toLocal8Bit();
//    const char * cJson= byJson.data();
//    XSDK_CFG::AlarmInfo alarmInfo;
//    if (0 == alarmInfo.Parse(cJson))
//    {
//        const char* buf = alarmInfo.Event.ToString();
//        qInfo() << "buf:"<<buf;
//        qInfo() << "OnDevAlarmCallback[Dev:" << hObject << "]"
//                << "\r\nEvent:" << alarmInfo.Event.Value()
//                << "\r\nChannel:" << alarmInfo.Channel.Value()
//                << "\r\nStartTime:" << alarmInfo.StartTime.Value()
//                << "\r\nStatus:" << alarmInfo.Status.Value();

//    }
//    else
//    {
//        qDebug() << "OnDevAlarmCallback[Dev:" << hObject << "][Event:" << szString << "]";
//    }
//    cv::Mat image;
//    MediaFaceImage* mediaFaceImage= MediaFaceImage::getInstance();
//    mediaFaceImage->FaceImageCallBack(hObject,sxMediaFaceImageReq->nChannel,image);
//    if (image.empty())
//    {
//        qInfo() << "Failed to read the image";
//        return -1;
//    }
//    this->updateImage(image, url);
//}


//void FaceDetectionParkingPush::updateImage(const cv::Mat & frame,const QString  &respUrl){
//    FaceReconition &faceRecognition = FaceReconition::getInstance();
//    LicensePlateRecognition &licensePlateRecogn =LicensePlateRecognition::getInstance();

//    //faceRecognition.search(frame,imageHandleList,names);

//    if(faceRecognition.doesItExistEmployee(frame)){

//    }
//    QString lpNumber;


//    licensePlateRecogn.licensePlateNumber(frame, lpNumber);
//    std::lock_guard<std::mutex> guard(queueMutex);
//    if (queuels.size() >= 10) {
//        queuels.dequeue();
//    }
//    RecognizedInfo recognizedInfo(lpNumber,QDateTime::currentMSecsSinceEpoch());
//    queuels.enqueue(recognizedInfo);
//    this->CheckAndUpdateCurrentPlate(recognizedInfo);
//    if(lpNumber.length()>0){
//        qDebug()<<QString("识别的车牌号是:%1").arg(lpNumber);
//    }else {
//        qDebug()<<QString("当前这帧图像未识别车牌");
//    }

//}
//void FaceDetectionParkingPush::CheckAndUpdateCurrentPlate( RecognizedInfo& newInfo){
//    std::lock_guard<std::mutex> guard(plateMutex);
//    if (newInfo.getLicensePlate() != currentPlate.getLicensePlate()) {
//        int count = 0;
//        for (auto& info : queuels) {
//            if (info.getLicensePlate() == newInfo.getLicensePlate()) {
//                count++;
//            }
//        }
//        //第一次进场 当前车牌就是进来这个，老车牌就是空
//        //出场的时候   当前车牌是空， 老车牌是出厂车牌
//        if (count >= 3) {
//            if(currentPlate.getLicensePlate().length()<=0){
//                qInfo()<<"未出场车:"<<currentPlate.getLicensePlate()<<"进场的车牌号:"<<newInfo.getLicensePlate();
//            }else {
//                qInfo()<<"出场车牌号:"<<currentPlate.getLicensePlate()<<"进场的车牌号:"<<newInfo.getLicensePlate();
//            }
//            XSDK_HANDLE h_device=getHdevice();
//            QMetaObject::invokeMethod(dev_snap_syn_timer, "stop", Qt::QueuedConnection);
//            QObject::disconnect(dev_snap_syn_timer, &QTimer::timeout, MainWindow::sp_this, nullptr);
//            QObject::connect(dev_snap_syn_timer, &QTimer::timeout, MainWindow::sp_this, [this, h_device]() {
//                this->SdkRealTimeDevSnapSyn(h_device);
//            }, Qt::QueuedConnection);
//            QMetaObject::invokeMethod(dev_snap_syn_timer, "start", Qt::QueuedConnection, Q_ARG(int, 15000));
//            currentPlate = newInfo;
//        }
//    }
//}
//void FaceDetectionParkingPush::SdkDevSnapSyn(XSDK_HANDLE hDevice, int nChannel){
//    if(hDevice<=0){
//        qInfo() << "相机断线";
//        return;
//    }
//    cv::Mat image;
//    MediaFaceImage* mediaFaceImage= MediaFaceImage::getInstance();
//    int ret=mediaFaceImage->FaceImageCallBack(hDevice,nChannel, image);
//    Common & instace= Common::getInstance();
//    vides_data::requestDeviceStatus reStatus;
//    reStatus.sSn=sSn;
//    if(ret>0){
//        if(!currentConStatus){
//            reStatus.status=1;
//            reStatus.type=2;
//            HttpService httpService(httpUrl);
//            vides_data::response*re= httpService.httpPostDeviceStatus(reStatus);
//            if(re->code!=0){
//                qInfo()<<"请求设备状态失败";
//            }
//            instace.deleteObj(re);
//        }
//        currentConStatus=true;
//    }else{
//        if(currentConStatus){
//            reStatus.status=0;
//            reStatus.type=2;
//            HttpService httpService(httpUrl);
//            vides_data::response*re= httpService.httpPostDeviceStatus(reStatus);
//            if(re->code!=0){
//                qInfo()<<"请求设备状态失败";
//            }
//            instace.deleteObj(re);
//        }
//        currentConStatus=false;
//    }
//    if (image.empty())
//    {
//        qInfo() << "Failed to read the image";
//        return;
//    }
//    this->updateImage(image, url);
//}
