From 2dfc05386d33ec9c258ab5a6f5388c74e0ec6200 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Mon, 18 Dec 2023 17:12:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=B5=8B=E8=AF=95=E8=BF=87?= =?UTF-8?q?=E7=A8=8B=E4=B8=AD=E6=96=AD=E5=BC=80usb=E4=BC=9A=E5=87=BA?= =?UTF-8?q?=E7=8E=B0=E5=8D=A1=E6=AD=BB=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/HGProductionTool/mainwindow.cpp | 53 +++++++++++++++++++---------- app/HGProductionTool/mainwindow.h | 10 ++++++ 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/app/HGProductionTool/mainwindow.cpp b/app/HGProductionTool/mainwindow.cpp index 700c67c..61a4763 100644 --- a/app/HGProductionTool/mainwindow.cpp +++ b/app/HGProductionTool/mainwindow.cpp @@ -53,6 +53,7 @@ MainWindow::MainWindow(Dialog_logIn::LogInType loginType, const QString &profile connect(this, SIGNAL(sane_dev_arrive(QString)), this, SLOT(on_sane_dev_arrive(QString)), Qt::QueuedConnection); connect(this, SIGNAL(sane_dev_remove(QString)), this, SLOT(on_sane_dev_remove(QString)), Qt::QueuedConnection); + connect(this, &MainWindow::sane_create_interface, this, &MainWindow::on_sane_create_interface, Qt::QueuedConnection); if (m_loginType == Dialog_logIn::LogInType_Burn) { @@ -112,7 +113,7 @@ MainWindow::MainWindow(Dialog_logIn::LogInType loginType, const QString &profile MainWindow::~MainWindow() { - HGBase_EnterLock(m_lock); + //HGBase_EnterLock(m_lock); if (m_top_splitter != nullptr) { while (0 != m_top_splitter->count()) @@ -131,7 +132,7 @@ MainWindow::~MainWindow() } } - HGBase_LeaveLock(m_lock); + //HGBase_LeaveLock(m_lock); sane_exit(); @@ -254,7 +255,7 @@ bool MainWindow::AddInterface(Form_mainInterface * mainInterface) { assert(nullptr != mainInterface); - HGBase_EnterLock(m_lock); + //HGBase_EnterLock(m_lock); bool ret = false; if (m_top_splitter->count() < 2) { @@ -266,7 +267,7 @@ bool MainWindow::AddInterface(Form_mainInterface * mainInterface) m_bot_splitter->addWidget(mainInterface); ret = true; } - HGBase_LeaveLock(m_lock); + //HGBase_LeaveLock(m_lock); updateSplitter(); return ret; @@ -275,9 +276,11 @@ bool MainWindow::AddInterface(Form_mainInterface * mainInterface) bool MainWindow::RemoveInterface(Form_mainInterface * mainInterface) { assert(nullptr != mainInterface); - HGBase_EnterLock(m_lock); + //HGBase_EnterLock(m_lock); delete mainInterface; - HGBase_LeaveLock(m_lock); + mainInterface = nullptr; + m_testingRef = 0; + //HGBase_LeaveLock(m_lock); updateSplitter(); return true; } @@ -343,17 +346,13 @@ int MainWindow::sane_ex_callback(SANE_Handle hdev, int code, void *data, unsigne if (code == SANE_EVENT_IMAGE_OK || code == SANE_EVENT_SCAN_FINISHED || code == SANE_EVENT_ERROR || code == SANE_EVENT_STATUS) { - HGBase_EnterLock(p->m_lock); - if (p->m_loginType != Dialog_logIn::LogInType_Burn) - { - Form_mainInterface* mainInterface = p->FindInterface(hdev); - if (nullptr != mainInterface) - { - if (nullptr != mainInterface->getScanner() && nullptr != mainInterface->getScanner()->cb_) - mainInterface->getScanner()->cb_(hdev, code, data, len, mainInterface->getScanner()); - } - } - HGBase_LeaveLock(p->m_lock); + SaneParams *saneParams = new SaneParams; + saneParams->hdev = hdev; + saneParams->code = code; + saneParams->data = data; + saneParams->len = len; + + emit p->sane_create_interface(saneParams); } return 0; @@ -496,7 +495,7 @@ void MainWindow::on_sane_dev_remove(QString devName) if (mainInterface != nullptr) { mainInterface->setDevDisconnect(); - if (!mainInterface->isTesting()) + //if (!mainInterface->isTesting()) { RemoveInterface(mainInterface); } @@ -504,6 +503,24 @@ void MainWindow::on_sane_dev_remove(QString devName) } } +void MainWindow::on_sane_create_interface(SaneParams *saneParams) +{ + if (m_loginType != Dialog_logIn::LogInType_Burn) + { + Form_mainInterface* mainInterface = FindInterface(saneParams->hdev); + if (nullptr != mainInterface) + { + if (nullptr != mainInterface->getScanner() && nullptr != mainInterface->getScanner()->cb_) + { + mainInterface->getScanner()->cb_(saneParams->hdev, saneParams->code, saneParams->data, saneParams->len, mainInterface->getScanner()); + } + } + } + + delete saneParams; + saneParams = nullptr; +} + void MainWindow::on_update_userStatus() { QString tips; diff --git a/app/HGProductionTool/mainwindow.h b/app/HGProductionTool/mainwindow.h index 9fc0294..470756f 100644 --- a/app/HGProductionTool/mainwindow.h +++ b/app/HGProductionTool/mainwindow.h @@ -46,13 +46,23 @@ private: QString getDevType(SANE_Handle handle); QString getDevFwNum(SANE_Handle handle); + struct SaneParams + { + SANE_Handle hdev; + int code; + void *data; + unsigned int *len; + }; + signals: void sane_dev_arrive(QString devName); void sane_dev_remove(QString devName); + void sane_create_interface(SaneParams *saneParams); private slots: void on_sane_dev_arrive(QString devName); void on_sane_dev_remove(QString devName); + void on_sane_create_interface(SaneParams *saneParams); void on_update_userStatus(); private slots: