X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=pv%2Fdata%2Fdecode%2Fdecoder.cpp;h=19f11399fec78bae58fc809d71bfb6b0aded71d1;hb=cbb2e4da8042495531b406f745ee9d9e20448ef6;hp=c6995bcf703a56cb13b4ba347acb2c61aa11d17e;hpb=8ce0e732cfe912e022eb96d06aaaa40390efcd6b;p=pulseview.git diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index c6995bcf..19f11399 100644 --- a/pv/data/decode/decoder.cpp +++ b/pv/data/decode/decoder.cpp @@ -29,7 +29,6 @@ #include #include -using pv::data::DecodeChannel; using std::map; using std::string; @@ -38,10 +37,18 @@ namespace data { namespace decode { Decoder::Decoder(const srd_decoder *const dec) : - decoder_(dec), + srd_decoder_(dec), shown_(true), decoder_inst_(nullptr) { + // Query the decoder outputs + uint32_t i = 0; + for (GSList *l = dec->binary; l; l = l->next) { + char **bin_class = (char**)l->data; + char *name = bin_class[0]; + char *desc = bin_class[1]; + bin_classes_.push_back({i++, name, desc}); + } } Decoder::~Decoder() @@ -52,7 +59,12 @@ Decoder::~Decoder() const srd_decoder* Decoder::decoder() const { - return decoder_; + return srd_decoder_; +} + +const char* Decoder::name() const +{ + return srd_decoder_->name; } bool Decoder::shown() const @@ -87,12 +99,21 @@ void Decoder::set_option(const char *id, GVariant *value) options_[id] = value; // If we have a decoder instance, apply option value immediately + apply_all_options(); +} + +void Decoder::apply_all_options() +{ if (decoder_inst_) { GHashTable *const opt_hash = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)g_variant_unref); - g_variant_ref(value); - g_hash_table_insert(opt_hash, (void*)g_strdup(id), value); + for (const auto& option : options_) { + GVariant *const value = option.second; + g_variant_ref(value); + g_hash_table_replace(opt_hash, (void*)g_strdup( + option.first.c_str()), value); + } srd_inst_option_set(decoder_inst_, opt_hash); g_hash_table_destroy(opt_hash); @@ -123,7 +144,7 @@ srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) if (decoder_inst_) qDebug() << "WARNING: previous decoder instance" << decoder_inst_ << "exists"; - decoder_inst_ = srd_inst_new(session, decoder_->id, opt_hash); + decoder_inst_ = srd_inst_new(session, srd_decoder_->id, opt_hash); g_hash_table_destroy(opt_hash); if (!decoder_inst_) @@ -163,6 +184,16 @@ void Decoder::invalidate_decoder_inst() decoder_inst_ = nullptr; } +uint32_t Decoder::get_binary_class_count() const +{ + return bin_classes_.size(); +} + +const DecodeBinaryClassInfo* Decoder::get_binary_class(uint32_t id) const +{ + return &(bin_classes_.at(id)); +} + } // namespace decode } // namespace data } // namespace pv