X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=a71ad1c56d2b2001bf0e65cdb2e706613ba09f1a;hp=b3f8ba87de7e31aa57bbc7dba5b4687fd45557f7;hb=73d5a9bbc2f32ed84077ca4e75a125a6b0fc1921;hpb=e887fe9e6ede73b9fe9ace9c6bfd4f6a096eb3b2 diff --git a/pv/session.cpp b/pv/session.cpp index b3f8ba87..a71ad1c5 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include "devicemanager.hpp" @@ -67,8 +68,8 @@ using std::bad_alloc; using std::dynamic_pointer_cast; using std::find_if; using std::function; -using std::lock_guard; using std::list; +using std::lock_guard; using std::make_pair; using std::make_shared; using std::map; @@ -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,7 +177,17 @@ void Session::set_name(QString name) name_changed(); } -const list< shared_ptr > Session::views() const +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_; } @@ -233,31 +252,40 @@ void Session::save_setup(QSettings &settings) const settings.setValue("views", i); + int view_id = 0; i = 0; - shared_ptr tv = dynamic_pointer_cast(main_view_); - for (const shared_ptr& time_item : tv->time_items()) { - - const shared_ptr flag = - dynamic_pointer_cast(time_item); - if (flag) { - if (!flag->enabled()) - continue; + for (const shared_ptr& vb : views_) { + shared_ptr tv = dynamic_pointer_cast(vb); + if (tv) { + for (const shared_ptr& time_item : tv->time_items()) { + + const shared_ptr flag = + dynamic_pointer_cast(time_item); + if (flag) { + if (!flag->enabled()) + continue; + + settings.beginGroup("meta_obj" + QString::number(i++)); + settings.setValue("type", "time_marker"); + settings.setValue("assoc_view", view_id); + GlobalSettings::store_timestamp(settings, "time", flag->time()); + settings.setValue("text", flag->get_text()); + settings.endGroup(); + } + } - settings.beginGroup("meta_obj" + QString::number(i++)); - settings.setValue("type", "time_marker"); - GlobalSettings::store_timestamp(settings, "time", flag->time()); - settings.setValue("text", flag->get_text()); - settings.endGroup(); + if (tv->cursors_shown()) { + settings.beginGroup("meta_obj" + QString::number(i++)); + settings.setValue("type", "selection"); + settings.setValue("assoc_view", view_id); + const shared_ptr cp = tv->cursors(); + GlobalSettings::store_timestamp(settings, "start_time", cp->first()->time()); + GlobalSettings::store_timestamp(settings, "end_time", cp->second()->time()); + settings.endGroup(); + } } - } - if (tv->cursors_shown()) { - settings.beginGroup("meta_obj" + QString::number(i++)); - settings.setValue("type", "selection"); - const shared_ptr cp = tv->cursors(); - GlobalSettings::store_timestamp(settings, "start_time", cp->first()->time()); - GlobalSettings::store_timestamp(settings, "end_time", cp->second()->time()); - settings.endGroup(); + view_id++; } settings.setValue("meta_objs", i); @@ -295,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); @@ -360,18 +399,26 @@ void Session::restore_setup(QSettings &settings) // Restore meta objects like markers and cursors int meta_objs = settings.value("meta_objs").toInt(); - shared_ptr tv = dynamic_pointer_cast(main_view_); for (int i = 0; i < meta_objs; i++) { settings.beginGroup("meta_obj" + QString::number(i)); + + shared_ptr vb; + shared_ptr tv; + if (settings.contains("assoc_view")) + vb = views_.at(settings.value("assoc_view").toInt()); + + if (vb) + tv = dynamic_pointer_cast(vb); + const QString type = settings.value("type").toString(); - if (type == "time_marker") { + if ((type == "time_marker") && tv) { Timestamp ts = GlobalSettings::restore_timestamp(settings, "time"); shared_ptr flag = tv->add_flag(ts); flag->set_text(settings.value("text").toString()); } - if (type == "selection") { + if ((type == "selection") && tv) { Timestamp start = GlobalSettings::restore_timestamp(settings, "start_time"); Timestamp end = GlobalSettings::restore_timestamp(settings, "end_time"); tv->set_cursors(start, end); @@ -419,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") { @@ -447,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()); + } } } @@ -484,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(); @@ -588,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