X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=80dad66ee929ef36974da0573cb982f3843b4e06;hp=f5f1e4974b6ea155dcdb923924a05c0fef4077c3;hb=72486b789078f024e4f3404f81118c03b03e2b70;hpb=79c4a9c8a28765422075b77b0dca23cd248c4d18 diff --git a/pv/session.cpp b/pv/session.cpp index f5f1e497..80dad66e 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -17,32 +17,26 @@ * along with this program; if not, see . */ -#ifdef _WIN32 -// Windows: Avoid boost/thread namespace pollution (which includes windows.h). -#define NOGDI -#define NORESOURCE -#endif -#include -#include - +#include #include #include +#include #include #include #include -#include "session.hpp" #include "devicemanager.hpp" +#include "mainwindow.hpp" +#include "session.hpp" #include "data/analog.hpp" #include "data/analogsegment.hpp" -#include "data/decoderstack.hpp" +#include "data/decode/decoder.hpp" #include "data/logic.hpp" #include "data/logicsegment.hpp" #include "data/signalbase.hpp" -#include "data/decode/decoder.hpp" #include "devices/hardwaredevice.hpp" #include "devices/inputfile.hpp" @@ -50,22 +44,19 @@ #include "toolbars/mainbar.hpp" -#include "view/analogsignal.hpp" -#include "view/decodetrace.hpp" -#include "view/logicsignal.hpp" -#include "view/signal.hpp" -#include "view/view.hpp" +#include "views/trace/analogsignal.hpp" +#include "views/trace/decodetrace.hpp" +#include "views/trace/logicsignal.hpp" +#include "views/trace/signal.hpp" +#include "views/trace/view.hpp" #include #ifdef ENABLE_DECODE #include +#include "data/decodesignal.hpp" #endif -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; @@ -81,9 +72,9 @@ using std::mutex; using std::pair; using std::recursive_mutex; using std::runtime_error; -using std::set; using std::shared_ptr; using std::string; +using std::unique_ptr; using std::unordered_set; using std::vector; @@ -92,20 +83,18 @@ using sigrok::Channel; using sigrok::ConfigKey; using sigrok::DatafeedCallbackFunction; using sigrok::Error; -using sigrok::Header; using sigrok::InputFormat; using sigrok::Logic; using sigrok::Meta; -using sigrok::OutputFormat; using sigrok::Packet; -using sigrok::PacketPayload; using sigrok::Session; -using sigrok::SessionDevice; using Glib::VariantBase; -using Glib::Variant; namespace pv { + +shared_ptr Session::sr_context; + Session::Session(DeviceManager &device_manager, QString name) : device_manager_(device_manager), default_name_(name), @@ -188,7 +177,7 @@ void Session::save_settings(QSettings &settings) const { map dev_info; list key_list; - int stacks = 0, views = 0; + int decode_signals = 0, views = 0; if (device_) { shared_ptr hw_device = @@ -232,14 +221,8 @@ void Session::save_settings(QSettings &settings) const for (shared_ptr base : signalbases_) { #ifdef ENABLE_DECODE if (base->is_decode_signal()) { - shared_ptr decoder_stack = - base->decoder_stack(); - shared_ptr top_decoder = - decoder_stack->stack().front(); - - settings.beginGroup("decoder_stack" + QString::number(stacks++)); - settings.setValue("id", top_decoder->decoder()->id); - settings.setValue("name", top_decoder->decoder()->name); + settings.beginGroup("decode_signal" + QString::number(decode_signals++)); + base->save_settings(settings); settings.endGroup(); } else #endif @@ -250,7 +233,7 @@ void Session::save_settings(QSettings &settings) const } } - settings.setValue("decoder_stacks", stacks); + settings.setValue("decode_signals", decode_signals); // Save view states and their signal settings // Note: main_view must be saved as view0 @@ -317,8 +300,9 @@ void Session::restore_settings(QSettings &settings) filename.toStdString()); set_device(device); - // TODO Perform error handling - start_capture([](QString infoMessage) { (void)infoMessage; }); + start_capture([](QString infoMessage) { + // TODO Emulate noquote() + qDebug() << "Session error:" << infoMessage; }); set_name(QFileInfo(filename).fileName()); } @@ -334,14 +318,12 @@ void Session::restore_settings(QSettings &settings) // Restore decoders #ifdef ENABLE_DECODE - int stacks = settings.value("decoder_stacks").toInt(); - - for (int i = 0; i < stacks; i++) { - settings.beginGroup("decoder_stack" + QString::number(i++)); - - QString id = settings.value("id").toString(); - add_decoder(srd_decoder_get_by_id(id.toStdString().c_str())); + int decode_signals = settings.value("decode_signals").toInt(); + for (int i = 0; i < decode_signals; i++) { + settings.beginGroup("decode_signal" + QString::number(i)); + shared_ptr signal = add_decode_signal(); + signal->restore_settings(settings); settings.endGroup(); } #endif @@ -372,8 +354,7 @@ void Session::select_device(shared_ptr device) else set_default_device(); } catch (const QString &e) { - main_bar_->session_error(tr("Failed to Select Device"), - tr("Failed to Select Device")); + MainWindow::show_session_error(tr("Failed to select device"), e); } } @@ -421,6 +402,7 @@ void Session::set_device(shared_ptr device) device_->open(); } catch (const QString &e) { device_.reset(); + MainWindow::show_session_error(tr("Failed to open device"), e); } if (device_) { @@ -446,30 +428,80 @@ void Session::set_default_device() // Try and find the demo device and select that by default 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); } +/** + * Convert generic options to data types that are specific to InputFormat. + * + * @param[in] user_spec Vector of tokenized words, string format. + * @param[in] fmt_opts Input format's options, result of InputFormat::options(). + * + * @return Map of options suitable for InputFormat::create_input(). + */ +map +Session::input_format_options(vector user_spec, + map> fmt_opts) +{ + map result; + + for (auto entry : user_spec) { + /* + * Split key=value specs. Accept entries without separator + * (for simplified boolean specifications). + */ + string key, val; + size_t pos = entry.find("="); + if (pos == std::string::npos) { + key = entry; + val = ""; + } else { + key = entry.substr(0, pos); + val = entry.substr(pos + 1); + } + + /* + * Skip user specifications that are not a member of the + * format's set of supported options. Have the text input + * spec converted to the required input format specific + * data type. + */ + auto found = fmt_opts.find(key); + if (found == fmt_opts.end()) + continue; + shared_ptr