X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Finput%2Fvcd.c;h=e14215712b75c56477342a4706de8cecee5e0cf1;hb=2617c81a4b101714bf90173f4da0724007c58219;hp=9d164f9884567e810ad4ff1c51dca2d110ff8562;hpb=d0181813315114b88ad38cf276045ee5c311ca3c;p=libsigrok.git diff --git a/src/input/vcd.c b/src/input/vcd.c index 9d164f98..e1421571 100644 --- a/src/input/vcd.c +++ b/src/input/vcd.c @@ -429,7 +429,7 @@ static int init(struct sr_input *in, GHashTable *options) inc->skip = g_variant_get_int32(g_hash_table_lookup(options, "skip")); inc->skip /= inc->downsample; - in->sdi = sr_dev_inst_new(SR_ST_ACTIVE, NULL, NULL, NULL); + in->sdi = g_malloc0(sizeof(struct sr_dev_inst)); in->priv = inc; for (i = 0; i < num_channels; i++) { @@ -457,7 +457,7 @@ static gboolean have_header(GString *buf) return FALSE; } -static int receive(struct sr_input *in, GString *buf) +static int process_buffer(struct sr_input *in) { struct sr_datafeed_packet packet; struct sr_datafeed_meta meta; @@ -466,21 +466,7 @@ static int receive(struct sr_input *in, GString *buf) uint64_t samplerate; char *p; - g_string_append_len(in->buf, buf->str, buf->len); - inc = in->priv; - if (!inc->got_header) { - if (!have_header(in->buf)) - return SR_OK; - if (!parse_header(in, in->buf) != SR_OK) - /* There was a header in there, but it was malformed. */ - return SR_ERR; - - in->sdi_ready = TRUE; - /* sdi is ready, notify frontend. */ - return SR_OK; - } - if (!inc->started) { std_session_send_df_header(in->sdi, LOG_PREFIX); @@ -506,23 +492,57 @@ static int receive(struct sr_input *in, GString *buf) return SR_OK; } -static int cleanup(struct sr_input *in) +static int receive(struct sr_input *in, GString *buf) +{ + struct context *inc; + int ret; + + g_string_append_len(in->buf, buf->str, buf->len); + + inc = in->priv; + if (!inc->got_header) { + if (!have_header(in->buf)) + return SR_OK; + if (!parse_header(in, in->buf) != SR_OK) + /* There was a header in there, but it was malformed. */ + return SR_ERR; + + in->sdi_ready = TRUE; + /* sdi is ready, notify frontend. */ + return SR_OK; + } + + ret = process_buffer(in); + + return ret; +} + +static int end(struct sr_input *in) { struct sr_datafeed_packet packet; struct context *inc; + int ret; + + if (in->sdi_ready) + ret = process_buffer(in); + else + ret = SR_OK; inc = in->priv; if (inc->started) { - /* End of stream. */ packet.type = SR_DF_END; sr_session_send(in->sdi, &packet); } - g_slist_free_full(inc->channels, free_channel); - g_free(inc); - in->priv = NULL; + return ret; +} - return SR_OK; +static void cleanup(struct sr_input *in) +{ + struct context *inc; + + inc = in->priv; + g_slist_free_full(inc->channels, free_channel); } static struct sr_option options[] = { @@ -549,10 +569,12 @@ SR_PRIV struct sr_input_module input_vcd = { .id = "vcd", .name = "VCD", .desc = "Value Change Dump", + .exts = (const char*[]){"vcd", NULL}, .metadata = { SR_INPUT_META_HEADER | SR_INPUT_META_REQUIRED }, .options = get_options, .format_match = format_match, .init = init, .receive = receive, + .end = end, .cleanup = cleanup, };