Merge branch 'sanei-usb-record-replay-multiple-open' into 'master'

sanei_usb: Support recording conversations within multiple open-close calls

See merge request sane-project/backends!380
merge-requests/381/merge
Povilas Kanapickas 2020-03-31 10:03:01 +00:00
commit d6d3c0566f
1 zmienionych plików z 26 dodań i 9 usunięć

Wyświetl plik

@ -195,15 +195,16 @@ 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_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;
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)
@ -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;
@ -1303,6 +1304,18 @@ 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_already_opened = 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,
@ -2303,6 +2316,9 @@ static void sanei_xml_indent_child(xmlNode* parent, unsigned indent_count)
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);
@ -2366,7 +2382,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