MCPcopy Create free account
hub / github.com/OpenPrinting/cups / find_device

Function find_device

backend/usb-libusb.c:820–1037  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

818 */
819
820static usb_printer_t * /* O - Found printer */
821find_device(usb_cb_t cb, /* I - Callback function */
822 const void *data) /* I - User data for callback */
823{
824 libusb_device **list; /* List of connected USB devices */
825 libusb_device *device = NULL; /* Current device */
826 struct libusb_device_descriptor devdesc;
827 /* Current device descriptor */
828 struct libusb_config_descriptor *confptr = NULL;
829 /* Pointer to current configuration */
830 const struct libusb_interface *ifaceptr = NULL;
831 /* Pointer to current interface */
832 const struct libusb_interface_descriptor *altptr = NULL;
833 /* Pointer to current alternate setting */
834 const struct libusb_endpoint_descriptor *endpptr = NULL;
835 /* Pointer to current endpoint */
836 ssize_t err = 0, /* Error code */
837 numdevs, /* number of connected devices */
838 i = 0;
839 uint8_t conf, /* Current configuration */
840 iface, /* Current interface */
841 altset, /* Current alternate setting */
842 protocol, /* Current protocol */
843 endp, /* Current endpoint */
844 read_endp, /* Current read endpoint */
845 write_endp; /* Current write endpoint */
846 char device_id[1024],/* IEEE-1284 device ID */
847 device_uri[1024];
848 /* Device URI */
849 static usb_printer_t printer; /* Current printer */
850
851
852 /*
853 * Initialize libusb...
854 */
855
856 err = libusb_init(NULL);
857 if (err)
858 {
859 fprintf(stderr, "ERROR: Unable to initialize USB access via libusb, libusb error %i (%s)\n", (int)err, libusb_strerror((int)err));
860 return (NULL);
861 }
862
863 numdevs = libusb_get_device_list(NULL, &list);
864 fprintf(stderr, "DEBUG: libusb_get_device_list=%d\n", (int)numdevs);
865
866 /*
867 * Then loop through the devices it found...
868 */
869
870 if (numdevs > 0)
871 for (i = 0; i < numdevs; i++)
872 {
873 device = list[i];
874
875 /*
876 * Ignore devices with no configuration data and anything that is not
877 * a printer...

Callers 2

list_devicesFunction · 0.85
print_deviceFunction · 0.85

Calls 5

find_quirksFunction · 0.85
make_device_uriFunction · 0.85
close_deviceFunction · 0.85
open_deviceFunction · 0.70
get_device_idFunction · 0.70

Tested by

no test coverage detected