Add sr_dev_open()/sr_dev_close()
Frontends will be required to open a device before using sr_config_set() or starting acquisition.
This commit is contained in:
parent
46a743c1fa
commit
efdecf4c05
24
device.c
24
device.c
|
@ -361,4 +361,28 @@ SR_API int sr_dev_clear(const struct sr_dev_driver *driver)
|
|||
return SR_OK;
|
||||
}
|
||||
|
||||
SR_API int sr_dev_open(struct sr_dev_inst *sdi)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!sdi || !sdi->driver || !sdi->driver->dev_open)
|
||||
return SR_ERR;
|
||||
|
||||
ret = sdi->driver->dev_open(sdi);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SR_API int sr_dev_close(struct sr_dev_inst *sdi)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!sdi || !sdi->driver || !sdi->driver->dev_close)
|
||||
return SR_ERR;
|
||||
|
||||
ret = sdi->driver->dev_close(sdi);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
|
2
proto.h
2
proto.h
|
@ -54,6 +54,8 @@ SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
|
|||
SR_API gboolean sr_dev_has_option(const struct sr_dev_inst *sdi, int key);
|
||||
SR_API GSList *sr_dev_list(const struct sr_dev_driver *driver);
|
||||
SR_API int sr_dev_clear(const struct sr_dev_driver *driver);
|
||||
SR_API int sr_dev_open(struct sr_dev_inst *sdi);
|
||||
SR_API int sr_dev_close(struct sr_dev_inst *sdi);
|
||||
|
||||
/*--- filter.c --------------------------------------------------------------*/
|
||||
|
||||
|
|
48
session.c
48
session.c
|
@ -116,48 +116,6 @@ 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all the devices from the current session.
|
||||
*
|
||||
|
@ -190,7 +148,6 @@ SR_API int sr_session_dev_remove_all(void)
|
|||
*/
|
||||
SR_API int sr_session_dev_add(const struct sr_dev_inst *sdi)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (!sdi) {
|
||||
sr_err("%s: sdi was NULL", __func__);
|
||||
|
@ -217,11 +174,6 @@ SR_API int sr_session_dev_add(const struct sr_dev_inst *sdi)
|
|||
return SR_ERR_BUG;
|
||||
}
|
||||
|
||||
if ((ret = sdi->driver->dev_open((struct sr_dev_inst *)sdi)) != SR_OK) {
|
||||
sr_err("%s: dev_open failed (%d)", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
session->devs = g_slist_append(session->devs, (gpointer)sdi);
|
||||
|
||||
return SR_OK;
|
||||
|
|
Loading…
Reference in New Issue