2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include <libsigrokcxx/libsigrokcxx.hpp>
23 #include <libsigrokdecode/libsigrokdecode.h>
25 #include "decoder.hpp"
27 #include <pv/data/signalbase.hpp>
31 using std::shared_ptr;
38 Decoder::Decoder(const srd_decoder *const dec) :
46 for (auto& option : options_)
47 g_variant_unref(option.second);
50 const srd_decoder* Decoder::decoder() const
55 bool Decoder::shown() const
60 void Decoder::show(bool show)
65 const map<const srd_channel*, shared_ptr<data::SignalBase> >&
66 Decoder::channels() const
71 void Decoder::set_channels(std::map<const srd_channel*,
72 std::shared_ptr<data::SignalBase> > channels)
77 const std::map<std::string, GVariant*>& Decoder::options() const
82 void Decoder::set_option(const char *id, GVariant *value)
89 bool Decoder::have_required_channels() const
91 for (GSList *l = decoder_->channels; l; l = l->next) {
92 const srd_channel *const pdch = (const srd_channel*)l->data;
94 if (channels_.find(pdch) == channels_.end())
101 set< shared_ptr<pv::data::Logic> > Decoder::get_data()
103 set< shared_ptr<pv::data::Logic> > data;
104 for (const auto& channel : channels_) {
105 shared_ptr<data::SignalBase> b(channel.second);
107 data.insert(b->logic_data());
113 srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session) const
115 GHashTable *const opt_hash = g_hash_table_new_full(g_str_hash,
116 g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
118 for (const auto& option : options_) {
119 GVariant *const value = option.second;
120 g_variant_ref(value);
121 g_hash_table_replace(opt_hash, (void*)g_strdup(
122 option.first.c_str()), value);
125 srd_decoder_inst *const decoder_inst = srd_inst_new(
126 session, decoder_->id, opt_hash);
127 g_hash_table_destroy(opt_hash);
132 // Setup the channels
133 GHashTable *const channels = g_hash_table_new_full(g_str_hash,
134 g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
136 for (const auto& channel : channels_) {
137 shared_ptr<data::SignalBase> b(channel.second);
138 GVariant *const gvar = g_variant_new_int32(b->index());
139 g_variant_ref_sink(gvar);
140 g_hash_table_insert(channels, channel.first->id, gvar);
143 srd_inst_channel_set_all(decoder_inst, channels);