Bug 1105

Summary: Factor out generic libusb_claim_interface() handling
Product: libsigrok Reporter: Uwe Hermann <uwe>
Component: OtherAssignee: Nobody <nobody>
Status: CONFIRMED ---    
Severity: normal    
Priority: Normal    
Version: unreleased development snapshot   
Target Milestone: ---   
Hardware: All   
OS: All   

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;
                }