From 1f4caa772cd691da7578816bf3744496c9cde1cf Mon Sep 17 00:00:00 2001 From: Joel Holdsworth Date: Thu, 13 Nov 2014 12:44:42 +0000 Subject: [PATCH 1/1] SigSession: Made _sr_session non-static --- pv/sigsession.cpp | 39 +++++++++++++++++++-------------------- pv/sigsession.h | 11 +++-------- pv/storesession.cpp | 6 +++--- pv/view/logicsignal.cpp | 2 +- 4 files changed, 26 insertions(+), 32 deletions(-) diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index ce748294..5a794417 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -78,17 +78,11 @@ using Glib::VariantBase; using Glib::Variant; namespace pv { - -// TODO: This should not be necessary -shared_ptr SigSession::_sr_session = nullptr; - SigSession::SigSession(DeviceManager &device_manager) : _device_manager(device_manager), + _session(device_manager.context()->create_session()), _capture_state(Stopped) { - // TODO: This should not be necessary - _sr_session = device_manager.context()->create_session(); - set_default_device(); } @@ -98,6 +92,11 @@ SigSession::~SigSession() stop_capture(); } +const shared_ptr& SigSession::session() const +{ + return _session; +} + shared_ptr SigSession::device() const { return _device; @@ -114,15 +113,15 @@ void SigSession::set_device(shared_ptr device) auto prev_session_device = dynamic_pointer_cast(_device); if (_device) { - _sr_session->remove_datafeed_callbacks(); + _session->remove_datafeed_callbacks(); if (!prev_session_device) { _device->close(); - _sr_session->remove_devices(); + _session->remove_devices(); } } if (session_device) - _sr_session = session_device->parent(); + _session = session_device->parent(); _device = device; _decode_traces.clear(); @@ -130,11 +129,11 @@ void SigSession::set_device(shared_ptr device) if (device) { if (!session_device) { - _sr_session = _device_manager.context()->create_session(); + _session = _device_manager.context()->create_session(); device->open(); - _sr_session->add_device(device); + _session->add_device(device); } - _sr_session->add_datafeed_callback([=] + _session->add_datafeed_callback([=] (shared_ptr device, shared_ptr packet) { data_feed_in(device, packet); }); @@ -144,10 +143,10 @@ void SigSession::set_device(shared_ptr device) void SigSession::set_file(const string &name) { - _sr_session = _device_manager.context()->load_session(name); - _device = _sr_session->devices()[0]; + _session = _device_manager.context()->load_session(name); + _device = _session->devices()[0]; _decode_traces.clear(); - _sr_session->add_datafeed_callback([=] + _session->add_datafeed_callback([=] (shared_ptr device, shared_ptr packet) { data_feed_in(device, packet); }); @@ -211,7 +210,7 @@ void SigSession::start_capture(function error_handler) void SigSession::stop_capture() { if (get_capture_state() != Stopped) - _sr_session->stop(); + _session->stop(); // Check that sampling stopped if (_sampling_thread.joinable()) @@ -421,16 +420,16 @@ void SigSession::sample_thread_proc(shared_ptr device, read_sample_rate(device); try { - _sr_session->start(); + _session->start(); } catch(Error e) { error_handler(e.what()); return; } - set_capture_state(_sr_session->trigger() ? + set_capture_state(_session->trigger() ? AwaitingTrigger : Running); - _sr_session->run(); + _session->run(); set_capture_state(Stopped); // Confirm that SR_DF_END was received diff --git a/pv/sigsession.h b/pv/sigsession.h index 55da3735..cea426a0 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -79,6 +79,8 @@ public: ~SigSession(); + const std::shared_ptr& session() const; + std::shared_ptr device() const; /** @@ -140,6 +142,7 @@ private: private: DeviceManager &_device_manager; + std::shared_ptr _session; /** * The device instance that will be used in the next capture session. @@ -172,14 +175,6 @@ Q_SIGNALS: void data_received(); void frame_ended(); - -public: - // Hack. The libsigrok API now allows for multiple sessions. However, - // sigrok::Session calls are scattered around the PV architecture and a - // single SigSession object is being used across multiple sequential - // sessions. This is a mess. For now just keep a single sigrok::Session - // pointer here which we can use for all those scattered calls. - static std::shared_ptr _sr_session; }; } // namespace pv diff --git a/pv/storesession.cpp b/pv/storesession.cpp index 484f1ff6..4de9d56d 100644 --- a/pv/storesession.cpp +++ b/pv/storesession.cpp @@ -116,9 +116,9 @@ bool StoreSession::start() // Begin storing try { - auto context = _session._sr_session->context(); + auto context = _session.session()->context(); auto output_format = context->output_formats()["srzip"]; - auto device = _session.get_device(); + auto device = _session.device(); _output = output_format->create_output(device, {{"filename", Glib::Variant::create(_file_name)}}); @@ -182,7 +182,7 @@ void StoreSession::store_proc(shared_ptr snapshot) size_t length = end_sample - start_sample; try { - auto context = _session._sr_session->context(); + auto context = _session.session()->context(); auto logic = context->create_logic_packet(data, length, unit_size); _output->receive(logic); } catch (Error error) { diff --git a/pv/view/logicsignal.cpp b/pv/view/logicsignal.cpp index e214ec78..6fda499b 100644 --- a/pv/view/logicsignal.cpp +++ b/pv/view/logicsignal.cpp @@ -94,7 +94,7 @@ LogicSignal::LogicSignal( /* Populate this channel's trigger setting with whatever we * find in the current session trigger, if anything. */ _trigger_match = nullptr; - if ((trigger = SigSession::_sr_session->trigger())) + if ((trigger = _session.session()->trigger())) for (auto stage : trigger->stages()) for (auto match : stage->matches()) if (match->channel() == _channel) -- 2.30.2