]> sigrok.org Git - pulseview.git/commitdiff
Made the sdi a persisent property of SigSession
authorJoel Holdsworth <redacted>
Wed, 24 Apr 2013 17:47:42 +0000 (18:47 +0100)
committerJoel Holdsworth <redacted>
Wed, 24 Apr 2013 17:47:42 +0000 (18:47 +0100)
pv/mainwindow.cpp
pv/sigsession.cpp
pv/sigsession.h

index 150c2fccfa348d9ba9aac48f73016abe2b4c5d96..fc5872875ef6ace5f44af61e3f964168d3a7bd64 100644 (file)
@@ -306,9 +306,8 @@ void MainWindow::run_stop()
 {
        switch(_session.get_capture_state()) {
        case SigSession::Stopped:
-               _session.start_capture(
-                       _sampling_bar->get_selected_device(),
-                       _sampling_bar->get_record_length(),
+               _session.set_device(_sampling_bar->get_selected_device());
+               _session.start_capture(_sampling_bar->get_record_length(),
                        boost::bind(&MainWindow::session_error, this,
                                QString("Capture failed"), _1));
                break;
index e22b75a642bfbe635d85f21bcf8275a7073413f8..131f057de5d881e72d442418dff4952ebef74a27 100644 (file)
@@ -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<void (const QString)> 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<void (const QString)> 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));
 }
 
index 8520a1e7fe5acbbdfcafc0645fd5bce94654a24c..fa2c7af413db55b174ad78ffa85593f409e69975 100644 (file)
@@ -62,13 +62,22 @@ public:
 
        ~SigSession();
 
+       /**
+        * Gets device instance that will be used in the next capture session.
+        */
+       struct sr_dev_inst* get_device() const;
+
+       /**
+        * Sets device instance that will be used in the next capture session.
+        */
+       void set_device(struct sr_dev_inst *sdi);
+
        void load_file(const std::string &name,
                boost::function<void (const QString)> error_handler);
 
        capture_state get_capture_state() const;
 
-       void start_capture(struct sr_dev_inst* sdi,
-               uint64_t record_length,
+       void start_capture(uint64_t record_length,
                boost::function<void (const QString)> error_handler);
 
        void stop_capture();
@@ -105,6 +114,12 @@ private:
                const struct sr_datafeed_packet *packet, void *cb_data);
 
 private:
+
+       /**
+        * The device instance that will be used in the next capture session.
+        */
+       struct sr_dev_inst *_sdi;
+
        mutable boost::mutex _sampling_mutex;
        capture_state _capture_state;