X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=50e89e567041c2ec186e47e0d387457808f452a3;hp=b1ce14680bbec848f6ae92fd3ec4010094d8320c;hb=d7168e582c71ebcc359b12efed83daa2a6b6f28e;hpb=a66e286e0276186c41b7ce07cfcbd0c4da2ca1cb diff --git a/pv/session.cpp b/pv/session.cpp index b1ce1468..50e89e56 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -28,6 +28,7 @@ #include #include "devicemanager.hpp" +#include "mainwindow.hpp" #include "session.hpp" #include "data/analog.hpp" @@ -299,8 +300,9 @@ void Session::restore_settings(QSettings &settings) filename.toStdString()); set_device(device); - // TODO Perform error handling - start_capture([](QString infoMessage) { (void)infoMessage; }); + start_capture([](QString infoMessage) { + // TODO Emulate noquote() + qDebug() << "Session error:" << infoMessage; }); set_name(QFileInfo(filename).fileName()); } @@ -352,7 +354,7 @@ void Session::select_device(shared_ptr device) else set_default_device(); } catch (const QString &e) { - main_bar_->session_error(tr("Failed to select device"), e); + MainWindow::show_session_error(tr("Failed to select device"), e); } } @@ -400,7 +402,7 @@ void Session::set_device(shared_ptr device) device_->open(); } catch (const QString &e) { device_.reset(); - main_bar_->session_error(tr("Failed to open device"), e); + MainWindow::show_session_error(tr("Failed to open device"), e); } if (device_) { @@ -481,6 +483,7 @@ void Session::load_init_file(const string &file_name, const string &format) map input_opts; if (!format.empty()) { + // Got a user provided input format spec. const map > formats = device_manager_.context()->input_formats(); auto user_opts = pv::util::split_string(format, ":"); @@ -490,13 +493,18 @@ void Session::load_init_file(const string &file_name, const string &format) [&](const pair > f) { return f.first == user_name; }); if (iter == formats.end()) { - main_bar_->session_error(tr("Error"), + MainWindow::show_session_error(tr("Error"), tr("Unexpected input format: %s").arg(QString::fromStdString(format))); return; } input_format = (*iter).second; input_opts = input_format_options(user_opts, input_format->options()); + } else { + // (Try to) auto detect the input format. Lookup failure + // is not fatal, when no input module claimed responsibility, + // then a session file gets loaded. + input_format = device_manager_.context()->input_format_match(file_name); } load_file(QString::fromStdString(file_name), input_format, input_opts); @@ -521,8 +529,8 @@ void Session::load_file(QString file_name, new devices::SessionFile( device_manager_.context(), file_name.toStdString()))); - } catch (Error e) { - main_bar_->session_error(tr("Failed to load ") + file_name, e.what()); + } catch (Error& e) { + MainWindow::show_session_error(tr("Failed to load ") + file_name, e.what()); set_default_device(); main_bar_->update_device_list(); return; @@ -531,7 +539,7 @@ void Session::load_file(QString file_name, main_bar_->update_device_list(); start_capture([&, errorMessage](QString infoMessage) { - main_bar_->session_error(errorMessage, infoMessage); }); + MainWindow::show_session_error(errorMessage, infoMessage); }); set_name(QFileInfo(file_name).fileName()); } @@ -732,7 +740,7 @@ shared_ptr Session::add_decode_signal() // Add the decode signal to all views for (shared_ptr view : views_) view->add_decode_signal(signal); - } catch (runtime_error e) { + } catch (runtime_error& e) { remove_decode_signal(signal); return nullptr; } @@ -934,7 +942,7 @@ void Session::sample_thread_proc(function error_handler) try { device_->start(); - } catch (Error e) { + } catch (Error& e) { error_handler(e.what()); return; } @@ -944,7 +952,7 @@ void Session::sample_thread_proc(function error_handler) try { device_->run(); - } catch (Error e) { + } catch (Error& e) { error_handler(e.what()); set_capture_state(Stopped); return; @@ -953,10 +961,8 @@ void Session::sample_thread_proc(function error_handler) set_capture_state(Stopped); // Confirm that SR_DF_END was received - if (cur_logic_segment_) { - qDebug("SR_DF_END was not received."); - assert(false); - } + if (cur_logic_segment_) + qDebug() << "WARNING: SR_DF_END was not received."; // Optimize memory usage free_unused_memory(); @@ -1132,6 +1138,11 @@ void Session::feed_in_frame_end() void Session::feed_in_logic(shared_ptr logic) { + if (logic->data_length() == 0) { + qDebug() << "WARNING: Received logic packet with 0 samples."; + return; + } + if (!cur_samplerate_) cur_samplerate_ = device_->read_config(ConfigKey::SAMPLERATE); @@ -1164,6 +1175,11 @@ void Session::feed_in_logic(shared_ptr logic) void Session::feed_in_analog(shared_ptr analog) { + if (analog->num_samples() == 0) { + qDebug() << "WARNING: Received analog packet with 0 samples."; + return; + } + if (!cur_samplerate_) cur_samplerate_ = device_->read_config(ConfigKey::SAMPLERATE); @@ -1253,7 +1269,7 @@ void Session::data_feed_in(shared_ptr device, case SR_DF_LOGIC: try { feed_in_logic(dynamic_pointer_cast(packet->payload())); - } catch (bad_alloc) { + } catch (bad_alloc&) { out_of_memory_ = true; device_->stop(); } @@ -1262,7 +1278,7 @@ void Session::data_feed_in(shared_ptr device, case SR_DF_ANALOG: try { feed_in_analog(dynamic_pointer_cast(packet->payload())); - } catch (bad_alloc) { + } catch (bad_alloc&) { out_of_memory_ = true; device_->stop(); } @@ -1282,6 +1298,15 @@ void Session::data_feed_in(shared_ptr device, // devices use frames, and for those devices, we need to do it here. { lock_guard lock(data_mutex_); + + if (cur_logic_segment_) + cur_logic_segment_->set_complete(); + + for (auto entry : cur_analog_segments_) { + shared_ptr segment = entry.second; + segment->set_complete(); + } + cur_logic_segment_.reset(); cur_analog_segments_.clear(); }