]> sigrok.org Git - pulseview.git/blame - pv/data/decode/decoder.cpp
Pass new unit_size argument to srd_inst_probe_set_all()
[pulseview.git] / pv / data / decode / decoder.cpp
CommitLineData
7491a29f
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
5 *
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.
10 *
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.
15 *
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
19 */
20
8d3e0764 21#include <libsigrok/libsigrok.h>
7491a29f
JH
22#include <libsigrokdecode/libsigrokdecode.h>
23
24#include "decoder.h"
25
26#include <pv/view/logicsignal.h>
27
819f4c25
JH
28using boost::shared_ptr;
29using std::map;
30using std::string;
7491a29f
JH
31
32namespace pv {
33namespace data {
34namespace decode {
35
36Decoder::Decoder(const srd_decoder *const dec) :
dd048a7e
JH
37 _decoder(dec),
38 _shown(true)
7491a29f
JH
39{
40}
41
42Decoder::~Decoder()
43{
615f6d25
JH
44 for (map<string, GVariant*>::const_iterator i = _options.begin();
45 i != _options.end(); i++)
46 g_variant_unref((*i).second);
7491a29f
JH
47}
48
49const srd_decoder* Decoder::decoder() const
50{
51 return _decoder;
52}
53
dd048a7e
JH
54bool Decoder::shown() const
55{
56 return _shown;
57}
58
59void Decoder::show(bool show)
60{
61 _shown = show;
62}
63
7491a29f
JH
64const map<const srd_probe*, shared_ptr<view::LogicSignal> >&
65Decoder::probes() const
66{
67 return _probes;
68}
69
70void Decoder::set_probes(std::map<const srd_probe*,
71 boost::shared_ptr<view::LogicSignal> > probes)
72{
73 _probes = probes;
74}
75
615f6d25 76const std::map<std::string, GVariant*>& Decoder::options() const
7491a29f
JH
77{
78 return _options;
79}
80
81void Decoder::set_option(const char *id, GVariant *value)
82{
615f6d25 83 assert(value);
7491a29f 84 g_variant_ref(value);
615f6d25 85 _options[id] = value;
7491a29f
JH
86}
87
a2d4b551
JH
88bool Decoder::have_required_probes() const
89{
90 for (GSList *p = _decoder->probes; p; p = p->next) {
91 const srd_probe *const probe = (const srd_probe*)p->data;
92 assert(probe);
93 if (_probes.find(probe) == _probes.end())
94 return false;
95 }
96
97 return true;
98}
99
13a3528c 100srd_decoder_inst* Decoder::create_decoder_inst(srd_session *session, int unit_size) const
7491a29f 101{
615f6d25
JH
102 GHashTable *const opt_hash = g_hash_table_new_full(g_str_hash,
103 g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
104
105 for (map<string, GVariant*>::const_iterator i = _options.begin();
106 i != _options.end(); i++)
107 {
108 GVariant *const value = (*i).second;
109 g_variant_ref(value);
110 g_hash_table_replace(opt_hash, (void*)g_strdup(
111 (*i).first.c_str()), value);
112 }
113
7491a29f 114 srd_decoder_inst *const decoder_inst = srd_inst_new(
615f6d25
JH
115 session, _decoder->id, opt_hash);
116 g_hash_table_destroy(opt_hash);
117
7491a29f
JH
118 if(!decoder_inst)
119 return NULL;
120
121 // Setup the probes
122 GHashTable *const probes = g_hash_table_new_full(g_str_hash,
123 g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
124
125 for(map<const srd_probe*, shared_ptr<view::LogicSignal> >::
126 const_iterator i = _probes.begin();
127 i != _probes.end(); i++)
128 {
129 shared_ptr<view::LogicSignal> signal((*i).second);
130 GVariant *const gvar = g_variant_new_int32(
131 signal->probe()->index);
132 g_variant_ref_sink(gvar);
133 g_hash_table_insert(probes, (*i).first->id, gvar);
134 }
135
13a3528c 136 srd_inst_probe_set_all(decoder_inst, probes, unit_size);
7491a29f
JH
137
138 return decoder_inst;
139}
140
141} // decode
142} // data
143} // pv