+
+ // Are we setting a session device?
+ auto session_device = dynamic_pointer_cast<SessionDevice>(device);
+ // Did we have a session device selected previously?
+ auto prev_session_device = dynamic_pointer_cast<SessionDevice>(_device);
+
+ if (_device) {
+ _session->remove_datafeed_callbacks();
+ if (!prev_session_device) {
+ _device->close();
+ _session->remove_devices();
+ }
+ }
+
+ if (session_device)
+ _session = session_device->parent();
+
+ _device = device;
+ _decode_traces.clear();
+
+ if (device) {
+ if (!session_device)
+ {
+ _session = _device_manager.context()->create_session();
+ device->open();
+ _session->add_device(device);
+ }
+ _session->add_datafeed_callback([=]
+ (shared_ptr<Device> device, shared_ptr<Packet> packet) {
+ data_feed_in(device, packet);
+ });
+ update_signals(device);
+ }
+}
+
+void SigSession::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);
+}
+
+void SigSession::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);
+ }