修复PNP BUG

This commit is contained in:
gb 2022-10-19 14:00:23 +08:00
parent 202579a4cd
commit 6deaffbb21
2 changed files with 39 additions and 20 deletions

View File

@ -545,6 +545,8 @@ bool usb_device::is_online(void)
void usb_device::set_online(bool online) void usb_device::set_online(bool online)
{ {
online_ = online; online_ = online;
if (!online_)
reg_key_ = "";
} }
uint8_t usb_device::port(void) uint8_t usb_device::port(void)
{ {
@ -552,6 +554,10 @@ uint8_t usb_device::port(void)
init(); init();
return port_; return port_;
} }
std::string usb_device::reg_path(void)
{
return reg_key_;
}
bool usb_device::init(void) bool usb_device::init(void)
{ {
@ -1068,7 +1074,7 @@ void usb_monitor::notify_usb_event(usb_device*& dev, bool arrive)
if (devices_[i]->is_online()) if (devices_[i]->is_online())
{ {
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s is already in device queue and received ARRIVE again, discard this event.\n", dev->name().c_str()); VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s is already in device queue and received ARRIVE again, discard this event.\n", dev->name().c_str());
dev->release(); // dev->release();
return; return;
} }
else else
@ -1090,31 +1096,43 @@ void usb_monitor::notify_usb_event(usb_device*& dev, bool arrive)
} }
else else
{ {
bool discard = false;
for (size_t i = 0; i < devices_.size(); ++i) for (size_t i = 0; i < devices_.size(); ++i)
{ {
if (!(devices_[i]->id() == id)) if (devices_[i]->id().vid != id.vid || devices_[i]->id().pid != id.pid)
continue; continue;
if (devices_[i]->reg_path().empty() || usb_device::usb_scan_name(devices_[i]->reg_path().c_str()).empty())
dev->release();
dev = devices_[i];
dev->add_ref();
if (dev->is_open())
{ {
if (dev->is_online())
dev->set_online(false);
else
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s is already offline and received LEAVE again, discard this event.\n", dev->name().c_str());
dev->release();
return;
}
}
else
{
devices_.erase(devices_.begin() + i);
dev->release(); dev->release();
dev = devices_[i];
dev->add_ref();
// if (dev->is_open())
{
if (dev->is_online())
{
dev->set_online(false);
discard = false;
break;
}
else
{
// VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s is already offline and received LEAVE again, discard this event.\n", dev->name().c_str());
// dev->release();
// return;
discard = true;
}
}
//else
//{
// devices_.erase(devices_.begin() + i);
// dev->release();
//}
} }
break; }
if (discard)
{
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "%s is already offline and received LEAVE again, discard this event.\n", dev->name().c_str());
return;
} }
} }

View File

@ -140,6 +140,7 @@ public:
bool is_online(void); bool is_online(void);
void set_online(bool online); void set_online(bool online);
uint8_t port(void); uint8_t port(void);
std::string reg_path(void);
bool init(void); bool init(void);
void clear(void); void clear(void);