+ if (device_) {
+ session_->remove_datafeed_callbacks();
+ if (!prev_session_device) {
+ device_->close();
+ session_->remove_devices();
+ }
+ }
+
+ if (session_device)
+ session_ = session_device->parent();
+
+ decode_traces_.clear();
+
+ if (device) {
+ if (!session_device)
+ {
+ session_ = device_manager_.context()->create_session();
+
+ try {
+ device->open();
+ } catch(const sigrok::Error &e) {
+ throw QString(e.what());
+ }
+
+ session_->add_device(device);
+ }
+
+ device_ = device;
+ session_->add_datafeed_callback([=]
+ (shared_ptr<Device> device, shared_ptr<Packet> packet) {
+ data_feed_in(device, packet);
+ });
+ update_signals(device);
+ } else
+ device_ = nullptr;
+
+ device_selected();
+}
+
+void Session::set_file(const string &name)
+{
+ session_ = device_manager_.context()->load_session(name);
+ device_ = session_->devices()[0];
+ decode_traces_.clear();
+ session_->add_datafeed_callback([=]
+ (shared_ptr<Device> device, shared_ptr<Packet> packet) {
+ data_feed_in(device, packet);
+ });
+ device_manager_.update_display_name(device_);
+ update_signals(device_);
+ device_selected();
+}
+
+void Session::set_default_device()
+{
+ shared_ptr<HardwareDevice> default_device;
+ const list< shared_ptr<HardwareDevice> > &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<HardwareDevice> dev : devices)
+ if (dev->driver()->name().compare("demo") == 0) {
+ default_device = dev;
+ break;
+ }
+
+ set_device(default_device);
+ }