X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=a8047f7da7f51ad9417f7861e447e465a2a77f94;hp=dc08afb245f8fc5e5ea54d3da40e745b0322d4a5;hb=4640a84e926ac4b82e2a1b6ef9fc80ef44c2bd3c;hpb=56c4de9ada023505b16b6d188fb77d9fb10e52e1 diff --git a/pv/session.cpp b/pv/session.cpp index dc08afb2..a8047f7d 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include "devicemanager.hpp" @@ -84,7 +85,6 @@ using std::string; using std::unique_lock; #endif using std::unique_ptr; -using std::unordered_set; using std::vector; using sigrok::Analog; @@ -106,6 +106,7 @@ using Gst::ElementFactory; using Gst::Pipeline; #endif +using pv::data::SignalGroup; using pv::util::Timestamp; using pv::views::trace::Signal; using pv::views::trace::AnalogSignal; @@ -116,6 +117,7 @@ namespace pv { shared_ptr Session::sr_context; Session::Session(DeviceManager &device_manager, QString name) : + shutting_down_(false), device_manager_(device_manager), default_name_(name), name_(name), @@ -127,8 +129,15 @@ Session::Session(DeviceManager &device_manager, QString name) : Session::~Session() { + shutting_down_ = true; + // Stop and join to the thread stop_capture(); + + for (SignalGroup* group : signal_groups_) { + group->clear(); + delete group; + } } DeviceManager& Session::device_manager() @@ -168,6 +177,16 @@ void Session::set_name(QString name) name_changed(); } +QString Session::save_path() const +{ + return save_path_; +} + +void Session::set_save_path(QString path) +{ + save_path_ = path; +} + const vector< shared_ptr > Session::views() const { return views_; @@ -235,7 +254,7 @@ void Session::save_setup(QSettings &settings) const int view_id = 0; i = 0; - for (const shared_ptr vb : views_) { + for (const shared_ptr& vb : views_) { shared_ptr tv = dynamic_pointer_cast(vb); if (tv) { for (const shared_ptr& time_item : tv->time_items()) { @@ -304,25 +323,36 @@ void Session::save_settings(QSettings &settings) const settings.endGroup(); } - shared_ptr sessionfile_device = - dynamic_pointer_cast(device_); - - if (sessionfile_device) { + // Having saved the data to srzip overrides the current device. This is + // a crappy hack around the fact that saving e.g. an imported file to + // srzip would require changing the underlying libsigrok device + if (!save_path_.isEmpty()) { + QFileInfo fi = QFileInfo(QDir(save_path_), name_); settings.setValue("device_type", "sessionfile"); settings.beginGroup("device"); - settings.setValue("filename", QString::fromStdString( - sessionfile_device->full_name())); + settings.setValue("filename", fi.absoluteFilePath()); settings.endGroup(); - } + } else { + shared_ptr sessionfile_device = + dynamic_pointer_cast(device_); + + if (sessionfile_device) { + settings.setValue("device_type", "sessionfile"); + settings.beginGroup("device"); + settings.setValue("filename", QString::fromStdString( + sessionfile_device->full_name())); + settings.endGroup(); + } - shared_ptr inputfile_device = - dynamic_pointer_cast(device_); + shared_ptr inputfile_device = + dynamic_pointer_cast(device_); - if (inputfile_device) { - settings.setValue("device_type", "inputfile"); - settings.beginGroup("device"); - inputfile_device->save_meta_to_settings(settings); - settings.endGroup(); + if (inputfile_device) { + settings.setValue("device_type", "inputfile"); + settings.beginGroup("device"); + inputfile_device->save_meta_to_settings(settings); + settings.endGroup(); + } } save_setup(settings); @@ -436,16 +466,17 @@ void Session::restore_settings(QSettings &settings) settings.endGroup(); } + + QString filename; if ((device_type == "sessionfile") || (device_type == "inputfile")) { if (device_type == "sessionfile") { settings.beginGroup("device"); - const QString filename = settings.value("filename").toString(); + filename = settings.value("filename").toString(); settings.endGroup(); - if (QFileInfo(filename).isReadable()) { + if (QFileInfo(filename).isReadable()) device = make_shared(device_manager_.context(), filename.toStdString()); - } } if (device_type == "inputfile") { @@ -464,6 +495,14 @@ void Session::restore_settings(QSettings &settings) set_name(QString::fromStdString( dynamic_pointer_cast(device)->display_name(device_manager_))); + + if (!filename.isEmpty()) { + // Only set the save path if we load an srzip file + if (device_type == "sessionfile") + set_save_path(QFileInfo(filename).absolutePath()); + + set_name(QFileInfo(filename).fileName()); + } } } @@ -501,14 +540,22 @@ void Session::set_device(shared_ptr device) // Remove all stored data and reset all views for (shared_ptr view : views_) { - view->clear_signals(); + view->clear_signalbases(); #ifdef ENABLE_DECODE view->clear_decode_signals(); #endif view->reset_view_state(); } + + for (SignalGroup* group : signal_groups_) { + group->clear(); + delete group; + } + signal_groups_.clear(); + for (const shared_ptr& d : all_signal_data_) d->clear(); + all_signal_data_.clear(); signalbases_.clear(); cur_logic_segment_.reset(); @@ -605,8 +652,12 @@ Session::input_format_options(vector user_spec, * data type. */ auto found = fmt_opts.find(key); - if (found == fmt_opts.end()) + if (found == fmt_opts.end()) { + qCritical() << "Supplied input option" << QString::fromStdString(key) << + "is not a valid option for this input module, it will be ignored!"; continue; + } + shared_ptr