这篇教程C++ udev_device_get_sysattr_value函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中udev_device_get_sysattr_value函数的典型用法代码示例。如果您正苦于以下问题:C++ udev_device_get_sysattr_value函数的具体用法?C++ udev_device_get_sysattr_value怎么用?C++ udev_device_get_sysattr_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了udev_device_get_sysattr_value函数的27个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: ftdi_context_match_nameftdi_device_t* ftdi_context_match_name(const ftdi_context_t* context, const char* name) { struct stat stat_buffer; struct udev* udev = 0; struct udev_device* dev = 0; int bus = 0; int address = 0; int i; if (!stat(name, &stat_buffer) && S_ISCHR(stat_buffer.st_mode)) { udev = udev_new(); dev = udev_device_new_from_devnum(udev, 'c', stat_buffer.st_rdev); if (dev) { string_scanf(udev_device_get_sysattr_value(dev, "busnum"), "%d", &bus); string_scanf(udev_device_get_sysattr_value(dev, "devnum"), "%d", &address); } udev_unref(udev); } for (i = 0; i < context->num_devices; ++i) { if ((context->devices[i].bus == bus) && (context->devices[i].address == address)) return &context->devices[i]; } return 0;}
开发者ID:engenhariaeletronica3,项目名称:tulibs,代码行数:31,
示例2: get_device_countint get_device_count(){ struct udev *udev = udev_new(); if (!udev) { return -1; } struct udev_enumerate *enumerate; struct udev_list_entry *devices, *dev_list_entry; struct udev_device *dev; enumerate = udev_enumerate_new(udev); udev_enumerate_add_match_subsystem(enumerate, "usb"); udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); const char *path; int count = 0; udev_list_entry_foreach(dev_list_entry, devices) { path = udev_list_entry_get_name(dev_list_entry); dev = udev_device_new_from_syspath(udev, path); if(!dev) return -1; const char * vid = udev_device_get_sysattr_value(dev,"idVendor"); const char * pid = udev_device_get_sysattr_value(dev,"idProduct"); if((vid && pid) && (!strcmp(vid, "04d8") && (!strcmp(pid, "e11c")))) count++; udev_device_unref(dev); }
开发者ID:seec,项目名称:TL866,代码行数:32,
示例3: names_macstatic int names_mac(struct udev_device *dev, struct netnames *names) { const char *s; unsigned int i; unsigned int a1, a2, a3, a4, a5, a6; /* check for NET_ADDR_PERM, skip random MAC addresses */ s = udev_device_get_sysattr_value(dev, "addr_assign_type"); if (!s) return EXIT_FAILURE; i = strtoul(s, NULL, 0); if (i != 0) return 0; s = udev_device_get_sysattr_value(dev, "address"); if (!s) return -ENOENT; if (sscanf(s, "%x:%x:%x:%x:%x:%x", &a1, &a2, &a3, &a4, &a5, &a6) != 6) return -EINVAL; /* skip empty MAC addresses */ if (a1 + a2 + a3 + a4 + a5 + a6 == 0) return -EINVAL; names->mac[0] = a1; names->mac[1] = a2; names->mac[2] = a3; names->mac[3] = a4; names->mac[4] = a5; names->mac[5] = a6; names->mac_valid = true; return 0;}
开发者ID:fest3er,项目名称:eudev,代码行数:32,
示例4: find_devicestatic int find_device(struct udev_device *udev_dev){ char path[PATH_MAX]; const char *busnum, *devnum; int fd; busnum = udev_device_get_sysattr_value(udev_dev, "busnum"); if (!busnum) return -1; devnum = udev_device_get_sysattr_value(udev_dev, "devnum"); if (!devnum) return -1; snprintf(path, sizeof(path), "/dev/bus/usb/%s/%s", busnum, devnum); fd = open(path, O_RDWR, O_CLOEXEC); if (fd < 0) { fprintf(stderr, "Can't open device: %s (%d)/n", strerror(errno), errno); return -1; } return fd;}
开发者ID:MDomagala,项目名称:bluez,代码行数:25,
示例5: udev_enumerate_newQUdevDeviceList QUdevPrivate::getUDevDevicesForSubsystem(const QString &strSubSystem, const QString &strDeviceType, const QString &strParentSubSystem, const QString &strParentDeviceType){ struct udev_enumerate *enumerate = udev_enumerate_new(m_pUdev); struct udev_list_entry *devices = 0; struct udev_list_entry *dev_list_entry = 0; struct udev_device *dev = 0; QList<QUdevDevice> lDevices; if(strSubSystem.isEmpty()) return lDevices; //get subsystem enumerator udev_enumerate_add_match_subsystem(enumerate, strSubSystem.toLatin1().constData()); //perform sysfs scanning udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); //iterate over all devices in the enumeration list udev_list_entry_foreach(dev_list_entry, devices) { QUdevDevice udDev; //create udev device for the sysfs path returned udDev.m_strSysfsPath = QString::fromLatin1(udev_list_entry_get_name(dev_list_entry)); dev = udev_device_new_from_syspath(m_pUdev, udDev.m_strSysfsPath.toLatin1().constData()); //filter the correct device types, ignored if empty device type is specified if(strDeviceType.isEmpty() || (QString::fromLatin1(udev_device_get_devtype(dev)) == strDeviceType)) { //get the path inside /dev udDev.m_strDevPath = QString::fromLatin1(udev_device_get_devnode(dev)); udDev.m_strSubsystem = strSubSystem; udDev.m_strDeviceType = strDeviceType; //if the caller wants a specific parent subsystem/devtype query the sysfs tree here if(!strParentSubSystem.isEmpty() && !strParentDeviceType.isEmpty()) { /* * retrieve the parent device with the subsystem/devtype pair of m_strParentSubSystem/m_strParentDeviceType. * * udev_device_get_parent_with_subsystem_devtype() will walk up the complete tree if needed */ dev = udev_device_get_parent_with_subsystem_devtype(dev, strParentSubSystem.toLatin1().constData(), strParentDeviceType.toLatin1().constData()); } if(dev) { //fill the device information udDev.m_strVendorID = QString::fromLatin1(udev_device_get_sysattr_value(dev,"idVendor")); udDev.m_strProductID = QString::fromLatin1(udev_device_get_sysattr_value(dev, "idProduct")); udDev.m_strManufacturer = QString::fromLatin1(udev_device_get_sysattr_value(dev,"manufacturer")); udDev.m_strProduct = QString::fromLatin1(udev_device_get_sysattr_value(dev,"product")); udDev.m_strSerial = QString::fromLatin1(udev_device_get_sysattr_value(dev, "serial")); lDevices.append(udDev); } udev_device_unref(dev); } }
开发者ID:jpfeiffer,项目名称:QUdev,代码行数:59,
示例6: udev_device_get_sysattr_value 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; }
开发者ID:cmotc,项目名称:usbguard,代码行数:57,
示例7: v4l2_get_devices /* This implementation uses udev to retrieve capture devices. We support both udev and default v4l2 ways to retrieve devices. Udev is not supported on all systems. */ std::vector<V4L2_Device> v4l2_get_devices() { std::vector<V4L2_Device> result; struct udev* udev; struct udev_enumerate* enumerate; struct udev_list_entry* devices; struct udev_list_entry* dev_list_entry; struct udev_device* dev; udev = udev_new(); if(!udev) { printf("Error: Cannot udev_new()/n"); return result; } enumerate = udev_enumerate_new(udev); udev_enumerate_add_match_subsystem(enumerate, "video4linux"); udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); udev_list_entry_foreach(dev_list_entry, devices) { /* Get the device by syspath. */ const char* syspath = udev_list_entry_get_name(dev_list_entry); dev = udev_device_new_from_syspath(udev, syspath); if(!dev) { printf("Error: cannot get the device using the syspath: %s/n", syspath); continue; } V4L2_Device v4l2_device; v4l2_device.path = udev_device_get_devnode(dev); if(v4l2_device.path.size() == 0) { printf("Error: Cannot find devpath./n"); continue; } dev = udev_device_get_parent_with_subsystem_devtype(dev, "usb", "usb_device"); if(!dev) { printf("Error:Cannot find related usb device./n"); continue; } v4l2_device.id_vendor = udev_device_get_sysattr_value(dev, "idVendor"); v4l2_device.id_product = udev_device_get_sysattr_value(dev, "idProduct"); result.push_back(v4l2_device); } udev_enumerate_unref(enumerate); udev_unref(udev); return result; }
开发者ID:cyrilcode,项目名称:video_capture,代码行数:63,
示例8: udev_device_get_udevstatic struct udev_device *handle_scsi_iscsi(struct udev_device *parent, char **path){ struct udev *udev = udev_device_get_udev(parent); struct udev_device *transportdev; struct udev_device *sessiondev = NULL; const char *target; char *connname; struct udev_device *conndev = NULL; const char *addr; const char *port; /* find iscsi session */ transportdev = parent; while (1) { transportdev = udev_device_get_parent(transportdev); if (transportdev == NULL) return NULL; if (strncmp(udev_device_get_sysname(transportdev), "session", 7) == 0) break; } if (transportdev == NULL) return NULL; /* find iscsi session device */ sessiondev = udev_device_new_from_subsystem_sysname(udev, "iscsi_session", udev_device_get_sysname(transportdev)); if (sessiondev == NULL) return NULL; target = udev_device_get_sysattr_value(sessiondev, "targetname"); if (target == NULL) { parent = NULL; goto out; } if (asprintf(&connname, "connection%s:0", udev_device_get_sysnum(transportdev)) < 0) { parent = NULL; goto out; } conndev = udev_device_new_from_subsystem_sysname(udev, "iscsi_connection", connname); free(connname); if (conndev == NULL) { parent = NULL; goto out; } addr = udev_device_get_sysattr_value(conndev, "persistent_address"); port = udev_device_get_sysattr_value(conndev, "persistent_port"); if (addr == NULL || port == NULL) { parent = NULL; goto out; } path_prepend(path, "ip-%s:%s-iscsi-%s-lun-%s", addr, port, target, udev_device_get_sysnum(parent));out: udev_device_unref(sessiondev); udev_device_unref(conndev); return parent;}
开发者ID:Lingvorn,项目名称:udev,代码行数:56,
示例9: get_usbinfoint get_usbinfo(int bus, int dev, usbinfo_t *ui){ struct udev *udev; struct udev_enumerate *enumerate; struct udev_list_entry *devices, *dev_list_entry; struct udev_device *udev_dev; char bus_str[16], dev_str[16]; int found = 0; memset(ui, 0, sizeof(usbinfo_t)); /* construct xenstore dev id */ if (dev > 0xFFF) { xd_log(LOG_ERR, "bad device id %d", dev); return -EINVAL; } ui->usb_virtid = bus << 12 | (dev & 0xFFF); ui->usb_bus = bus; ui->usb_device = dev; /* udev scan */ udev = udev_new(); if (!udev) { xd_log(LOG_ERR, "Can't create udev"); return -ENOMEM; } enumerate = udev_enumerate_new(udev); if (!enumerate) { xd_log(LOG_ERR, "Can't create enumeration"); return -ENOMEM; } snprintf(bus_str, sizeof(bus_str), "%d", bus); snprintf(dev_str, sizeof(dev_str), "%d", dev); udev_enumerate_add_match_subsystem(enumerate, "usb"); udev_enumerate_add_match_sysattr(enumerate, "busnum", bus_str); udev_enumerate_add_match_sysattr(enumerate, "devnum", dev_str); udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); udev_list_entry_foreach(dev_list_entry, devices) { const char *path; path = udev_list_entry_get_name(dev_list_entry); udev_dev = udev_device_new_from_syspath(udev, path); sscanf(udev_device_get_sysattr_value(udev_dev, "idVendor"), "%x", &ui->usb_vendor); sscanf(udev_device_get_sysattr_value(udev_dev, "idProduct"), "%x", &ui->usb_product); udev_device_unref(udev_dev); udev_enumerate_unref(enumerate); udev_unref(udev); return 0; } udev_enumerate_unref(enumerate); udev_unref(udev); return -ENOENT;}
开发者ID:OpenXT-Extras,项目名称:xc-vusb-daemon,代码行数:56,
示例10: udev_device_get_sysattr_value |