//#include "FaceDetectionParkingPush.h"
//#include "RecognitionInfo.h"
//#include "XSDKPublic.h"
//#include "Common.h"
//#include "MediaFaceImage.h"
//#include "Json_Header/AlarmInfo.h"
//#include "FaceRecognition.h"
//#include "LicensePlateRecognition.h"
//#include "mainwindow.h"
//#include "HttpService.h"
//#include <string.h>
//#include <functional>
//#include <QQueue>
//#include <QtCore/QThread>
//#include <QJsonDocument>

//class FaceDetectionParkingPushImpl {
//public:
//    FaceDetectionParkingPushImpl(FaceDetectionParkingPush* parent,QString &url,QTimer* devSnapSynTimer,QString &httpUrl,QString &sSn);
//    ~FaceDetectionParkingPushImpl();
    
//    int SdkInit(QString &szConfigPath, QString &szTempPath,int channel);
    
//    XSDK_HANDLE SdkDevLoginSyn(QString sDevId, int nDevPort, QString sUserName, QString sPassword, int nTimeout);
//    XSDK_HANDLE SdkDevSetAlarmListener(XSDK_HANDLE hDevice, int bListener);

//    int CallbackFunction(XSDK_HANDLE hObject,QString &szString);
    
//    void updateImage(const cv::Mat & frame,const QString  &respUrl);
    
//    void SdkDevSnapSyn(XSDK_HANDLE hDevice,int nChannel);
    
//    void CheckAndUpdateCurrentPlate(RecognizedInfo& newInfo);
    
//    CameraThread *getCameraThread();

//    bool findInitAndCurrentStatus( bool initConStatus,bool currentConStatus);
    
//private:
//    FaceDetectionParkingPush* parent;

//    SXSDKLoginParam *loginParam;
//    SXMediaFaceImageReq *sxMediaFaceImageReq;
//    std::mutex queueMutex;
//    std::mutex plateMutex;
    
//    QQueue<RecognizedInfo> queuels;
    
//    RecognizedInfo currentPlate;

//    QString sSn;
//    QString url;
    
//    QString httpUrl;
//    int channel;
//    QTimer* devSnapSynTimer;
    
//    volatile bool currentConStatus=false;

//    XSDK_HANDLE hDevice;
    
//};
//void FaceDetectionParkingPushImpl::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=parent->getHdevice();
//            QMetaObject::invokeMethod(devSnapSynTimer, "stop", Qt::QueuedConnection);
//            QObject::disconnect(devSnapSynTimer, &QTimer::timeout, MainWindow::sp_this, nullptr);
//            QObject::connect(devSnapSynTimer, &QTimer::timeout, MainWindow::sp_this, [this, h_device]() {
//                this->parent->SdkRealTimeDevSnapSyn(h_device);
//            }, Qt::QueuedConnection);
//            QMetaObject::invokeMethod(devSnapSynTimer, "start", Qt::QueuedConnection, Q_ARG(int, 15000));
//            currentPlate = newInfo;
//        }
//    }
//}
//void FaceDetectionParkingPushImpl::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);
//}
//int XNetSDK_Media_CallBack(XSDK_HANDLE hMedia, int nDataType, int nDataLen, int nParam2, int nParam3, const char* szString, void* pData, int64 pDataInfo, int nSeq, void* pUserData, void* pMsg)
//{
    
//    if (EXSDK_DATA_FORMATE_FRAME == nDataType)
//    {
//    }
//    return 0;
//}

//FaceDetectionParkingPushImpl::FaceDetectionParkingPushImpl(FaceDetectionParkingPush* parent, QString &url,QTimer* devSnapSynTimer,QString &httpUrl,QString &sSn)
//    :parent(parent),
//      loginParam(new SXSDKLoginParam()),
//      sxMediaFaceImageReq(new SXMediaFaceImageReq()),
//      url(url),
//      devSnapSynTimer(devSnapSynTimer),
//      httpUrl(httpUrl),
//      sSn(sSn)
//{
//}
//XSDK_HANDLE FaceDetectionParkingPushImpl::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;
//}

//void FaceDetectionParkingPushImpl::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("当前这帧图像未识别车牌");
//    }
    
//}

//XSDK_HANDLE FaceDetectionParkingPushImpl::SdkDevSetAlarmListener(XSDK_HANDLE hDevice, int bListener) {
//    this->hDevice=hDevice;
//    return XSDK_DevSetAlarmListener(hDevice,bListener);
//}
//int FaceDetectionParkingPushImpl::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);
//}

//FaceDetectionParkingPushImpl::~FaceDetectionParkingPushImpl() {
//    Common & instace= Common::getInstance();
//    instace.deleteObj(loginParam);
//    instace.deleteObj(sxMediaFaceImageReq);
//    XSDK_DevLogout(this->hDevice);

//}

//FaceDetectionParkingPush::FaceDetectionParkingPush(QString &url,QString &httpUrl,QString &sSn,QTimer* devSnapSynTimer, int &channel)
//    : m_pImpl(new FaceDetectionParkingPushImpl(this, url,devSnapSynTimer,httpUrl,sSn)),
//      channel(channel) {
//     currentThread=new CameraThread(this);
//     dev_snap_syn_timer=new QTimer(this);
//}

//FaceDetectionParkingPush::~FaceDetectionParkingPush() {
//    Common & instace= Common::getInstance();
//    instace.deleteObj(currentThread);
//    delete m_pImpl;
//}


//int FaceDetectionParkingPush::SdkDevLoginSyn(QString sDevId, int nDevPort, QString sUserName, QString sPassword, int nTimeout) {
//    return m_pImpl->SdkDevLoginSyn(sDevId, nDevPort, sUserName, sPassword, nTimeout);
//}

//XSDK_HANDLE FaceDetectionParkingPush::SdkDevSetAlarmListener(XSDK_HANDLE hDevice,int bListener) {
//    this->hDevice=hDevice;
//    return m_pImpl->SdkDevSetAlarmListener(hDevice, bListener);
//}
//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){
//    auto task =std::bind(&FaceDetectionParkingPushImpl::SdkDevSnapSyn, m_pImpl, hDevice, this->channel);
//    this->getCameraThread()->addTask(task);
//    this->getCameraThread()->start();
//    qDebug() << "SdkRealTimeDevSnapSyn===========";

//}
//int FaceDetectionParkingPush::getHdevice(){
//    return hDevice;
//}
//int FaceDetectionParkingPush::CallbackFunction(int hObject,QString &szString) {
//    return m_pImpl->CallbackFunction(hObject,szString);
//}
//CameraThread *FaceDetectionParkingPush::getCameraThread(){
//    return currentThread;
//}
//FaceDetectionParkingPushImpl *FaceDetectionParkingPush::getImpl(){
//    return m_pImpl;
//}
