X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fdevices%2Fhardwaredevice.cpp;h=b98b0e02f8aa9b2e43756af75835d8bae55723b4;hb=8fe262de9a59039431bd3b4d9a7b3ee4a4429d4d;hp=6374dafe6e03aaddb219a05c1fa4c3a21ab71dd5;hpb=b485408f20c39ae8d05372a5faffe15653c74705;p=pulseview.git diff --git a/pv/devices/hardwaredevice.cpp b/pv/devices/hardwaredevice.cpp index 6374daf..b98b0e0 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(); } @@ -98,15 +101,17 @@ string HardwareDevice::display_name( void HardwareDevice::create() { // Open the device - try { - device_->open(); - } catch(const sigrok::Error &e) { - throw QString(e.what()); - } - - // Set up the session - session_ = context_->create_session(); - session_->add_device(device_); + try { + device_->open(); + } catch(const sigrok::Error &e) { + throw QString(e.what()); + } + + device_open_ = true; + + // Set up the session + session_ = context_->create_session(); + session_->add_device(device_); } } // namespace devices