]> sigrok.org Git - pulseview.git/commitdiff
Simplify segment complete notifications and fix error msg handling
authorSoeren Apel <redacted>
Sat, 2 Jan 2021 23:26:57 +0000 (00:26 +0100)
committerSoeren Apel <redacted>
Sat, 2 Jan 2021 23:26:57 +0000 (00:26 +0100)
pv/data/analog.hpp
pv/data/decodesignal.cpp
pv/data/decodesignal.hpp
pv/data/logic.cpp
pv/data/logic.hpp
pv/data/signaldata.hpp

index 630dc9db435bf36617aca313d220de8126a4ebdf..560732f8bef8bebf238e948b37249ccd8d4f5141 100644 (file)
@@ -73,8 +73,6 @@ Q_SIGNALS:
 
        void min_max_changed(float min, float max);
 
-       void segment_completed();
-
 private Q_SLOTS:
        void on_segment_completed();
 
index 610bfc4fe6e89771c678f33453bcef1ad78c474e..91bee1da35f5d022cdaf0ffbbe3c7bf48ab4a930 100644 (file)
@@ -829,6 +829,8 @@ void DecodeSignal::restore_settings(QSettings &settings)
                settings.endGroup();
        }
 
+       connect_input_notifiers();
+
        // Update the internal structures
        stack_config_changed_ = true;
        update_channel_list();
@@ -1134,8 +1136,6 @@ void DecodeSignal::logic_mux_proc()
        // Logic mux data is being updated
        logic_mux_data_invalid_ = false;
 
-       connect_input_segment_notifiers(segment_id);
-
        uint64_t samples_to_process;
        do {
                do {
@@ -1175,8 +1175,6 @@ void DecodeSignal::logic_mux_proc()
 
                                if (segment_id < get_input_segment_count() - 1) {
 
-                                       disconnect_input_segment_notifiers(segment_id);
-
                                        // Process next segment
                                        segment_id++;
 
@@ -1186,8 +1184,6 @@ void DecodeSignal::logic_mux_proc()
                                        logic_mux_data_->push_segment(output_segment);
 
                                        output_segment->set_samplerate(get_input_samplerate(segment_id));
-
-                                       connect_input_segment_notifiers(segment_id);
                                } else {
                                        // Wait for more input data if we're processing the currently last segment
                                        unique_lock<mutex> logic_mux_lock(logic_mux_mutex_);
@@ -1200,8 +1196,6 @@ void DecodeSignal::logic_mux_proc()
                        }
                }
        } while (!logic_mux_interrupt_);
-
-       disconnect_input_segment_notifiers(segment_id);
 }
 
 void DecodeSignal::decode_data(
@@ -1451,9 +1445,13 @@ void DecodeSignal::connect_input_notifiers()
                const data::SignalBase *signal = ch.assigned_signal.get();
 
                connect(signal, SIGNAL(samples_cleared()),
-                       this, SLOT(on_data_cleared()));
+                       this, SLOT(on_data_cleared()), Qt::UniqueConnection);
                connect(signal, SIGNAL(samples_added(uint64_t, uint64_t, uint64_t)),
-                       this, SLOT(on_data_received()));
+                       this, SLOT(on_data_received()), Qt::UniqueConnection);
+
+               if (signal->logic_data())
+                       connect(signal->logic_data().get(), SIGNAL(segment_completed()),
+                               this, SLOT(on_input_segment_completed()), Qt::UniqueConnection);
        }
 }
 
@@ -1466,51 +1464,10 @@ void DecodeSignal::disconnect_input_notifiers()
                const data::SignalBase *signal = ch.assigned_signal.get();
                disconnect(signal, nullptr, this, SLOT(on_data_cleared()));
                disconnect(signal, nullptr, this, SLOT(on_data_received()));
-       }
-}
-
-void DecodeSignal::connect_input_segment_notifiers(uint32_t segment_id)
-{
-       for (decode::DecodeChannel& ch : channels_)
-               if (ch.assigned_signal) {
-                       const shared_ptr<Logic> logic_data = ch.assigned_signal->logic_data();
-
-                       shared_ptr<const LogicSegment> segment;
-                       if (segment_id < logic_data->logic_segments().size()) {
-                               segment = logic_data->logic_segments().at(segment_id)->get_shared_ptr();
-                       } else {
-                               qWarning() << "Signal" << name() << ":" << ch.assigned_signal->name() \
-                                       << "has no logic segment, can't connect notifier" << segment_id;
-                               continue;
-                       }
-
-                       if (!segment) {
-                               qWarning() << "Signal" << name() << ":" << ch.assigned_signal->name() \
-                                       << "has no logic segment, can't connect notifier" << segment_id;
-                               continue;
-                       }
-
-                       connect(segment.get(), SIGNAL(completed()), this, SLOT(on_input_segment_completed()));
-               }
-}
-
-void DecodeSignal::disconnect_input_segment_notifiers(uint32_t segment_id)
-{
-       for (decode::DecodeChannel& ch : channels_)
-               if (ch.assigned_signal) {
-                       const shared_ptr<Logic> logic_data = ch.assigned_signal->logic_data();
-
-                       shared_ptr<const LogicSegment> segment;
-                       if (segment_id < logic_data->logic_segments().size())
-                               segment = logic_data->logic_segments().at(segment_id)->get_shared_ptr();
-                       else
-                               continue;
-
-                       if (!segment)
-                               continue;
 
-                       disconnect(segment.get(), SIGNAL(completed()), this, SLOT(on_input_segment_completed()));
-               }
+               if (signal->logic_data())
+                       disconnect(signal->logic_data().get(), nullptr, this, SLOT(on_input_segment_completed()));
+       }
 }
 
 void DecodeSignal::create_decode_segment()
@@ -1704,14 +1661,15 @@ void DecodeSignal::on_data_cleared()
 void DecodeSignal::on_data_received()
 {
        // If we detected a lack of input data when trying to start decoding,
-       // we have set an error message. Only try again if we now have data
+       // we have set an error message. Bail out if we still don't have data
        // to work with
        if ((!error_message_.isEmpty()) && (get_input_segment_count() == 0))
                return;
-       else {
+
+       if (!error_message_.isEmpty()) {
                error_message_.clear();
                // TODO Emulate noquote()
-               qDebug().nospace() << name() << ": Error cleared";
+               qDebug().nospace() << name() << ": Input data available, error cleared";
        }
 
        if (!logic_mux_thread_.joinable())
index 527b988a92a8be6dfdfac6eaa7e2b2db2772165d..ab85246a0bc7aaf7d4a7a94059590fb42761f68a 100644 (file)
@@ -211,8 +211,6 @@ private:
 
        void connect_input_notifiers();
        void disconnect_input_notifiers();
-       void connect_input_segment_notifiers(uint32_t segment_id);
-       void disconnect_input_segment_notifiers(uint32_t segment_id);
 
        void create_decode_segment();
 
index ab779228817bcb798edf4daaed9e13ab32e8288d..4a13e568bc80ff38770a245b1e9b38b1861d15a9 100644 (file)
@@ -49,6 +49,8 @@ void Logic::push_segment(shared_ptr<LogicSegment> &segment)
 
        if ((samplerate_ == 1) && (segment->samplerate() > 1))
                samplerate_ = segment->samplerate();
+
+       connect(segment.get(), SIGNAL(completed()), this, SLOT(on_segment_completed()));
 }
 
 const deque< shared_ptr<LogicSegment> >& Logic::logic_segments() const
@@ -106,5 +108,10 @@ void Logic::notify_samples_added(shared_ptr<Segment> segment, uint64_t start_sam
        samples_added(segment, start_sample, end_sample);
 }
 
+void Logic::on_segment_completed()
+{
+       segment_completed();
+}
+
 } // namespace data
 } // namespace pv
index b5e532c45e9a0523d13991f39fb8c653d498eca3..07f8222c1946cc699828c6ac3cdc6c3d761eb67d 100644 (file)
@@ -71,6 +71,9 @@ Q_SIGNALS:
        void samples_added(SharedPtrToSegment segment, uint64_t start_sample,
                uint64_t end_sample);
 
+private Q_SLOTS:
+       void on_segment_completed();
+
 private:
        double samplerate_;
        const unsigned int num_channels_;
index 6d2283abeaddc962d6529dc1b9150df94a459428..7a9d6d39b96bada864b2f46017c802587dedf37e 100644 (file)
@@ -54,6 +54,9 @@ public:
        virtual void set_samplerate(double value) = 0;
 
        virtual double get_samplerate() const = 0;
+
+Q_SIGNALS:
+       void segment_completed();
 };
 
 } // namespace data