From: Joel Holdsworth Date: Tue, 1 Jan 2013 19:47:07 +0000 (+0000) Subject: Create decoder instance X-Git-Tag: pulseview-0.2.0~308 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e332f6d399ecba201389c1e048239a7fe0cc87d5;p=pulseview.git Create decoder instance --- diff --git a/pv/data/decoder.cpp b/pv/data/decoder.cpp index cdfe57f9..65854ee0 100644 --- a/pv/data/decoder.cpp +++ b/pv/data/decoder.cpp @@ -18,10 +18,15 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#include + #include "decoder.h" #include +using namespace boost; +using namespace std; + namespace pv { namespace data { @@ -29,8 +34,10 @@ Decoder::Decoder(const srd_decoder *const dec, std::map > probes) : _decoder(dec), - _probes(probes) + _probes(probes), + _decoder_inst(NULL) { + init_decoder(); } const srd_decoder* Decoder::get_decoder() const @@ -38,6 +45,28 @@ const srd_decoder* Decoder::get_decoder() const return _decoder; } +void Decoder::init_decoder() +{ + _decoder_inst = srd_inst_new(_decoder->id, NULL); + assert(_decoder_inst); + + GHashTable *probes = g_hash_table_new_full(g_str_hash, + g_str_equal, g_free, (GDestroyNotify)g_variant_unref); + + for(map >:: + const_iterator i = _probes.begin(); + i != _probes.end(); i++) + { + shared_ptr signal((*i).second); + GVariant *const gvar = g_variant_new_int32( + signal->probe()->index); + g_variant_ref_sink(gvar); + g_hash_table_insert(probes, (*i).first->id, gvar); + } + + srd_inst_probe_set_all(_decoder_inst, probes); +} + void Decoder::clear_snapshots() { } diff --git a/pv/data/decoder.h b/pv/data/decoder.h index ddcf6674..c4f71152 100644 --- a/pv/data/decoder.h +++ b/pv/data/decoder.h @@ -28,6 +28,7 @@ #include struct srd_decoder; +struct srd_decoder_inst; struct srd_probe; namespace pv { @@ -41,17 +42,23 @@ namespace data { class Decoder : public SignalData { public: - Decoder(const srd_decoder *const dec, std::map > probes); + Decoder(const srd_decoder *const decoder, + std::map > probes); const srd_decoder* get_decoder() const; void clear_snapshots(); +private: + void init_decoder(); + private: const srd_decoder *const _decoder; std::map > _probes; + + srd_decoder_inst *_decoder_inst; }; } // namespace data