projects
/
pulseview.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
InputFile: Don't try to create device twice
[pulseview.git]
/
pv
/
devices
/
inputfile.cpp
diff --git
a/pv/devices/inputfile.cpp
b/pv/devices/inputfile.cpp
index 13af3db9cd85c791935da6c80bf1a14220d492a0..935b0c47bdf6e41714bf889a530af61513ccb420 100644
(file)
--- a/
pv/devices/inputfile.cpp
+++ b/
pv/devices/inputfile.cpp
@@
-36,36
+36,44
@@
InputFile::InputFile(const std::shared_ptr<sigrok::Context> &context,
const std::map<std::string, Glib::VariantBase> &options) :
File(file_name),
context_(context),
const std::map<std::string, Glib::VariantBase> &options) :
File(file_name),
context_(context),
-
input_(format->create_input(options)
),
- interrupt_(false) {
- i
f (!input_
)
- throw QString("Failed to create input");
+
format_(format
),
+ options_(options),
+ i
nterrupt_(false
)
+{
}
}
-void InputFile::open() {
+void InputFile::open()
+{
if (session_)
close();
if (session_)
close();
-
- session_ = context_->create_session();
+ else
+
session_ = context_->create_session();
}
}
-void InputFile::close() {
+void InputFile::close()
+{
if (session_)
session_->remove_devices();
}
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_);
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;
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();
while (!interrupt_ && f) {
f.read(buffer, BufferSize);
const std::streamsize size = f.gcount();
@@
-81,6
+89,7
@@
void InputFile::run() {
break;
}
break;
}
+ session_->remove_devices(); // Remove instance from previous run
session_->add_device(device_);
need_device = false;
}
session_->add_device(device_);
need_device = false;
}
@@
-92,7
+101,8
@@
void InputFile::run() {
input_->end();
}
input_->end();
}
-void InputFile::stop() {
+void InputFile::stop()
+{
interrupt_ = true;
}
interrupt_ = true;
}