sr: Fix handling of virtual devices.

I.e., handling of sessions which use input from files (not from actual
logic analyzer hardware).
This commit is contained in:
Uwe Hermann 2012-03-18 12:57:34 +01:00
parent 21b50ee183
commit d6eb0c333c
2 changed files with 21 additions and 14 deletions

View File

@ -372,13 +372,20 @@ SR_API gboolean sr_dev_has_hwcap(const struct sr_dev *dev, int hwcap)
{
int *hwcaps, i;
sr_spew("dev: %s: requesting hwcap %d", __func__, hwcap);
if (!dev) {
sr_err("dev: %s: dev was NULL", __func__);
return FALSE; /* TODO: SR_ERR_ARG. */
}
/*
* Virtual devices (which have dev->driver set to NULL) always say that
* they don't have the capability (they can't call hwcap_get_all()).
*/
if (!dev->driver) {
sr_err("dev: %s: dev->driver was NULL", __func__);
sr_dbg("dev: %s: dev->driver was NULL, this seems to be "
"a virtual device without capabilities", __func__);
return FALSE; /* TODO: SR_ERR_ARG. */
}

View File

@ -127,22 +127,27 @@ SR_API int sr_session_dev_add(struct sr_dev *dev)
return SR_ERR_ARG;
}
if (!dev->driver) {
sr_err("session: %s: dev->driver was NULL", __func__);
return SR_ERR_ARG;
if (!session) {
sr_err("session: %s: session was NULL", __func__);
return SR_ERR_BUG;
}
/* If dev->driver is NULL, this is a virtual device. */
if (!dev->driver) {
sr_dbg("session: %s: dev->driver was NULL, this seems to be "
"a virtual device; continuing", __func__);
/* Just add the device, don't run dev_open(). */
session->devs = g_slist_append(session->devs, dev);
return SR_OK;
}
/* dev->driver is non-NULL (i.e. we have a real device). */
if (!dev->driver->dev_open) {
sr_err("session: %s: dev->driver->dev_open was NULL",
__func__);
return SR_ERR_ARG;
}
if (!session) {
sr_err("session: %s: session was NULL", __func__);
return SR_ERR_BUG;
}
if ((ret = dev->driver->dev_open(dev->driver_index)) != SR_OK) {
sr_err("session: %s: dev_open failed (%d)", __func__, ret);
return ret;
@ -438,11 +443,6 @@ SR_PRIV int sr_session_send(struct sr_dev *dev,
return SR_ERR_ARG;
}
if (!dev->driver) {
sr_err("session: %s: dev->driver was NULL", __func__);
return SR_ERR_ARG;
}
if (!packet) {
sr_err("session: %s: packet was NULL", __func__);
return SR_ERR_ARG;