Use shared_ptr for async samples_added() notification
authorSoeren Apel <soeren@apelpie.net>
Thu, 5 Mar 2020 20:54:15 +0000 (21:54 +0100)
committerSoeren Apel <soeren@apelpie.net>
Mon, 11 May 2020 19:24:22 +0000 (21:24 +0200)
main.cpp
pv/data/logic.hpp
pv/data/logicsegment.cpp
pv/data/segment.hpp
pv/data/signalbase.cpp
pv/data/signalbase.hpp

index 793f4ce12d77dd83e6b7f976a1a70de29216caf1..b0e631f6382cbd4697d2171e30ebab8620065989 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -277,7 +277,7 @@ int main(int argc, char *argv[])
 
        qRegisterMetaType<uint64_t>("uint64_t");
        qRegisterMetaType<pv::util::Timestamp>("util::Timestamp");
-       qRegisterMetaType<pv::data::Segment>("data::Segment");
+       qRegisterMetaType<SharedPtrToSegment>("SharedPtrToSegment");
 
        // Prepare the global settings since logging needs them early on
        pv::GlobalSettings settings;
index e45ff2f69e99463ac6492f9fdfa997f6a44ca836..b5e532c45e9a0523d13991f39fb8c653d498eca3 100644 (file)
@@ -21,6 +21,7 @@
 #define PULSEVIEW_PV_DATA_LOGIC_HPP
 
 #include "signaldata.hpp"
+#include "segment.hpp"
 
 #include <deque>
 
@@ -67,7 +68,7 @@ public:
 Q_SIGNALS:
        void samples_cleared();
 
-       void samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
+       void samples_added(SharedPtrToSegment segment, uint64_t start_sample,
                uint64_t end_sample);
 
 private:
index a1832576916ae1dabad15ceb464768cb3521a205..a7df235a32d1c7a613de2824b14ca5ae6edff113 100644 (file)
@@ -341,10 +341,10 @@ void LogicSegment::append_payload(void *data, uint64_t data_size)
        append_payload_to_mipmap();
 
        if (sample_count > 1)
-               owner_.notify_samples_added(shared_ptr<Segment>(shared_from_this()),
+               owner_.notify_samples_added(SharedPtrToSegment(shared_from_this()),
                        prev_sample_count + 1, prev_sample_count + 1 + sample_count);
        else
-               owner_.notify_samples_added(shared_ptr<Segment>(shared_from_this()),
+               owner_.notify_samples_added(SharedPtrToSegment(shared_from_this()),
                        prev_sample_count + 1, prev_sample_count + 1);
 }
 
index 54d236eb05c6abb66636124131891d05f22d258b..8465949c3a13e444846b9596e2aa413592092f5c 100644 (file)
@@ -121,6 +121,8 @@ protected:
 } // namespace data
 } // namespace pv
 
-Q_DECLARE_METATYPE(pv::data::Segment);
+typedef std::shared_ptr<pv::data::Segment> SharedPtrToSegment;
+
+Q_DECLARE_METATYPE(SharedPtrToSegment);
 
 #endif // PULSEVIEW_PV_DATA_SEGMENT_HPP
index 2ca5a835db2d2ffb3cb1836f49bcd5db844f7e74..86ef68566ce118b0b09d0ccdfc94d4f06b35bf87 100644 (file)
@@ -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(shared_ptr<Segment>, uint64_t, uint64_t)),
-                       this, SLOT(on_samples_added(shared_ptr<Segment>, uint64_t, uint64_t)));
+               connect(data.get(), SIGNAL(samples_added(SharedPtrToSegment, uint64_t, uint64_t)),
+                       this, SLOT(on_samples_added(SharedPtrToSegment, 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(shared_ptr<Segment> segment, uint64_t start_sample,
+void SignalBase::on_samples_added(SharedPtrToSegment segment, uint64_t start_sample,
        uint64_t end_sample)
 {
        if (conversion_type_ != NoConversion) {
index 733900d56c7caa64c79a32141ea0f68a982d821b..065dbc99f68801fb36e99df52f19638a59b07720 100644 (file)
@@ -35,6 +35,8 @@
 
 #include <libsigrokcxx/libsigrokcxx.hpp>
 
+#include "segment.hpp"
+
 using std::atomic;
 using std::condition_variable;
 using std::map;
@@ -323,7 +325,7 @@ Q_SIGNALS:
 private Q_SLOTS:
        void on_samples_cleared();
 
-       void on_samples_added(shared_ptr<Segment> segment, uint64_t start_sample,
+       void on_samples_added(SharedPtrToSegment segment, uint64_t start_sample,
                uint64_t end_sample);
 
        void on_min_max_changed(float min, float max);