]> sigrok.org Git - pulseview.git/blobdiff - pv/sigsession.cpp
Moved SigSession::is_trigger_enabled into DevInst
[pulseview.git] / pv / sigsession.cpp
index a2f44dab1aaf01a462ef8383f83759f5b8147925..9af7df74e7a5f967023a20a62c4f6e68ed3d8c16 100644 (file)
@@ -25,7 +25,7 @@
 #include "sigsession.h"
 
 #include "devicemanager.h"
-#include "devinst.h"
+#include "device/device.h"
 
 #include "data/analog.h"
 #include "data/analogsnapshot.h"
@@ -73,41 +73,48 @@ SigSession::SigSession(DeviceManager &device_manager) :
 
 SigSession::~SigSession()
 {
+       using pv::device::Device;
+
        stop_capture();
 
-       _sampling_thread.join();
+       if (_sampling_thread.joinable())
+               _sampling_thread.join();
 
-       if (_dev_inst)
-               _device_manager.release_device(_dev_inst);
+       _dev_inst->release();
 
        // TODO: This should not be necessary
        _session = NULL;
 }
 
-shared_ptr<DevInst> SigSession::get_device() const
+shared_ptr<device::DevInst> SigSession::get_device() const
 {
        return _dev_inst;
 }
 
-void SigSession::set_device(shared_ptr<DevInst> dev_inst)
+void SigSession::set_device(shared_ptr<device::DevInst> dev_inst)
 {
+       using pv::device::Device;
+
        // Ensure we are not capturing before setting the device
        stop_capture();
 
        if (_dev_inst)
-               _device_manager.release_device(_dev_inst);
+               _dev_inst->release();
+
        if (dev_inst)
-               _device_manager.use_device(dev_inst, this);
+               dev_inst->use(this);
+
        _dev_inst = dev_inst;
        update_signals(dev_inst);
 }
 
-void SigSession::release_device(shared_ptr<DevInst> dev_inst)
+void SigSession::release_device(device::DevInst *dev_inst)
 {
        (void)dev_inst;
+       assert(_dev_inst.get() == dev_inst);
 
        assert(_capture_state == Stopped);
-       _dev_inst = shared_ptr<DevInst>();
+       _dev_inst = shared_ptr<device::DevInst>();
 }
 
 void SigSession::load_file(const string &name,
@@ -125,8 +132,8 @@ void SigSession::load_file(const string &name,
                        return;
                }
 
-               shared_ptr<DevInst> dev_inst(
-                       new DevInst((sr_dev_inst*)devlist->data));
+               shared_ptr<device::DevInst> dev_inst(
+                       new device::Device((sr_dev_inst*)devlist->data));
                g_slist_free(devlist);
 
                _decode_traces.clear();
@@ -145,7 +152,8 @@ void SigSession::load_file(const string &name,
                        return;
 
                _decode_traces.clear();
-               update_signals(shared_ptr<DevInst>(new DevInst(in->sdi)));
+               update_signals(shared_ptr<device::DevInst>(
+                       new device::Device(in->sdi)));
                read_sample_rate(in->sdi);
 
                _sampling_thread = boost::thread(
@@ -200,7 +208,8 @@ void SigSession::stop_capture()
        sr_session_stop();
 
        // Check that sampling stopped
-       _sampling_thread.join();
+       if (_sampling_thread.joinable())
+               _sampling_thread.join();
 }
 
 set< shared_ptr<data::SignalData> > SigSession::get_data() const
@@ -384,7 +393,7 @@ sr_input* SigSession::load_input_file_format(const string &filename,
        return in;
 }
 
-void SigSession::update_signals(shared_ptr<DevInst> dev_inst)
+void SigSession::update_signals(shared_ptr<device::DevInst> dev_inst)
 {
        assert(dev_inst);
        assert(_capture_state == Stopped);
@@ -442,7 +451,7 @@ void SigSession::update_signals(shared_ptr<DevInst> dev_inst)
                        switch(probe->type) {
                        case SR_PROBE_LOGIC:
                                signal = shared_ptr<view::Signal>(
-                                       new view::LogicSignal(*this, dev_inst,
+                                       new view::LogicSignal(dev_inst,
                                                probe, _logic_data));
                                break;
 
@@ -451,7 +460,7 @@ void SigSession::update_signals(shared_ptr<DevInst> dev_inst)
                                shared_ptr<data::Analog> data(
                                        new data::Analog());
                                signal = shared_ptr<view::Signal>(
-                                       new view::AnalogSignal(*this, dev_inst,
+                                       new view::AnalogSignal(dev_inst,
                                                probe, data));
                                break;
                        }
@@ -470,20 +479,6 @@ void SigSession::update_signals(shared_ptr<DevInst> dev_inst)
        signals_changed();
 }
 
-bool SigSession::is_trigger_enabled() const
-{
-       assert(_dev_inst);
-       assert(_dev_inst->dev_inst());
-       for (const GSList *l = _dev_inst->dev_inst()->probes; l; l = l->next) {
-               const sr_probe *const p = (const sr_probe *)l->data;
-               assert(p);
-               if (p->trigger && p->trigger[0] != '\0')
-                       return true;
-       }
-
-       return false;
-}
-
 shared_ptr<view::Signal> SigSession::signal_from_probe(
        const sr_probe *probe) const
 {
@@ -566,7 +561,7 @@ void SigSession::load_input_thread_proc(const string name,
        delete in;
 }
 
-void SigSession::sample_thread_proc(shared_ptr<DevInst> dev_inst,
+void SigSession::sample_thread_proc(shared_ptr<device::DevInst> dev_inst,
        function<void (const QString)> error_handler)
 {
        assert(dev_inst);
@@ -587,7 +582,8 @@ void SigSession::sample_thread_proc(shared_ptr<DevInst> dev_inst,
                return;
        }
 
-       set_capture_state(is_trigger_enabled() ? AwaitingTrigger : Running);
+       set_capture_state(dev_inst->is_trigger_enabled() ?
+               AwaitingTrigger : Running);
 
        sr_session_run();
        sr_session_destroy();
@@ -645,7 +641,7 @@ void SigSession::feed_in_logic(const sr_datafeed_logic &logic)
 
                // Create a new data snapshot
                _cur_logic_snapshot = shared_ptr<data::LogicSnapshot>(
-                       new data::LogicSnapshot(logic));
+                       new data::LogicSnapshot(logic, _dev_inst->get_sample_limit()));
                _logic_data->push_snapshot(_cur_logic_snapshot);
        }
        else
@@ -687,7 +683,7 @@ void SigSession::feed_in_analog(const sr_datafeed_analog &analog)
 
                        // Create a snapshot, keep it in the maps of probes
                        snapshot = shared_ptr<data::AnalogSnapshot>(
-                               new data::AnalogSnapshot());
+                               new data::AnalogSnapshot(_dev_inst->get_sample_limit()));
                        _cur_analog_snapshots[probe] = snapshot;
 
                        // Find the annalog data associated with the probe