2 * This file is part of the PulseView project.
4 * Copyright (C) 2015 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
25 #include "inputfile.hpp"
30 const std::streamsize InputFile::BufferSize = 16384;
32 InputFile::InputFile(const std::shared_ptr<sigrok::Context> &context,
33 const std::string &file_name,
34 std::shared_ptr<sigrok::InputFormat> format,
35 const std::map<std::string, Glib::VariantBase> &options) :
44 void InputFile::open()
49 session_ = context_->create_session();
51 input_ = format_->create_input(options_);
54 throw QString("Failed to create input");
56 // open() should add the input device to the session but
57 // we can't open the device without sending some data first
58 f = new std::ifstream(file_name_, std::ios::binary);
60 char buffer[BufferSize];
61 f->read(buffer, BufferSize);
62 const std::streamsize size = f->gcount();
66 input_->send(buffer, size);
69 device_ = input_->device();
70 } catch (sigrok::Error) {
74 session_->add_device(device_);
77 void InputFile::close()
80 session_->remove_devices();
83 void InputFile::start()
89 char buffer[BufferSize];
92 // Previous call to run() processed the entire file already
93 f = new std::ifstream(file_name_, std::ios::binary);
98 while (!interrupt_ && !f->eof()) {
99 f->read(buffer, BufferSize);
100 const std::streamsize size = f->gcount();
104 input_->send(buffer, size);
106 if (size != BufferSize)
116 void InputFile::stop()
121 } // namespace devices