From b961bf17ba19203193ab70598ca53312520af99d Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Wed, 1 Jul 2015 16:35:29 +0200 Subject: [PATCH] Fix #602 by keeping track of device state internally --- pv/devices/hardwaredevice.cpp | 9 +++++++-- pv/devices/hardwaredevice.hpp | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pv/devices/hardwaredevice.cpp b/pv/devices/hardwaredevice.cpp index 6374dafe..953864d5 100644 --- a/pv/devices/hardwaredevice.cpp +++ b/pv/devices/hardwaredevice.cpp @@ -43,12 +43,15 @@ namespace devices { HardwareDevice::HardwareDevice(const std::shared_ptr &context, std::shared_ptr 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_); diff --git a/pv/devices/hardwaredevice.hpp b/pv/devices/hardwaredevice.hpp index 9f052d7e..df11ed25 100644 --- a/pv/devices/hardwaredevice.hpp +++ b/pv/devices/hardwaredevice.hpp @@ -57,6 +57,7 @@ public: private: const std::shared_ptr context_; + bool device_open_; }; } // namespace devices -- 2.30.2