From 62614a46609d85f03d9b73a826f8c94a3554e2b1 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 28 Mar 2020 22:08:39 +0200 Subject: [PATCH 1/3] sanei_usb: Use internal linkage for private static variables --- sanei/sanei_usb.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sanei/sanei_usb.c b/sanei/sanei_usb.c index db0f452ae..291a48024 100644 --- a/sanei/sanei_usb.c +++ b/sanei/sanei_usb.c @@ -195,15 +195,15 @@ static sanei_usb_testing_mode testing_mode = sanei_usb_testing_mode_disabled; #if WITH_USB_RECORD_REPLAY static int testing_development_mode = 0; -int testing_known_commands_input_failed = 0; -unsigned testing_last_known_seq = 0; -SANE_String testing_record_backend = NULL; -xmlNode* testing_append_commands_node = NULL; +static int testing_known_commands_input_failed = 0; +static unsigned testing_last_known_seq = 0; +static SANE_String testing_record_backend = NULL; +static xmlNode* testing_append_commands_node = NULL; // XML file from which we read testing data -SANE_String testing_xml_path = NULL; -xmlDoc* testing_xml_doc = NULL; -xmlNode* testing_xml_next_tx_node = NULL; +static SANE_String testing_xml_path = NULL; +static xmlDoc* testing_xml_doc = NULL; +static xmlNode* testing_xml_next_tx_node = NULL; #endif // WITH_USB_RECORD_REPLAY #if defined(HAVE_LIBUSB_LEGACY) || defined(HAVE_LIBUSB) From 7d97a1aaf46b8adf5808fdb4204e99af7a095c6a Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 28 Mar 2020 22:08:42 +0200 Subject: [PATCH 2/3] sanei_usb: Reset all testing data on exit --- sanei/sanei_usb.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sanei/sanei_usb.c b/sanei/sanei_usb.c index 291a48024..6a4939a41 100644 --- a/sanei/sanei_usb.c +++ b/sanei/sanei_usb.c @@ -1303,6 +1303,17 @@ static void sanei_usb_testing_exit() xmlFreeDoc(testing_xml_doc); free(testing_xml_path); xmlCleanupParser(); + + // reset testing-related all data to initial values + testing_development_mode = 0; + testing_known_commands_input_failed = 0; + testing_last_known_seq = 0; + testing_record_backend = NULL; + testing_append_commands_node = NULL; + + testing_xml_path = NULL; + testing_xml_doc = NULL; + testing_xml_next_tx_node = NULL; } #else // WITH_USB_RECORD_REPLAY SANE_Status sanei_usb_testing_enable_replay(SANE_String_Const path, From 770b204702d00d243d4739ad9b0d68d5800c1469 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 28 Mar 2020 22:08:43 +0200 Subject: [PATCH 3/3] sanei_usb: Support devices that are being opened multiple times --- sanei/sanei_usb.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sanei/sanei_usb.c b/sanei/sanei_usb.c index 6a4939a41..7499d211c 100644 --- a/sanei/sanei_usb.c +++ b/sanei/sanei_usb.c @@ -195,6 +195,7 @@ static sanei_usb_testing_mode testing_mode = sanei_usb_testing_mode_disabled; #if WITH_USB_RECORD_REPLAY static int testing_development_mode = 0; +static int testing_already_opened = 0; static int testing_known_commands_input_failed = 0; static unsigned testing_last_known_seq = 0; static SANE_String testing_record_backend = NULL; @@ -1200,7 +1201,7 @@ static SANE_Status sanei_usb_testing_init() memset(&device, 0, sizeof(device)); device.devname = strdup(testing_xml_path); - // other code shouldn't depend on methon because testing_mode is + // other code shouldn't depend on method because testing_mode is // sanei_usb_testing_mode_replay device.method = sanei_usb_method_libusb; device.vendor = device_id; @@ -1306,6 +1307,7 @@ static void sanei_usb_testing_exit() // reset testing-related all data to initial values testing_development_mode = 0; + testing_already_opened = 0; testing_known_commands_input_failed = 0; testing_last_known_seq = 0; testing_record_backend = NULL; @@ -2301,6 +2303,9 @@ sanei_usb_get_endpoint (SANE_Int dn, SANE_Int ep_type) #if WITH_USB_RECORD_REPLAY static void sanei_usb_record_open(SANE_Int dn) { + if (testing_already_opened) + return; + xmlNode* e_root = xmlNewNode(NULL, (const xmlChar*) "device_capture"); xmlDocSetRootElement(testing_xml_doc, e_root); xmlNewProp(e_root, (const xmlChar*)"backend", (const xmlChar*) testing_record_backend); @@ -2352,7 +2357,8 @@ static void sanei_usb_record_open(SANE_Int dn) xmlNode* e_transactions = xmlNewChild(e_root, NULL, (const xmlChar*)"transactions", NULL); // add an empty node so that we have something to append to - testing_append_commands_node = xmlAddChild(e_transactions, xmlNewText((const xmlChar*)""));; + testing_append_commands_node = xmlAddChild(e_transactions, xmlNewText((const xmlChar*)"")); + testing_already_opened = 1; } #endif // WITH_USB_RECORD_REPLAY