]> sigrok.org Git - pulseview.git/blobdiff - pv/devices/hardwaredevice.cpp
Fix #605 by closing current device when another is selected
[pulseview.git] / pv / devices / hardwaredevice.cpp
index b98b0e02f8aa9b2e43756af75835d8bae55723b4..d1161aa26669a614bc36fc52e4871bdc1fb68496 100644 (file)
@@ -49,11 +49,7 @@ HardwareDevice::HardwareDevice(const std::shared_ptr<sigrok::Context> &context,
 }
 
 HardwareDevice::~HardwareDevice() {
-       if (device_open_)
-               device_->close();
-
-       if (session_)
-               session_->remove_devices();
+       close();
 }
 
 string HardwareDevice::full_name() const {
@@ -99,8 +95,10 @@ string HardwareDevice::display_name(
        return join(parts, " ");
 }
 
-void HardwareDevice::create() {
-       // Open the device
+void HardwareDevice::open() {
+       if (device_open_)
+               close();
+
        try {
                device_->open();
        } catch(const sigrok::Error &e) {
@@ -114,5 +112,15 @@ void HardwareDevice::create() {
        session_->add_device(device_);
 }
 
+void HardwareDevice::close() {
+       if (device_open_)
+               device_->close();
+
+       if (session_)
+               session_->remove_devices();
+
+       device_open_ = false;
+}
+
 } // namespace devices
 } // namespace pv