+ map<const srd_probe*, shared_ptr<view::LogicSignal> > probes;
+
+ try
+ {
+ lock_guard<mutex> lock(_signals_mutex);
+
+ // Create the decoder
+ shared_ptr<data::Decoder> decoder(new data::Decoder(dec));
+
+ // Auto select the initial probes
+ for(const GSList *i = dec->probes; i; i = i->next)
+ {
+ const srd_probe *const probe = (const srd_probe*)i->data;
+ BOOST_FOREACH(shared_ptr<view::Signal> s, _signals)
+ {
+ shared_ptr<view::LogicSignal> l =
+ dynamic_pointer_cast<view::LogicSignal>(s);
+ if (l && QString(probe->name).toLower().contains(
+ l->get_name().toLower()))
+ probes[probe] = l;
+ }
+ }
+
+ decoder->set_probes(probes);
+
+ // Create the decode signal
+ shared_ptr<view::DecodeSignal> d(
+ new view::DecodeSignal(*this, decoder,
+ _decode_traces.size()));
+ _decode_traces.push_back(d);
+ }
+ catch(std::runtime_error e)
+ {
+ return false;
+ }
+
+ signals_changed();
+
+ return true;
+}
+
+vector< shared_ptr<view::DecodeSignal> > SigSession::get_decode_signals() const
+{
+ lock_guard<mutex> lock(_signals_mutex);
+ return _decode_traces;
+}
+
+void SigSession::remove_decode_signal(view::DecodeSignal *signal)
+{
+ for (vector< shared_ptr<view::DecodeSignal> >::iterator i =
+ _decode_traces.begin();
+ i != _decode_traces.end();
+ i++)
+ if ((*i).get() == signal)
+ {
+ _decode_traces.erase(i);
+ signals_changed();
+ return;
+ }
+}
+
+void SigSession::set_capture_state(capture_state state)
+{
+ lock_guard<mutex> lock(_sampling_mutex);
+ const bool changed = _capture_state != state;
+ _capture_state = state;
+ if(changed)
+ 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;
+ }
+
+ /* Otherwise, try to find an input module that can handle this file. */
+ for (i = 0; inputs[i]; i++) {
+ if (inputs[i]->format_match(filename.c_str()))
+ break;
+ }
+
+ /* Return NULL if no input module wanted to touch this. */
+ if (!inputs[i]) {
+ g_critical("Error: no matching input module found.");
+ return NULL;
+ }
+
+ 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;
+ }
+