]> sigrok.org Git - libsigrok.git/blobdiff - session.c
Add Rigol DS1052E/1102E VID:PID
[libsigrok.git] / session.c
index 7bff474b0aeb982afe448e5e3a73e12dfd5f4ade..ac5981ad050b6993478ca04f0838345c704e2eb8 100644 (file)
--- a/session.c
+++ b/session.c
@@ -107,10 +107,46 @@ SR_API int sr_session_destroy(void)
        return SR_OK;
 }
 
+/**
+ * Close a device instance.
+ *
+ * @param sdi The device instance to close. Must not be NULL. Also,
+ *            sdi->driver, sdi->driver->priv, and sdi->priv must not be NULL.
+ */
 static void sr_dev_close(struct sr_dev_inst *sdi)
 {
-       if (sdi->driver && sdi->driver->dev_close)
-               sdi->driver->dev_close(sdi);
+       int ret;
+
+       if (!sdi) {
+               sr_err("Invalid device instance, can't close device.");
+               return;
+       }
+
+       /* In the drivers sdi->priv is a 'struct dev_context *devc'. */
+       if (!sdi->priv) {
+               /*
+                * Should be sr_err() in theory, but the 'demo' driver has
+                * NULL for sdi->priv, so we use sr_dbg() until that's fixed.
+                */
+               sr_dbg("Invalid device context, can't close device.");
+               return;
+       }
+
+       if (!sdi->driver) {
+               sr_err("Invalid driver, can't close device.");
+               return;
+       }
+
+       if (!sdi->driver->priv) {
+               sr_err("Driver not initialized, can't close device.");
+               return;
+       }
+
+       sr_spew("Closing '%s' device instance %d.", sdi->driver->name,
+               sdi->index);
+
+       if ((ret = sdi->driver->dev_close(sdi)) < 0)
+               sr_err("Failed to close device instance: %d.", ret);
 }
 
 /**
@@ -278,7 +314,7 @@ SR_API int sr_session_start(void)
                return SR_ERR_BUG;
        }
 
-       sr_info("session: starting");
+       sr_info("Starting.");
 
        ret = SR_OK;
        for (l = session->devs; l; l = l->next) {
@@ -330,20 +366,6 @@ SR_API int sr_session_run(void)
        return SR_OK;
 }
 
-/**
- * Halt the current session.
- *
- * This function is deprecated and should not be used in new code, use
- * sr_session_stop() instead. The behaviour of this function is identical to
- * sr_session_stop().
- *
- * @return SR_OK upon success, SR_ERR_BUG if no session exists.
- */
-SR_API int sr_session_halt(void)
-{
-       return sr_session_stop();
-}
-
 /**
  * Stop the current session.
  *