Added assertions to confirm that the session was terminated cleanly
[pulseview.git] / pv / sigsession.cpp
index e22b75a642bfbe635d85f21bcf8275a7073413f8..4fe51dd57131682ae11c31f45eb85f6aee4de461 100644 (file)
@@ -40,6 +40,7 @@ namespace pv {
 SigSession* SigSession::_session = NULL;
 
 SigSession::SigSession() :
+       _sdi(NULL),
        _capture_state(Stopped)
 {
        // TODO: This should not be necessary
@@ -58,6 +59,15 @@ SigSession::~SigSession()
        _session = NULL;
 }
 
+void SigSession::set_device(struct sr_dev_inst *sdi)
+{
+       if (_sdi)
+               sr_dev_close(_sdi);
+       if (sdi)
+               sr_dev_open(sdi);
+       _sdi = sdi;
+}
+
 void SigSession::load_file(const string &name,
        function<void (const QString)> error_handler)
 {
@@ -73,15 +83,20 @@ SigSession::capture_state SigSession::get_capture_state() const
        return _capture_state;
 }
 
-void SigSession::start_capture(struct sr_dev_inst *sdi,
-       uint64_t record_length,
+void SigSession::start_capture(uint64_t record_length,
        function<void (const QString)> error_handler)
 {
        stop_capture();
 
+       // Check that a device instance has been selected.
+       if (!_sdi) {
+               qDebug() << "No device selected";
+               return;
+       }
+
        // Check that at least one probe is enabled
        const GSList *l;
-       for (l = sdi->probes; l; l = l->next) {
+       for (l = _sdi->probes; l; l = l->next) {
                sr_probe *const probe = (sr_probe*)l->data;
                assert(probe);
                if (probe->enabled)
@@ -95,7 +110,7 @@ void SigSession::start_capture(struct sr_dev_inst *sdi,
 
        // Begin the session
        _sampling_thread.reset(new boost::thread(
-               &SigSession::sample_thread_proc, this, sdi,
+               &SigSession::sample_thread_proc, this, _sdi,
                record_length, error_handler));
 }
 
@@ -151,6 +166,10 @@ void SigSession::load_thread_proc(const string name,
        sr_session_destroy();
 
        set_capture_state(Stopped);
+
+       // Confirm that SR_DF_END was received
+       assert(!_cur_logic_snapshot);
+       assert(!_cur_analog_snapshot);
 }
 
 void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
@@ -189,6 +208,10 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
        sr_session_destroy();
 
        set_capture_state(Stopped);
+
+       // Confirm that SR_DF_END was received
+       assert(!_cur_logic_snapshot);
+       assert(!_cur_analog_snapshot);
 }
 
 void SigSession::feed_in_header(const sr_dev_inst *sdi)