From: Bert Vermeulen Date: Tue, 30 Apr 2013 14:03:37 +0000 (+0200) Subject: output: Use sr_config_get() wrapper X-Git-Tag: dsupstream~26 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=af51a7718eb22e9630107af814db6ae9f179a969;p=libsigrok.git output: Use sr_config_get() wrapper This obviates the need for a valid driver, and thus makes converting from any (non-sr) input format to any output format possible; the only thing missing is the samplerate. Fixes bug 105. --- diff --git a/output/chronovu_la8.c b/output/chronovu_la8.c index 3a8aee45..a6184da2 100644 --- a/output/chronovu_la8.c +++ b/output/chronovu_la8.c @@ -105,11 +105,6 @@ static int init(struct sr_output *o) return SR_ERR_ARG; } - if (!o->sdi->driver) { - sr_warn("%s: o->sdi->driver was NULL", __func__); - return SR_ERR_ARG; - } - if (!(ctx = g_try_malloc0(sizeof(struct context)))) { sr_warn("%s: ctx malloc failed", __func__); return SR_ERR_MALLOC; @@ -126,8 +121,8 @@ 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, &gvar, o->sdi); + if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar, + o->sdi) == SR_OK) { ctx->samplerate = g_variant_get_uint64(gvar); g_variant_unref(gvar); } else diff --git a/output/csv.c b/output/csv.c index a12d6519..0b70b2d6 100644 --- a/output/csv.c +++ b/output/csv.c @@ -73,11 +73,6 @@ static int init(struct sr_output *o) return SR_ERR_ARG; } - if (!o->sdi->driver) { - sr_err("%s: o->sdi->driver was NULL", __func__); - return SR_ERR_ARG; - } - if (!(ctx = g_try_malloc0(sizeof(struct context)))) { sr_err("%s: ctx malloc failed", __func__); return SR_ERR_MALLOC; @@ -96,8 +91,8 @@ 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, &gvar, o->sdi); + if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar, + o->sdi) == SR_OK) { ctx->samplerate = g_variant_get_uint64(gvar); g_variant_unref(gvar); } else diff --git a/output/gnuplot.c b/output/gnuplot.c index 7c033a91..9e1f2af6 100644 --- a/output/gnuplot.c +++ b/output/gnuplot.c @@ -78,11 +78,6 @@ static int init(struct sr_output *o) return SR_ERR_ARG; } - if (!o->sdi->driver) { - sr_err("%s: o->sdi->driver was NULL", __func__); - return SR_ERR_ARG; - } - if (!(ctx = g_try_malloc0(sizeof(struct context)))) { sr_err("%s: ctx malloc failed", __func__); return SR_ERR_MALLOC; @@ -100,19 +95,18 @@ 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, &gvar, o->sdi); + if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar, + o->sdi) == SR_OK) { samplerate = g_variant_get_uint64(gvar); + g_variant_unref(gvar); if (!(frequency_s = sr_samplerate_string(samplerate))) { sr_err("%s: sr_samplerate_string failed", __func__); 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 */ diff --git a/output/text/text.c b/output/text/text.c index 4d231c90..58094223 100644 --- a/output/text/text.c +++ b/output/text/text.c @@ -129,14 +129,12 @@ 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)) { - if ((ret = o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, - o->sdi)) != SR_OK) - goto err; + if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar, + o->sdi) == SR_OK) { samplerate = g_variant_get_uint64(gvar); + g_variant_unref(gvar); if (!(samplerate_s = sr_samplerate_string(samplerate))) { ret = SR_ERR; - g_variant_unref(gvar); goto err; } snprintf(ctx->header + strlen(ctx->header), @@ -144,7 +142,6 @@ 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 6e13d704..d8928492 100644 --- a/output/vcd.c +++ b/output/vcd.c @@ -95,19 +95,18 @@ static int init(struct sr_output *o) g_string_append_printf(ctx->header, "$version %s %s $end\n", PACKAGE, PACKAGE_VERSION); - if (o->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) { - o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi); + if (sr_config_get(o->sdi->driver, SR_CONF_SAMPLERATE, &gvar, + o->sdi) == SR_OK) { ctx->samplerate = g_variant_get_uint64(gvar); + g_variant_unref(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 */