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

Function close_device

backend/usb-libusb.c:691–796  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

689 */
690
691static int /* I - 0 on success, -1 on failure */
692close_device(usb_printer_t *printer) /* I - Printer */
693{
694 struct libusb_device_descriptor devdesc;
695 /* Current device descriptor */
696 struct libusb_config_descriptor *confptr;
697 /* Pointer to current configuration */
698
699
700 if (printer->handle)
701 {
702 /*
703 * Release interfaces before closing so that we know all data is written
704 * to the device...
705 */
706
707 int errcode; /* Return value of libusb function */
708 int number1, /* Interface number */
709 number2; /* Configuration number */
710
711 errcode =
712 libusb_get_config_descriptor(printer->device, printer->conf, &confptr);
713 if (errcode >= 0)
714 {
715 number1 = confptr->interface[printer->iface].
716 altsetting[printer->altset].bInterfaceNumber;
717 libusb_release_interface(printer->handle, number1);
718
719 number2 = confptr->bConfigurationValue;
720
721 libusb_free_config_descriptor(confptr);
722
723 /*
724 * If we have changed the configuration from one valid configuration
725 * to another, restore the old one
726 */
727 if (printer->origconf > 0 && printer->origconf != number2)
728 {
729 fprintf(stderr, "DEBUG: Restoring USB device configuration: %d -> %d\n",
730 number2, printer->origconf);
731 if ((errcode = libusb_set_configuration(printer->handle,
732 printer->origconf)) < 0)
733 {
734 if (errcode != LIBUSB_ERROR_BUSY)
735 {
736 errcode =
737 libusb_get_device_descriptor (printer->device, &devdesc);
738 if (errcode < 0)
739 fprintf(stderr,
740 "DEBUG: Failed to set configuration %d\n",
741 printer->origconf);
742 else
743 fprintf(stderr,
744 "DEBUG: Failed to set configuration %d for %04x:%04x\n",
745 printer->origconf, devdesc.idVendor, devdesc.idProduct);
746 }
747 }
748 }

Callers 2

print_deviceFunction · 0.85
find_deviceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected