+ return _sdi;
+}
+
+void SigSession::set_device(struct sr_dev_inst *sdi)
+{
+ if (_sdi)
+ _device_manager.release_device(_sdi);
+ if (sdi)
+ _device_manager.use_device(sdi, this);
+ _sdi = sdi;
+ update_signals();
+}
+
+void SigSession::release_device(struct sr_dev_inst *sdi)
+{
+ (void)sdi;
+
+ assert(_capture_state == Stopped);
+ _sdi = NULL;
+ update_signals();
+}
+
+void SigSession::load_file(const string &name,
+ function<void (const QString)> error_handler)
+{
+ stop_capture();
+ _sampling_thread.reset(new boost::thread(
+ &SigSession::load_thread_proc, this, name,
+ error_handler));
+}
+
+SigSession::capture_state SigSession::get_capture_state() const
+{
+ lock_guard<mutex> lock(_sampling_mutex);
+ return _capture_state;
+}
+
+void SigSession::start_capture(uint64_t record_length,
+ function<void (const QString)> error_handler)
+{
+ stop_capture();
+
+ // Check that a device instance has been selected.
+ if (!_sdi) {
+ qDebug() << "No device selected";
+ return;
+ }
+
+ // Check that at least one probe is enabled
+ const GSList *l;
+ for (l = _sdi->probes; l; l = l->next) {
+ sr_probe *const probe = (sr_probe*)l->data;
+ assert(probe);
+ if (probe->enabled)
+ break;
+ }
+
+ if (!l) {
+ error_handler(tr("No probes enabled."));
+ return;
+ }
+
+ // Begin the session
+ _sampling_thread.reset(new boost::thread(
+ &SigSession::sample_thread_proc, this, _sdi,
+ record_length, error_handler));
+}
+
+void SigSession::stop_capture()
+{
+ if (get_capture_state() == Stopped)
+ return;
+
+ sr_session_stop();
+
+ // Check that sampling stopped
+ if (_sampling_thread.get())
+ _sampling_thread->join();
+ _sampling_thread.reset();
+}
+
+vector< shared_ptr<view::Signal> > SigSession::get_signals()
+{
+ lock_guard<mutex> lock(_signals_mutex);
+ return _signals;
+}
+
+boost::shared_ptr<data::Logic> SigSession::get_data()
+{
+ return _logic_data;
+}
+
+void SigSession::set_capture_state(capture_state state)
+{
+ lock_guard<mutex> lock(_sampling_mutex);
+ _capture_state = state;
+ capture_state_changed(state);
+}
+
+/**
+ * Attempts to autodetect the format. Failing that
+ * @param filename The filename of the input file.
+ * @return A pointer to the 'struct sr_input_format' that should be used,
+ * or NULL if no input format was selected or auto-detected.
+ */
+sr_input_format* SigSession::determine_input_file_format(
+ const string &filename)
+{
+ int i;
+
+ /* If there are no input formats, return NULL right away. */
+ sr_input_format *const *const inputs = sr_input_list();
+ if (!inputs) {
+ g_critical("No supported input formats available.");
+ return NULL;