]> sigrok.org Git - libsigrok.git/blobdiff - src/input/csv.c
rigol-ds: Add DS1074Z Plus and DS1104Z Plus.
[libsigrok.git] / src / input / csv.c
index 063145a07b4e0284483364414a28273aa37fe6e5..8d151fdc93818422e4a7916dab04f25c84f3172e 100644 (file)
@@ -89,7 +89,7 @@ struct context {
        /* Comment prefix character(s). */
        GString *comment;
 
-       /* Termination  character(s) used in current stream. */
+       /* Termination character(s) used in current stream. */
        char *termination;
 
        /* Determines if sample data is stored in multiple columns. */
@@ -133,17 +133,6 @@ struct context {
        size_t line_number;
 };
 
-static int format_match(GHashTable *metadata)
-{
-       char *buf;
-
-       buf = g_hash_table_lookup(metadata, GINT_TO_POINTER(SR_INPUT_META_MIMETYPE));
-       if (!strcmp(buf, "text/csv"))
-               return SR_OK;
-
-       return SR_ERR;
-}
-
 static void strip_comment(char *buf, const GString *prefix)
 {
        char *ptr;
@@ -623,7 +612,7 @@ static int process_buffer(struct sr_input *in)
 
        inc = in->priv;
        if (!inc->started) {
-               std_session_send_df_header(in->sdi, LOG_PREFIX);
+               std_session_send_df_header(in->sdi);
 
                if (inc->samplerate) {
                        packet.type = SR_DF_META;
@@ -632,6 +621,7 @@ static int process_buffer(struct sr_input *in)
                        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);
+                       g_slist_free(meta.config);
                        sr_config_free(src);
                }
 
@@ -748,7 +738,6 @@ static int receive(struct sr_input *in, GString *buf)
 static int end(struct sr_input *in)
 {
        struct context *inc;
-       struct sr_datafeed_packet packet;
        int ret;
 
        if (in->sdi_ready)
@@ -757,11 +746,8 @@ static int end(struct sr_input *in)
                ret = SR_OK;
 
        inc = in->priv;
-       if (inc->started) {
-               /* End of stream. */
-               packet.type = SR_DF_END;
-               sr_session_send(in->sdi, &packet);
-       }
+       if (inc->started)
+               std_session_send_df_end(in->sdi);
 
        return ret;
 }
@@ -782,6 +768,17 @@ static void cleanup(struct sr_input *in)
        g_free(inc->sample_buffer);
 }
 
+static int reset(struct sr_input *in)
+{
+       struct context *inc = in->priv;
+
+       cleanup(in);
+       inc->started = FALSE;
+       g_string_truncate(in->buf, 0);
+
+       return SR_OK;
+}
+
 static struct sr_option options[] = {
        { "single-column", "Single column", "Enable/specify single column", NULL, NULL },
        { "numchannels", "Max channels", "Number of channels", NULL, NULL },
@@ -795,7 +792,7 @@ static struct sr_option options[] = {
        ALL_ZERO
 };
 
-static struct sr_option *get_options(void)
+static const struct sr_option *get_options(void)
 {
        if (!options[0].def) {
                options[0].def = g_variant_ref_sink(g_variant_new_int32(0));
@@ -817,11 +814,10 @@ SR_PRIV struct sr_input_module input_csv = {
        .name = "CSV",
        .desc = "Comma-separated values",
        .exts = (const char*[]){"csv", NULL},
-       .metadata = { SR_INPUT_META_MIMETYPE },
        .options = get_options,
-       .format_match = format_match,
        .init = init,
        .receive = receive,
        .end = end,
        .cleanup = cleanup,
+       .reset = reset,
 };