Fix a race condition caused by virtual hid nodes

When a virtual hidraw node is being tested while the real one is tested,
this causes the devices to misidentify reports. This solves that by
making the device monitor synchronous.
This commit is contained in:
pixl 2022-01-29 00:05:40 -05:00
parent 3808f0a6cf
commit 6e8c24b2f9
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
4 changed files with 9 additions and 12 deletions

View File

@ -138,7 +138,9 @@ void Device::_init()
} });
try {
auto rsp = sendReport({ReportType::Short, _index, 0, 0,
auto rsp = sendReport(
{ReportType::Short, _index,
hidpp20::FeatureID::ROOT, hidpp20::Root::Ping,
LOGID_HIDPP_SOFTWARE_ID});
if(rsp.deviceIndex() != _index) {
throw InvalidDevice(InvalidDevice::VirtualNode);

View File

@ -42,7 +42,7 @@ std::vector<uint8_t> EssentialFeature::callFunction(uint8_t function_id,
std::copy(params.begin(), params.end(), request.paramBegin());
auto response = _device->sendReport(request);
return std::vector<uint8_t>(response.paramBegin(), response.paramEnd());
return {response.paramBegin(), response.paramEnd()};
}
EssentialFeature::EssentialFeature(hidpp::Device* dev, uint16_t _id) :
@ -56,9 +56,7 @@ EssentialFeature::EssentialFeature(hidpp::Device* dev, uint16_t _id) :
getFunc_req[0] = (_id >> 8) & 0xff;
getFunc_req[1] = _id & 0xff;
try {
auto getFunc_resp = this->callFunction(Root::GetFeature,
getFunc_req);
_index = getFunc_resp[0];
_index = this->callFunction(Root::GetFeature,getFunc_req).at(0);
} catch(Error& e) {
if(e.code() == Error::InvalidFeatureIndex)
throw UnsupportedFeature(_id);

View File

@ -75,9 +75,6 @@ uint8_t EssentialDeviceName::getNameLength()
auto response = this->callFunction(DeviceName::Function::GetLength, params);
if(response[0] == 1)
return 1;
return response[0];
}

View File

@ -99,9 +99,9 @@ void DeviceMonitor::ready()
std::string devnode = udev_device_get_devnode(device);
if (action == "add")
spawn_task([this, devnode]() { _addHandler(devnode); } );
_addHandler(devnode);
else if (action == "remove")
spawn_task([this, devnode]() { _removeHandler(devnode); } );
_removeHandler(devnode);
udev_device_unref(device);
},
@ -141,7 +141,7 @@ void DeviceMonitor::enumerate()
std::string devnode = udev_device_get_devnode(device);
udev_device_unref(device);
spawn_task([this, devnode]() { _addHandler(devnode); } );
_addHandler(devnode);
}
udev_enumerate_unref(udev_enum);