2 * This file is part of the PulseView project.
4 * Copyright (C) 2013 Joel Holdsworth <joel@airwebreathe.org.uk>
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.
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.
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
21 #include <libsigrokdecode/libsigrokdecode.h>
23 #include "decoderoptions.h"
25 #include <boost/foreach.hpp>
26 #include <boost/none_t.hpp>
28 #include <pv/data/decoder.h>
29 #include <pv/prop/int.h>
30 #include <pv/prop/string.h>
32 using namespace boost;
39 DecoderOptions::DecoderOptions(shared_ptr<pv::data::Decoder> decoder) :
44 const srd_decoder *const dec = _decoder->decoder();
47 for (GSList *l = dec->options; l; l = l->next)
49 const srd_decoder_option *const opt =
50 (srd_decoder_option*)l->data;
52 const QString name(opt->desc);
54 const Property::Getter getter = bind(
55 &DecoderOptions::getter, this, opt->id);
56 const Property::Setter setter = bind(
57 &DecoderOptions::setter, this, opt->id, _1);
59 shared_ptr<Property> prop;
61 if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("x")))
62 prop = shared_ptr<Property>(
63 new Int(name, "", none, getter, setter));
64 else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s")))
65 prop = shared_ptr<Property>(
66 new String(name, getter, setter));
70 _properties.push_back(prop);
74 GVariant* DecoderOptions::getter(const char *id)
78 // Get the value from the hash table if it is already present
79 GVariant *val = (GVariant*)g_hash_table_lookup(
80 (GHashTable*)_decoder->options(), id);
84 assert(_decoder->decoder());
86 // Get the default value if not
87 for (GSList *l = _decoder->decoder()->options; l; l = l->next)
89 const srd_decoder_option *const opt =
90 (srd_decoder_option*)l->data;
91 if (strcmp(opt->id, id) == 0) {
104 void DecoderOptions::setter(const char *id, GVariant *value)
107 _decoder->set_option(id, value);