From: Martin Ling Date: Sat, 6 Sep 2014 12:53:09 +0000 (+0100) Subject: C++: Add Configurable::config_check() method. X-Git-Tag: libsigrok-0.4.0~1025 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d9eed47d5bbf9c1a706fbda7ae56f87f7202f995;p=libsigrok.git C++: Add Configurable::config_check() method. --- diff --git a/bindings/cxx/classes.cpp b/bindings/cxx/classes.cpp index 68124b5a..dc8eded7 100644 --- a/bindings/cxx/classes.cpp +++ b/bindings/cxx/classes.cpp @@ -380,6 +380,34 @@ vector Configurable::config_keys(const ConfigKey *key) return result; } +bool Configurable::config_check(const ConfigKey *key, + const ConfigKey *index_key) +{ + GVariant *gvar_opts; + gsize num_opts; + const int32_t *opts; + + if (sr_config_list(config_driver, config_sdi, config_channel_group, + index_key->get_id(), &gvar_opts) != SR_OK) + return false; + + opts = (const int32_t *) g_variant_get_fixed_array( + gvar_opts, &num_opts, sizeof(int32_t)); + + for (gsize i = 0; i < num_opts; i++) + { + if (opts[i] == key->get_id()) + { + g_variant_unref(gvar_opts); + return true; + } + } + + g_variant_unref(gvar_opts); + + return false; +} + Device::Device(struct sr_dev_inst *structure) : Configurable(structure->driver, structure, NULL), structure(structure) diff --git a/bindings/cxx/include/libsigrok/libsigrok.hpp b/bindings/cxx/include/libsigrok/libsigrok.hpp index 637daf91..29d6c736 100644 --- a/bindings/cxx/include/libsigrok/libsigrok.hpp +++ b/bindings/cxx/include/libsigrok/libsigrok.hpp @@ -297,6 +297,8 @@ public: Glib::VariantContainerBase config_list(const ConfigKey *key); /** Enumerate available keys, according to a given index key. */ vector config_keys(const ConfigKey *key); + /** Check for a key in the list from a given index key. */ + bool config_check(const ConfigKey *key, const ConfigKey *index_key); protected: Configurable( struct sr_dev_driver *driver,