Bug 1105 - Factor out generic libusb_claim_interface() handling
Summary: Factor out generic libusb_claim_interface() handling
Status: CONFIRMED
Alias: None
Product: libsigrok
Classification: Unclassified
Component: Other (show other bugs)
Version: unreleased development snapshot
Hardware: All All
: Normal normal
Target Milestone: ---
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-01 14:33 CET by Uwe Hermann
Modified: 2018-01-01 14:33 CET (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Uwe Hermann 2018-01-01 14:33:02 CET
Many drivers in libsigrok call libusb_claim_interface(), but all of them use open-coded, different handling around it.

It would be a nice refactoring to factor out a generic wrapper function for this (probably into src/usb.c) which will always do the same thing and emit the same log messages across all drivers.

A good example to factor out is saleae-logic16 for example:

                ret = libusb_claim_interface(usb->devhdl, USB_INTERFACE);
                if (ret == LIBUSB_ERROR_BUSY) {
                        sr_err("Unable to claim USB interface. Another "
                               "program or driver has already claimed it.");
                        ret = SR_ERR;
                        break;
                } else if (ret == LIBUSB_ERROR_NO_DEVICE) {
                        sr_err("Device has been disconnected.");
                        ret = SR_ERR;
                        break;
                } else if (ret != 0) {
                        sr_err("Unable to claim interface: %s.",
                               libusb_error_name(ret));
                        ret = SR_ERR;
                        break;
                }