modify digital compare bug, add lock on reset callback
This commit is contained in:
parent
0dceb19ac5
commit
c5e337ad06
|
@ -103,6 +103,10 @@ void hg_scanner_mgr::clear(void)
|
||||||
{
|
{
|
||||||
if (hg_scanner_mgr::inst_)
|
if (hg_scanner_mgr::inst_)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock(hg_scanner_mgr::inst_->mutex_dev_);
|
||||||
|
hg_scanner_mgr::event_callback_ = nullptr;
|
||||||
|
}
|
||||||
delete hg_scanner_mgr::inst_;
|
delete hg_scanner_mgr::inst_;
|
||||||
hg_scanner_mgr::inst_ = NULL;
|
hg_scanner_mgr::inst_ = NULL;
|
||||||
}
|
}
|
||||||
|
@ -131,6 +135,7 @@ void hg_scanner_mgr::on_hgscanner_pnp(usb_event ev, libusb_device* device, int v
|
||||||
scanner_handle h = NULL;
|
scanner_handle h = NULL;
|
||||||
unsigned int len = sizeof(de);
|
unsigned int len = sizeof(de);
|
||||||
std::string name(""), type("");
|
std::string name(""), type("");
|
||||||
|
std::lock_guard<std::mutex> lock(mutex_dev_);
|
||||||
|
|
||||||
sprintf(model, "%x", pid);
|
sprintf(model, "%x", pid);
|
||||||
sprintf(vendor, "%x", vid);
|
sprintf(vendor, "%x", vid);
|
||||||
|
@ -158,7 +163,6 @@ void hg_scanner_mgr::on_hgscanner_pnp(usb_event ev, libusb_device* device, int v
|
||||||
|
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_dev_);
|
|
||||||
bool add = true;
|
bool add = true;
|
||||||
for (size_t i = 0; i < online_devices_.size(); ++i)
|
for (size_t i = 0; i < online_devices_.size(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -216,7 +220,6 @@ void hg_scanner_mgr::on_hgscanner_pnp(usb_event ev, libusb_device* device, int v
|
||||||
}
|
}
|
||||||
else if (ev == USB_EVENT_DEVICE_LEFT)
|
else if (ev == USB_EVENT_DEVICE_LEFT)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_dev_);
|
|
||||||
std::vector<OLSCANNER>::iterator it = std::find(online_devices_.begin(), online_devices_.end(), device);
|
std::vector<OLSCANNER>::iterator it = std::find(online_devices_.begin(), online_devices_.end(), device);
|
||||||
if (it != online_devices_.end())
|
if (it != online_devices_.end())
|
||||||
{
|
{
|
||||||
|
|
|
@ -408,7 +408,7 @@ bool usb_manager::get_device_info(libusb_device* device, usb_dev* devinfo)
|
||||||
devinfo->ver = descriptor.bcdUSB;
|
devinfo->ver = descriptor.bcdUSB;
|
||||||
devinfo->vid = descriptor.idVendor;
|
devinfo->vid = descriptor.idVendor;
|
||||||
devinfo->pid = descriptor.idProduct;
|
devinfo->pid = descriptor.idProduct;
|
||||||
devinfo->addr = libusb_get_device_address(device);
|
devinfo->addr = 0; // libusb_get_device_address(device); - initialize at open
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -541,7 +541,7 @@ int usb_manager::register_hotplug(usb_event_handler cb, void* user)
|
||||||
}
|
}
|
||||||
init_notify_thread();
|
init_notify_thread();
|
||||||
|
|
||||||
return 0;
|
return HG_ERR_OK;
|
||||||
}
|
}
|
||||||
int usb_manager::open(libusb_device* device, usb_io** usbio, std::string* msg)
|
int usb_manager::open(libusb_device* device, usb_io** usbio, std::string* msg)
|
||||||
{
|
{
|
||||||
|
@ -614,6 +614,8 @@ bool usb_io::make_singleton(void)
|
||||||
key <<= 16;
|
key <<= 16;
|
||||||
key |= dev_info_.pid;
|
key |= dev_info_.pid;
|
||||||
key <<= 16;
|
key <<= 16;
|
||||||
|
if (dev_info_.addr == 0)
|
||||||
|
dev_info_.addr = libusb_get_device_address(dev_info_.device);
|
||||||
key |= dev_info_.addr;
|
key |= dev_info_.addr;
|
||||||
if (singleton_)
|
if (singleton_)
|
||||||
singleton_->release();
|
singleton_->release();
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <mutex>
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
@ -491,6 +492,7 @@ namespace local_utility
|
||||||
static sane_callback cb_ui_ = NULL;
|
static sane_callback cb_ui_ = NULL;
|
||||||
static void* cb_ui_parm_ = NULL;
|
static void* cb_ui_parm_ = NULL;
|
||||||
static SANE_Auth_Callback cb_auth_ = NULL;
|
static SANE_Auth_Callback cb_auth_ = NULL;
|
||||||
|
static std::mutex cb_lock_;
|
||||||
|
|
||||||
static std::string sane_event(SANE_Event ev)
|
static std::string sane_event(SANE_Event ev)
|
||||||
{
|
{
|
||||||
|
@ -516,6 +518,8 @@ namespace local_utility
|
||||||
}
|
}
|
||||||
int ui_cb(scanner_handle dev, int code, void* data, unsigned int* len, void* unused)
|
int ui_cb(scanner_handle dev, int code, void* data, unsigned int* len, void* unused)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lck(cb_lock_);
|
||||||
|
|
||||||
if (SANE_EVENT_SUPPORT_ASYNC_IO == code)
|
if (SANE_EVENT_SUPPORT_ASYNC_IO == code)
|
||||||
return cb_ui_ ? HG_ERR_OK : HG_ERR_DEVICE_NOT_SUPPORT;
|
return cb_ui_ ? HG_ERR_OK : HG_ERR_DEVICE_NOT_SUPPORT;
|
||||||
|
|
||||||
|
@ -556,6 +560,7 @@ namespace local_utility
|
||||||
}
|
}
|
||||||
void stop_work(void)
|
void stop_work(void)
|
||||||
{
|
{
|
||||||
|
std::lock_guard<std::mutex> lck(cb_lock_);
|
||||||
cb_ui_ = NULL;
|
cb_ui_ = NULL;
|
||||||
cb_ui_parm_ = NULL;
|
cb_ui_parm_ = NULL;
|
||||||
cb_auth_ = NULL;
|
cb_auth_ = NULL;
|
||||||
|
@ -1085,11 +1090,11 @@ std::string hg_sane_middleware::option_value_2_string(SANE_Value_Type type, void
|
||||||
ret = *(SANE_Bool*)val ? "true" : "false";
|
ret = *(SANE_Bool*)val ? "true" : "false";
|
||||||
break;
|
break;
|
||||||
case SANE_TYPE_INT:
|
case SANE_TYPE_INT:
|
||||||
sprintf(buf, "%d ", *(SANE_Word*)val);
|
sprintf(buf, "%d", *(SANE_Word*)val);
|
||||||
ret = buf;
|
ret = buf;
|
||||||
break;
|
break;
|
||||||
case SANE_TYPE_FIXED:
|
case SANE_TYPE_FIXED:
|
||||||
sprintf(buf, "%f ", hg_sane_middleware::sane_fixed_2_double(*(SANE_Word*)val));
|
sprintf(buf, "%f", hg_sane_middleware::sane_fixed_2_double(*(SANE_Word*)val));
|
||||||
ret = buf;
|
ret = buf;
|
||||||
break;
|
break;
|
||||||
case SANE_TYPE_STRING:
|
case SANE_TYPE_STRING:
|
||||||
|
|
Loading…
Reference in New Issue