+bool SigSession::is_trigger_enabled() const
+{
+ assert(_sdi);
+ for (const GSList *l = _sdi->probes; l; l = l->next) {
+ const sr_probe *const p = (const sr_probe *)l->data;
+ assert(p);
+ if (p->trigger && p->trigger[0] != '\0')
+ return true;
+ }
+
+ return false;
+}
+
+void SigSession::load_thread_proc(const string name,
+ function<void (const QString)> error_handler)
+{
+ sr_input *in = NULL;
+
+ if (sr_session_load(name.c_str()) == SR_OK) {
+ if (sr_session_start() != SR_OK) {
+ error_handler(tr("Failed to start session."));
+ return;
+ }
+ }
+ else if(!(in = load_input_file_format(name.c_str(), error_handler)))
+ return;
+
+ sr_session_datafeed_callback_add(data_feed_in_proc, NULL);
+
+ set_capture_state(Running);
+
+ if(in) {
+ assert(in->format);
+ in->format->loadfile(in, name.c_str());
+ } else
+ sr_session_run();
+
+ sr_session_destroy();
+ set_capture_state(Stopped);
+
+ // Confirm that SR_DF_END was received
+ assert(!_cur_logic_snapshot);
+ assert(!_cur_analog_snapshot);
+
+ delete in;
+}
+
+void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
+ uint64_t record_length,
+ function<void (const QString)> error_handler)
+{
+ assert(sdi);
+ assert(error_handler);
+
+ sr_session_new();
+ sr_session_datafeed_callback_add(data_feed_in_proc, NULL);
+
+ if (sr_session_dev_add(sdi) != SR_OK) {
+ error_handler(tr("Failed to use device."));
+ sr_session_destroy();
+ return;
+ }
+
+ // Set the sample limit
+ if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES,
+ g_variant_new_uint64(record_length)) != SR_OK) {
+ error_handler(tr("Failed to configure "
+ "time-based sample limit."));
+ sr_session_destroy();
+ return;
+ }
+
+ if (sr_session_start() != SR_OK) {
+ error_handler(tr("Failed to start session."));
+ return;
+ }
+
+ set_capture_state(is_trigger_enabled() ? AwaitingTrigger : Running);
+
+ sr_session_run();
+ sr_session_destroy();
+
+ set_capture_state(Stopped);
+
+ // Confirm that SR_DF_END was received
+ assert(!_cur_logic_snapshot);
+ assert(!_cur_analog_snapshot);
+}
+
+void SigSession::feed_in_header(const sr_dev_inst *sdi)
+{
+ GVariant *gvar;
+ uint64_t sample_rate = 0;