From: Martin Ling Date: Sat, 19 Jul 2014 17:19:47 +0000 (+0100) Subject: Update to new session API. X-Git-Tag: pulseview-0.3.0~577 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=bb3030b34e44733036acdfe5b4d4ec0705146831;p=pulseview.git Update to new session API. --- diff --git a/pv/device/device.cpp b/pv/device/device.cpp index c6fc5bbe..40044f8c 100644 --- a/pv/device/device.cpp +++ b/pv/device/device.cpp @@ -46,11 +46,11 @@ void Device::use(SigSession *owner) throw(QString) { DevInst::use(owner); - sr_session_new(); + sr_session_new(&SigSession::_sr_session); assert(_sdi); sr_dev_open(_sdi); - if (sr_session_dev_add(_sdi) != SR_OK) + if (sr_session_dev_add(SigSession::_sr_session, _sdi) != SR_OK) throw QString(tr("Failed to use device.")); } @@ -58,7 +58,7 @@ void Device::release() { if (_owner) { DevInst::release(); - sr_session_destroy(); + sr_session_destroy(SigSession::_sr_session); } sr_dev_close(_sdi); diff --git a/pv/device/devinst.cpp b/pv/device/devinst.cpp index 4543e5c8..cb37ceef 100644 --- a/pv/device/devinst.cpp +++ b/pv/device/devinst.cpp @@ -126,13 +126,13 @@ bool DevInst::is_trigger_enabled() const void DevInst::start() { - if (sr_session_start() != SR_OK) + if (sr_session_start(SigSession::_sr_session) != SR_OK) throw tr("Failed to start session."); } void DevInst::run() { - sr_session_run(); + sr_session_run(SigSession::_sr_session); } } // device diff --git a/pv/device/devinst.h b/pv/device/devinst.h index 7f467cf4..0443d3ea 100644 --- a/pv/device/devinst.h +++ b/pv/device/devinst.h @@ -34,9 +34,9 @@ struct sr_dev_inst; struct sr_channel; struct sr_channel_group; -namespace pv { +#include -class SigSession; +namespace pv { namespace device { diff --git a/pv/device/file.cpp b/pv/device/file.cpp index e33be854..0286a258 100644 --- a/pv/device/file.cpp +++ b/pv/device/file.cpp @@ -43,10 +43,10 @@ std::string File::format_device_title() const File* File::create(const string &name) { - if (sr_session_load(name.c_str()) == SR_OK) { + if (sr_session_load(name.c_str(), &SigSession::_sr_session) == SR_OK) { GSList *devlist = NULL; - sr_session_dev_list(&devlist); - sr_session_destroy(); + sr_session_dev_list(SigSession::_sr_session, &devlist); + sr_session_destroy(SigSession::_sr_session); if (devlist) { sr_dev_inst *const sdi = (sr_dev_inst*)devlist->data; diff --git a/pv/device/inputfile.cpp b/pv/device/inputfile.cpp index 55a0fa56..61aa85a1 100644 --- a/pv/device/inputfile.cpp +++ b/pv/device/inputfile.cpp @@ -52,9 +52,9 @@ void InputFile::use(SigSession *owner) throw(QString) _input = load_input_file_format(_path, NULL); File::use(owner); - sr_session_new(); + sr_session_new(&SigSession::_sr_session); - if (sr_session_dev_add(_input->sdi) != SR_OK) + if (sr_session_dev_add(SigSession::_sr_session, _input->sdi) != SR_OK) throw tr("Failed to add session device."); } @@ -66,7 +66,7 @@ void InputFile::release() assert(_input); File::release(); sr_dev_close(_input->sdi); - sr_session_destroy(); + sr_session_destroy(SigSession::_sr_session); _input = NULL; } diff --git a/pv/device/sessionfile.cpp b/pv/device/sessionfile.cpp index 80345799..a2810d42 100644 --- a/pv/device/sessionfile.cpp +++ b/pv/device/sessionfile.cpp @@ -42,11 +42,11 @@ void SessionFile::use(SigSession *owner) throw(QString) { assert(!_sdi); - if (sr_session_load(_path.c_str()) != SR_OK) + if (sr_session_load(_path.c_str(), &SigSession::_sr_session) != SR_OK) throw tr("Failed to open file.\n"); GSList *devlist = NULL; - sr_session_dev_list(&devlist); + sr_session_dev_list(SigSession::_sr_session, &devlist); if (!devlist || !devlist->data) { if (devlist) @@ -69,7 +69,7 @@ void SessionFile::release() File::release(); sr_dev_close(_sdi); sr_dev_clear(_sdi->driver); - sr_session_destroy(); + sr_session_destroy(SigSession::_sr_session); _sdi = NULL; } diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index e42ba2cb..d89ca61c 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -63,6 +63,9 @@ namespace pv { // TODO: This should not be necessary SigSession* SigSession::_session = NULL; +// TODO: This should not be necessary +struct sr_session *SigSession::_sr_session = NULL; + SigSession::SigSession(DeviceManager &device_manager) : _device_manager(device_manager), _capture_state(Stopped) @@ -100,7 +103,7 @@ void SigSession::set_device( stop_capture(); if (_dev_inst) { - sr_session_datafeed_callback_remove_all(); + sr_session_datafeed_callback_remove_all(_sr_session); _dev_inst->release(); } @@ -109,7 +112,7 @@ void SigSession::set_device( if (dev_inst) { dev_inst->use(this); - sr_session_datafeed_callback_add(data_feed_in_proc, NULL); + sr_session_datafeed_callback_add(_sr_session, data_feed_in_proc, NULL); update_signals(dev_inst); } } @@ -194,7 +197,7 @@ void SigSession::start_capture(function error_handler) void SigSession::stop_capture() { if (get_capture_state() != Stopped) - sr_session_stop(); + sr_session_stop(_sr_session); // Check that sampling stopped if (_sampling_thread.joinable()) @@ -444,7 +447,7 @@ void SigSession::sample_thread_proc(shared_ptr dev_inst, return; } - set_capture_state(sr_session_trigger_get() ? + set_capture_state(sr_session_trigger_get(_sr_session) ? AwaitingTrigger : Running); dev_inst->run(); diff --git a/pv/sigsession.h b/pv/sigsession.h index 927b2e7c..d1f11ea9 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -196,6 +196,16 @@ private: // sessions should should be supported and it should be // possible to associate a pointer with a sr_session. static SigSession *_session; + +public: + // TODO: Even more of a hack. The libsigrok API now allows for + // multiple sessions. However sr_session_* calls are scattered + // around the PV architecture and a single SigSession object is + // being used across multiple sequential sessions, which are + // created and destroyed in other classes in pv::device. This + // is a mess. For now just keep a single sr_session pointer here + // which we can use for all those scattered calls. + static struct sr_session *_sr_session; }; } // namespace pv diff --git a/pv/storesession.cpp b/pv/storesession.cpp index dede6a06..9b8dac9c 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -120,7 +120,7 @@ bool StoreSession::start() probes[sigs.size()] = NULL; // Begin storing - if (sr_session_save_init(_file_name.c_str(), + if (sr_session_save_init(SigSession::_sr_session, _file_name.c_str(), data->samplerate(), probes) != SR_OK) { _error = tr("Error while saving."); return false; @@ -179,8 +179,8 @@ void StoreSession::store_proc(shared_ptr snapshot) start_sample + samples_per_block, sample_count); snapshot->get_samples(data, start_sample, end_sample); - if(sr_session_append(_file_name.c_str(), data, unit_size, - end_sample - start_sample) != SR_OK) + if(sr_session_append(SigSession::_sr_session, _file_name.c_str(), data, + unit_size, end_sample - start_sample) != SR_OK) { _error = tr("Error while saving."); break; diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index 5e5cb7db..3a2ec486 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -85,7 +85,7 @@ LogicSignal::LogicSignal(shared_ptr dev_inst, /* Populate this channel's trigger setting with whatever we * find in the current session trigger, if anything. */ _trigger_match = 0; - if ((trigger = sr_session_trigger_get())) { + if ((trigger = sr_session_trigger_get(SigSession::_sr_session))) { for (l = trigger->stages; l && !_trigger_match; l = l->next) { stage = (struct sr_trigger_stage *)l->data; for (m = stage->matches; m && !_trigger_match; m = m->next) {