if (!open_file_name.empty()) {
shared_ptr<Session> session = add_session();
- session->main_bar()->load_init_file(open_file_name, open_file_format);
+ session->load_init_file(open_file_name, open_file_format);
}
// Add empty default session if there aren't any sessions
}
// ...and if there isn't any, just use demo then
- session->main_bar()->select_device(other_device ?
- other_device : demo_device);
+ session->select_device(other_device ? other_device : demo_device);
}
}
#include "data/decode/decoder.hpp"
#include "devices/hardwaredevice.hpp"
+#include "devices/inputfile.hpp"
#include "devices/sessionfile.hpp"
#include "toolbars/mainbar.hpp"
using std::list;
using std::map;
using std::mutex;
+using std::pair;
using std::recursive_mutex;
using std::set;
using std::shared_ptr;
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;
}
}
+void Session::select_device(shared_ptr<devices::Device> device)
+{
+ try {
+ if (device)
+ set_device(device);
+ else
+ set_default_device();
+ } catch (const QString &e) {
+ main_bar_->session_error(tr("Failed to Select Device"),
+ tr("Failed to Select Device"));
+ }
+}
+
void Session::set_device(shared_ptr<devices::Device> device)
{
assert(device);
set_device((iter == devices.end()) ? devices.front() : *iter);
}
+void Session::load_init_file(const std::string &file_name,
+ const std::string &format)
+{
+ shared_ptr<InputFormat> input_format;
+
+ if (!format.empty()) {
+ const map<string, shared_ptr<InputFormat> > formats =
+ device_manager_.context()->input_formats();
+ const auto iter = find_if(formats.begin(), formats.end(),
+ [&](const pair<string, shared_ptr<InputFormat> > f) {
+ return f.first == format; });
+ if (iter == formats.end()) {
+ main_bar_->session_error(tr("Error"),
+ tr("Unexpected input format: %s").arg(QString::fromStdString(format)));
+ return;
+ }
+
+ input_format = (*iter).second;
+ }
+
+ load_file(QString::fromStdString(file_name), input_format);
+}
+
+void Session::load_file(QString file_name,
+ std::shared_ptr<sigrok::InputFormat> format,
+ const std::map<std::string, Glib::VariantBase> &options)
+{
+ const QString errorMessage(
+ QString("Failed to load file %1").arg(file_name));
+
+ try {
+ if (format)
+ set_device(shared_ptr<devices::Device>(
+ new devices::InputFile(
+ device_manager_.context(),
+ file_name.toStdString(),
+ format, options)));
+ else
+ set_device(shared_ptr<devices::Device>(
+ new devices::SessionFile(
+ device_manager_.context(),
+ file_name.toStdString())));
+ } catch (Error e) {
+ main_bar_->session_error(tr("Failed to load ") + file_name, e.what());
+ set_default_device();
+ main_bar_->update_device_list();
+ return;
+ }
+
+ main_bar_->update_device_list();
+
+ start_capture([&, errorMessage](QString infoMessage) {
+ main_bar_->session_error(errorMessage, infoMessage); });
+
+ set_name(QFileInfo(file_name).fileName());
+}
+
Session::capture_state Session::get_capture_state() const
{
lock_guard<mutex> lock(sampling_mutex_);
class Analog;
class Channel;
class Device;
+class InputFormat;
class Logic;
class Meta;
+class OutputFormat;
class Packet;
class Session;
}
std::shared_ptr<views::ViewBase> main_view() const;
- void set_main_bar(std::shared_ptr<pv::toolbars::MainBar> main_bar);
-
std::shared_ptr<pv::toolbars::MainBar> main_bar() const;
+ void set_main_bar(std::shared_ptr<pv::toolbars::MainBar> main_bar);
+
void save_settings(QSettings &settings) const;
void restore_settings(QSettings &settings);
+ /**
+ * Attempts to set device instance, may fall back to demo if needed
+ */
+ void select_device(std::shared_ptr<devices::Device> device);
+
/**
* Sets device instance that will be used in the next capture session.
*/
void set_default_device();
+ void load_init_file(const std::string &file_name,
+ const std::string &format);
+
+ void load_file(QString file_name,
+ std::shared_ptr<sigrok::InputFormat> format = nullptr,
+ const std::map<std::string, Glib::VariantBase> &options =
+ std::map<std::string, Glib::VariantBase>());
+
capture_state get_capture_state() const;
void start_capture(std::function<void (const QString)> error_handler);
using std::map;
using std::max;
using std::min;
-using std::pair;
using std::shared_ptr;
using std::string;
using std::vector;
device_selector_.reset();
}
-void MainBar::select_device(shared_ptr<devices::Device> device)
-{
- try {
- if (device)
- session_.set_device(device);
- else
- session_.set_default_device();
- } catch (const QString &e) {
- QMessageBox msg(this);
- msg.setText(e);
- msg.setInformativeText(tr("Failed to Select Device"));
- msg.setStandardButtons(QMessageBox::Ok);
- msg.setIcon(QMessageBox::Warning);
- msg.exec();
- }
-}
-
-void MainBar::load_init_file(const std::string &file_name,
- const std::string &format)
-{
- shared_ptr<InputFormat> input_format;
-
- DeviceManager& device_manager = session_.device_manager();
-
- if (!format.empty()) {
- const map<string, shared_ptr<InputFormat> > formats =
- device_manager.context()->input_formats();
- const auto iter = find_if(formats.begin(), formats.end(),
- [&](const pair<string, shared_ptr<InputFormat> > f) {
- return f.first == format; });
- if (iter == formats.end()) {
- cerr << "Unexpected input format: " << format << endl;
- return;
- }
-
- input_format = (*iter).second;
- }
-
- load_file(QString::fromStdString(file_name), input_format);
-}
-
QAction* MainBar::action_open() const
{
return action_open_;
return action_view_show_cursors_;
}
-void MainBar::load_file(QString file_name,
- std::shared_ptr<sigrok::InputFormat> format,
- const std::map<std::string, Glib::VariantBase> &options)
-{
- DeviceManager& device_manager = session_.device_manager();
-
- const QString errorMessage(
- QString("Failed to load file %1").arg(file_name));
-
- try {
- if (format)
- session_.set_device(shared_ptr<devices::Device>(
- new devices::InputFile(
- device_manager.context(),
- file_name.toStdString(),
- format, options)));
- else
- session_.set_device(shared_ptr<devices::Device>(
- new devices::SessionFile(
- device_manager.context(),
- file_name.toStdString())));
- } catch (Error e) {
- show_session_error(tr("Failed to load ") + file_name, e.what());
- session_.set_default_device();
- update_device_list();
- return;
- }
-
- update_device_list();
-
- session_.start_capture([&, errorMessage](QString infoMessage) {
- session_error(errorMessage, infoMessage); });
-
- session_.set_name(QFileInfo(file_name).fileName());
-}
-
void MainBar::update_sample_rate_selector()
{
Glib::VariantContainerBase gvar_dict;
options = dlg.options();
}
- load_file(file_name, format, options);
+ session_.load_file(file_name, format, options);
const QString abs_path = QFileInfo(file_name).absolutePath();
settings.setValue(SettingOpenDirectory, abs_path);
return;
}
- select_device(device);
+ session_.select_device(device);
}
void MainBar::on_device_changed()
"All Files (*.*)"));
if (!file_name.isEmpty()) {
- load_file(file_name);
+ session_.load_file(file_name);
const QString abs_path = QFileInfo(file_name).absolutePath();
settings.setValue(SettingOpenDirectory, abs_path);
// If the user selected a device, select it in the device list. Select the
// current device otherwise.
if (dlg.exec())
- select_device(dlg.get_selected_device());
+ session_.select_device(dlg.get_selected_device());
update_device_list();
}
void reset_device_selector();
- void select_device(std::shared_ptr<devices::Device> device);
-
- void load_init_file(const std::string &file_name,
- const std::string &format);
-
QAction* action_new_view() const;
QAction* action_open() const;
QAction* action_save_as() const;
QAction* action_view_zoom_one_to_one() const;
QAction* action_view_show_cursors() const;
+ void session_error(const QString text, const QString info_text);
+
private:
void run_stop();
void select_init_device();
- void load_file(QString file_name,
- std::shared_ptr<sigrok::InputFormat> format = nullptr,
- const std::map<std::string, Glib::VariantBase> &options =
- std::map<std::string, Glib::VariantBase>());
-
void save_selection_to_file();
void update_sample_rate_selector();
void commit_sample_rate();
void commit_sample_count();
- void session_error(const QString text, const QString info_text);
-
QAction *const action_new_view_;
QAction *const action_open_;
QAction *const action_save_as_;