From: Uwe Hermann Date: Sun, 18 Mar 2012 11:57:34 +0000 (+0100) Subject: sr: Fix handling of virtual devices. X-Git-Tag: libsigrok-0.1.0~40 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d6eb0c333c8424d151637c18e1a1aef849d5fb31;p=libsigrok.git sr: Fix handling of virtual devices. I.e., handling of sessions which use input from files (not from actual logic analyzer hardware). --- diff --git a/device.c b/device.c index 3166ea8e..ba29adb5 100644 --- a/device.c +++ b/device.c @@ -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. */ } diff --git a/session.c b/session.c index 8687f432..ffa7e072 100644 --- a/session.c +++ b/session.c @@ -127,22 +127,27 @@ SR_API int sr_session_dev_add(struct sr_dev *dev) 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_err("session: %s: dev->driver was NULL", __func__); - return SR_ERR_ARG; + 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;