]> sigrok.org Git - pulseview.git/blame - pv/data/decoder.cpp
Create decoder instance
[pulseview.git] / pv / data / decoder.cpp
CommitLineData
119aff65
JH
1/*
2 * This file is part of the PulseView project.
3 *
4 * Copyright (C) 2012 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
e332f6d3
JH
21#include <libsigrokdecode/libsigrokdecode.h>
22
119aff65
JH
23#include "decoder.h"
24
708c5523
JH
25#include <pv/view/signal.h>
26
e332f6d3
JH
27using namespace boost;
28using namespace std;
29
119aff65
JH
30namespace pv {
31namespace data {
32
708c5523
JH
33Decoder::Decoder(const srd_decoder *const dec,
34 std::map<const srd_probe*,
35 boost::shared_ptr<pv::view::Signal> > probes) :
36 _decoder(dec),
e332f6d3
JH
37 _probes(probes),
38 _decoder_inst(NULL)
119aff65 39{
e332f6d3 40 init_decoder();
119aff65
JH
41}
42
43const srd_decoder* Decoder::get_decoder() const
44{
45 return _decoder;
46}
47
e332f6d3
JH
48void Decoder::init_decoder()
49{
50 _decoder_inst = srd_inst_new(_decoder->id, NULL);
51 assert(_decoder_inst);
52
53 GHashTable *probes = g_hash_table_new_full(g_str_hash,
54 g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
55
56 for(map<const srd_probe*, shared_ptr<view::Signal> >::
57 const_iterator i = _probes.begin();
58 i != _probes.end(); i++)
59 {
60 shared_ptr<view::Signal> signal((*i).second);
61 GVariant *const gvar = g_variant_new_int32(
62 signal->probe()->index);
63 g_variant_ref_sink(gvar);
64 g_hash_table_insert(probes, (*i).first->id, gvar);
65 }
66
67 srd_inst_probe_set_all(_decoder_inst, probes);
68}
69
119aff65
JH
70void Decoder::clear_snapshots()
71{
72}
73
74} // namespace data
75} // namespace pv