]> sigrok.org Git - libsigrok.git/commitdiff
sr: session: Close a device when it is removed from a session
authorLars-Peter Clausen <redacted>
Thu, 5 Jul 2012 19:15:07 +0000 (21:15 +0200)
committerBert Vermeulen <redacted>
Wed, 11 Jul 2012 21:28:35 +0000 (23:28 +0200)
A device is opened when it is added to a session, in the same fashion it should
be closed again when it is removed from a session.

Also remove all still attached devices from a session when the session is
destroyed.

Signed-off-by: Lars-Peter Clausen <redacted>
session.c

index 8fde4bf31a2421623459002f8614331ded818351..0cd4e2000387c8591900e9495a3cc6d1700802e9 100644 (file)
--- a/session.c
+++ b/session.c
@@ -74,8 +74,7 @@ SR_API int sr_session_destroy(void)
                return SR_ERR_BUG;
        }
 
-       g_slist_free(session->devs);
-       session->devs = NULL;
+       sr_session_dev_remove_all();
 
        /* TODO: Error checks needed? */
 
@@ -87,6 +86,12 @@ SR_API int sr_session_destroy(void)
        return SR_OK;
 }
 
+static void sr_dev_close(struct sr_dev *dev)
+{
+       if (dev->driver->dev_close)
+               dev->driver->dev_close(dev->driver_index);
+}
+
 /**
  * Remove all the devices from the current session. TODO?
  *
@@ -102,7 +107,7 @@ SR_API int sr_session_dev_remove_all(void)
                return SR_ERR_BUG;
        }
 
-       g_slist_free(session->devs);
+       g_slist_free_full(session->devs, (GDestroyNotify)sr_dev_close);
        session->devs = NULL;
 
        return SR_OK;