*/
#include <cassert>
+#include <type_traits>
+
+#include <QApplication>
+#include <QDebug>
+#include <QString>
#include <libsigrokcxx/libsigrokcxx.hpp>
#include "device.hpp"
+using std::is_same;
using std::shared_ptr;
using sigrok::ConfigKey;
return device_;
}
-template
-uint64_t Device::read_config(const sigrok::ConfigKey*,
- const uint64_t);
+template uint64_t Device::read_config(const sigrok::ConfigKey*, const uint64_t);
template<typename T>
T Device::read_config(const ConfigKey *key, const T default_value)
if (!device_)
return default_value;
- if (!device_->config_check(key, Capability::GET))
+ if (!device_->config_check(key, Capability::GET)) {
+ qWarning() << QApplication::tr("Querying config key %1 is not allowed")
+ .arg(QString::fromStdString(key->identifier()));
return default_value;
-
- return VariantBase::cast_dynamic<Glib::Variant<guint64>>(
- device_->config_get(ConfigKey::SAMPLERATE)).get();
+ }
+
+ VariantBase value;
+ try {
+ value = device_->config_get(key);
+ } catch (const sigrok::Error &e) {
+ qWarning() << QApplication::tr("Querying config key %1 resulted in %2")
+ .arg(QString::fromStdString(key->identifier()), e.what());
+ return default_value;
+ }
+
+ if (is_same<T, uint32_t>::value)
+ return VariantBase::cast_dynamic<Glib::Variant<guint32>>(value).get();
+ if (is_same<T, int32_t>::value)
+ return VariantBase::cast_dynamic<Glib::Variant<gint32>>(value).get();
+ if (is_same<T, uint64_t>::value)
+ return VariantBase::cast_dynamic<Glib::Variant<guint64>>(value).get();
+ if (is_same<T, int64_t>::value)
+ return VariantBase::cast_dynamic<Glib::Variant<gint64>>(value).get();
+
+ qWarning() << QApplication::tr("Unknown type supplied when attempting to query %1")
+ .arg(QString::fromStdString(key->identifier()));
+ return default_value;
}
void Device::start()
#include <cassert>
#include <QCheckBox>
+#include <QDebug>
+
+#include <libsigrokcxx/libsigrokcxx.hpp>
#include "bool.hpp"
if (!getter_)
return nullptr;
- Glib::VariantBase variant = getter_();
- if (!variant.gobj())
+ try {
+ Glib::VariantBase variant = getter_();
+ if (!variant.gobj())
+ return nullptr;
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
return nullptr;
+ }
check_box_ = new QCheckBox(name(), parent);
check_box_->setToolTip(desc());
if (!check_box_)
return;
- Glib::VariantBase variant = getter_();
- assert(variant.gobj());
+ Glib::VariantBase variant;
+ try {
+ variant = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return;
+ }
+
+ assert(variant.gobj());
bool value = Glib::VariantBase::cast_dynamic<Glib::Variant<bool>>(
variant).get();
if (!check_box_)
return;
- setter_(Glib::Variant<bool>::create(
- check_box_->checkState() == Qt::Checked));
+ setter_(Glib::Variant<bool>::create(check_box_->checkState() == Qt::Checked));
}
void Bool::on_state_changed(int)
#include <cassert>
+#include <QDebug>
#include <QDoubleSpinBox>
+#include <libsigrokcxx/libsigrokcxx.hpp>
+
#include "double.hpp"
using boost::optional;
if (!getter_)
return nullptr;
- Glib::VariantBase variant = getter_();
- if (!variant.gobj())
+ try {
+ Glib::VariantBase variant = getter_();
+ if (!variant.gobj())
+ return nullptr;
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
return nullptr;
+ }
spin_box_ = new QDoubleSpinBox(parent);
spin_box_->setDecimals(decimals_);
if (!spin_box_)
return;
- Glib::VariantBase variant = getter_();
+ Glib::VariantBase variant;
+
+ try {
+ variant = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return;
+ }
+
assert(variant.gobj());
double value = Glib::VariantBase::cast_dynamic<Glib::Variant<double>>(
#include <QLabel>
#include <QSlider>
+#include <libsigrokcxx/libsigrokcxx.hpp>
+
#include "enum.hpp"
using std::abs;
if (!getter_)
return nullptr;
- Glib::VariantBase variant = getter_();
+ Glib::VariantBase variant;
+
+ try {
+ variant = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return nullptr;
+ }
+
if (!variant.gobj())
return nullptr;
void Enum::update_widget()
{
- Glib::VariantBase variant = getter_();
+ Glib::VariantBase variant;
+
+ try {
+ variant = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return;
+ }
+
assert(variant.gobj());
if (is_range_) {
#include <cassert>
#include <cstdint>
+#include <QDebug>
#include <QSpinBox>
+#include <libsigrokcxx/libsigrokcxx.hpp>
+
#include "int.hpp"
using boost::optional;
if (!getter_)
return nullptr;
- value_ = getter_();
+ try {
+ value_ = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return nullptr;
+ }
GVariant *value = value_.gobj();
if (!value)
if (!spin_box_)
return;
- value_ = getter_();
+ try {
+ value_ = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return;
+ }
+
GVariant *value = value_.gobj();
assert(value);
const Getter getter_;
const Setter setter_;
-private:
+protected:
QString name_;
QString desc_;
};
#include <cassert>
+#include <QDebug>
#include <QLineEdit>
#include <QSpinBox>
+#include <libsigrokcxx/libsigrokcxx.hpp>
+
#include "string.hpp"
using std::string;
if (!getter_)
return nullptr;
- Glib::VariantBase variant = getter_();
- if (!variant.gobj())
+ try {
+ Glib::VariantBase variant = getter_();
+ if (!variant.gobj())
+ return nullptr;
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
return nullptr;
+ }
line_edit_ = new QLineEdit(parent);
if (!line_edit_)
return;
- Glib::VariantBase variant = getter_();
+ Glib::VariantBase variant;
+
+ try {
+ variant = getter_();
+ } catch (const sigrok::Error &e) {
+ qWarning() << tr("Querying config key %1 resulted in %2").arg(name_, e.what());
+ return;
+ }
+
assert(variant.gobj());
string value = Glib::VariantBase::cast_dynamic<Glib::Variant<ustring>>(
sample_rate_.set_value(samplerate);
updating_sample_rate_ = false;
} catch (Error& error) {
- qDebug() << tr("Failed to get value of sample rate:") << error.what();
+ qDebug() << tr("Failed to get sample rate:") << error.what();
}
}