]> sigrok.org Git - libsigrok.git/blobdiff - src/std.c
sr_dev_clear(): Always free sdi->priv (devc).
[libsigrok.git] / src / std.c
index f68cc12bd8954c29c684043fe368ef514427dca5..a4f5d8835e25b0026e29693f6bf7e9eca58300d5 100644 (file)
--- a/src/std.c
+++ b/src/std.c
@@ -93,6 +93,62 @@ SR_PRIV int std_cleanup(const struct sr_dev_driver *di)
        return ret;
 }
 
+/**
+ * Dummmy driver dev_open() callback API helper.
+ *
+ * @param[in] sdi The device instance to use. May be NULL (unused).
+ *
+ * @retval SR_OK Success.
+ */
+SR_PRIV int std_dummy_dev_open(struct sr_dev_inst *sdi)
+{
+       (void)sdi;
+
+       return SR_OK;
+}
+
+/**
+ * Dummmy driver dev_close() callback API helper.
+ *
+ * @param[in] sdi The device instance to use. May be NULL (unused).
+ *
+ * @retval SR_OK Success.
+ */
+SR_PRIV int std_dummy_dev_close(struct sr_dev_inst *sdi)
+{
+       (void)sdi;
+
+       return SR_OK;
+}
+
+/**
+ * Dummmy driver dev_acquisition_start() callback API helper.
+ *
+ * @param[in] sdi The device instance to use. May be NULL (unused).
+ *
+ * @retval SR_OK Success.
+ */
+SR_PRIV int std_dummy_dev_acquisition_start(const struct sr_dev_inst *sdi)
+{
+       (void)sdi;
+
+       return SR_OK;
+}
+
+/**
+ * Dummmy driver dev_acquisition_stop() callback API helper.
+ *
+ * @param[in] sdi The device instance to use. May be NULL (unused).
+ *
+ * @retval SR_OK Success.
+ */
+SR_PRIV int std_dummy_dev_acquisition_stop(struct sr_dev_inst *sdi)
+{
+       (void)sdi;
+
+       return SR_OK;
+}
+
 /**
  * Standard API helper for sending an SR_DF_HEADER packet.
  *
@@ -277,23 +333,25 @@ SR_PRIV int std_serial_dev_acquisition_stop(struct sr_dev_inst *sdi)
  * This function can be used to implement the dev_clear() driver API
  * callback. dev_close() is called before every sr_dev_inst is cleared.
  *
- * The only limitation is driver-specific device contexts (sdi->priv).
+ * The only limitation is driver-specific device contexts (sdi->priv / devc).
  * These are freed, but any dynamic allocation within structs stored
  * there cannot be freed.
  *
  * @param[in] driver The driver which will have its instances released.
  *                   Must not be NULL.
  * @param[in] clear_private If not NULL, this points to a function called
- *            with sdi->priv as argument. The function can then clear
+ *            with sdi->priv (devc) as argument. The function can then clear
  *            any device instance-specific resources kept there.
- *            It must also clear the struct pointed to by sdi->priv.
+ *            It must NOT clear the struct pointed to by sdi->priv (devc),
+ *            since this function will always free it after clear_private()
+ *            has run.
  *
  * @retval SR_OK Success.
  * @retval SR_ERR_ARG Invalid argument.
  * @retval SR_ERR_BUG Implementation bug.
  * @retval other Other error.
  */
-SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
+SR_PRIV int std_dev_clear_with_callback(const struct sr_dev_driver *driver,
                std_dev_clear_callback clear_private)
 {
        struct drv_context *drvc;
@@ -332,12 +390,13 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
                        if (sdi->inst_type == SR_INST_MODBUS)
                                sr_modbus_free(sdi->conn);
                }
+
+               /* Clear driver-specific stuff, if any. */
                if (clear_private)
-                       /* The helper function is responsible for freeing
-                        * its own sdi->priv! */
                        clear_private(sdi->priv);
-               else
-                       g_free(sdi->priv);
+
+               /* Clear sdi->priv (devc). */
+               g_free(sdi->priv);
 
                sr_dev_inst_free(sdi);
        }
@@ -348,6 +407,11 @@ SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver,
        return ret;
 }
 
+SR_PRIV int std_dev_clear(const struct sr_dev_driver *driver)
+{
+       return std_dev_clear_with_callback(driver, NULL);
+}
+
 /**
  * Standard driver dev_list() callback API helper.
  *