sr: session: Close a device when it is removed from a session

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 <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2012-07-05 21:15:07 +02:00 committed by Bert Vermeulen
parent 615183ea16
commit ed229aaa8f
1 changed files with 8 additions and 3 deletions

View File

@ -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;