virtual std::string display_name(
const DeviceManager &device_manager) const = 0;
- virtual void create() = 0;
+ virtual void open() = 0;
+
+ virtual void close() = 0;
virtual void start();
}
HardwareDevice::~HardwareDevice() {
- if (device_open_)
- device_->close();
-
- if (session_)
- session_->remove_devices();
+ close();
}
string HardwareDevice::full_name() const {
return join(parts, " ");
}
-void HardwareDevice::create() {
- // Open the device
+void HardwareDevice::open() {
+ if (device_open_)
+ close();
+
try {
device_->open();
} catch(const sigrok::Error &e) {
session_->add_device(device_);
}
+void HardwareDevice::close() {
+ if (device_open_)
+ device_->close();
+
+ if (session_)
+ session_->remove_devices();
+
+ device_open_ = false;
+}
+
} // namespace devices
} // namespace pv
*/
std::string display_name(const DeviceManager &device_manager) const;
- void create();
+ void open();
+
+ void close();
private:
const std::shared_ptr<sigrok::Context> context_;
throw QString("Failed to create input");
}
-void InputFile::create() {
+void InputFile::open() {
+ if (session_)
+ close();
+
session_ = context_->create_session();
}
+void InputFile::close() {
+ if (session_)
+ session_->remove_devices();
+}
+
void InputFile::start() {
}
std::shared_ptr<sigrok::InputFormat> format,
const std::map<std::string, Glib::VariantBase> &options);
- void create();
+ void open();
+
+ void close();
void start();
context_(context) {
}
-void SessionFile::create() {
+void SessionFile::open() {
+ if (session_)
+ close();
+
session_ = context_->load_session(file_name_);
device_ = session_->devices()[0];
}
+void SessionFile::close() {
+ if (session_)
+ session_->remove_devices();
+}
+
} // namespace devices
} // namespace pv
SessionFile(const std::shared_ptr<sigrok::Context> context,
const std::string &file_name);
- void create();
+ void open();
+
+ void close();
private:
const std::shared_ptr<sigrok::Context> context_;
// Ensure we are not capturing before setting the device
stop_capture();
+ if (device_)
+ device_->close();
+
device_ = std::move(device);
- device_->create();
+ device_->open();
device_->session()->add_datafeed_callback([=]
(shared_ptr<sigrok::Device> device, shared_ptr<Packet> packet) {
data_feed_in(device, packet);