X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fsession.cpp;h=6767951cf85961ea303d9fc6f830e8a7d9eb576d;hb=1ec3e43f7489cae3a9ca43e665044c8717f345f1;hp=eec1a051b5a8838ba3f81b58c0759adbadb024a9;hpb=303eec78f3c499cd30fc88b282aa1f336e82a806;p=pulseview.git
diff --git a/pv/session.cpp b/pv/session.cpp
index eec1a05..6767951 100644
--- a/pv/session.cpp
+++ b/pv/session.cpp
@@ -17,6 +17,7 @@
* along with this program; if not, see .
*/
+#include
#include
#include
@@ -27,12 +28,12 @@
#include
#include "devicemanager.hpp"
+#include "mainwindow.hpp"
#include "session.hpp"
#include "data/analog.hpp"
#include "data/analogsegment.hpp"
#include "data/decode/decoder.hpp"
-#include "data/decoderstack.hpp"
#include "data/logic.hpp"
#include "data/logicsegment.hpp"
#include "data/signalbase.hpp"
@@ -43,16 +44,17 @@
#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 std::bad_alloc;
@@ -90,6 +92,9 @@ using sigrok::Session;
using Glib::VariantBase;
namespace pv {
+
+shared_ptr Session::sr_context;
+
Session::Session(DeviceManager &device_manager, QString name) :
device_manager_(device_manager),
default_name_(name),
@@ -172,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 =
@@ -216,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
@@ -234,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
@@ -301,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());
}
@@ -318,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
@@ -356,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);
}
}
@@ -405,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_) {
@@ -430,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