]> sigrok.org Git - pulseview.git/commitdiff
Rework signals for modularity
authorSoeren Apel <redacted>
Tue, 5 May 2020 16:39:25 +0000 (18:39 +0200)
committerSoeren Apel <redacted>
Mon, 11 May 2020 19:24:22 +0000 (21:24 +0200)
12 files changed:
main.cpp
pv/data/analog.cpp
pv/data/analog.hpp
pv/data/analogsegment.cpp
pv/data/analogsegment.hpp
pv/data/logic.cpp
pv/data/logic.hpp
pv/data/logicsegment.cpp
pv/data/logicsegment.hpp
pv/data/segment.hpp
pv/data/signalbase.cpp
pv/data/signalbase.hpp

index da5fffcdb3af28d4ada2044e32e88c4a2cd7cd3b..793f4ce12d77dd83e6b7f976a1a70de29216caf1 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -60,6 +60,7 @@
 #include "pv/mainwindow.hpp"
 #include "pv/session.hpp"
 #include "pv/util.hpp"
+#include "pv/data/segment.hpp"
 
 #ifdef ANDROID
 #include <libsigrokandroidutils/libsigrokandroidutils.h>
@@ -274,8 +275,9 @@ int main(int argc, char *argv[])
        for (int i = 0; i < argc; i++)
                open_files.emplace_back(argv[i]);
 
-       qRegisterMetaType<pv::util::Timestamp>("util::Timestamp");
        qRegisterMetaType<uint64_t>("uint64_t");
+       qRegisterMetaType<pv::util::Timestamp>("util::Timestamp");
+       qRegisterMetaType<pv::data::Segment>("data::Segment");
 
        // Prepare the global settings since logging needs them early on
        pv::GlobalSettings settings;
index 57d09502ae754503c507953e5e413e0102497e4d..02cb83e40c7e474729c7c6d82035f673138f6d36 100644 (file)
@@ -84,7 +84,7 @@ uint64_t Analog::max_sample_count() const
        return l;
 }
 
-void Analog::notify_samples_added(QObject* segment, uint64_t start_sample,
+void Analog::notify_samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
        uint64_t end_sample)
 {
        samples_added(segment, start_sample, end_sample);
index 026d80463dcd24562507f8ebea6d4b96776cc774..bcdf7bc92300e7b9fe53eac5f8cf364bd8c701a4 100644 (file)
@@ -59,7 +59,7 @@ public:
 
        uint64_t max_sample_count() const;
 
-       void notify_samples_added(QObject* segment, uint64_t start_sample,
+       void notify_samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
                uint64_t end_sample);
 
        void notify_min_max_changed(float min, float max);
@@ -67,7 +67,7 @@ public:
 Q_SIGNALS:
        void samples_cleared();
 
-       void samples_added(QObject* segment, uint64_t start_sample,
+       void samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
                uint64_t end_sample);
 
        void min_max_changed(float min, float max);
index 342612aae02e15954671d2044f3bdb337682cd09..e6f9626c8c07bdaf0cd0382c674ac50b4771e2b2 100644 (file)
@@ -89,11 +89,11 @@ void AnalogSegment::append_interleaved_samples(const float *data,
        append_payload_to_envelope_levels();
 
        if (sample_count > 1)
-               owner_.notify_samples_added(this, prev_sample_count + 1,
-                       prev_sample_count + 1 + sample_count);
+               owner_.notify_samples_added(shared_ptr<Segment>(shared_from_this()),
+                       prev_sample_count + 1, prev_sample_count + 1 + sample_count);
        else
-               owner_.notify_samples_added(this, prev_sample_count + 1,
-                       prev_sample_count + 1);
+               owner_.notify_samples_added(shared_ptr<Segment>(shared_from_this()),
+                       prev_sample_count + 1, prev_sample_count + 1);
 }
 
 void AnalogSegment::get_samples(int64_t start_sample, int64_t end_sample,
index df25f0b74a669109663a08e0df4dbeff3b5a7641..846837ce75f47c2df2afedeaae64f9159d3bd53b 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <QObject>
 
+using std::enable_shared_from_this;
 using std::pair;
 
 namespace AnalogSegmentTest {
@@ -38,7 +39,7 @@ namespace data {
 
 class Analog;
 
-class AnalogSegment : public Segment
+class AnalogSegment : public Segment, public enable_shared_from_this<Segment>
 {
        Q_OBJECT
 
index 7aefbf5f20f46af4c38736e2e4888f476396eaf1..038da649896a0f915883403fb420a37d9d36db0d 100644 (file)
@@ -53,6 +53,11 @@ const deque< shared_ptr<LogicSegment> >& Logic::logic_segments() const
        return segments_;
 }
 
+deque< shared_ptr<LogicSegment> >& Logic::logic_segments()
+{
+       return segments_;
+}
+
 vector< shared_ptr<Segment> > Logic::segments() const
 {
        return vector< shared_ptr<Segment> >(segments_.begin(), segments_.end());
@@ -90,7 +95,7 @@ uint64_t Logic::max_sample_count() const
        return l;
 }
 
-void Logic::notify_samples_added(QObject* segment, uint64_t start_sample,
+void Logic::notify_samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
        uint64_t end_sample)
 {
        samples_added(segment, start_sample, end_sample);
index 18622c1e6391f7a4fe39e38a79c4aca2afecddd1..e45ff2f69e99463ac6492f9fdfa997f6a44ca836 100644 (file)
@@ -47,6 +47,7 @@ public:
        void push_segment(shared_ptr<LogicSegment> &segment);
 
        const deque< shared_ptr<LogicSegment> >& logic_segments() const;
+       deque< shared_ptr<LogicSegment> >& logic_segments();
 
        vector< shared_ptr<Segment> > segments() const;
 
@@ -60,13 +61,13 @@ public:
 
        uint64_t max_sample_count() const;
 
-       void notify_samples_added(QObject* segment, uint64_t start_sample,
+       void notify_samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
                uint64_t end_sample);
 
 Q_SIGNALS:
        void samples_cleared();
 
-       void samples_added(QObject* segment, uint64_t start_sample,
+       void samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
                uint64_t end_sample);
 
 private:
index b9e57caa9e797725ed5532e226353cef527b7649..a1832576916ae1dabad15ceb464768cb3521a205 100644 (file)
@@ -341,11 +341,11 @@ void LogicSegment::append_payload(void *data, uint64_t data_size)
        append_payload_to_mipmap();
 
        if (sample_count > 1)
-               owner_.notify_samples_added(this, prev_sample_count + 1,
-                       prev_sample_count + 1 + sample_count);
+               owner_.notify_samples_added(shared_ptr<Segment>(shared_from_this()),
+                       prev_sample_count + 1, prev_sample_count + 1 + sample_count);
        else
-               owner_.notify_samples_added(this, prev_sample_count + 1,
-                       prev_sample_count + 1);
+               owner_.notify_samples_added(shared_ptr<Segment>(shared_from_this()),
+                       prev_sample_count + 1, prev_sample_count + 1);
 }
 
 void LogicSegment::get_samples(int64_t start_sample,
index 67959b31ec17e402bca93466249355fd60cc5ea4..1f151eeb7a71e2e0f5e931f6ec0f3a7a08d7e0b4 100644 (file)
 
 #include "segment.hpp"
 
-#include <utility>
 #include <vector>
 
 #include <QObject>
 
+using std::enable_shared_from_this;
 using std::pair;
 using std::shared_ptr;
 using std::vector;
@@ -48,7 +48,7 @@ namespace data {
 
 class Logic;
 
-class LogicSegment : public Segment
+class LogicSegment : public Segment, public enable_shared_from_this<Segment>
 {
        Q_OBJECT
 
index f5a00c9581530529044cb33d283f52cbb7c1d162..54d236eb05c6abb66636124131891d05f22d258b 100644 (file)
@@ -121,4 +121,6 @@ protected:
 } // namespace data
 } // namespace pv
 
+Q_DECLARE_METATYPE(pv::data::Segment);
+
 #endif // PULSEVIEW_PV_DATA_SEGMENT_HPP
index d09615c8fc1130fb95fbf0f05629c50ec8c918a8..2ca5a835db2d2ffb3cb1836f49bcd5db844f7e74 100644 (file)
@@ -155,8 +155,8 @@ void SignalBase::set_data(shared_ptr<pv::data::SignalData> data)
        if (data_) {
                disconnect(data.get(), SIGNAL(samples_cleared()),
                        this, SLOT(on_samples_cleared()));
-               disconnect(data.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
-                       this, SLOT(on_samples_added(QObject*, uint64_t, uint64_t)));
+               disconnect(data.get(), SIGNAL(samples_added(shared_ptr<Segment>, uint64_t, uint64_t)),
+                       this, SLOT(on_samples_added(shared_ptr<Segment>, uint64_t, uint64_t)));
 
                if (channel_type_ == AnalogChannel) {
                        shared_ptr<Analog> analog = analog_data();
@@ -172,8 +172,8 @@ void SignalBase::set_data(shared_ptr<pv::data::SignalData> data)
        if (data_) {
                connect(data.get(), SIGNAL(samples_cleared()),
                        this, SLOT(on_samples_cleared()));
-               connect(data.get(), SIGNAL(samples_added(QObject*, uint64_t, uint64_t)),
-                       this, SLOT(on_samples_added(QObject*, uint64_t, uint64_t)));
+               connect(data.get(), SIGNAL(samples_added(shared_ptr<Segment>, uint64_t, uint64_t)),
+                       this, SLOT(on_samples_added(shared_ptr<Segment>, uint64_t, uint64_t)));
 
                if (channel_type_ == AnalogChannel) {
                        shared_ptr<Analog> analog = analog_data();
@@ -752,7 +752,7 @@ void SignalBase::on_samples_cleared()
        samples_cleared();
 }
 
-void SignalBase::on_samples_added(QObject* segment, uint64_t start_sample,
+void SignalBase::on_samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
        uint64_t end_sample)
 {
        if (conversion_type_ != NoConversion) {
@@ -766,8 +766,7 @@ void SignalBase::on_samples_added(QObject* segment, uint64_t start_sample,
                }
        }
 
-       data::Segment* s = qobject_cast<data::Segment*>(segment);
-       samples_added(s->segment_id(), start_sample, end_sample);
+       samples_added(segment->segment_id(), start_sample, end_sample);
 }
 
 void SignalBase::on_min_max_changed(float min, float max)
index d6f11d82929ca40584cfbcaa78b5c154d3188bef..733900d56c7caa64c79a32141ea0f68a982d821b 100644 (file)
@@ -55,6 +55,7 @@ class AnalogSegment;
 class DecoderStack;
 class Logic;
 class LogicSegment;
+class Segment;
 class SignalData;
 
 class SignalBase : public QObject
@@ -322,7 +323,7 @@ Q_SIGNALS:
 private Q_SLOTS:
        void on_samples_cleared();
 
-       void on_samples_added(QObject* segment, uint64_t start_sample,
+       void on_samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
                uint64_t end_sample);
 
        void on_min_max_changed(float min, float max);