diff --git a/include/sane/sanei_usb.h b/include/sane/sanei_usb.h index 1f92faf40..f70010c36 100644 --- a/include/sane/sanei_usb.h +++ b/include/sane/sanei_usb.h @@ -224,6 +224,19 @@ extern SANE_String sanei_usb_testing_get_backend(); */ extern SANE_Bool sanei_usb_is_replay_mode_enabled(); +/** Clears currently recorded data. + + This is useful on certain backends to clear the currently recorded data if it relates to + other devices than the one that the scan will be performed on. On these backends all + devices that the backend supports are opened multiple times. Recording this interaction + to XML file makes it impossible to replay it, as the existence of these devices is not mocked + currently. + + This function may only be called when no USB devices are open, otherwise the behavior is + unpredictable. + */ +extern void sanei_usb_testing_record_clear(); + /** Records a debug message in the captured USB data if testing mode is enabled. If testing mode * is not enabled, this function does nothing. * diff --git a/sanei/sanei_usb.c b/sanei/sanei_usb.c index 8ff065947..ae4f9b5c3 100644 --- a/sanei/sanei_usb.c +++ b/sanei/sanei_usb.c @@ -1124,6 +1124,19 @@ static void sanei_usb_replay_debug_msg(SANE_String_Const message) } } +extern void sanei_usb_testing_record_clear() +{ + if (testing_mode != sanei_usb_testing_mode_record) + return; + + // we only need to indicate that we never opened a device and sanei_usb_record_open() will + // reinitialize everything for us. + testing_already_opened = 0; + testing_known_commands_input_failed = 0; + testing_last_known_seq = 0; + testing_append_commands_node = NULL; +} + extern void sanei_usb_testing_record_message(SANE_String_Const message) { if (testing_mode == sanei_usb_testing_mode_record) @@ -1356,6 +1369,10 @@ SANE_Bool sanei_usb_is_replay_mode_enabled() return SANE_FALSE; } +void sanei_usb_testing_record_clear() +{ +} + void sanei_usb_testing_record_message(SANE_String_Const message) { (void) message;