From c99a54af4132d4dc04791c3bcabcc794154b536c Mon Sep 17 00:00:00 2001 From: Solomon Peachy Date: Tue, 20 Nov 2012 19:05:03 -0500 Subject: [PATCH] [libusb] Match printer serial number when called as a CUPS backend. This way we don't automatically bind to the first supported/matching printer we find. --- selphy_print.c | 13 +++++++++---- selphy_print_common.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/selphy_print.c b/selphy_print.c index 24c126a..99af236 100644 --- a/selphy_print.c +++ b/selphy_print.c @@ -120,6 +120,7 @@ static int dump_data_libusb(int remaining, int present, int data_fd, static int find_and_enumerate(struct libusb_context *ctx, struct libusb_device ***list, + char *match_serno, int printer_type, int scan_only) { @@ -231,8 +232,6 @@ static int find_and_enumerate(struct libusb_context *ctx, (found == i) ? "MATCH: " : "", desc.idProduct, product, serial); - // XXX MATCH based on passed-in serial number? - if (valid && scan_only) { /* URL-ify model. */ char buf[128]; // XXX ugly.. @@ -251,6 +250,12 @@ static int find_and_enumerate(struct libusb_context *ctx, product + strlen("Canon "), product, serial); } + /* If a serial number was passed down, use it. */ + if (found && match_serno && + strcmp(match_serno, (char*)serial)) { + found = -1; + } + libusb_close(dev); } @@ -301,7 +306,7 @@ int main (int argc, char **argv) VERSION, argv[0], argv[0]); libusb_init(&ctx); - find_and_enumerate(ctx, &list, printer_type, 1); + find_and_enumerate(ctx, &list, NULL, printer_type, 1); libusb_free_device_list(list, 1); libusb_exit(ctx); exit(1); @@ -357,7 +362,7 @@ int main (int argc, char **argv) /* Libusb setup */ libusb_init(&ctx); - found = find_and_enumerate(ctx, &list, printer_type, 0); + found = find_and_enumerate(ctx, &list, use_serno, printer_type, 0); if (found == -1) { ERROR("No suitable printers found!\n"); diff --git a/selphy_print_common.h b/selphy_print_common.h index 712ace7..efd2bfb 100644 --- a/selphy_print_common.h +++ b/selphy_print_common.h @@ -25,7 +25,7 @@ * */ -#define VERSION "0.35" +#define VERSION "0.36" #define DEBUG( ... ) fprintf(stderr, "DEBUG: " __VA_ARGS__ ) #define ERROR( ... ) fprintf(stderr, "ERROR: " __VA_ARGS__ )