]> sigrok.org Git - pulseview.git/blob - pv/data/decoder.cpp
e1be16e3ea14898fcea05f0f9f34b48d101e04c0
[pulseview.git] / pv / data / decoder.cpp
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
21 #include <libsigrokdecode/libsigrokdecode.h>
22
23 #include "decoder.h"
24
25 #include <pv/view/signal.h>
26
27 using namespace boost;
28 using namespace std;
29
30 namespace pv {
31 namespace data {
32
33 Decoder::Decoder(const srd_decoder *const dec,
34         std::map<const srd_probe*,
35                 boost::shared_ptr<pv::view::Signal> > probes) :
36         _decoder(dec),
37         _probes(probes),
38         _decoder_inst(NULL)
39 {
40         init_decoder();
41 }
42
43 Decoder::~Decoder()
44 {
45         _decode_thread.interrupt();
46         _decode_thread.join();
47 }
48
49 const srd_decoder* Decoder::get_decoder() const
50 {
51         return _decoder;
52 }
53
54 void Decoder::begin_decode()
55 {
56         _decode_thread.interrupt();
57         _decode_thread.join();
58
59         _decode_thread = boost::thread(&Decoder::decode_proc, this,
60                 shared_ptr<data::Logic>());
61 }
62
63 void Decoder::clear_snapshots()
64 {
65 }
66
67 void Decoder::init_decoder()
68 {
69         _decoder_inst = srd_inst_new(_decoder->id, NULL);
70         assert(_decoder_inst);
71
72         GHashTable *probes = g_hash_table_new_full(g_str_hash,
73                 g_str_equal, g_free, (GDestroyNotify)g_variant_unref);
74
75         for(map<const srd_probe*, shared_ptr<view::Signal> >::
76                 const_iterator i = _probes.begin();
77                 i != _probes.end(); i++)
78         {
79                 shared_ptr<view::Signal> signal((*i).second);
80                 GVariant *const gvar = g_variant_new_int32(
81                         signal->probe()->index);
82                 g_variant_ref_sink(gvar);
83                 g_hash_table_insert(probes, (*i).first->id, gvar);
84         }
85
86         srd_inst_probe_set_all(_decoder_inst, probes);
87 }
88
89 void Decoder::decode_proc(shared_ptr<data::Logic> data)
90 {
91         (void)data;
92 }
93
94 } // namespace data
95 } // namespace pv