}
HardwareDevice::~HardwareDevice() {
- if (device_open_)
- device_->close();
-
- if (session_)
- session_->remove_devices();
+ close();
}
string HardwareDevice::full_name() const {
return join(parts, " ");
}
-void HardwareDevice::create() {
- // Open the device
- try {
- device_->open();
- } catch(const sigrok::Error &e) {
- throw QString(e.what());
- }
+void HardwareDevice::open() {
+ if (device_open_)
+ close();
+
+ 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_);
+}
+
+void HardwareDevice::close() {
+ if (device_open_)
+ device_->close();
- device_open_ = true;
+ if (session_)
+ session_->remove_devices();
- // Set up the session
- session_ = context_->create_session();
- session_->add_device(device_);
+ device_open_ = false;
}
} // namespace devices