From: Soeren Apel Date: Wed, 1 Jul 2015 14:35:29 +0000 (+0200) Subject: Fix #602 by keeping track of device state internally X-Git-Tag: pulseview-0.3.0~173 X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=commitdiff_plain;h=b961bf17ba19203193ab70598ca53312520af99d;hp=d16704e0dc5b5a4712b258ac15dd0a17ae3a81b0 Fix #602 by keeping track of device state internally --- 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