+ return inputs[i];
+}
+
+sr_input* SigSession::load_input_file_format(const string &filename,
+ function<void (const QString)> error_handler,
+ sr_input_format *format)
+{
+ struct stat st;
+ sr_input *in;
+
+ if (!format && !(format =
+ determine_input_file_format(filename.c_str()))) {
+ /* The exact cause was already logged. */
+ return NULL;
+ }
+
+ if (stat(filename.c_str(), &st) == -1) {
+ error_handler(tr("Failed to load file"));
+ return NULL;
+ }
+
+ /* Initialize the input module. */
+ if (!(in = new sr_input)) {
+ qDebug("Failed to allocate input module.\n");
+ return NULL;
+ }
+
+ in->format = format;
+ in->param = NULL;
+ if (in->format->init &&
+ in->format->init(in, filename.c_str()) != SR_OK) {
+ qDebug("Input format init failed.\n");
+ return NULL;
+ }
+
+ sr_session_new();
+
+ if (sr_session_dev_add(in->sdi) != SR_OK) {
+ qDebug("Failed to use device.\n");
+ sr_session_destroy();
+ return NULL;
+ }
+
+ return in;
+}
+
+void SigSession::update_signals(shared_ptr<device::DevInst> dev_inst)
+{
+ assert(dev_inst);
+ assert(_capture_state == Stopped);
+
+ unsigned int logic_probe_count = 0;
+
+ // Clear the decode traces
+ _decode_traces.clear();
+
+ // Detect what data types we will receive
+ if(dev_inst) {
+ assert(dev_inst->dev_inst());
+ for (const GSList *l = dev_inst->dev_inst()->probes;
+ l; l = l->next) {
+ const sr_probe *const probe = (const sr_probe *)l->data;
+ if (!probe->enabled)
+ continue;
+
+ switch(probe->type) {
+ case SR_PROBE_LOGIC:
+ logic_probe_count++;
+ break;
+ }
+ }
+ }
+
+ // Create data containers for the logic data snapshots
+ {
+ lock_guard<mutex> data_lock(_data_mutex);
+
+ _logic_data.reset();
+ if (logic_probe_count != 0) {
+ _logic_data.reset(new data::Logic(
+ logic_probe_count));
+ assert(_logic_data);
+ }
+ }
+
+ // Make the Signals list
+ do {
+ lock_guard<mutex> lock(_signals_mutex);
+
+ _signals.clear();
+
+ if(!dev_inst)
+ break;
+
+ assert(dev_inst->dev_inst());
+ for (const GSList *l = dev_inst->dev_inst()->probes;
+ l; l = l->next) {
+ shared_ptr<view::Signal> signal;
+ sr_probe *const probe = (sr_probe *)l->data;
+ assert(probe);
+
+ switch(probe->type) {
+ case SR_PROBE_LOGIC:
+ signal = shared_ptr<view::Signal>(
+ new view::LogicSignal(dev_inst,
+ probe, _logic_data));
+ break;
+
+ case SR_PROBE_ANALOG:
+ {
+ shared_ptr<data::Analog> data(
+ new data::Analog());
+ signal = shared_ptr<view::Signal>(
+ new view::AnalogSignal(dev_inst,
+ probe, data));
+ break;
+ }
+
+ default:
+ assert(0);
+ break;
+ }
+
+ assert(signal);
+ _signals.push_back(signal);
+ }
+
+ } while(0);
+
+ signals_changed();
+}
+
+shared_ptr<view::Signal> SigSession::signal_from_probe(
+ const sr_probe *probe) const
+{
+ lock_guard<mutex> lock(_signals_mutex);
+ BOOST_FOREACH(shared_ptr<view::Signal> sig, _signals) {
+ assert(sig);
+ if (sig->probe() == probe)
+ return sig;
+ }
+ return shared_ptr<view::Signal>();
+}
+
+void SigSession::read_sample_rate(const sr_dev_inst *const sdi)
+{
+ GVariant *gvar;
+ uint64_t sample_rate = 0;
+
+ // Read out the sample rate
+ if(sdi->driver)
+ {
+ const int ret = sr_config_get(sdi->driver, sdi, NULL,
+ SR_CONF_SAMPLERATE, &gvar);
+ if (ret != SR_OK) {
+ qDebug("Failed to get samplerate\n");
+ return;
+ }
+
+ sample_rate = g_variant_get_uint64(gvar);
+ g_variant_unref(gvar);