]> sigrok.org Git - pulseview.git/commitdiff
Fix #602 by keeping track of device state internally
authorSoeren Apel <redacted>
Wed, 1 Jul 2015 14:35:29 +0000 (16:35 +0200)
committerSoeren Apel <redacted>
Sat, 18 Jul 2015 20:43:49 +0000 (22:43 +0200)
pv/devices/hardwaredevice.cpp
pv/devices/hardwaredevice.hpp

index 6374dafe6e03aaddb219a05c1fa4c3a21ab71dd5..953864d589429fb9fb1c20e05d106de5132f55f9 100644 (file)
@@ -43,12 +43,15 @@ namespace devices {
 
 HardwareDevice::HardwareDevice(const std::shared_ptr<sigrok::Context> &context,
        std::shared_ptr<sigrok::HardwareDevice> device) :
-       context_(context) {
+       context_(context),
+       device_open_(false) {
        device_ = device;
 }
 
 HardwareDevice::~HardwareDevice() {
-       device_->close();
+       if (device_open_)
+               device_->close();
+
        if (session_)
                session_->remove_devices();
 }
@@ -104,6 +107,8 @@ void HardwareDevice::create() {
                 throw QString(e.what());
         }
 
+        device_open_ = true;
+
         // Set up the session
         session_ = context_->create_session();
         session_->add_device(device_);
index 9f052d7e85efa5a5a35b494b201dd310354631af..df11ed25783caa8221fb269a6b0b60fff3554eec 100644 (file)
@@ -57,6 +57,7 @@ public:
 
 private:
        const std::shared_ptr<sigrok::Context> context_;
+       bool device_open_;
 };
 
 } // namespace devices