]> sigrok.org Git - libsigrok.git/blobdiff - output/gnuplot.c
probe_groups: API changes required to implement probe groups.
[libsigrok.git] / output / gnuplot.c
index 4157323af57f2f555dc09c7b37689bf43c7bce39..e93556f834b0aebed65a7b8a75f110ae8b99f6ba 100644 (file)
 #include "libsigrok.h"
 #include "libsigrok-internal.h"
 
-/* Message logging helpers with driver-specific prefix string. */
-#define DRIVER_LOG_DOMAIN "output/gnuplot: "
-#define sr_log(l, s, args...) sr_log(l, DRIVER_LOG_DOMAIN s, ## args)
-#define sr_spew(s, args...) sr_spew(DRIVER_LOG_DOMAIN s, ## args)
-#define sr_dbg(s, args...) sr_dbg(DRIVER_LOG_DOMAIN s, ## args)
-#define sr_info(s, args...) sr_info(DRIVER_LOG_DOMAIN s, ## args)
-#define sr_warn(s, args...) sr_warn(DRIVER_LOG_DOMAIN s, ## args)
-#define sr_err(s, args...) sr_err(DRIVER_LOG_DOMAIN s, ## args)
+/* Message logging helpers with subsystem-specific prefix string. */
+#define LOG_PREFIX "output/gnuplot: "
+#define sr_log(l, s, args...) sr_log(l, LOG_PREFIX s, ## args)
+#define sr_spew(s, args...) sr_spew(LOG_PREFIX s, ## args)
+#define sr_dbg(s, args...) sr_dbg(LOG_PREFIX s, ## args)
+#define sr_info(s, args...) sr_info(LOG_PREFIX s, ## args)
+#define sr_warn(s, args...) sr_warn(LOG_PREFIX s, ## args)
+#define sr_err(s, args...) sr_err(LOG_PREFIX s, ## args)
 
 struct context {
        unsigned int num_enabled_probes;
@@ -41,9 +41,6 @@ struct context {
        uint8_t *old_sample;
 };
 
-#define MAX_HEADER_LEN \
-       (1024 + (SR_MAX_NUM_PROBES * (SR_MAX_PROBENAME_LEN + 10)))
-
 static const char *gnuplot_header = "\
 # Sample data in space-separated columns format usable by gnuplot\n\
 #\n\
@@ -66,7 +63,7 @@ static int init(struct sr_output *o)
        GVariant *gvar;
        uint64_t samplerate;
        unsigned int i;
-       int b, num_probes;
+       int num_probes;
        char *c, *frequency_s;
        char wbuf[1000], comment[128];
        time_t t;
@@ -81,22 +78,11 @@ 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;
        }
 
-       if (!(ctx->header = g_try_malloc0(MAX_HEADER_LEN + 1))) {
-               sr_err("%s: ctx->header malloc failed", __func__);
-               g_free(ctx);
-               return SR_ERR_MALLOC;
-       }
-
        o->internal = ctx;
        ctx->num_enabled_probes = 0;
        for (l = o->sdi->probes; l; l = l->next) {
@@ -109,20 +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, o->sdi, NULL, SR_CONF_SAMPLERATE,
+                       &gvar) == 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->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 */
@@ -137,24 +121,15 @@ static int init(struct sr_output *o)
 
        if (!(frequency_s = sr_period_string(samplerate))) {
                sr_err("%s: sr_period_string failed", __func__);
-               g_free(ctx->header);
                g_free(ctx);
                return SR_ERR;
        }
 
        t = time(NULL);
-       b = snprintf(ctx->header, MAX_HEADER_LEN, gnuplot_header,
-                    PACKAGE_STRING, ctime(&t), comment, frequency_s,
-                    (char *)&wbuf);
+       ctx->header = g_strdup_printf(gnuplot_header, PACKAGE_STRING,
+                       ctime(&t), comment, frequency_s, (char *)&wbuf);
        g_free(frequency_s);
 
-       if (b < 0) {
-               sr_err("%s: sprintf failed", __func__);
-               g_free(ctx->header);
-               g_free(ctx);
-               return SR_ERR;
-       }
-
        if (!(ctx->old_sample = g_try_malloc0(ctx->unitsize))) {
                sr_err("%s: ctx->old_sample malloc failed", __func__);
                g_free(ctx->header);