X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fsigsession.cpp;h=131f057de5d881e72d442418dff4952ebef74a27;hb=d64d159628c795e1413127aafd83ec1bc9ace91c;hp=55b33087a3dbd5b2533df32001efe8836b934974;hpb=568b90d4fcfb5f67f5fb642a9f0fdb3a54607bf3;p=pulseview.git diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 55b3308..131f057 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,16 @@ SigSession::~SigSession() _session = NULL; } +struct sr_dev_inst* SigSession::get_device() const +{ + return _sdi; +} + +void SigSession::set_device(struct sr_dev_inst *sdi) +{ + _sdi = sdi; +} + void SigSession::load_file(const string &name, function error_handler) { @@ -73,15 +84,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 +111,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)); } @@ -138,7 +154,7 @@ void SigSession::load_thread_proc(const string name, return; } - sr_session_datafeed_callback_add(data_feed_in_proc); + sr_session_datafeed_callback_add(data_feed_in_proc, NULL); if (sr_session_start() != SR_OK) { error_handler(tr("Failed to start session.")); @@ -148,7 +164,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); } @@ -161,7 +177,7 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, assert(error_handler); sr_session_new(); - sr_session_datafeed_callback_add(data_feed_in_proc); + sr_session_datafeed_callback_add(data_feed_in_proc, NULL); if (sr_session_dev_add(sdi) != SR_OK) { error_handler(tr("Failed to use device.")); @@ -171,7 +187,7 @@ 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) { + g_variant_new_uint64(record_length)) != SR_OK) { error_handler(tr("Failed to configure " "time-based sample limit.")); sr_session_destroy(); @@ -194,7 +210,8 @@ 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; + GVariant *gvar; + uint64_t sample_rate = 0; unsigned int logic_probe_count = 0; unsigned int analog_probe_count = 0; @@ -219,8 +236,14 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) assert(sdi->driver); const int ret = sr_config_get(sdi->driver, SR_CONF_SAMPLERATE, - (const void**)&sample_rate, sdi); - assert(ret == SR_OK); + &gvar, sdi); + if (ret != SR_OK) { + qDebug("Failed to get samplerate\n"); + return; + } + + sample_rate = g_variant_get_uint64(gvar); + g_variant_unref(gvar); // Create data containers for the coming data snapshots { @@ -228,12 +251,12 @@ void SigSession::feed_in_header(const sr_dev_inst *sdi) 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); } } @@ -384,8 +407,9 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, } void SigSession::data_feed_in_proc(const struct sr_dev_inst *sdi, - const struct sr_datafeed_packet *packet) + const struct sr_datafeed_packet *packet, void *cb_data) { + (void) cb_data; assert(_session); _session->data_feed_in(sdi, packet); }