]> sigrok.org Git - sigrok-cli.git/commitdiff
Use getters now that 'struct sr_dev_inst' is opaque.
authorUwe Hermann <redacted>
Tue, 11 Nov 2014 15:32:33 +0000 (16:32 +0100)
committerUwe Hermann <redacted>
Tue, 11 Nov 2014 15:34:35 +0000 (16:34 +0100)
decode.c
device.c
main.c
parsers.c
session.c
show.c

index b020b68baab2ea14aedfea89ee202179216ce2c7..2e831f74ee1985a735e3da027a933ea2d3328bca 100644 (file)
--- a/decode.c
+++ b/decode.c
@@ -250,9 +250,13 @@ static void map_pd_inst_channels(void *key, void *value, void *user_data)
 
 void map_pd_channels(struct sr_dev_inst *sdi)
 {
+       GSList *channels;
+
+       channels = sr_dev_inst_channels_get(sdi);
+
        if (pd_channel_maps) {
                g_hash_table_foreach(pd_channel_maps, &map_pd_inst_channels,
-                                    sdi->channels);
+                                    channels);
                g_hash_table_destroy(pd_channel_maps);
                pd_channel_maps = NULL;
        }
index ea4d073bf98cfd08156176d77b64cf72fa146ca3..2a5d14a2a7267138498c1d1942e23fb2de02a0ec 100644 (file)
--- a/device.c
+++ b/device.c
@@ -64,17 +64,19 @@ GSList *device_scan(void)
 struct sr_channel_group *select_channel_group(struct sr_dev_inst *sdi)
 {
        struct sr_channel_group *cg;
-       GSList *l;
+       GSList *l, *channel_groups;
 
        if (!opt_channel_group)
                return NULL;
 
-       if (!sdi->channel_groups) {
+       channel_groups = sr_dev_inst_channel_groups_get(sdi);
+
+       if (!channel_groups) {
                g_critical("This device does not have any channel groups.");
                return NULL;
        }
 
-       for (l = sdi->channel_groups; l; l = l->next) {
+       for (l = channel_groups; l; l = l->next) {
                cg = l->data;
                if (!strcasecmp(opt_channel_group, cg->name)) {
                        return cg;
diff --git a/main.c b/main.c
index 17076724388c7808bc9fa21d16fac1e7a8e46390..81dc4ad21055a11bfc6f199d1dff732e388eb620 100644 (file)
--- a/main.c
+++ b/main.c
@@ -50,13 +50,15 @@ static void logger(const gchar *log_domain, GLogLevelFlags log_level,
 int select_channels(struct sr_dev_inst *sdi)
 {
        struct sr_channel *ch;
-       GSList *selected_channels, *l;
+       GSList *selected_channels, *l, *channels;
+
+       channels = sr_dev_inst_channels_get(sdi);
 
        if (opt_channels) {
                if (!(selected_channels = parse_channelstring(sdi, opt_channels)))
                        return SR_ERR;
 
-               for (l = sdi->channels; l; l = l->next) {
+               for (l = channels; l; l = l->next) {
                        ch = l->data;
                        if (g_slist_find(selected_channels, ch))
                                ch->enabled = TRUE;
@@ -81,6 +83,7 @@ static void get_option(void)
        GHashTable *devargs;
        int ret;
        char *s;
+       struct sr_dev_driver *driver;
 
        if (!(devices = device_scan())) {
                g_critical("No devices found.");
@@ -89,6 +92,8 @@ static void get_option(void)
        sdi = devices->data;
        g_slist_free(devices);
 
+       driver = sr_dev_inst_driver_get(sdi);
+
        if (sr_dev_open(sdi) != SR_OK) {
                g_critical("Failed to open device.");
                return;
@@ -102,7 +107,7 @@ static void get_option(void)
                set_dev_options(sdi, devargs);
        else devargs = NULL;
 
-       if ((ret = sr_config_get(sdi->driver, sdi, cg, ci->key, &gvar)) != SR_OK)
+       if ((ret = sr_config_get(driver, sdi, cg, ci->key, &gvar)) != SR_OK)
                g_critical("Failed to get '%s': %s", opt_get, sr_strerror(ret));
        s = g_variant_print(gvar, FALSE);
        printf("%s\n", s);
index ad5f37925f7d0e156e9158e0865f813c2de6d70d..ee992712bd126fb261fea9991e9e529dba260fb0 100644 (file)
--- a/parsers.c
+++ b/parsers.c
@@ -45,13 +45,15 @@ struct sr_channel *find_channel(GSList *channellist, const char *channelname)
 GSList *parse_channelstring(struct sr_dev_inst *sdi, const char *channelstring)
 {
        struct sr_channel *ch;
-       GSList *channellist;
+       GSList *channellist, *channels;
        int ret, n, b, e, i;
        char **tokens, **range, **names, *eptr, str[8];
 
+       channels = sr_dev_inst_channels_get(sdi);
+
        if (!channelstring || !channelstring[0])
                /* Use all channels by default. */
-               return g_slist_copy(sdi->channels);
+               return g_slist_copy(channels);
 
        ret = SR_OK;
        range = NULL;
@@ -102,7 +104,7 @@ GSList *parse_channelstring(struct sr_dev_inst *sdi, const char *channelstring)
                                        ret = SR_ERR;
                                        break;
                                }
-                               ch = find_channel(sdi->channels, str);
+                               ch = find_channel(channels, str);
                                if (!ch) {
                                        g_critical("unknown channel '%d'.", b);
                                        ret = SR_ERR;
@@ -127,7 +129,7 @@ range_fail:
                                break;
                        }
 
-                       ch = find_channel(sdi->channels, names[0]);
+                       ch = find_channel(channels, names[0]);
                        if (!ch) {
                                g_critical("unknown channel '%s'.", names[0]);
                                g_strfreev(names);
@@ -185,7 +187,7 @@ int parse_triggerstring(const struct sr_dev_inst *sdi, const char *s,
        struct sr_channel *ch;
        struct sr_trigger_stage *stage;
        GVariant *gvar;
-       GSList *l;
+       GSList *l, *channels;
        gsize num_matches;
        gboolean found_match, error;
        const int32_t *matches;
@@ -193,8 +195,12 @@ int parse_triggerstring(const struct sr_dev_inst *sdi, const char *s,
        unsigned int j;
        int t, i;
        char **tokens, *sep;
+       struct sr_dev_driver *driver;
+
+       driver = sr_dev_inst_driver_get(sdi);
+       channels = sr_dev_inst_channels_get(sdi);
 
-       if (sr_config_list(sdi->driver, sdi, NULL, SR_CONF_TRIGGER_MATCH,
+       if (sr_config_list(driver, sdi, NULL, SR_CONF_TRIGGER_MATCH,
                        &gvar) != SR_OK) {
                g_critical("Device doesn't support any triggers.");
                return FALSE;
@@ -212,7 +218,7 @@ int parse_triggerstring(const struct sr_dev_inst *sdi, const char *s,
                }
                *sep++ = 0;
                ch = NULL;
-               for (l = sdi->channels; l; l = l->next) {
+               for (l = channels; l; l = l->next) {
                        ch = l->data;
                        if (ch->enabled && !strcmp(ch->name, tokens[i]))
                                break;
index 65cc2918d37adf0a95e0a49f0226479636e69806..dad592b381a1955caef9be0e9c81110c8cc226ed 100644 (file)
--- a/session.c
+++ b/session.c
@@ -36,6 +36,9 @@ static int set_limit_time(const struct sr_dev_inst *sdi)
        GVariant *gvar;
        uint64_t time_msec;
        uint64_t samplerate;
+       struct sr_dev_driver *driver;
+
+       driver = sr_dev_inst_driver_get(sdi);
 
        if (!(time_msec = sr_parse_timestring(opt_time))) {
                g_critical("Invalid time '%s'", opt_time);
@@ -50,7 +53,7 @@ static int set_limit_time(const struct sr_dev_inst *sdi)
                }
        } else if (sr_dev_has_option(sdi, SR_CONF_SAMPLERATE)) {
                /* Convert to samples based on the samplerate.  */
-               sr_config_get(sdi->driver, sdi, NULL, SR_CONF_SAMPLERATE, &gvar);
+               sr_config_get(driver, sdi, NULL, SR_CONF_SAMPLERATE, &gvar);
                samplerate = g_variant_get_uint64(gvar);
                g_variant_unref(gvar);
                limit_samples = (samplerate) * time_msec / (uint64_t)1000;
@@ -130,13 +133,17 @@ void datafeed_in(const struct sr_dev_inst *sdi,
        static uint64_t samplerate = 0;
        static int triggered = 0;
        static FILE *outfile = NULL;
-       GSList *l;
+       GSList *l, *channels_sdi;
        GString *out;
        GVariant *gvar;
        uint64_t end_sample;
        uint64_t input_len;
        int i;
        char **channels;
+       struct sr_dev_driver *driver;
+
+       driver = sr_dev_inst_driver_get(sdi);
+       channels_sdi = sr_dev_inst_channels_get(sdi);
 
        /* If the first packet to come in isn't a header, don't even try. */
        if (packet->type != SR_DF_HEADER && o == NULL)
@@ -165,7 +172,7 @@ void datafeed_in(const struct sr_dev_inst *sdi,
                }
                rcvd_samples_logic = rcvd_samples_analog = 0;
 
-               if (sr_config_get(sdi->driver, sdi, NULL, SR_CONF_SAMPLERATE,
+               if (sr_config_get(driver, sdi, NULL, SR_CONF_SAMPLERATE,
                                &gvar) == SR_OK) {
                        samplerate = g_variant_get_uint64(gvar);
                        g_variant_unref(gvar);
@@ -246,8 +253,8 @@ void datafeed_in(const struct sr_dev_inst *sdi,
                        /* Saving to a session file. */
                        if (rcvd_samples_logic == 0) {
                                /* First packet with logic data, init session file. */
-                               channels = g_malloc(sizeof(char *) * g_slist_length(sdi->channels));
-                               for (i = 0, l = sdi->channels; l; l = l->next) {
+                               channels = g_malloc(sizeof(char *) * g_slist_length(channels_sdi));
+                               for (i = 0, l = channels_sdi; l; l = l->next) {
                                        ch = l->data;
                                        if (ch->type == SR_CHANNEL_LOGIC)
                                                channels[i++] = ch->name;
@@ -468,6 +475,7 @@ void run_session(void)
        gsize n_elements, i;
        const uint32_t *dev_opts;
        int is_demo_dev;
+       struct sr_dev_driver *driver;
 
        devices = device_scan();
        if (!devices) {
@@ -479,7 +487,9 @@ void run_session(void)
        for (sd = devices; sd; sd = sd->next) {
                sdi = sd->data;
 
-               if (sr_config_list(sdi->driver, sdi, NULL, SR_CONF_DEVICE_OPTIONS, &gvar) != SR_OK) {
+               driver = sr_dev_inst_driver_get(sdi);
+
+               if (sr_config_list(driver, sdi, NULL, SR_CONF_DEVICE_OPTIONS, &gvar) != SR_OK) {
                        g_critical("Failed to query sr_config_list(SR_CONF_DEVICE_OPTIONS).");
                        return;
                }
@@ -574,7 +584,7 @@ void run_session(void)
                        sr_session_destroy(session);
                        return;
                }
-               if (sr_config_list(sdi->driver, sdi, NULL,
+               if (sr_config_list(driver, sdi, NULL,
                                SR_CONF_LIMIT_SAMPLES, &gvar) == SR_OK) {
                        /* The device has no compression, or compression is turned
                         * off, and publishes its sample memory size. */
diff --git a/show.c b/show.c
index fa2305f0f98b675c86e744f86b062d978f5b0652..86845ff2d6183385981afae3256677c830b20197 100644 (file)
--- a/show.c
+++ b/show.c
@@ -138,30 +138,38 @@ static gint sort_channels(gconstpointer a, gconstpointer b)
 static void print_dev_line(const struct sr_dev_inst *sdi)
 {
        struct sr_channel *ch;
-       GSList *sl, *l;
+       GSList *sl, *l, *channels;
        GString *s;
        GVariant *gvar;
+       struct sr_dev_driver *driver;
+       const char *vendor, *model, *version;
+
+       driver = sr_dev_inst_driver_get(sdi);
+       vendor = sr_dev_inst_vendor_get(sdi);
+       model = sr_dev_inst_model_get(sdi);
+       version = sr_dev_inst_version_get(sdi);
+       channels = sr_dev_inst_channels_get(sdi);
 
        s = g_string_sized_new(128);
-       g_string_assign(s, sdi->driver->name);
-       if (sr_config_get(sdi->driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) {
+       g_string_assign(s, driver->name);
+       if (sr_config_get(driver, sdi, NULL, SR_CONF_CONN, &gvar) == SR_OK) {
                g_string_append(s, ":conn=");
                g_string_append(s, g_variant_get_string(gvar, NULL));
                g_variant_unref(gvar);
        }
        g_string_append(s, " - ");
-       if (sdi->vendor && sdi->vendor[0])
-               g_string_append_printf(s, "%s ", sdi->vendor);
-       if (sdi->model && sdi->model[0])
-               g_string_append_printf(s, "%s ", sdi->model);
-       if (sdi->version && sdi->version[0])
-               g_string_append_printf(s, "%s ", sdi->version);
-       if (sdi->channels) {
-               if (g_slist_length(sdi->channels) == 1) {
-                       ch = sdi->channels->data;
+       if (vendor && vendor[0])
+               g_string_append_printf(s, "%s ", vendor);
+       if (model && model[0])
+               g_string_append_printf(s, "%s ", model);
+       if (version && version[0])
+               g_string_append_printf(s, "%s ", version);
+       if (channels) {
+               if (g_slist_length(channels) == 1) {
+                       ch = channels->data;
                        g_string_append_printf(s, "with 1 channel: %s", ch->name);
                } else {
-                       sl = g_slist_sort(g_slist_copy(sdi->channels), sort_channels);
+                       sl = g_slist_sort(g_slist_copy(channels), sort_channels);
                        g_string_append_printf(s, "with %d channels:", g_slist_length(sl));
                        for (l = sl; l; l = l->next) {
                                ch = l->data;
@@ -233,12 +241,12 @@ void show_drv_detail(struct sr_dev_driver *driver)
 
 void show_dev_detail(void)
 {
-       struct sr_dev_driver *driver;
+       struct sr_dev_driver *driver_from_opt, *driver;
        struct sr_dev_inst *sdi;
        const struct sr_config_info *srci;
        struct sr_channel *ch;
        struct sr_channel_group *channel_group, *cg;
-       GSList *devices, *cgl, *chl;
+       GSList *devices, *cgl, *chl, *channel_groups;
        GVariant *gvar_opts, *gvar_dict, *gvar_list, *gvar;
        gsize num_opts, num_elements;
        double dlow, dhigh, dcur_low, dcur_high;
@@ -251,9 +259,9 @@ void show_dev_detail(void)
        char *tmp_str, *s, c;
        const char **stropts;
 
-       if (parse_driver(opt_drv, &driver, NULL)) {
+       if (parse_driver(opt_drv, &driver_from_opt, NULL)) {
                /* A driver was specified, report driver-wide options now. */
-               show_drv_detail(driver);
+               show_drv_detail(driver_from_opt);
        }
 
        if (!(devices = device_scan())) {
@@ -272,6 +280,9 @@ void show_dev_detail(void)
        g_slist_free(devices);
        print_dev_line(sdi);
 
+       driver = sr_dev_inst_driver_get(sdi);
+       channel_groups = sr_dev_inst_channel_groups_get(sdi);
+
        if (sr_dev_open(sdi) != SR_OK) {
                g_critical("Failed to open device.");
                return;
@@ -282,14 +293,14 @@ void show_dev_detail(void)
        select_channels(sdi);
        channel_group = select_channel_group(sdi);
 
-       if ((sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_DEVICE_OPTIONS,
+       if ((sr_config_list(driver, sdi, channel_group, SR_CONF_DEVICE_OPTIONS,
                        &gvar_opts)) != SR_OK)
                /* Driver supports no device instance options. */
                return;
 
-       if (sdi->channel_groups) {
+       if (channel_groups) {
                printf("Channel groups:\n");
-               for (cgl = sdi->channel_groups; cgl; cgl = cgl->next) {
+               for (cgl = channel_groups; cgl; cgl = cgl->next) {
                        cg = cgl->data;
                        printf("    %s: channel%s", cg->name,
                                        g_slist_length(cg->channels) > 1 ? "s" : "");
@@ -302,7 +313,7 @@ void show_dev_detail(void)
        }
 
        printf("Supported configuration options");
-       if (sdi->channel_groups) {
+       if (channel_groups) {
                if (!channel_group)
                        printf(" across all channel groups");
                else
@@ -316,7 +327,7 @@ void show_dev_detail(void)
                        continue;
 
                if (key == SR_CONF_TRIGGER_MATCH) {
-                       if (sr_config_list(sdi->driver, sdi, channel_group, key,
+                       if (sr_config_list(driver, sdi, channel_group, key,
                                        &gvar_list) != SR_OK) {
                                printf("\n");
                                continue;
@@ -364,7 +375,7 @@ void show_dev_detail(void)
                         * only to those that don't support compression, or
                         * have it turned off by default. The values returned
                         * are the low/high limits. */
-                       if (sr_config_list(sdi->driver, sdi, channel_group, key,
+                       if (sr_config_list(driver, sdi, channel_group, key,
                                        &gvar) != SR_OK) {
                                continue;
                        }
@@ -375,7 +386,7 @@ void show_dev_detail(void)
                } else if (key == SR_CONF_SAMPLERATE) {
                        /* Supported samplerates */
                        printf("    %s", srci->id);
-                       if (sr_config_list(sdi->driver, sdi, channel_group, SR_CONF_SAMPLERATE,
+                       if (sr_config_list(driver, sdi, channel_group, SR_CONF_SAMPLERATE,
                                        &gvar_dict) != SR_OK) {
                                printf("\n");
                                continue;
@@ -418,13 +429,13 @@ void show_dev_detail(void)
                } else if (srci->datatype == SR_T_UINT64) {
                        printf("    %s", srci->id);
                        gvar = NULL;
-                       if (sr_config_get(sdi->driver, sdi, channel_group, key,
+                       if (sr_config_get(driver, sdi, channel_group, key,
                                        &gvar) == SR_OK) {
                                tmp_uint64 = g_variant_get_uint64(gvar);
                                g_variant_unref(gvar);
                        } else
                                tmp_uint64 = 0;
-                       if (sr_config_list(sdi->driver, sdi, channel_group,
+                       if (sr_config_list(driver, sdi, channel_group,
                                        SR_CONF_BUFFERSIZE, &gvar_list) != SR_OK) {
                                if (gvar) {
                                        /* Can't list it, but we have a value to show. */
@@ -446,14 +457,14 @@ void show_dev_detail(void)
 
                } else if (srci->datatype == SR_T_STRING) {
                        printf("    %s: ", srci->id);
-                       if (sr_config_get(sdi->driver, sdi, channel_group, key,
+                       if (sr_config_get(driver, sdi, channel_group, key,
                                        &gvar) == SR_OK) {
                                tmp_str = g_strdup(g_variant_get_string(gvar, NULL));
                                g_variant_unref(gvar);
                        } else
                                tmp_str = NULL;
 
-                       if (sr_config_list(sdi->driver, sdi, channel_group, key,
+                       if (sr_config_list(driver, sdi, channel_group, key,
                                        &gvar) != SR_OK) {
                                if (tmp_str) {
                                        /* Can't list it, but we have a value to show. */
@@ -479,13 +490,13 @@ void show_dev_detail(void)
 
                } else if (srci->datatype == SR_T_UINT64_RANGE) {
                        printf("    %s: ", srci->id);
-                       if (sr_config_list(sdi->driver, sdi, channel_group, key,
+                       if (sr_config_list(driver, sdi, channel_group, key,
                                        &gvar_list) != SR_OK) {
                                printf("\n");
                                continue;
                        }
 
-                       if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) {
+                       if (sr_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
                                g_variant_get(gvar, "(tt)", &cur_low, &cur_high);
                                g_variant_unref(gvar);
                        } else {
@@ -509,7 +520,7 @@ void show_dev_detail(void)
 
                } else if (srci->datatype == SR_T_BOOL) {
                        printf("    %s: ", srci->id);
-                       if (sr_config_get(sdi->driver, sdi, channel_group, key,
+                       if (sr_config_get(driver, sdi, channel_group, key,
                                        &gvar) == SR_OK) {
                                if (g_variant_get_boolean(gvar))
                                        printf("on (current), off\n");
@@ -521,13 +532,13 @@ void show_dev_detail(void)
 
                } else if (srci->datatype == SR_T_DOUBLE_RANGE) {
                        printf("    %s: ", srci->id);
-                       if (sr_config_list(sdi->driver, sdi, channel_group, key,
+                       if (sr_config_list(driver, sdi, channel_group, key,
                                        &gvar_list) != SR_OK) {
                                printf("\n");
                                continue;
                        }
 
-                       if (sr_config_get(sdi->driver, sdi, channel_group, key, &gvar) == SR_OK) {
+                       if (sr_config_get(driver, sdi, channel_group, key, &gvar) == SR_OK) {
                                g_variant_get(gvar, "(dd)", &dcur_low, &dcur_high);
                                g_variant_unref(gvar);
                        } else {
@@ -551,7 +562,7 @@ void show_dev_detail(void)
 
                } else if (srci->datatype == SR_T_FLOAT) {
                        printf("    %s: ", srci->id);
-                       if (sr_config_get(sdi->driver, sdi, channel_group, key,
+                       if (sr_config_get(driver, sdi, channel_group, key,
                                        &gvar) == SR_OK) {
                                printf("%f\n", g_variant_get_double(gvar));
                                g_variant_unref(gvar);
@@ -561,14 +572,14 @@ void show_dev_detail(void)
                } else if (srci->datatype == SR_T_RATIONAL_PERIOD
                                || srci->datatype == SR_T_RATIONAL_VOLT) {
                        printf("    %s", srci->id);
-                       if (sr_config_get(sdi->driver, sdi, channel_group, key,
+                       if (sr_config_get(driver, sdi, channel_group, key,
                                        &gvar) == SR_OK) {
                                g_variant_get(gvar, "(tt)", &cur_p, &cur_q);
                                g_variant_unref(gvar);
                        } else
                                cur_p = cur_q = 0;
 
-                       if (sr_config_list(sdi->driver, sdi, channel_group,
+                       if (sr_config_list(driver, sdi, channel_group,
                                        key, &gvar_list) != SR_OK) {
                                printf("\n");
                                continue;