Pointer<Rule> DevicePrivate::getDeviceRule(const bool include_port) { Pointer<Rule> device_rule = makePointer<Rule>(); std::unique_lock<std::mutex> device_lock(refDeviceMutex()); logger->trace("Generating rule for device {}:{}@{} (name={}); include_port={}", _vendor_id, _product_id, _port, _name, include_port); device_rule->setSeqn(_seqn); device_rule->setTarget(_target); device_rule->setVendorID(_vendor_id); device_rule->setProductID(_product_id); device_rule->setSerialNumber(_serial_number); if (include_port) { device_rule->refDevicePorts().push_back(_port); device_rule->setDevicePortsSetOperator(Rule::SetOperator::Equals); } device_rule->setInterfaceTypes(refInterfaceTypes()); device_rule->setInterfaceTypesSetOperator(Rule::SetOperator::Equals); device_rule->setDeviceName(_name); device_rule->setDeviceHash(getDeviceHash(/*include_port=*/false)); return std::move(device_rule); }
LinuxDevice::LinuxDevice(struct udev_device* dev) { log->debug("Creating a new LinuxDevice instance"); const char *name = udev_device_get_sysattr_value(dev, "product"); if (name) { log->debug("DeviceName={}", name); setDeviceName(name); } const char *id_vendor = udev_device_get_sysattr_value(dev, "idVendor"); if (id_vendor) { log->debug("VendorID={}", id_vendor); setVendorID(id_vendor); } const char *id_product = udev_device_get_sysattr_value(dev, "idProduct"); if (id_product) { log->debug("ProductID={}", id_product); setProductID(id_product); } const char *serial = udev_device_get_sysattr_value(dev, "serial"); if (serial) { log->debug("Serial={}", serial); setSerialNumber(serial); } const char *syspath = udev_device_get_syspath(dev); if (syspath) { log->debug("Syspath={}", syspath); _syspath = syspath; } else { throw std::runtime_error("device wihtout syspath"); } const char *sysname = udev_device_get_sysname(dev); if (sysname) { log->debug("Sysname={}", sysname); setDevicePort(sysname); } else { throw std::runtime_error("device wihtout sysname"); } log->debug("DeviceHash={}", getDeviceHash()); setTarget(Rule::Target::Unknown); std::ifstream descriptor_stream(_syspath + "/descriptors", std::ifstream::binary); if (!descriptor_stream.good()) { throw std::runtime_error("cannot load USB descriptors"); } else { readDescriptors(descriptor_stream); } return; }