]> sigrok.org Git - pulseview.git/commitdiff
SigSession: Made _sr_session non-static
authorJoel Holdsworth <redacted>
Thu, 13 Nov 2014 12:44:42 +0000 (12:44 +0000)
committerUwe Hermann <redacted>
Thu, 13 Nov 2014 18:34:39 +0000 (19:34 +0100)
pv/sigsession.cpp
pv/sigsession.h
pv/storesession.cpp
pv/view/logicsignal.cpp

index ce74829401486f0c6597486398f1cf68e9c78dd3..5a794417f2112754f6cf0cc566202b452b49c5d8 100644 (file)
@@ -78,17 +78,11 @@ using Glib::VariantBase;
 using Glib::Variant;
 
 namespace pv {
-
-// TODO: This should not be necessary
-shared_ptr<Session> 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<sigrok::Session>& SigSession::session() const
+{
+       return _session;
+}
+
 shared_ptr<Device> SigSession::device() const
 {
        return _device;
@@ -114,15 +113,15 @@ void SigSession::set_device(shared_ptr<Device> device)
        auto prev_session_device = dynamic_pointer_cast<SessionDevice>(_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> 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> device, shared_ptr<Packet> packet) {
                                data_feed_in(device, packet);
                        });
@@ -144,10 +143,10 @@ void SigSession::set_device(shared_ptr<Device> 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> device, shared_ptr<Packet> packet) {
                        data_feed_in(device, packet);
                });
@@ -211,7 +210,7 @@ void SigSession::start_capture(function<void (const QString)> 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> 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
index 55da3735cbdb574df7576aaaf9d7f1691eb0313c..cea426a0d2eb12833a1a9b1f705188cee91c95dc 100644 (file)
@@ -79,6 +79,8 @@ public:
 
        ~SigSession();
 
+       const std::shared_ptr<sigrok::Session>& session() const;
+
        std::shared_ptr<sigrok::Device> device() const;
 
        /**
@@ -140,6 +142,7 @@ private:
 
 private:
        DeviceManager &_device_manager;
+       std::shared_ptr<sigrok::Session> _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<sigrok::Session> _sr_session;
 };
 
 } // namespace pv
index 484f1ff60f2547cad7924f10c9e1dd202958e7a4..4de9d56dde2cc676899404a27040ab6ec88f0967 100644 (file)
@@ -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<Glib::ustring>::create(_file_name)}});
@@ -182,7 +182,7 @@ void StoreSession::store_proc(shared_ptr<data::LogicSnapshot> 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) {
index e214ec78426c505d621808fb38e9e5f34dc65462..6fda499b47d1ac551431f41c48c67e983bf754c0 100644 (file)
@@ -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)