]> sigrok.org Git - pulseview.git/commitdiff
Update to new session API.
authorMartin Ling <redacted>
Sat, 19 Jul 2014 17:19:47 +0000 (18:19 +0100)
committerMartin Ling <redacted>
Sat, 19 Jul 2014 17:19:47 +0000 (18:19 +0100)
pv/device/device.cpp
pv/device/devinst.cpp
pv/device/devinst.h
pv/device/file.cpp
pv/device/inputfile.cpp
pv/device/sessionfile.cpp
pv/sigsession.cpp
pv/sigsession.h
pv/storesession.cpp
pv/view/logicsignal.cpp

index c6fc5bbe2fa037d0e221cabe3449302d0ccf38b9..40044f8cd9490d8cae5be998f8359881114696e8 100644 (file)
@@ -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);
index 4543e5c81d8dba5cf212918bdb31cfa199e6476d..cb37ceefd51d39b5a5783c4960af9aabbc58f4d0 100644 (file)
@@ -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
index 7f467cf442be629771fa776e327e2b9e9dab9f49..0443d3ea339c6edd36bf70d7cbc8daf903d34721 100644 (file)
@@ -34,9 +34,9 @@ struct sr_dev_inst;
 struct sr_channel;
 struct sr_channel_group;
 
-namespace pv {
+#include <pv/sigsession.h>
 
-class SigSession;
+namespace pv {
 
 namespace device {
 
index e33be854af1922680b8dae89bfe1581caadaace6..0286a2581471225fae43fa0ea4f793b23e1ee1af 100644 (file)
@@ -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;
index 55a0fa566529281f4cd7f4cf19d1c411beba89a1..61aa85a1199ae06b258e7791447a2ccded3d4711 100644 (file)
@@ -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;
 }
 
index 80345799e04d16631d87934ae8a0d3668d7bb4d5..a2810d421913c7017a57a6d839f665d0eac87cc2 100644 (file)
@@ -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;
 }
 
index e42ba2cbdc3f997d73f67e0b855f6affb4f55e0b..d89ca61c0d0d44863e180df07da6ac0802713f1c 100644 (file)
@@ -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<void (const QString)> 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<device::DevInst> dev_inst,
                return;
        }
 
-       set_capture_state(sr_session_trigger_get() ?
+       set_capture_state(sr_session_trigger_get(_sr_session) ?
                AwaitingTrigger : Running);
 
        dev_inst->run();
index 927b2e7c3a5e41800b0669aff04997d267e18b7d..d1f11ea9682767131757758139437468f6752140 100644 (file)
@@ -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
index dede6a064cb8eda309f7384e180059bdb6398fd8..9b8dac9c579783aafada6f25fea13f0db53a19af 100644 (file)
@@ -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<data::LogicSnapshot> 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;
index 5e5cb7db9fcc1753ff7d74c19f581cbd8f8116ff..3a2ec4862dc5d6ae94432e799fcdf8860b5669b8 100644 (file)
@@ -85,7 +85,7 @@ LogicSignal::LogicSignal(shared_ptr<pv::device::DevInst> 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) {