设备被占用的错误消息,返回占用设备的进程名称及PID

This commit is contained in:
gb 2023-07-02 14:13:55 +08:00
parent 0c851dc2a0
commit 291fe2ccbb
4 changed files with 16 additions and 6 deletions

View File

@ -1,4 +1,4 @@
#include "hg_scanner_200.h"
#include "hg_scanner_200.h"
#include "../wrapper/hg_log.h"
#if defined(WIN32) || defined(_WIN64)

View File

@ -134,6 +134,7 @@ int hg_scanner_mgr::ver_build_ = 0;
int hg_scanner_mgr::ver_patch_ = 1;
std::string hg_scanner_mgr::pe_path_("");
std::string hg_scanner_mgr::pe_name_("");
std::string hg_scanner_mgr::last_open_msg_("");
bool hg_scanner_mgr::read_over_with_eof_ = true;
uint32_t hg_scanner_mgr::unique_img_id_ = 0;;
@ -701,8 +702,8 @@ scanner_err hg_scanner_mgr::hg_scanner_open(scanner_handle* h, const char* name,
it = std::find(devs.begin(), devs.end(), name);
if (it != devs.end())
{
std::string msg("");
ret = (scanner_err)usb_manager::instance()->open(it->dev, &io, &msg);
hg_scanner_mgr::last_open_msg_ = "";
ret = (scanner_err)usb_manager::instance()->open(it->dev, &io, &hg_scanner_mgr::last_open_msg_);
if (ret == SCANNER_ERR_OK)
{
hg_scanner* scanner = g_supporting_devices[it->ind].create_scanner(it->display_name.c_str(), io, h);
@ -763,8 +764,8 @@ scanner_err hg_scanner_mgr::hg_scanner_open(scanner_handle* h, const char* name,
if (ptr != online_devices_.end())
ptr->scanner = (hg_scanner*)*h;
}
else if(msg.length())
hg_scanner_mgr::ui_default_callback(nullptr, SANE_EVENT_ERROR, (void*)msg.c_str(), (unsigned int*)&ret, nullptr);
else if(hg_scanner_mgr::last_open_msg_.length())
hg_scanner_mgr::ui_default_callback(nullptr, SANE_EVENT_ERROR, (void*)hg_scanner_mgr::last_open_msg_.c_str(), (unsigned int*)&ret, nullptr);
if(io)
io->release();
@ -1089,4 +1090,8 @@ void hg_scanner_mgr::on_language_changed(void)
if (v.scanner)
v.scanner->on_language_changed();
}
}
}
const char* hg_scanner_mgr::last_open_message(void)
{
return hg_scanner_mgr::last_open_msg_.c_str();
}

View File

@ -70,6 +70,7 @@ class hg_scanner_mgr
static sane_callback event_callback_;
static bool async_io_enabled_;
static std::string last_open_msg_;
static std::string pe_path_;
static std::string pe_name_;
static bool read_over_with_eof_;
@ -135,5 +136,6 @@ public:
scanner_err hg_scanner_control(scanner_handle h, unsigned long code, void* data, unsigned* len);
void on_language_changed(void);
const char* last_open_message(void);
};

View File

@ -266,6 +266,9 @@ extern "C"
if (err < 0x100)
err = err_map::sane_2_scanner(err);
if (err == SCANNER_ERR_OPENED_BY_OTHER_PROCESS && *hg_scanner_mgr::instance()->last_open_message())
return hg_scanner_mgr::instance()->last_open_message();
RETURN_DESC_IF(err, SCANNER_ERR_OK);
RETURN_DESC_IF(err, SCANNER_ERR_DEVICE_NOT_SUPPORT);
RETURN_DESC_IF(err, SCANNER_ERR_USER_CANCELED);