From 4e86ec7042631d4b54876cba89c01a73abaf7213 Mon Sep 17 00:00:00 2001 From: Soeren Apel Date: Sun, 29 Oct 2017 23:38:06 +0100 Subject: [PATCH] Rework new segment notification mechanism --- pv/session.cpp | 55 ++++++++++++++++++++++++++-------- pv/session.hpp | 7 +++-- pv/views/trace/standardbar.cpp | 12 ++++---- pv/views/trace/standardbar.hpp | 2 +- pv/views/trace/view.cpp | 5 ++++ pv/views/trace/view.hpp | 1 + pv/views/viewbase.cpp | 7 +++++ pv/views/viewbase.hpp | 1 + 8 files changed, 67 insertions(+), 23 deletions(-) diff --git a/pv/session.cpp b/pv/session.cpp index 07ee594d..dd06cfed 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -681,11 +681,12 @@ int Session::get_segment_count() const { int min_val = INT_MAX; + // Find the lowest common number of segments for (shared_ptr data : all_signal_data_) if (data->get_segment_count() < min_val) min_val = data->get_segment_count(); - return min_val; + return (min_val != INT_MAX) ? min_val : 0; } const unordered_set< shared_ptr > Session::signalbases() const @@ -899,6 +900,13 @@ void Session::sample_thread_proc(function error_handler) out_of_memory_ = false; + { + lock_guard lock(data_mutex_); + cur_logic_segment_.reset(); + cur_analog_segments_.clear(); + } + highest_segment_id_ = -1; + try { device_->start(); } catch (Error e) { @@ -950,6 +958,36 @@ void Session::free_unused_memory() } } +void Session::signal_new_segment() +{ + int new_segment_id = 1; + + if ((cur_logic_segment_ != nullptr) || !cur_analog_segments_.empty()) { + + // Determine new frame/segment number, assuming that all + // signals have the same number of frames/segments + if (cur_logic_segment_) { + new_segment_id = logic_data_->get_segment_count(); + } else { + shared_ptr any_channel = + (*cur_analog_segments_.begin()).first; + + shared_ptr base = signalbase_from_channel(any_channel); + assert(base); + + shared_ptr data(base->analog_data()); + assert(data); + + new_segment_id = data->get_segment_count(); + } + } + + if (new_segment_id > highest_segment_id_) { + highest_segment_id_ = new_segment_id; + new_segment(highest_segment_id_); + } +} + void Session::feed_in_header() { // Nothing to do here for now @@ -1002,9 +1040,6 @@ void Session::feed_in_trigger() void Session::feed_in_frame_begin() { frame_began_ = true; - - if (cur_logic_segment_ || !cur_analog_segments_.empty()) - frame_began(); } void Session::feed_in_frame_end() @@ -1015,10 +1050,8 @@ void Session::feed_in_frame_end() cur_analog_segments_.clear(); } - if (frame_began_) { + if (frame_began_) frame_began_ = false; - frame_ended(); - } } void Session::feed_in_logic(shared_ptr logic) @@ -1044,11 +1077,7 @@ void Session::feed_in_logic(shared_ptr logic) *logic_data_, logic->unit_size(), cur_samplerate_); logic_data_->push_segment(cur_logic_segment_); - // @todo Putting this here means that only listeners querying - // for logic will be notified. Currently the only user of - // frame_began is DecoderStack, but in future we need to signal - // this after both analog and logic sweeps have begun. - frame_began(); + signal_new_segment(); } cur_logic_segment_->append_payload(logic); @@ -1103,6 +1132,8 @@ void Session::feed_in_analog(shared_ptr analog) // Push the segment into the analog data. data->push_segment(segment); + + signal_new_segment(); } assert(segment); diff --git a/pv/session.hpp b/pv/session.hpp index dcb4ad1d..1cb370a9 100644 --- a/pv/session.hpp +++ b/pv/session.hpp @@ -196,6 +196,8 @@ private: void free_unused_memory(); + void signal_new_segment(); + void feed_in_header(); void feed_in_meta(shared_ptr meta); @@ -234,6 +236,7 @@ private: shared_ptr cur_logic_segment_; map< shared_ptr, shared_ptr > cur_analog_segments_; + int32_t highest_segment_id_; std::thread sampling_thread_; @@ -251,12 +254,10 @@ Q_SIGNALS: void trigger_event(util::Timestamp location); - void frame_began(); + void new_segment(int new_frame_id); void data_received(); - void frame_ended(); - void add_view(const QString &title, views::ViewType type, Session *session); diff --git a/pv/views/trace/standardbar.cpp b/pv/views/trace/standardbar.cpp index e2d6f3e2..d773a5c1 100644 --- a/pv/views/trace/standardbar.cpp +++ b/pv/views/trace/standardbar.cpp @@ -87,8 +87,8 @@ StandardBar::StandardBar(Session &session, QWidget *parent, segment_selector_->setMinimum(1); segment_selector_->hide(); - connect(&session_, SIGNAL(frame_ended()), - this, SLOT(on_segment_added())); + connect(&session_, SIGNAL(new_segment(int)), + this, SLOT(on_new_segment(int))); connect(segment_selector_, SIGNAL(valueChanged(int)), view_, SLOT(on_segment_changed(int))); @@ -186,13 +186,11 @@ void StandardBar::on_always_zoom_to_fit_changed(bool state) action_view_zoom_fit_->setChecked(state); } -void StandardBar::on_segment_added() +void StandardBar::on_new_segment(int new_segment_id) { - const int segment_count = session_.get_segment_count(); - - if (segment_count > 1) { + if (new_segment_id > 1) { show_multi_segment_ui(true); - segment_selector_->setMaximum(segment_count); + segment_selector_->setMaximum(new_segment_id); } else show_multi_segment_ui(false); } diff --git a/pv/views/trace/standardbar.hpp b/pv/views/trace/standardbar.hpp index 94a6d81b..8640b4c9 100644 --- a/pv/views/trace/standardbar.hpp +++ b/pv/views/trace/standardbar.hpp @@ -88,7 +88,7 @@ protected Q_SLOTS: void on_always_zoom_to_fit_changed(bool state); - void on_segment_added(); + void on_new_segment(int new_segment_id); private: vector multi_segment_actions_; diff --git a/pv/views/trace/view.cpp b/pv/views/trace/view.cpp index 29c6fef4..07919c28 100644 --- a/pv/views/trace/view.cpp +++ b/pv/views/trace/view.cpp @@ -1383,6 +1383,11 @@ void View::capture_state_updated(int state) } } +void View::on_new_segment(int new_segment_id) +{ + on_segment_changed(new_segment_id); +} + void View::on_segment_changed(int segment) { current_segment_ = segment - 1; diff --git a/pv/views/trace/view.hpp b/pv/views/trace/view.hpp index b6759a4f..8fd7e968 100644 --- a/pv/views/trace/view.hpp +++ b/pv/views/trace/view.hpp @@ -366,6 +366,7 @@ private Q_SLOTS: void signals_changed(); void capture_state_updated(int state); + void on_new_segment(int new_segment_id); void on_segment_changed(int segment); virtual void perform_delayed_view_update(); diff --git a/pv/views/viewbase.cpp b/pv/views/viewbase.cpp index 4031211f..30fd7cec 100644 --- a/pv/views/viewbase.cpp +++ b/pv/views/viewbase.cpp @@ -44,6 +44,8 @@ ViewBase::ViewBase(Session &session, bool is_main_view, QWidget *parent) : this, SLOT(signals_changed())); connect(&session_, SIGNAL(capture_state_changed(int)), this, SLOT(capture_state_updated(int))); + connect(&session_, SIGNAL(new_segment(int)), + this, SLOT(on_new_segment(int))); connect(&delayed_view_updater_, SIGNAL(timeout()), this, SLOT(perform_delayed_view_update())); @@ -127,6 +129,11 @@ void ViewBase::signals_changed() { } +void ViewBase::on_new_segment(int new_segment_id) +{ + (void)new_segment_id; +} + void ViewBase::capture_state_updated(int state) { (void)state; diff --git a/pv/views/viewbase.hpp b/pv/views/viewbase.hpp index e6a003a5..fdf12a86 100644 --- a/pv/views/viewbase.hpp +++ b/pv/views/viewbase.hpp @@ -95,6 +95,7 @@ public Q_SLOTS: virtual void trigger_event(util::Timestamp location); virtual void signals_changed(); virtual void capture_state_updated(int state); + virtual void on_new_segment(int new_segment_id); virtual void perform_delayed_view_update(); private Q_SLOTS: -- 2.30.2