X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Finput%2Finput.c;h=3c7fd516a309ea7e05aff2da1b3c16a592355d6a;hb=676877f6cee574f2a32805b946e56710db502264;hp=02f7db1b928c92bbed73f15e115d725c48c7b238;hpb=d0181813315114b88ad38cf276045ee5c311ca3c;p=libsigrok.git diff --git a/src/input/input.c b/src/input/input.c index 02f7db1b..3c7fd516 100644 --- a/src/input/input.c +++ b/src/input/input.c @@ -271,15 +271,17 @@ SR_API struct sr_input *sr_input_new(const struct sr_input_module *imod, if (in->module->init && in->module->init(in, new_opts) != SR_OK) { g_free(in); in = NULL; + } else { + in->buf = g_string_sized_new(128); } + if (new_opts) g_hash_table_destroy(new_opts); - in->buf = g_string_sized_new(128); return in; } -/* Returns TRUE is all required meta items are available. */ +/* Returns TRUE if all required meta items are available. */ static gboolean check_required_metadata(const uint8_t *metadata, uint8_t *avail) { int m, a; @@ -364,7 +366,7 @@ SR_API int sr_input_scan_buffer(GString *buf, const struct sr_input **in) /* Module didn't recognize this buffer. */ continue; } else if (ret != SR_OK) { - /* Can be SR_OK_CONTINUE. */ + /* Can be SR_ERR_NA. */ return ret; } @@ -477,7 +479,7 @@ SR_API int sr_input_scan_file(const char *filename, const struct sr_input **in) /* Module didn't recognize this buffer. */ continue; } else if (ret != SR_OK) { - /* Can be SR_OK_CONTINUE. */ + /* Can be SR_ERR_NA. */ return ret; } @@ -519,7 +521,7 @@ SR_API struct sr_dev_inst *sr_input_dev_inst_get(const struct sr_input *in) * the device instance associated with this input instance, this is * guaranteed to return the moment it's ready. This gives the caller * the chance to examine the device instance, attach session callbacks - * and on so. + * and so on. * * @since 0.4.0 */ @@ -530,31 +532,40 @@ SR_API int sr_input_send(const struct sr_input *in, GString *buf) } /** - * Free the specified input instance and all associated resources. + * Signal the input module no more data will come. + * + * This will cause the module to process any data it may have buffered. + * The SR_DF_END packet will also typically be sent at this time. * * @since 0.4.0 */ -SR_API int sr_input_free(const struct sr_input *in) +SR_API int sr_input_end(const struct sr_input *in) { - int ret; + sr_spew("Calling end() on %s module.", in->module->id); + return in->module->end((struct sr_input *)in); +} +/** + * Free the specified input instance and all associated resources. + * + * @since 0.4.0 + */ +SR_API void sr_input_free(const struct sr_input *in) +{ if (!in) - return SR_ERR_ARG; + return; - ret = SR_OK; if (in->module->cleanup) - ret = in->module->cleanup((struct sr_input *)in); + in->module->cleanup((struct sr_input *)in); if (in->sdi) sr_dev_inst_free(in->sdi); if (in->buf->len > 64) { /* That seems more than just some sub-unitsize leftover... */ sr_warn("Found %d unprocessed bytes at free time.", in->buf->len); } - if (in->buf) - g_string_free(in->buf, TRUE); + g_string_free(in->buf, TRUE); + g_free(in->priv); g_free((gpointer)in); - - return ret; }