X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=pv%2Fdata%2Fdecode%2Fdecoder.cpp;h=14d298d24fd41b4835a9d0f9dc8ddc0222949805;hb=ac9494eff3ebc74ae7a87746a4d8668c68f32b52;hp=c6995bcf703a56cb13b4ba347acb2c61aa11d17e;hpb=8ce0e732cfe912e022eb96d06aaaa40390efcd6b;p=pulseview.git diff --git a/pv/data/decode/decoder.cpp b/pv/data/decode/decoder.cpp index c6995bcf..14d298d2 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; @@ -42,6 +41,14 @@ Decoder::Decoder(const srd_decoder *const 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() @@ -55,6 +62,11 @@ const srd_decoder* Decoder::decoder() const return decoder_; } +const char* Decoder::name() const +{ + return decoder_->name; +} + bool Decoder::shown() const { return shown_; @@ -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); @@ -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