mirror of
https://github.com/PixlOne/logiops.git
synced 2025-07-13 21:02:43 +08:00
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:
parent
3808f0a6cf
commit
6e8c24b2f9
@ -138,8 +138,10 @@ void Device::_init()
|
||||
} });
|
||||
|
||||
try {
|
||||
auto rsp = sendReport({ReportType::Short, _index, 0, 0,
|
||||
LOGID_HIDPP_SOFTWARE_ID});
|
||||
auto rsp = sendReport(
|
||||
{ReportType::Short, _index,
|
||||
hidpp20::FeatureID::ROOT, hidpp20::Root::Ping,
|
||||
LOGID_HIDPP_SOFTWARE_ID});
|
||||
if(rsp.deviceIndex() != _index) {
|
||||
throw InvalidDevice(InvalidDevice::VirtualNode);
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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];
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user