+
+ sample_rate = g_variant_get_uint64(gvar);
+ g_variant_unref(gvar);
+ }
+
+ // Set the sample rate of all data
+ const set< shared_ptr<data::SignalData> > data_set = get_data();
+ for (shared_ptr<data::SignalData> data : data_set) {
+ assert(data);
+ data->set_samplerate(sample_rate);
+ }
+}
+
+void SigSession::sample_thread_proc(shared_ptr<device::DevInst> dev_inst,
+ function<void (const QString)> error_handler)
+{
+ assert(dev_inst);
+ assert(dev_inst->dev_inst());
+ assert(error_handler);
+
+ read_sample_rate(dev_inst->dev_inst());
+
+ try {
+ dev_inst->start();
+ } catch(const QString e) {
+ error_handler(e);
+ return;
+ }
+
+ set_capture_state(sr_session_trigger_get() ?
+ AwaitingTrigger : Running);
+
+ dev_inst->run();
+ set_capture_state(Stopped);
+
+ // Confirm that SR_DF_END was received
+ if (_cur_logic_snapshot)
+ {
+ qDebug("SR_DF_END was not received.");
+ assert(0);
+ }
+}
+
+void SigSession::feed_in_header(const sr_dev_inst *sdi)
+{
+ read_sample_rate(sdi);
+}
+
+void SigSession::feed_in_meta(const sr_dev_inst *sdi,
+ const sr_datafeed_meta &meta)
+{
+ (void)sdi;
+
+ for (const GSList *l = meta.config; l; l = l->next) {
+ const sr_config *const src = (const sr_config*)l->data;
+ switch (src->key) {
+ case SR_CONF_SAMPLERATE:
+ /// @todo handle samplerate changes
+ /// samplerate = (uint64_t *)src->value;
+ break;
+ default:
+ // Unknown metadata is not an error.
+ break;
+ }
+ }
+
+ signals_changed();
+}
+
+void SigSession::feed_in_frame_begin()
+{
+ if (_cur_logic_snapshot || !_cur_analog_snapshots.empty())
+ frame_began();
+}
+
+void SigSession::feed_in_logic(const sr_datafeed_logic &logic)
+{
+ lock_guard<mutex> lock(_data_mutex);
+
+ if (!_logic_data)
+ {
+ qDebug() << "Unexpected logic packet";
+ return;
+ }
+
+ if (!_cur_logic_snapshot)
+ {
+ // This could be the first packet after a trigger
+ set_capture_state(Running);
+
+ // Create a new data snapshot
+ _cur_logic_snapshot = shared_ptr<data::LogicSnapshot>(
+ new data::LogicSnapshot(logic, _dev_inst->get_sample_limit()));
+ _logic_data->push_snapshot(_cur_logic_snapshot);
+
+ // @todo Putting this here means that only listeners querying
+ // for logic will be notified. Currently the only user of
+ // frame_began is DecoderStack, but in future we need to signal
+ // this after both analog and logic sweeps have begun.
+ frame_began();
+ }
+ else
+ {
+ // Append to the existing data snapshot
+ _cur_logic_snapshot->append_payload(logic);
+ }
+
+ data_received();
+}
+
+void SigSession::feed_in_analog(const sr_datafeed_analog &analog)
+{
+ lock_guard<mutex> lock(_data_mutex);
+
+ const unsigned int probe_count = g_slist_length(analog.channels);
+ const size_t sample_count = analog.num_samples / probe_count;
+ const float *data = analog.data;
+ bool sweep_beginning = false;
+
+ for (GSList *p = analog.channels; p; p = p->next)
+ {
+ shared_ptr<data::AnalogSnapshot> snapshot;
+
+ sr_channel *const probe = (sr_channel*)p->data;
+ assert(probe);
+
+ // Try to get the snapshot of the probe
+ const map< const sr_channel*, shared_ptr<data::AnalogSnapshot> >::
+ iterator iter = _cur_analog_snapshots.find(probe);
+ if (iter != _cur_analog_snapshots.end())
+ snapshot = (*iter).second;