解决点击取消扫描后取法取消的问题

This commit is contained in:
yangjiaxuan 2023-08-12 18:43:35 +08:00
parent 2f7157c238
commit a3abedfaa3
2 changed files with 27 additions and 11 deletions

View File

@ -644,6 +644,7 @@ HGSaneDeviceImpl::HGSaneDeviceImpl(HGSaneSourceImpl* sourceImpl)
m_imageParam = NULL;
m_stopThread = HGFALSE;
m_thread = NULL;
m_cancelScan = false;
}
HGSaneDeviceImpl::~HGSaneDeviceImpl()
@ -871,6 +872,7 @@ HGResult HGSaneDeviceImpl::Start(HGWindow parent, HGSane_DeviceEventFunc eventFu
GetScanCount(&m_oldScanCount);
m_stopThread = HGFALSE;
m_cancelScan = false;
HGBase_OpenThread(ThreadFunc, this, &m_thread);
return HGBASE_ERR_OK;
}
@ -912,6 +914,7 @@ HGResult HGSaneDeviceImpl::StartWithSingleScan(HGWindow parent, HGSane_DeviceEve
SetScanCount(1);
m_stopThread = HGFALSE;
m_cancelScan = false;
HGBase_OpenThread(ThreadFunc, this, &m_thread);
return HGBASE_ERR_OK;
}
@ -941,6 +944,7 @@ void HGSaneDeviceImpl::UIResultCallback(ui_result result)
{
if (NULL != m_curDevice->m_thread)
{
m_curDevice->m_cancelScan = true;
m_curDevice->m_sourceImpl->m_saneApi.sane_cancel_api(m_curDevice->m_devHandle);
}
}
@ -1010,6 +1014,14 @@ void HGAPI HGSaneDeviceImpl::ThreadFunc(HGThread thread, HGPointer param)
}
else if (SANE_STATUS_EOF == stat2)
{
if (0 == readSize && p->m_cancelScan)
{
free(buffer);
if (NULL != p->m_scanNotify)
p->m_scanNotify((int)SANE_EVENT_SCAN_FINISHED, (void*)saneAPI.sane_strstatus_api(SANE_STATUS_CANCELLED), (int)SANE_STATUS_CANCELLED);
break;
}
if (0 == readSize || readSize != params.bytes_per_line * params.lines)
{
free(buffer);
@ -1060,18 +1072,21 @@ void HGAPI HGSaneDeviceImpl::ThreadFunc(HGThread thread, HGPointer param)
buffer = NULL;
bufferSize = 0;
SANE_Status stat3 = saneAPI.sane_start_api(p->m_devHandle);
if (SANE_STATUS_NO_DOCS == stat3)
if (!p->m_cancelScan)
{
if (NULL != p->m_scanNotify)
p->m_scanNotify((int)SANE_EVENT_SCAN_FINISHED, NULL, 0);
break;
}
else if (SANE_STATUS_GOOD != stat3)
{
if (NULL != p->m_scanNotify)
p->m_scanNotify((int)SANE_EVENT_SCAN_FINISHED, (void*)saneAPI.sane_strstatus_api(stat3), (int)stat3);
break;
SANE_Status stat3 = saneAPI.sane_start_api(p->m_devHandle);
if (SANE_STATUS_NO_DOCS == stat3)
{
if (NULL != p->m_scanNotify)
p->m_scanNotify((int)SANE_EVENT_SCAN_FINISHED, NULL, 0);
break;
}
else if (SANE_STATUS_GOOD != stat3)
{
if (NULL != p->m_scanNotify)
p->m_scanNotify((int)SANE_EVENT_SCAN_FINISHED, (void*)saneAPI.sane_strstatus_api(stat3), (int)stat3);
break;
}
}
}
}

View File

@ -120,6 +120,7 @@ private:
HGInt m_oldScanCount;
volatile HGBool m_stopThread;
HGThread m_thread;
volatile bool m_cancelScan;
};
#endif /* __HGSANEIMPL_HPP__ */