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, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <libsigrokcxx/libsigrokcxx.hpp>
24 #include <libsigrokdecode/libsigrokdecode.h>
26 #include "decoder.hpp"
28 #include <pv/view/logicsignal.hpp>
32 using std::shared_ptr;
39 Decoder::Decoder(const srd_decoder *const dec) :
47 for (auto i = options_.begin(); i != options_.end(); i++)
48 g_variant_unref((*i).second);
51 const srd_decoder* Decoder::decoder() const
56 bool Decoder::shown() const
61 void Decoder::show(bool show)
66 const map<const srd_channel*, shared_ptr<view::LogicSignal> >&
67 Decoder::channels() const
72 void Decoder::set_channels(std::map<const srd_channel*,
73 std::shared_ptr<view::LogicSignal> > channels)
78 const std::map<std::string, GVariant*>& Decoder::options() const
83 void Decoder::set_option(const char *id, GVariant *value)
90 bool Decoder::have_required_channels() const
92 for (GSList *l = decoder_->channels; l; l = l->next) {
93 const srd_channel *const pdch = (const srd_channel*)l->data;
95 if (channels_.find(pdch) == channels_.end())
102 set< shared_ptr<pv::data::Logic> > Decoder::get_data()
104 set< shared_ptr<pv::data::Logic> > data;
105 for(auto i = channels_.cbegin(); i != channels_.cend(); i++) {
106 shared_ptr<view::LogicSignal> signal((*i).second);
108 data.insert(signal->logic_data());
114 srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session, int unit_size) const
116 GHashTable *const opt_hash = g_hash_table_new_full(g_str_hash,
117 g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
119 for (auto i = options_.cbegin(); i != options_.cend(); i++)
121 GVariant *const value = (*i).second;
122 g_variant_ref(value);
123 g_hash_table_replace(opt_hash, (void*)g_strdup(
124 (*i).first.c_str()), value);
127 srd_decoder_inst *const decoder_inst = srd_inst_new(
128 session, decoder_->id, opt_hash);
129 g_hash_table_destroy(opt_hash);
134 // Setup the channels
135 GHashTable *const channels = g_hash_table_new_full(g_str_hash,
136 g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
138 for(auto i = channels_.cbegin(); i != channels_.cend(); i++)
140 shared_ptr<view::LogicSignal> signal((*i).second);
141 GVariant *const gvar = g_variant_new_int32(
142 signal->channel()->index());
143 g_variant_ref_sink(gvar);
144 g_hash_table_insert(channels, (*i).first->id, gvar);
147 srd_inst_channel_set_all(decoder_inst, channels, unit_size);