+
+ if (_dev_inst) {
+ sr_session_datafeed_callback_remove_all(_sr_session);
+ _dev_inst->release();
+ }
+
+ _dev_inst = dev_inst;
+ _decode_traces.clear();
+
+ if (dev_inst) {
+ dev_inst->use(this);
+ sr_session_datafeed_callback_add(_sr_session, data_feed_in_proc, NULL);
+ update_signals(dev_inst);
+ }
+}
+
+void SigSession::set_file(const string &name) throw(QString)
+{
+ // Deselect the old device, because file type detection in File::create
+ // destroys the old session inside libsigrok.
+ set_device(shared_ptr<device::DevInst>());
+ set_device(shared_ptr<device::DevInst>(device::File::create(name)));
+}
+
+void SigSession::set_default_device()
+{
+ shared_ptr<pv::device::DevInst> default_device;
+ const list< shared_ptr<device::Device> > &devices =
+ _device_manager.devices();
+
+ if (!devices.empty()) {
+ // Fall back to the first device in the list.
+ default_device = devices.front();
+
+ // Try and find the demo device and select that by default
+ for (shared_ptr<pv::device::Device> dev : devices)
+ if (strcmp(dev->dev_inst()->driver->name,
+ "demo") == 0) {
+ default_device = dev;
+ break;
+ }
+ }
+
+ set_device(default_device);
+}
+
+void SigSession::release_device(device::DevInst *dev_inst)
+{
+ (void)dev_inst;
+ assert(_dev_inst.get() == dev_inst);
+
+ assert(_capture_state == Stopped);
+ _dev_inst = shared_ptr<device::DevInst>();