From: Joel Holdsworth Date: Wed, 24 Apr 2013 17:47:42 +0000 (+0100) Subject: Made the sdi a persisent property of SigSession X-Git-Tag: pulseview-0.1.0~20 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d64d159628c795e1413127aafd83ec1bc9ace91c;p=pulseview.git Made the sdi a persisent property of SigSession --- diff --git a/pv/mainwindow.cpp b/pv/mainwindow.cpp index 150c2fcc..fc587287 100644 --- a/pv/mainwindow.cpp +++ b/pv/mainwindow.cpp @@ -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; diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index e22b75a6..131f057d 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -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 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 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)); } diff --git a/pv/sigsession.h b/pv/sigsession.h index 8520a1e7..fa2c7af4 100644 --- a/pv/sigsession.h +++ b/pv/sigsession.h @@ -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 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 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;