X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fsigsession.cpp;h=c5a7d494ecf8ed55237b4c440bd3f4497e72c398;hb=884971565598bdd7641f64d9e76dba2cc9b16c01;hp=9c03b882ffc9c02cc174be25d3c2f22218a9003c;hpb=5045f16d20921a6befc0c367a77a1cb838d9278e;p=pulseview.git diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 9c03b88..c5a7d49 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -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 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 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)); } @@ -148,7 +163,7 @@ void SigSession::load_thread_proc(const string name, set_capture_state(Running); sr_session_run(); - sr_session_stop(); + sr_session_destroy(); set_capture_state(Stopped); } @@ -221,7 +236,11 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) const int ret = sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, &gvar, sdi); - assert(ret == SR_OK); + if (ret != SR_OK) { + qDebug("Failed to get samplerate\n"); + return; + } + sample_rate = g_variant_get_uint64(gvar); g_variant_unref(gvar);