X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fsigsession.cpp;h=e4a58a6190af8bc023c31297751cfd7ccf430596;hb=7d29656f1e4de945eee3a9ea5dbc0ef88c4a7e30;hp=63a683df8eb7a5310907b95154891728a42481f4;hpb=3868e5fa3081573891ff2ae5b9dd67eb4a6afa4b;p=pulseview.git diff --git a/pv/sigsession.cpp b/pv/sigsession.cpp index 63a683d..e4a58a6 100644 --- a/pv/sigsession.cpp +++ b/pv/sigsession.cpp @@ -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,36 @@ void SigSession::load_file(const std::string &name) } } +SigSession::capture_state SigSession::get_capture_state() const +{ + lock_guard 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(); +} + vector< shared_ptr > SigSession::get_signals() { lock_guard lock(_signals_mutex); @@ -86,6 +107,13 @@ boost::shared_ptr SigSession::get_data() return _logic_data; } +void SigSession::set_capture_state(capture_state state) +{ + lock_guard lock(_state_mutex); + _capture_state = state; + capture_state_changed(state); +} + void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, uint64_t record_length, uint64_t sample_rate) { @@ -117,8 +145,12 @@ void SigSession::sample_thread_proc(struct sr_dev_inst *sdi, return; } + set_capture_state(Running); + sr_session_run(); sr_session_destroy(); + + set_capture_state(Stopped); } void SigSession::data_feed_in(const struct sr_dev_inst *sdi, @@ -196,6 +228,7 @@ void SigSession::data_feed_in(const struct sr_dev_inst *sdi, *(sr_datafeed_logic*)packet->payload); } + data_updated(); break; }