]> sigrok.org Git - libsigrok.git/blobdiff - src/input/csv.c
Factor out std_session_send_df_end() helper.
[libsigrok.git] / src / input / csv.c
index 0a2d7276d996eb14b5f0310999feb1ed2e3c8c06..984a58c7d9753ae1d11869d829ad2e5507e9d686 100644 (file)
@@ -17,6 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
 #include <stdlib.h>
 #include <string.h>
 #include <glib.h>
@@ -132,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;
@@ -631,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);
                }
 
@@ -747,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)
@@ -756,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, LOG_PREFIX);
 
        return ret;
 }
@@ -794,7 +781,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));
@@ -816,9 +803,7 @@ 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,