X-Git-Url: http://git.code-monkey.de/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=e84f78042b89593e9cb96adef18ed187067e5b11;hp=ef2f39bb8ed3ddb88ded541959042ad531a5096a;hb=6f925ba9d6faf1077b73c5a5808259576081716a;hpb=067bb62415847791709f4c3cad8bb252a63f45f8 diff --git a/pv/session.cpp b/pv/session.cpp index ef2f39b..e84f780 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -66,17 +66,23 @@ using boost::shared_lock; using boost::shared_mutex; using boost::unique_lock; +using std::bad_alloc; using std::dynamic_pointer_cast; +using std::find_if; using std::function; using std::lock_guard; using std::list; +using std::make_pair; +using std::make_shared; using std::map; +using std::max; +using std::move; using std::mutex; using std::pair; using std::recursive_mutex; +using std::runtime_error; using std::set; using std::shared_ptr; -using std::make_shared; using std::string; using std::unordered_set; using std::vector; @@ -154,17 +160,17 @@ void Session::set_name(QString name) name_changed(); } -const std::list< std::shared_ptr > Session::views() const +const list< shared_ptr > Session::views() const { return views_; } -std::shared_ptr Session::main_view() const +shared_ptr Session::main_view() const { return main_view_; } -void Session::set_main_bar(std::shared_ptr main_bar) +void Session::set_main_bar(shared_ptr main_bar) { main_bar_ = main_bar; } @@ -193,11 +199,11 @@ void Session::save_settings(QSettings &settings) const settings.setValue("device_type", "hardware"); settings.beginGroup("device"); - key_list.push_back("vendor"); - key_list.push_back("model"); - key_list.push_back("version"); - key_list.push_back("serial_num"); - key_list.push_back("connection_id"); + key_list.emplace_back("vendor"); + key_list.emplace_back("model"); + key_list.emplace_back("version"); + key_list.emplace_back("serial_num"); + key_list.emplace_back("connection_id"); dev_info = device_manager_.get_device_info(device_); @@ -229,7 +235,7 @@ void Session::save_settings(QSettings &settings) const if (base->is_decode_signal()) { shared_ptr decoder_stack = base->decoder_stack(); - std::shared_ptr top_decoder = + shared_ptr top_decoder = decoder_stack->stack().front(); settings.beginGroup("decoder_stack" + QString::number(stacks++)); @@ -277,11 +283,11 @@ void Session::restore_settings(QSettings &settings) // Re-select last used device if possible but only if it's not demo settings.beginGroup("device"); - key_list.push_back("vendor"); - key_list.push_back("model"); - key_list.push_back("version"); - key_list.push_back("serial_num"); - key_list.push_back("connection_id"); + key_list.emplace_back("vendor"); + key_list.emplace_back("model"); + key_list.emplace_back("version"); + key_list.emplace_back("serial_num"); + key_list.emplace_back("connection_id"); for (string key : key_list) { const QString k = QString::fromStdString(key); @@ -290,7 +296,7 @@ void Session::restore_settings(QSettings &settings) const string value = settings.value(k).toString().toStdString(); if (!value.empty()) - dev_info.insert(std::make_pair(key, value)); + dev_info.insert(make_pair(key, value)); } if (dev_info.count("model") > 0) @@ -389,7 +395,7 @@ void Session::set_device(shared_ptr device) name_changed(); // Remove all stored data - for (std::shared_ptr view : views_) { + for (shared_ptr view : views_) { view->clear_signals(); #ifdef ENABLE_DECODE view->clear_decode_signals(); @@ -410,7 +416,7 @@ void Session::set_device(shared_ptr device) signals_changed(); - device_ = std::move(device); + device_ = move(device); try { device_->open(); @@ -439,15 +445,13 @@ void Session::set_default_device() return; // Try and find the demo device and select that by default - const auto iter = std::find_if(devices.begin(), devices.end(), + const auto iter = find_if(devices.begin(), devices.end(), [] (const shared_ptr &d) { - return d->hardware_device()->driver()->name() == - "demo"; }); + return d->hardware_device()->driver()->name() == "demo"; }); set_device((iter == devices.end()) ? devices.front() : *iter); } -void Session::load_init_file(const std::string &file_name, - const std::string &format) +void Session::load_init_file(const string &file_name, const string &format) { shared_ptr input_format; @@ -470,8 +474,8 @@ void Session::load_init_file(const std::string &file_name, } void Session::load_file(QString file_name, - std::shared_ptr format, - const std::map &options) + shared_ptr format, + const map &options) { const QString errorMessage( QString("Failed to load file %1").arg(file_name)); @@ -522,7 +526,7 @@ void Session::start_capture(function error_handler) const shared_ptr sr_dev = device_->device(); if (sr_dev) { const auto channels = sr_dev->channels(); - if (!std::any_of(channels.begin(), channels.end(), + if (!any_of(channels.begin(), channels.end(), [](shared_ptr channel) { return channel->enabled(); })) { error_handler(tr("No channels enabled.")); @@ -534,9 +538,15 @@ void Session::start_capture(function error_handler) for (const shared_ptr d : all_signal_data_) d->clear(); - // Revert name back to default name (e.g. "Session 1") as the data is gone - name_ = default_name_; - name_changed(); + // Revert name back to default name (e.g. "Session 1") for real devices + // as the (possibly saved) data is gone. File devices keep their name. + shared_ptr hw_device = + dynamic_pointer_cast< devices::HardwareDevice >(device_); + + if (hw_device) { + name_ = default_name_; + name_changed(); + } // Begin the session sampling_thread_ = std::thread( @@ -553,7 +563,7 @@ void Session::stop_capture() sampling_thread_.join(); } -void Session::register_view(std::shared_ptr view) +void Session::register_view(shared_ptr view) { if (views_.empty()) { main_view_ = view; @@ -564,10 +574,9 @@ void Session::register_view(std::shared_ptr view) update_signals(); } -void Session::deregister_view(std::shared_ptr view) +void Session::deregister_view(shared_ptr view) { - views_.remove_if([&](std::shared_ptr v) { - return v == view; }); + views_.remove_if([&](shared_ptr v) { return v == view; }); if (views_.empty()) { main_view_.reset(); @@ -577,9 +586,9 @@ void Session::deregister_view(std::shared_ptr view) } } -bool Session::has_view(std::shared_ptr view) +bool Session::has_view(shared_ptr view) { - for (std::shared_ptr v : views_) + for (shared_ptr v : views_) if (v == view) return true; @@ -595,7 +604,7 @@ double Session::get_samplerate() const const vector< shared_ptr > segments = d->segments(); for (const shared_ptr &s : segments) - samplerate = std::max(samplerate, s->samplerate()); + samplerate = max(samplerate, s->samplerate()); } // If there is no sample rate given we use samples as unit if (samplerate == 0.0) @@ -604,8 +613,7 @@ double Session::get_samplerate() const return samplerate; } -const std::unordered_set< std::shared_ptr > - Session::signalbases() const +const unordered_set< shared_ptr > Session::signalbases() const { return signalbases_; } @@ -621,7 +629,7 @@ bool Session::add_decoder(srd_decoder *const dec) decoder_stack = make_shared(*this, dec); // Make a list of all the channels - std::vector all_channels; + vector all_channels; for (const GSList *i = dec->channels; i; i = i->next) all_channels.push_back((const srd_channel*)i->data); for (const GSList *i = dec->opt_channels; i; i = i->next) @@ -649,9 +657,9 @@ bool Session::add_decoder(srd_decoder *const dec) signalbase->set_decoder_stack(decoder_stack); signalbases_.insert(signalbase); - for (std::shared_ptr view : views_) + for (shared_ptr view : views_) view->add_decode_signal(signalbase); - } catch (std::runtime_error e) { + } catch (runtime_error e) { return false; } @@ -667,7 +675,7 @@ void Session::remove_decode_signal(shared_ptr signalbase) { signalbases_.erase(signalbase); - for (std::shared_ptr view : views_) + for (shared_ptr view : views_) view->remove_decode_signal(signalbase); signals_changed(); @@ -693,7 +701,7 @@ void Session::update_signals() if (!device_) { signalbases_.clear(); logic_data_.reset(); - for (std::shared_ptr view : views_) { + for (shared_ptr view : views_) { view->clear_signals(); #ifdef ENABLE_DECODE view->clear_decode_signals(); @@ -708,7 +716,7 @@ void Session::update_signals() if (!sr_dev) { signalbases_.clear(); logic_data_.reset(); - for (std::shared_ptr view : views_) { + for (shared_ptr view : views_) { view->clear_signals(); #ifdef ENABLE_DECODE view->clear_decode_signals(); @@ -719,7 +727,7 @@ void Session::update_signals() // Detect what data types we will receive auto channels = sr_dev->channels(); - unsigned int logic_channel_count = std::count_if( + unsigned int logic_channel_count = count_if( channels.begin(), channels.end(), [] (shared_ptr channel) { return channel->type() == ChannelType::LOGIC; }); @@ -739,7 +747,7 @@ void Session::update_signals() } // Make the signals list - for (std::shared_ptr viewbase : views_) { + for (shared_ptr viewbase : views_) { views::TraceView::View *trace_view = qobject_cast(viewbase.get()); @@ -753,7 +761,7 @@ void Session::update_signals() shared_ptr signal; // Find the channel in the old signals - const auto iter = std::find_if( + const auto iter = find_if( prev_sigs.cbegin(), prev_sigs.cend(), [&](const shared_ptr &s) { return s->base()->channel() == channel; @@ -1059,7 +1067,7 @@ void Session::data_feed_in(shared_ptr device, case SR_DF_LOGIC: try { feed_in_logic(dynamic_pointer_cast(packet->payload())); - } catch (std::bad_alloc) { + } catch (bad_alloc) { out_of_memory_ = true; device_->stop(); } @@ -1068,7 +1076,7 @@ void Session::data_feed_in(shared_ptr device, case SR_DF_ANALOG: try { feed_in_analog(dynamic_pointer_cast(packet->payload())); - } catch (std::bad_alloc) { + } catch (bad_alloc) { out_of_memory_ = true; device_->stop(); }