]> sigrok.org Git - pulseview.git/blobdiff - pv/devices/inputfile.cpp
Fix #733: Open import files using binary mode
[pulseview.git] / pv / devices / inputfile.cpp
index 411877473b9bf30e235b990243c574f7418c1a61..22c9b1c8297e4e3d8d71eb73d925c122fc67c8f9 100644 (file)
@@ -34,22 +34,35 @@ InputFile::InputFile(const std::shared_ptr<sigrok::Context> &context,
        const std::string &file_name,
        std::shared_ptr<sigrok::InputFormat> format,
        const std::map<std::string, Glib::VariantBase> &options) :
+       File(file_name),
        context_(context),
        input_(format->create_input(options)),
-       file_name_(file_name),
-       interrupt_(false) {
+       interrupt_(false)
+{
        if (!input_)
                throw QString("Failed to create input");
 }
 
-void InputFile::create() {
+void InputFile::open()
+{
+       if (session_)
+               close();
+
        session_ = context_->create_session();
 }
 
-void InputFile::start() {
+void InputFile::close()
+{
+       if (session_)
+               session_->remove_devices();
+}
+
+void InputFile::start()
+{
 }
 
-void InputFile::run() {
+void InputFile::run()
+{
        char buffer[BufferSize];
        bool need_device = true;
 
@@ -57,7 +70,7 @@ void InputFile::run() {
        assert(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();
@@ -84,7 +97,8 @@ void InputFile::run() {
        input_->end();
 }
 
-void InputFile::stop() {
+void InputFile::stop()
+{
        interrupt_ = true;
 }