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 "decoderoptions.h"
23 #include <boost/foreach.hpp>
24 #include <boost/none_t.hpp>
26 #include <pv/prop/int.h>
27 #include <pv/prop/string.h>
29 using namespace boost;
36 DecoderOptions::DecoderOptions(const srd_decoder *decoder,
37 GHashTable *options) :
44 for (GSList *l = decoder->options; l; l = l->next)
46 const srd_decoder_option *const opt =
47 (srd_decoder_option*)l->data;
49 const QString name(opt->desc);
51 const Property::Getter getter = bind(
52 &DecoderOptions::getter, this, opt->id);
53 const Property::Setter setter = bind(
54 &DecoderOptions::setter, this, opt->id, _1);
56 shared_ptr<Property> prop;
58 if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("x")))
59 prop = shared_ptr<Property>(
60 new Int(name, "", none, getter, setter));
61 else if (g_variant_is_of_type(opt->def, G_VARIANT_TYPE("s")))
62 prop = shared_ptr<Property>(
63 new String(name, getter, setter));
67 _properties.push_back(prop);
71 GVariant* DecoderOptions::getter(const char *id)
73 // Get the value from the hash table if it is already present
74 GVariant *val = (GVariant*)g_hash_table_lookup(_options, id);
78 // Get the default value if not
79 for (GSList *l = _decoder->options; l; l = l->next)
81 const srd_decoder_option *const opt =
82 (srd_decoder_option*)l->data;
83 if (strcmp(opt->id, id) == 0)
94 void DecoderOptions::setter(const char *id, GVariant *value)
97 g_hash_table_insert(_options, (void*)id, value);