X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsigsession.cpp;h=8ab7dab845708a1cc1c818e549096a1807b647b3;hp=5b9630631a1fe9c1e104e9f8437745c49d2c61ba;hb=f2edb55712e1f295935582558f694077da8d81e6;hpb=eec446e1588c41eb14de5e21a8383d10653c15bd diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 5b963063..8ab7dab8 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -27,8 +27,6 @@ #include "view/analogsignal.h" #include "view/logicsignal.h" -#include - #include using namespace boost; @@ -58,11 +56,13 @@ SigSession::~SigSession() _session = NULL; } -void SigSession::load_file(const string &name) +void SigSession::load_file(const string &name, + function error_handler) { stop_capture(); _sampling_thread.reset(new boost::thread( - &SigSession::load_thread_proc, this, name)); + &SigSession::load_thread_proc, this, name, + error_handler)); } SigSession::capture_state SigSession::get_capture_state() const @@ -72,16 +72,14 @@ SigSession::capture_state SigSession::get_capture_state() const } void SigSession::start_capture(struct sr_dev_inst *sdi, - uint64_t record_length, uint64_t sample_rate) + uint64_t record_length, + function error_handler) { stop_capture(); - lock_guard lock(_sampling_mutex); - _sample_rate = sample_rate; - _sampling_thread.reset(new boost::thread( &SigSession::sample_thread_proc, this, sdi, - record_length)); + record_length, error_handler)); } void SigSession::stop_capture() @@ -115,17 +113,18 @@ void SigSession::set_capture_state(capture_state state) capture_state_changed(state); } -void SigSession::load_thread_proc(const string name) +void SigSession::load_thread_proc(const string name, + function error_handler) { if (sr_session_load(name.c_str()) != SR_OK) { - qDebug() << "Failed to load file."; + error_handler(tr("Failed to load file.")); return; } sr_session_datafeed_callback_add(data_feed_in_proc); if (sr_session_start() != SR_OK) { - qDebug() << "Failed to start session."; + error_handler(tr("Failed to start session.")); return; } @@ -138,15 +137,17 @@ void SigSession::load_thread_proc(const string name) } void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, - uint64_t record_length) + uint64_t record_length, + function error_handler) { assert(sdi); + assert(error_handler); sr_session_new(); sr_session_datafeed_callback_add(data_feed_in_proc); if (sr_session_dev_add(sdi) != SR_OK) { - qDebug() << "Failed to use device."; + error_handler(tr("Failed to use device.")); sr_session_destroy(); return; } @@ -154,24 +155,14 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, // Set the sample limit if (sr_config_set(sdi, SR_CONF_LIMIT_SAMPLES, &record_length) != SR_OK) { - qDebug() << "Failed to configure time-based sample limit."; + error_handler(tr("Failed to configure " + "time-based sample limit.")); sr_session_destroy(); return; } - // Set the samplerate - { - lock_guard lock(_sampling_mutex); - if (sr_config_set(sdi, SR_CONF_SAMPLERATE, - &_sample_rate) != SR_OK) { - qDebug() << "Failed to configure samplerate."; - sr_session_destroy(); - return; - } - } - if (sr_session_start() != SR_OK) { - qDebug() << "Failed to start session."; + error_handler(tr("Failed to start session.")); return; } @@ -186,6 +177,7 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, void SigSession::feed_in_header(const sr_dev_inst *sdi) { shared_ptr signal; + uint64_t *sample_rate = NULL; unsigned int logic_probe_count = 0; unsigned int analog_probe_count = 0; @@ -206,19 +198,25 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) } } + // Read out the sample rate + assert(sdi->driver); + + const int ret = sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, + (const void**)&sample_rate, sdi); + assert(ret == SR_OK); + // Create data containers for the coming data snapshots { lock_guard data_lock(_data_mutex); - lock_guard sampling_lock(_sampling_mutex); if (logic_probe_count != 0) { _logic_data.reset(new data::Logic( - logic_probe_count, _sample_rate)); + logic_probe_count, *sample_rate)); assert(_logic_data); } if (analog_probe_count != 0) { - _analog_data.reset(new data::Analog(_sample_rate)); + _analog_data.reset(new data::Analog(*sample_rate)); assert(_analog_data); } } @@ -260,6 +258,8 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) void SigSession::feed_in_meta(const sr_dev_inst *sdi, const sr_datafeed_meta &meta) { + (void)sdi; + for (const GSList *l = meta.config; l; l = l->next) { const sr_config *const src = (const sr_config*)l->data; switch (src->key) {