]> sigrok.org Git - pulseview.git/commitdiff
Added proof of concept start/stop support
authorJoel Holdsworth <redacted>
Sun, 2 Dec 2012 16:25:13 +0000 (16:25 +0000)
committerJoel Holdsworth <redacted>
Tue, 11 Dec 2012 20:05:19 +0000 (20:05 +0000)
pv/mainwindow.cpp
pv/sigsession.cpp
pv/sigsession.h

index c8c091d8938d5c863bd9cd1508df20f557ed146f..f1493667b766787100f9e8e07a3b9f1107fcb613 100644 (file)
@@ -184,10 +184,18 @@ void MainWindow::on_actionAbout_triggered()
 
 void MainWindow::run_stop()
 {
-       _session.start_capture(
-               _sampling_bar->get_selected_device(),
-               _sampling_bar->get_record_length(),
-               _sampling_bar->get_sample_rate());
+       switch(_session.get_capture_state()) {
+       case SigSession::Stopped:
+               _session.start_capture(
+                       _sampling_bar->get_selected_device(),
+                       _sampling_bar->get_record_length(),
+                       _sampling_bar->get_sample_rate());
+               break;
+
+       case SigSession::Running:
+               _session.stop_capture();
+               break;
+       }
 }
 
 } // namespace pv
index abe9b2dae0f7176f33c3d95726f6a5554f1a03de..580b6796c680f8a76c679dfad20d7ea11640aaa4 100644 (file)
@@ -36,7 +36,8 @@ namespace pv {
 // TODO: This should not be necessary
 SigSession* SigSession::_session = NULL;
 
-SigSession::SigSession()
+SigSession::SigSession() :
+       _capture_state(Stopped)
 {
        // TODO: This should not be necessary
        _session = this;
@@ -44,6 +45,8 @@ SigSession::SigSession()
 
 SigSession::~SigSession()
 {
+       stop_capture();
+
        if(_sampling_thread.get())
                _sampling_thread->join();
        _sampling_thread.reset();
@@ -63,18 +66,38 @@ void SigSession::load_file(const std::string &name)
        }
 }
 
+SigSession::capture_state SigSession::get_capture_state() const
+{
+       lock_guard<mutex> lock(_state_mutex);
+       return _capture_state;
+}
+
 void SigSession::start_capture(struct sr_dev_inst *sdi,
        uint64_t record_length, uint64_t sample_rate)
 {
-       // Check sampling isn't already active
-       if(_sampling_thread.get())
-               _sampling_thread->join();
+       stop_capture();
+
 
        _sampling_thread.reset(new boost::thread(
                &SigSession::sample_thread_proc, this, sdi,
                record_length, sample_rate));
 }
 
+void SigSession::stop_capture()
+{
+       if(get_capture_state() == Stopped)
+               return;
+
+       sr_session_stop();
+
+       // Check that sampling stopped
+       if(_sampling_thread.get())
+               _sampling_thread->join();
+       _sampling_thread.reset();
+
+       _capture_state = Stopped;
+}
+
 vector< shared_ptr<view::Signal> > SigSession::get_signals()
 {
        lock_guard<mutex> lock(_signals_mutex);
@@ -117,6 +140,11 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi,
                return;
        }
 
+       {
+               lock_guard<mutex> lock(_state_mutex);
+               _capture_state = Running;
+       }
+
        sr_session_run();
        sr_session_destroy();
 }
index 307330ecb3e40065cc26b5dd8a05b6617b71ace3..8da89d09b3fd6d0cde07fea0fde589d90e779902 100644 (file)
@@ -47,6 +47,12 @@ class SigSession : public QObject
 {
        Q_OBJECT
 
+public:
+       enum capture_state {
+               Stopped,
+               Running
+       };
+
 public:
        SigSession();
 
@@ -54,9 +60,13 @@ public:
 
        void load_file(const std::string &name);
 
+       capture_state get_capture_state() const;
+
        void start_capture(struct sr_dev_inst* sdi, uint64_t record_length,
                uint64_t sample_rate);
 
+       void stop_capture();
+
        std::vector< boost::shared_ptr<view::Signal> >
                get_signals();
 
@@ -73,6 +83,9 @@ private:
                struct sr_datafeed_packet *packet);
 
 private:
+       mutable boost::mutex _state_mutex;
+       capture_state _capture_state;
+
        mutable boost::mutex _signals_mutex;
        std::vector< boost::shared_ptr<view::Signal> > _signals;