]> sigrok.org Git - libsigrok.git/blobdiff - src/input/input.c
input: sr_input_free() is now a void function.
[libsigrok.git] / src / input / input.c
index a5182e2b5e969d8bcc8ccbf41872b291b9c6dc7a..3547d9e1800888cbe62473920b8ba5f19343126d 100644 (file)
@@ -495,11 +495,18 @@ SR_API int sr_input_scan_file(const char *filename, const struct sr_input **in)
  * Return the input instance's (virtual) device instance. This can be
  * used to find out the number of channels and other information.
  *
+ * If the device instance has not yet been fully populated by the input
+ * module, NULL is returned. This indicates the module needs more data
+ * to identify the number of channels and so on.
+ *
  * @since 0.4.0
  */
 SR_API struct sr_dev_inst *sr_input_dev_inst_get(const struct sr_input *in)
 {
-       return in->sdi;
+       if (in->sdi_ready)
+               return in->sdi;
+       else
+               return NULL;
 }
 
 /**
@@ -508,35 +515,55 @@ SR_API struct sr_dev_inst *sr_input_dev_inst_get(const struct sr_input *in)
  * When an input module instance is created with sr_input_new(), this
  * function is used to feed data to the instance.
  *
+ * As enough data gets fed into this function to completely populate
+ * 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.
+ *
  * @since 0.4.0
  */
 SR_API int sr_input_send(const struct sr_input *in, GString *buf)
 {
-       return in->module->receive(in, buf);
+       sr_spew("Sending %d bytes to %s module.", buf->len, in->module->id);
+       return in->module->receive((struct sr_input *)in, 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)
-               g_string_free(in->buf, TRUE);
+       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);
+       }
+       g_string_free(in->buf, TRUE);
+       g_free(in->priv);
        g_free((gpointer)in);
-
-       return ret;
 }