]> sigrok.org Git - libsigrok.git/commitdiff
output: Use sr_config_get() wrapper
authorBert Vermeulen <redacted>
Tue, 30 Apr 2013 14:03:37 +0000 (16:03 +0200)
committerBert Vermeulen <redacted>
Tue, 30 Apr 2013 14:03:37 +0000 (16:03 +0200)
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.

output/chronovu_la8.c
output/csv.c
output/gnuplot.c
output/text/text.c
output/vcd.c

index 3a8aee4591d85cd313c3c471f55c461500e6c023..a6184da2f00fd14087845fdb3a9128cf1bf60865 100644 (file)
@@ -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
index a12d6519aa1a35b9afbec5c714a6cc378473498f..0b70b2d6cf9803af0fc6c1a02a4d5dec6ace3c23 100644 (file)
@@ -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
index 7c033a91c3136f9016c7355605b5c129121c6a1d..9e1f2af6c3e4e081278c828e6a6099e85557472a 100644 (file)
@@ -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 */
index 4d231c90da4ab797e100a24469cab28ae345603f..580942238aec1c62bef2bfd51072ff29ec4c56ff 100644 (file)
@@ -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;
index 6e13d7046b17655c4db9251a5a15cb3e5f64a574..d89284927602a55d7a3e87beb5753b0d02e0cf07 100644 (file)
@@ -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 */