X-Git-Url: https://sigrok.org/gitweb/?p=pulseview.git;a=blobdiff_plain;f=pv%2Fsession.cpp;h=4edba0f7a2de9c5f428e9f07fe38d7532e69ad1e;hp=a1a078788c4e49631e7d00df1ab5e82646a6cbe3;hb=e771b42d654ecb1e8e4d6ca60687c545461e3750;hpb=12ea3616767553ee0a615f14bbcb8ec614589e34 diff --git a/pv/session.cpp b/pv/session.cpp index a1a07878..4edba0f7 100644 --- a/pv/session.cpp +++ b/pv/session.cpp @@ -17,32 +17,25 @@ * 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 "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 +43,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 +71,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,18 +82,13 @@ 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 { Session::Session(DeviceManager &device_manager, QString name) : @@ -188,7 +173,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 +217,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 +229,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 @@ -334,14 +313,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++)); + // TODO Split up add_decoder() into add_decode_signal() and add_decoder(), + // then call add_decode_signal() and signal->restore_settings() here settings.endGroup(); } #endif @@ -450,26 +427,76 @@ void Session::set_default_device() 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