configure.ac: Bump package version to 0.7.1.
[sigrok-cli.git] / main.c
diff --git a/main.c b/main.c
index 8c957e9d50ed9532942e659cb30965e545cccf25..689c2d57496ba5b4506698165318a88459ea7e2e 100644 (file)
--- a/main.c
+++ b/main.c
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "sigrok-cli.h"
+#include <config.h>
 #include <stdlib.h>
 #include <glib.h>
+#include "sigrok-cli.h"
 
 struct sr_context *sr_ctx = NULL;
 #ifdef HAVE_SRD
@@ -50,6 +51,7 @@ static void logger(const gchar *log_domain, GLogLevelFlags log_level,
 int select_channels(struct sr_dev_inst *sdi)
 {
        struct sr_channel *ch;
+       gboolean enabled;
        GSList *selected_channels, *l, *channels;
 
        channels = sr_dev_inst_channels_get(sdi);
@@ -60,10 +62,9 @@ int select_channels(struct sr_dev_inst *sdi)
 
                for (l = channels; l; l = l->next) {
                        ch = l->data;
-                       if (g_slist_find(selected_channels, ch))
-                               ch->enabled = TRUE;
-                       else
-                               ch->enabled = FALSE;
+                       enabled = (g_slist_find(selected_channels, ch) != NULL);
+                       if (sr_dev_channel_enable(ch, enabled) != SR_OK)
+                               return SR_ERR;
                }
                g_slist_free(selected_channels);
        }
@@ -73,40 +74,11 @@ int select_channels(struct sr_dev_inst *sdi)
        return SR_OK;
 }
 
-gboolean config_key_has_cap(struct sr_dev_driver *driver,
-               const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
-               uint32_t key, uint32_t capability)
-{
-       GVariant *gvar_opts;
-       const uint32_t *opts;
-       gsize num_opts, i;
-       gboolean result;
-
-       if (sr_config_list(driver, sdi, cg, SR_CONF_DEVICE_OPTIONS,
-                       &gvar_opts) != SR_OK)
-               return FALSE;
-
-       opts = g_variant_get_fixed_array(gvar_opts, &num_opts, sizeof(uint32_t));
-       result = FALSE;
-       for (i = 0; i < num_opts; i++) {
-               if ((opts[i] & SR_CONF_MASK) == key) {
-                       if ((opts[i] & capability) == capability)
-                               result = TRUE;
-                       else
-                               result = FALSE;
-                       break;
-               }
-       }
-       g_variant_unref(gvar_opts);
-
-       return result;
-}
-
 int maybe_config_get(struct sr_dev_driver *driver,
                const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
                uint32_t key, GVariant **gvar)
 {
-       if (config_key_has_cap(driver, sdi, cg, key, SR_CONF_GET))
+       if (sr_dev_config_capabilities_list(sdi, cg, key) & SR_CONF_GET)
                return sr_config_get(driver, sdi, cg, key, gvar);
 
        return SR_ERR_NA;
@@ -116,7 +88,9 @@ int maybe_config_set(struct sr_dev_driver *driver,
                const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
                uint32_t key, GVariant *gvar)
 {
-       if (config_key_has_cap(driver, sdi, cg, key, SR_CONF_SET))
+       (void)driver;
+
+       if (sr_dev_config_capabilities_list(sdi, cg, key) & SR_CONF_SET)
                return sr_config_set(sdi, cg, key, gvar);
 
        return SR_ERR_NA;
@@ -126,7 +100,7 @@ int maybe_config_list(struct sr_dev_driver *driver,
                const struct sr_dev_inst *sdi, struct sr_channel_group *cg,
                uint32_t key, GVariant **gvar)
 {
-       if (config_key_has_cap(driver, sdi, cg, key, SR_CONF_LIST))
+       if (sr_dev_config_capabilities_list(sdi, cg, key) & SR_CONF_LIST)
                return sr_config_list(driver, sdi, cg, key, gvar);
 
        return SR_ERR_NA;
@@ -136,7 +110,7 @@ static void get_option(void)
 {
        struct sr_dev_inst *sdi;
        struct sr_channel_group *cg;
-       const struct sr_config_info *ci;
+       const struct sr_key_info *ci;
        GSList *devices;
        GVariant *gvar;
        GHashTable *devargs;
@@ -159,12 +133,13 @@ static void get_option(void)
        }
 
        cg = select_channel_group(sdi);
-       if (!(ci = sr_config_info_name_get(opt_get)))
+       if (!(ci = sr_key_info_name_get(SR_KEY_CONFIG, opt_get)))
                g_critical("Unknown option '%s'", opt_get);
 
        if ((devargs = parse_generic_arg(opt_config, FALSE)))
                set_dev_options(sdi, devargs);
-       else devargs = NULL;
+       else
+               devargs = NULL;
 
        if ((ret = maybe_config_get(driver, sdi, cg, ci->key, &gvar)) != SR_OK)
                g_critical("Failed to get '%s': %s", opt_get, sr_strerror(ret));
@@ -240,8 +215,6 @@ int main(int argc, char **argv)
                }
                if (register_pds(opt_pds, opt_pd_annotations) != 0)
                        goto done;
-               if (setup_pd_stack(opt_pds, opt_pd_stack, opt_pd_annotations) != 0)
-                       goto done;
 
                /* Only one output type is ever shown. */
                if (opt_pd_binary) {
@@ -269,6 +242,8 @@ int main(int argc, char **argv)
 
        if (opt_version)
                show_version();
+       else if (opt_list_supported)
+               show_supported();
        else if (opt_input_format && opt_show)
                show_input();
        else if (opt_output_format && opt_show)