]> sigrok.org Git - pulseview.git/commitdiff
Create decoder instance
authorJoel Holdsworth <redacted>
Tue, 1 Jan 2013 19:47:07 +0000 (19:47 +0000)
committerJoel Holdsworth <redacted>
Sun, 29 Sep 2013 01:34:42 +0000 (10:34 +0900)
pv/data/decoder.cpp
pv/data/decoder.h

index cdfe57f9540b3bd8de3c8c787ed8121490567523..65854ee056b9384c1c0a7a774de78ee9fdb3f1b3 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
  */
 
+#include <libsigrokdecode/libsigrokdecode.h>
+
 #include "decoder.h"
 
 #include <pv/view/signal.h>
 
+using namespace boost;
+using namespace std;
+
 namespace pv {
 namespace data {
 
@@ -29,8 +34,10 @@ Decoder::Decoder(const srd_decoder *const dec,
        std::map<const srd_probe*,
                boost::shared_ptr<pv::view::Signal> > 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 srd_probe*, shared_ptr<view::Signal> >::
+               const_iterator i = _probes.begin();
+               i != _probes.end(); i++)
+       {
+               shared_ptr<view::Signal> 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()
 {
 }
index ddcf6674ba15c0d5bb59dc6abd37ae81a7683e33..c4f7115254141dc5f565960708c54ce47535d0a9 100644 (file)
@@ -28,6 +28,7 @@
 #include <boost/shared_ptr.hpp>
 
 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<const srd_probe*,
-               boost::shared_ptr<pv::view::Signal> > probes);
+       Decoder(const srd_decoder *const decoder,
+               std::map<const srd_probe*,
+                       boost::shared_ptr<pv::view::Signal> > probes);
 
        const srd_decoder* get_decoder() const;
 
        void clear_snapshots();
 
+private:
+       void init_decoder();
+
 private:
        const srd_decoder *const _decoder;
        std::map<const srd_probe*, boost::shared_ptr<view::Signal> >
                _probes;
+
+       srd_decoder_inst *_decoder_inst;
 };
 
 } // namespace data