X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=pv%2Fsession.cpp;h=516e1acd5ad6ff1e6b52a277f97c042e28e37872;hb=6e2a5b1d677a26a637465cd4d304e2bc52e14f36;hp=97741ebf7b944a4c6507bd1a4e64c1d8128a5d5b;hpb=26a883ede0bcf68d087eda5dd2082890d36c7aef;p=pulseview.git
diff --git a/pv/session.cpp b/pv/session.cpp
index 97741eb..516e1ac 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 "session.hpp"
#include "devicemanager.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"
-#include "data/decode/decoder.hpp"
#include "devices/hardwaredevice.hpp"
#include "devices/inputfile.hpp"
@@ -50,11 +43,11 @@
#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
@@ -62,42 +55,39 @@
#include
#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;
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::set;
+using std::runtime_error;
using std::shared_ptr;
using std::string;
+using std::unique_ptr;
using std::unordered_set;
using std::vector;
using sigrok::Analog;
using sigrok::Channel;
-using sigrok::ChannelType;
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) :
@@ -153,17 +143,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;
}
@@ -192,11 +182,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_);
@@ -228,7 +218,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++));
@@ -276,11 +266,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);
@@ -289,7 +279,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)
@@ -307,7 +297,7 @@ void Session::restore_settings(QSettings &settings)
settings.endGroup();
if (QFileInfo(filename).isReadable()) {
- device = std::make_shared(device_manager_.context(),
+ device = make_shared(device_manager_.context(),
filename.toStdString());
set_device(device);
@@ -383,12 +373,12 @@ void Session::set_device(shared_ptr device)
device_.reset();
- // Revert name back to default name (e.g. "Untitled-1") as the data is gone
+ // Revert name back to default name (e.g. "Session 1") as the data is gone
name_ = default_name_;
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();
@@ -409,22 +399,23 @@ void Session::set_device(shared_ptr device)
signals_changed();
- device_ = std::move(device);
+ device_ = move(device);
try {
device_->open();
} catch (const QString &e) {
device_.reset();
- device_changed();
- throw;
}
- device_->session()->add_datafeed_callback([=]
- (shared_ptr device, shared_ptr packet) {
- data_feed_in(device, packet);
- });
+ if (device_) {
+ device_->session()->add_datafeed_callback([=]
+ (shared_ptr device, shared_ptr packet) {
+ data_feed_in(device, packet);
+ });
+
+ update_signals();
+ }
- update_signals();
device_changed();
}
@@ -437,39 +428,87 @@ 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)
+/**
+ * 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