Decoder::Decoder(const srd_decoder *const dec,
std::map<const srd_probe*,
- boost::shared_ptr<pv::view::Signal> > probes) :
+ boost::shared_ptr<pv::view::Signal> > probes,
+ GHashTable *options) :
_decoder(dec),
_probes(probes),
+ _options(options),
_decoder_inst(NULL)
{
init_decoder();
{
_decode_thread.interrupt();
_decode_thread.join();
+
+ g_hash_table_destroy(_options);
}
const srd_decoder* Decoder::get_decoder() const
}
}
- _decoder_inst = srd_inst_new(_decoder->id, NULL);
+ _decoder_inst = srd_inst_new(_decoder->id, _options);
assert(_decoder_inst);
_decoder_inst->data_samplerate = _samplerate;
public:
Decoder(const srd_decoder *const decoder,
std::map<const srd_probe*,
- boost::shared_ptr<pv::view::Signal> > probes);
+ boost::shared_ptr<pv::view::Signal> > probes,
+ GHashTable *options);
virtual ~Decoder();
const srd_decoder *const _decoder;
std::map<const srd_probe*, boost::shared_ptr<view::Signal> >
_probes;
+ GHashTable *_options;
srd_decoder_inst *_decoder_inst;
namespace dialogs {
Decoder::Decoder(QWidget *parent, const srd_decoder *decoder,
- const vector< shared_ptr<view::Signal> > &sigs) :
+ const vector< shared_ptr<view::Signal> > &sigs, GHashTable *options) :
QDialog(parent),
_decoder(decoder),
_sigs(sigs),
+ _options(options),
+ _binding(decoder, options),
_layout(this),
_form(this),
_form_layout(&_form),
_form_layout.addRow(new QLabel(
tr("<i>* Required Probes</i>"), &_form));
+
+ // Add the options
+ if (!_binding.properties().empty()) {
+ _form_layout.addRow(new QLabel(tr("<h3>Options</h3>"),
+ &_form));
+ _binding.add_properties_to_form(&_form_layout);
+ }
+}
+
+void Decoder::accept()
+{
+ QDialog::accept();
+ _binding.commit();
}
QComboBox* Decoder::create_probe_selector(
#include <QLabel>
#include <QVBoxLayout>
+#include <pv/prop/binding/decoderoptions.h>
+
struct srd_decoder;
namespace pv {
{
public:
Decoder(QWidget *parent, const srd_decoder *decoder,
- const std::vector< boost::shared_ptr<view::Signal> > &sigs);
+ const std::vector< boost::shared_ptr<view::Signal> > &sigs,
+ GHashTable *options);
+
+ void accept();
std::map<const srd_probe*, boost::shared_ptr<view::Signal> >
get_probes();
std::map<const srd_probe*, QComboBox*> _probe_selector_map;
+ GHashTable *const _options;
+ pv::prop::binding::DecoderOptions _binding;
+
QVBoxLayout _layout;
QWidget _form;
const std::vector< boost::shared_ptr<view::Signal> > &sigs =
_session.get_signals();
- dialogs::Decoder dlg(this, dec, sigs);
- if(dlg.exec() != QDialog::Accepted)
+ GHashTable *const options = g_hash_table_new_full(g_str_hash,
+ g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
+
+ dialogs::Decoder dlg(this, dec, sigs, options);
+ if(dlg.exec() != QDialog::Accepted) {
+ g_hash_table_destroy(options);
return;
+ }
- _session.add_decoder(dec, dlg.get_probes());
+ _session.add_decoder(dec, dlg.get_probes(), options);
}
void MainWindow::run_stop()
#include "decoderoptions.h"
+#include <boost/foreach.hpp>
+#include <boost/none_t.hpp>
+
+#include <pv/prop/int.h>
+#include <pv/prop/string.h>
+
+using namespace boost;
+using namespace std;
+
namespace pv {
namespace prop {
namespace binding {
-DecoderOptions::DecoderOptions(struct srd_decoder *decoder) :
- _decoder(decoder)
+DecoderOptions::DecoderOptions(const srd_decoder *decoder,
+ GHashTable *options) :
+ _decoder(decoder),
+ _options(options)
+{
+ assert(decoder);
+
+
+ for (GSList *l = decoder->options; l; l = l->next)
+ {
+ const srd_decoder_option *const opt =
+ (srd_decoder_option*)l->data;
+
+ const QString name(opt->desc);
+
+ const Property::Getter getter = bind(
+ &DecoderOptions::getter, this, opt->id);
+ const Property::Setter setter = bind(
+ &DecoderOptions::setter, this, opt->id, _1);
+
+ shared_ptr<Property> prop;
+
+ if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("x")))
+ prop = shared_ptr<Property>(
+ new Int(name, "", none, getter, setter));
+ else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s")))
+ prop = shared_ptr<Property>(
+ new String(name, getter, setter));
+ else
+ continue;
+
+ _properties.push_back(prop);
+ }
+}
+
+GVariant* DecoderOptions::getter(const char *id)
+{
+ // Get the value from the hash table if it is already present
+ GVariant *val = (GVariant*)g_hash_table_lookup(_options, id);
+
+ if (!val)
+ {
+ // Get the default value if not
+ for (GSList *l = _decoder->options; l; l = l->next)
+ {
+ const srd_decoder_option *const opt =
+ (srd_decoder_option*)l->data;
+ if (strcmp(opt->id, id) == 0)
+ val = opt->def;
+ }
+ }
+
+ if (val)
+ g_variant_ref(val);
+
+ return val;
+}
+
+void DecoderOptions::setter(const char *id, GVariant *value)
{
+ g_variant_ref(value);
+ g_hash_table_insert(_options, (void*)id, value);
}
} // binding
} // prop
} // pv
-
class DecoderOptions : public Binding
{
public:
- DecoderOptions(struct srd_decoder *decoder);
+ DecoderOptions(const srd_decoder *decoder, GHashTable *options);
-protected:
- struct srd_decoder *const _decoder;
+private:
+ GVariant* getter(const char *id);
+
+ void setter(const char *id, GVariant *value);
+
+private:
+ const srd_decoder *const _decoder;
+ GHashTable *const _options;
};
} // binding
void SigSession::add_decoder(srd_decoder *const dec,
std::map<const srd_probe*,
- boost::shared_ptr<view::Signal> > probes)
+ boost::shared_ptr<view::Signal> > probes,
+ GHashTable *options)
{
{
lock_guard<mutex> lock(_signals_mutex);
}
shared_ptr<data::Decoder> decoder(
- new data::Decoder(dec, probes));
+ new data::Decoder(dec, probes, options));
shared_ptr<view::DecodeSignal> d(
new view::DecodeSignal(*this, decoder,
_decode_traces.size()));
void add_decoder(srd_decoder *const dec,
std::map<const srd_probe*,
- boost::shared_ptr<view::Signal> > probes);
+ boost::shared_ptr<view::Signal> > probes,
+ GHashTable *options);
std::vector< boost::shared_ptr<view::DecodeSignal> >
get_decode_signals() const;