SANE属性管理移文件到独立文件夹

This commit is contained in:
gb 2023-09-22 09:42:37 +08:00
parent 4126436934
commit 5c17d26304
10 changed files with 28 additions and 12 deletions

View File

@ -6,14 +6,13 @@
#include "scanner_setting.h" #include "scanner_setting.h"
#include "scanner_manager.h" #include "scanner_manager.h"
#include "../../sdk/json/gb_json.h" #include "../../sdk/json/gb_json.h"
#include "device_opt.h" #include "user-opt/device_opt.h"
#include <string.h> #include <string.h>
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
#include <direct.h> #include <direct.h>
#endif #endif
#define DYN_JSON_BETWEEN_PAPER_AND_DPI
#if defined(WIN32) || defined(_WIN64) #if defined(WIN32) || defined(_WIN64)
static int load_dll(const wchar_t* path_dll, HMODULE* dll) static int load_dll(const wchar_t* path_dll, HMODULE* dll)
@ -199,7 +198,7 @@ hg_scanner::hg_scanner(ScannerSerial serial, const char* dev_name, usb_io* io, i
if (!mem.empty()) if (!mem.empty())
{ {
memory_size_ = std::stoi(mem); memory_size_ = std::stoi(mem);
utils::to_log(LOG_LEVEL_DEBUG, "Get the config file --->memory_size_ set is :%lld", memory_size_); utils::to_log(LOG_LEVEL_DEBUG, "Get the config file --->memory_size_ set is :%lld\n", memory_size_);
} }
getl = GetPrivateProfileStringA("cpu", "advanced", "", strbuf, sizeof(strbuf) - 1, config_file.c_str()); getl = GetPrivateProfileStringA("cpu", "advanced", "", strbuf, sizeof(strbuf) - 1, config_file.c_str());
strbuf[getl] = 0; strbuf[getl] = 0;
@ -207,7 +206,7 @@ hg_scanner::hg_scanner(ScannerSerial serial, const char* dev_name, usb_io* io, i
if (!adv.empty()) if (!adv.empty())
{ {
isx86_Advan_ = adv == "0" ? false : true; isx86_Advan_ = adv == "0" ? false : true;
utils::to_log(LOG_LEVEL_DEBUG, "Get the config file --->isx86_Advan_ set is :%d", isx86_Advan_); utils::to_log(LOG_LEVEL_DEBUG, "Get the config file --->isx86_Advan_ set is :%d\n", isx86_Advan_);
} }
if (utils::create_folder(final_path_.c_str())) if (utils::create_folder(final_path_.c_str()))

View File

@ -166,13 +166,13 @@ hg_scanner_mgr::hg_scanner_mgr() : same_ind_(1), user_(""), pwd_(""), cf_name(""
} }
hg_scanner_mgr::~hg_scanner_mgr() hg_scanner_mgr::~hg_scanner_mgr()
{ {
usb_manager::instance()->register_hotplug(nullptr, nullptr);
{ {
std::lock_guard<std::mutex> lock(mutex_dev_); std::lock_guard<std::mutex> lock(mutex_dev_);
for (auto& v : online_devices_) for (auto& v : online_devices_)
libusb_unref_device(v.dev); libusb_unref_device(v.dev);
online_devices_.clear(); online_devices_.clear();
} }
usb_manager::clear(); usb_manager::clear();
} }

View File

@ -234,9 +234,18 @@ void usb_manager::notify_usb_event(PNPDEV& pd, bool* retry)
, HIBYTE(ud.ver), LOBYTE(ud.ver) / 0x10, ud.pid, ud.vid, evstr.c_str()); , HIBYTE(ud.ver), LOBYTE(ud.ver) / 0x10, ud.pid, ud.vid, evstr.c_str());
if (ev != USB_EVENT_NULL) if (ev != USB_EVENT_NULL)
{ {
usb_event_handler cb(&usb_manager::usb_event_handle);
void* cbp = nullptr;
{
std::lock_guard<std::mutex> lock(usb_cb_locker_);
cb = usb_cb_;
cbp = usb_cb_param_;
}
if (!retry) if (!retry)
retry = &re_try; retry = &re_try;
usb_cb_(ev, pd.dev, ud.vid, ud.pid, HIBYTE(ud.ver), LOBYTE(ud.ver) / 0x10, retry, usb_cb_param_); cb(ev, pd.dev, ud.vid, ud.pid, HIBYTE(ud.ver), LOBYTE(ud.ver) / 0x10, retry, cbp);
} }
libusb_unref_device(pd.dev); // response for libusb_ref_device in usb_manager::usb_pnp_callback libusb_unref_device(pd.dev); // response for libusb_ref_device in usb_manager::usb_pnp_callback
} }
@ -526,11 +535,18 @@ void usb_manager::enum_endpoints(libusb_device* device, USBTRANSENDP* endp)
int usb_manager::register_hotplug(usb_event_handler cb, void* user) int usb_manager::register_hotplug(usb_event_handler cb, void* user)
{ {
if (cb) {
usb_cb_ = cb; std::lock_guard<std::mutex> lock(usb_cb_locker_);
else if (cb)
usb_cb_ = &usb_manager::usb_event_handle; usb_cb_ = cb;
usb_cb_param_ = user; else
{
usb_cb_ = &usb_manager::usb_event_handle;
return SCANNER_ERR_OK;
}
usb_cb_param_ = user;
}
int ret = register_usb_pnp(); int ret = register_usb_pnp();
if (ret != LIBUSB_SUCCESS) if (ret != LIBUSB_SUCCESS)

View File

@ -62,6 +62,7 @@ class usb_manager
{ {
volatile bool run_; volatile bool run_;
usb_event_handler usb_cb_; usb_event_handler usb_cb_;
std::mutex usb_cb_locker_;
libusb_context* context_; // declare my own context, avoid sharing the default context with other processes libusb_context* context_; // declare my own context, avoid sharing the default context with other processes
int status_; int status_;
void* usb_cb_param_; void* usb_cb_param_;

View File

@ -2,7 +2,7 @@
#include <hginclude/utils.h> #include <hginclude/utils.h>
#include <huagao/hgscanner_error.h> #include <huagao/hgscanner_error.h>
#include "../../sdk/hginclude/huagaoxxx_warraper_ex.h" #include "../../../sdk/hginclude/huagaoxxx_warraper_ex.h"
#include <lang/app_language.h> #include <lang/app_language.h>