static bool test_match(const hs_match *match, const hs_device *dev) { if (match->type && hs_device_get_type(dev) != (hs_device_type)match->type) return false; if (match->vid && hs_device_get_vid(dev) != match->vid) return false; if (match->pid && hs_device_get_pid(dev) != match->pid) return false; if (match->path && !match_paths(hs_device_get_path(dev), match->path)) return false; return true; }
static int device_callback(hs_device *dev, void *udata) { (void)(udata); const char *event = "?", *type = "?"; /* Use hs_device_get_status() to differenciate between added and removed devices, when called from hs_monitor_list() it is always HS_DEVICE_STATUS_ONLINE. */ switch (hs_device_get_status(dev)) { case HS_DEVICE_STATUS_DISCONNECTED: event = "remove"; break; case HS_DEVICE_STATUS_ONLINE: event = "add"; break; } switch (hs_device_get_type(dev)) { case HS_DEVICE_TYPE_HID: type = "hid"; break; case HS_DEVICE_TYPE_SERIAL: type = "serial"; break; } printf("%s %s@%"PRIu8" %04"PRIx16":%04"PRIx16" (%s)\n", event, hs_device_get_location(dev), hs_device_get_interface_number(dev), hs_device_get_vid(dev), hs_device_get_pid(dev), type); #define PRINT_PROPERTY(name, prop) \ if (prop(dev)) \ printf(" - " name " %s\n", prop(dev)); PRINT_PROPERTY("device node: ", hs_device_get_path); PRINT_PROPERTY("manufacturer: ", hs_device_get_manufacturer_string); PRINT_PROPERTY("product: ", hs_device_get_product_string); PRINT_PROPERTY("serial number:", hs_device_get_serial_number_string); #undef PRINT_PROPERTY /* If you return a non-zero value, the enumeration/refresh is aborted and this value is returned from the calling function. */ return 0; }