X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fdevices%2Finputfile.cpp;h=935b0c47bdf6e41714bf889a530af61513ccb420;hp=411877473b9bf30e235b990243c574f7418c1a61;hb=519d0ccbe67d005a9c442795ce3b8255e78ca46d;hpb=5237f0c50352b523c6a0c3d7f931081ecdbdecaa;ds=sidebyside diff --git a/pv/devices/inputfile.cpp b/pv/devices/inputfile.cpp index 41187747..935b0c47 100644 --- a/pv/devices/inputfile.cpp +++ b/pv/devices/inputfile.cpp @@ -34,30 +34,46 @@ InputFile::InputFile(const std::shared_ptr &context, const std::string &file_name, std::shared_ptr format, const std::map &options) : + File(file_name), context_(context), - input_(format->create_input(options)), - file_name_(file_name), - interrupt_(false) { - if (!input_) - throw QString("Failed to create input"); + format_(format), + options_(options), + interrupt_(false) +{ +} + +void InputFile::open() +{ + if (session_) + close(); + else + session_ = context_->create_session(); } -void InputFile::create() { - session_ = context_->create_session(); +void InputFile::close() +{ + if (session_) + session_->remove_devices(); } -void InputFile::start() { +void InputFile::start() +{ } -void InputFile::run() { +void InputFile::run() +{ char buffer[BufferSize]; 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::ifstream f(file_name_, std::ios::binary); while (!interrupt_ && f) { f.read(buffer, BufferSize); const std::streamsize size = f.gcount(); @@ -73,6 +89,7 @@ void InputFile::run() { break; } + session_->remove_devices(); // Remove instance from previous run session_->add_device(device_); need_device = false; } @@ -84,7 +101,8 @@ void InputFile::run() { input_->end(); } -void InputFile::stop() { +void InputFile::stop() +{ interrupt_ = true; }