From: Bert Vermeulen Date: Mon, 25 Mar 2013 19:27:26 +0000 (+0100) Subject: input/output modules: Adjust to GVariant-based sr_config_* functions X-Git-Tag: dsupstream~215 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=ec4063b83c9b8a0693b9837787306dd5405e076b;p=libsigrok.git input/output modules: Adjust to GVariant-based sr_config_* functions --- diff --git a/input/binary.c b/input/binary.c index 67d42f02..8484a80e 100644 --- a/input/binary.c +++ b/input/binary.c @@ -121,9 +121,11 @@ static int loadfile(struct sr_input *in, const char *filename) if (ctx->samplerate) { packet.type = SR_DF_META; packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, (const void *)&ctx->samplerate); + src = sr_config_new(SR_CONF_SAMPLERATE, + g_variant_new_uint64(ctx->samplerate)); meta.config = g_slist_append(NULL, src); sr_session_send(in->sdi, &packet); + sr_config_free(src); } /* Chop up the input file into chunks & send it to the session bus. */ diff --git a/input/chronovu_la8.c b/input/chronovu_la8.c index a78f3560..e8aef290 100644 --- a/input/chronovu_la8.c +++ b/input/chronovu_la8.c @@ -172,9 +172,10 @@ static int loadfile(struct sr_input *in, const char *filename) /* Send metadata about the SR_DF_LOGIC packets to come. */ packet.type = SR_DF_META; packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, (const void *)&samplerate); + src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate)); meta.config = g_slist_append(NULL, src); sr_session_send(in->sdi, &packet); + sr_config_free(src); /* TODO: Handle trigger point. */ diff --git a/input/vcd.c b/input/vcd.c index 814988f7..102c1bd0 100644 --- a/input/vcd.c +++ b/input/vcd.c @@ -571,9 +571,10 @@ static int loadfile(struct sr_input *in, const char *filename) packet.type = SR_DF_META; packet.payload = &meta; samplerate = ctx->samplerate / ctx->downsample; - src = sr_config_new(SR_CONF_SAMPLERATE, (const void *)&samplerate); + src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate)); meta.config = g_slist_append(NULL, src); sr_session_send(in->sdi, &packet); + sr_config_free(src); /* Parse the contents of the VCD file */ parse_contents(file, in->sdi, ctx); diff --git a/input/wav.c b/input/wav.c index 7cd75067..593f6fca 100644 --- a/input/wav.c +++ b/input/wav.c @@ -148,9 +148,11 @@ static int loadfile(struct sr_input *in, const char *filename) packet.type = SR_DF_META; packet.payload = &meta; - src = sr_config_new(SR_CONF_SAMPLERATE, (const void *)&ctx->samplerate); + src = sr_config_new(SR_CONF_SAMPLERATE, + g_variant_new_uint64(ctx->samplerate)); meta.config = g_slist_append(NULL, src); sr_session_send(in->sdi, &packet); + sr_config_free(src); if ((fd = open(filename, O_RDONLY)) == -1) return SR_ERR; diff --git a/output/chronovu_la8.c b/output/chronovu_la8.c index f5da904a..625d839b 100644 --- a/output/chronovu_la8.c +++ b/output/chronovu_la8.c @@ -94,7 +94,7 @@ static int init(struct sr_output *o) struct context *ctx; struct sr_probe *probe; GSList *l; - uint64_t *samplerate; + GVariant *gvar; if (!o) { sr_warn("%s: o was NULL", __func__); @@ -129,9 +129,9 @@ static int init(struct sr_output *o) ctx->unitsize = (ctx->num_enabled_probes + 7) / 8; if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { - o->sdi->driver->config_get(SR_CONF_SAMPLERATE, - (const void **)&samplerate, o->sdi); - ctx->samplerate = *samplerate; + o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); + ctx->samplerate = g_variant_get_uint64(gvar); + g_variant_unref(gvar); } else ctx->samplerate = 0; diff --git a/output/csv.c b/output/csv.c index e2901efb..844ca4fe 100644 --- a/output/csv.c +++ b/output/csv.c @@ -60,8 +60,8 @@ static int init(struct sr_output *o) struct context *ctx; struct sr_probe *probe; GSList *l; + GVariant *gvar; int num_probes; - uint64_t *samplerate; time_t t; unsigned int i; @@ -100,9 +100,9 @@ static int init(struct sr_output *o) num_probes = g_slist_length(o->sdi->probes); if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { - o->sdi->driver->config_get(SR_CONF_SAMPLERATE, - (const void **)&samplerate, o->sdi); - ctx->samplerate = *samplerate; + o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); + ctx->samplerate = g_variant_get_uint64(gvar); + g_variant_unref(gvar); } else ctx->samplerate = 0; diff --git a/output/gnuplot.c b/output/gnuplot.c index 96513898..a871bd3e 100644 --- a/output/gnuplot.c +++ b/output/gnuplot.c @@ -63,7 +63,8 @@ static int init(struct sr_output *o) struct context *ctx; struct sr_probe *probe; GSList *l; - uint64_t *samplerate; + GVariant *gvar; + uint64_t samplerate; unsigned int i; int b, num_probes; char *c, *frequency_s; @@ -99,7 +100,7 @@ static int init(struct sr_output *o) o->internal = ctx; ctx->num_enabled_probes = 0; for (l = o->sdi->probes; l; l = l->next) { - probe = l->data; /* TODO: Error checks. */ + probe = l->data; if (!probe->enabled) continue; ctx->probelist[ctx->num_enabled_probes++] = probe->name; @@ -109,18 +110,21 @@ static int init(struct sr_output *o) num_probes = g_slist_length(o->sdi->probes); comment[0] = '\0'; + samplerate = 0; if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { - o->sdi->driver->config_get(SR_CONF_SAMPLERATE, - (const void **)&samplerate, o->sdi); - if (!(frequency_s = sr_samplerate_string(*samplerate))) { + o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); + samplerate = g_variant_get_uint64(gvar); + if (!(frequency_s = sr_samplerate_string(samplerate))) { sr_err("%s: sr_samplerate_string failed", __func__); g_free(ctx->header); g_free(ctx); + g_variant_unref(gvar); return SR_ERR; } snprintf(comment, 127, gnuplot_header_comment, ctx->num_enabled_probes, num_probes, frequency_s); g_free(frequency_s); + g_variant_unref(gvar); } /* Columns / channels */ @@ -130,7 +134,7 @@ static int init(struct sr_output *o) sprintf(c, "# %d\t\t%s\n", i + 1, ctx->probelist[i]); } - if (!(frequency_s = sr_period_string(*samplerate))) { + if (!(frequency_s = sr_period_string(samplerate))) { sr_err("%s: sr_period_string failed", __func__); g_free(ctx->header); g_free(ctx); diff --git a/output/ols.c b/output/ols.c index 97694b8f..c3b5799c 100644 --- a/output/ols.c +++ b/output/ols.c @@ -51,7 +51,8 @@ static int init(struct sr_output *o) struct context *ctx; struct sr_probe *probe; GSList *l; - uint64_t *samplerate, tmp; + GVariant *gvar; + uint64_t samplerate; int num_enabled_probes; if (!(ctx = g_try_malloc(sizeof(struct context)))) { @@ -69,16 +70,16 @@ static int init(struct sr_output *o) } ctx->unitsize = (num_enabled_probes + 7) / 8; - if (o->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) - o->sdi->driver->config_get(SR_CONF_SAMPLERATE, - (const void **)&samplerate, o->sdi); - else { - tmp = 0; - samplerate = &tmp; + if (o->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { + o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); + samplerate = g_variant_get_uint64(gvar); + g_variant_unref(gvar); + } else { + samplerate = 0; } ctx->header = g_string_sized_new(512); - g_string_append_printf(ctx->header, ";Rate: %"PRIu64"\n", *samplerate); + g_string_append_printf(ctx->header, ";Rate: %"PRIu64"\n", samplerate); g_string_append_printf(ctx->header, ";Channels: %d\n", num_enabled_probes); g_string_append_printf(ctx->header, ";EnabledChannels: -1\n"); g_string_append_printf(ctx->header, ";Compressed: true\n"); diff --git a/output/text/text.c b/output/text/text.c index 71526b10..31bf3989 100644 --- a/output/text/text.c +++ b/output/text/text.c @@ -79,7 +79,8 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode) struct context *ctx; struct sr_probe *probe; GSList *l; - uint64_t *samplerate; + GVariant *gvar; + uint64_t samplerate; int num_probes, ret; char *samplerate_s; @@ -124,12 +125,13 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode) snprintf(ctx->header, 511, "%s\n", PACKAGE_STRING); num_probes = g_slist_length(o->sdi->probes); if (o->sdi->driver || sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { - ret = o->sdi->driver->config_get(SR_CONF_SAMPLERATE, - (const void **)&samplerate, o->sdi); - if (ret != SR_OK) + if ((ret = o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, + o->sdi)) != SR_OK) goto err; - if (!(samplerate_s = sr_samplerate_string(*samplerate))) { + samplerate = g_variant_get_uint64(gvar); + if (!(samplerate_s = sr_samplerate_string(samplerate))) { ret = SR_ERR; + g_variant_unref(gvar); goto err; } snprintf(ctx->header + strlen(ctx->header), @@ -137,6 +139,7 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode) "Acquisition with %d/%d probes at %s\n", ctx->num_enabled_probes, num_probes, samplerate_s); g_free(samplerate_s); + g_variant_unref(gvar); } ctx->linebuf_len = ctx->samples_per_line * 2 + 4; diff --git a/output/vcd.c b/output/vcd.c index b60890ae..829fcde7 100644 --- a/output/vcd.c +++ b/output/vcd.c @@ -53,7 +53,7 @@ static int init(struct sr_output *o) struct context *ctx; struct sr_probe *probe; GSList *l; - uint64_t *samplerate; + GVariant *gvar; int num_probes, i; char *samplerate_s, *frequency_s, *timestamp; time_t t; @@ -93,17 +93,18 @@ static int init(struct sr_output *o) PACKAGE, PACKAGE_VERSION); if (o->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { - o->sdi->driver->config_get(SR_CONF_SAMPLERATE, - (const void **)&samplerate, o->sdi); - ctx->samplerate = *samplerate; + o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); + ctx->samplerate = g_variant_get_uint64(gvar); if (!((samplerate_s = sr_samplerate_string(ctx->samplerate)))) { g_string_free(ctx->header, TRUE); g_free(ctx); + g_variant_unref(gvar); return SR_ERR; } g_string_append_printf(ctx->header, vcd_header_comment, ctx->num_enabled_probes, num_probes, samplerate_s); g_free(samplerate_s); + g_variant_unref(gvar); } /* timescale */