From: Soeren Apel Date: Fri, 8 Apr 2016 21:32:54 +0000 (+0200) Subject: InputFile: Don't try to create device twice X-Git-Tag: pulseview-0.4.0~310 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=519d0ccbe67d005a9c442795ce3b8255e78ca46d;p=pulseview.git InputFile: Don't try to create device twice The InputFile currently only keeps track of the need for a device instance local to run(). This means that when calling run() a second time (e.g. by clicking the "Run" button after loading a file), the function will try to create the device instance and add it to the session. This fails as the first created instance is still assigned to the session and thus the session will reject adding another device. Furthermore, simply clearing the session devices isn't enough for proper operation. The issue is that once a file's content has been sent to an input module, the module is not going to accept another file. It needs to be reset to its initial state. To do this, we create the input module instance every time we want to read the file. --- diff --git a/pv/devices/inputfile.cpp b/pv/devices/inputfile.cpp index 22c9b1c8..935b0c47 100644 --- a/pv/devices/inputfile.cpp +++ b/pv/devices/inputfile.cpp @@ -36,19 +36,18 @@ InputFile::InputFile(const std::shared_ptr &context, const std::map &options) : File(file_name), context_(context), - input_(format->create_input(options)), + format_(format), + options_(options), interrupt_(false) { - if (!input_) - throw QString("Failed to create input"); } void InputFile::open() { if (session_) close(); - - session_ = context_->create_session(); + else + session_ = context_->create_session(); } void InputFile::close() @@ -67,7 +66,11 @@ void InputFile::run() bool need_device = true; assert(session_); - assert(input_); + + input_ = format_->create_input(options_); + + if (!input_) + throw QString("Failed to create input"); interrupt_ = false; std::ifstream f(file_name_, std::ios::binary); @@ -86,6 +89,7 @@ void InputFile::run() break; } + session_->remove_devices(); // Remove instance from previous run session_->add_device(device_); need_device = false; } diff --git a/pv/devices/inputfile.hpp b/pv/devices/inputfile.hpp index 9b9aee88..02d4417c 100644 --- a/pv/devices/inputfile.hpp +++ b/pv/devices/inputfile.hpp @@ -53,7 +53,9 @@ public: private: const std::shared_ptr context_; - const std::shared_ptr input_; + const std::shared_ptr format_; + const std::map options_; + std::shared_ptr input_; std::atomic interrupt_; };