]> sigrok.org Git - libsigrok.git/blobdiff - src/session.c
Change type of SR_CONF keys to uint32_t.
[libsigrok.git] / src / session.c
index 504af479d4b2d3cce6b0a34de39993dee172bfd3..dc8fd4fbeaffc2ce3c78cdeabcd5156f30c44363 100644 (file)
@@ -67,7 +67,7 @@ struct datafeed_callback {
  *                    is undefined and should not be used. Must not be NULL.
  *
  * @retval SR_OK Success.
- * @retval SR_ERR_BUG A session exists already.
+ * @retval SR_ERR_ARG Invalid argument.
  *
  * @since 0.4.0
  */
@@ -75,6 +75,9 @@ SR_API int sr_session_new(struct sr_session **new_session)
 {
        struct sr_session *session;
 
+       if (!new_session)
+               return SR_ERR_ARG;
+
        session = g_malloc0(sizeof(struct sr_session));
 
        session->source_timeout = -1;
@@ -186,8 +189,6 @@ SR_API int sr_session_dev_add(struct sr_session *session,
 
        /* If sdi->driver is NULL, this is a virtual device. */
        if (!sdi->driver) {
-               sr_dbg("%s: sdi->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, (gpointer)sdi);
                sdi->session = session;
@@ -433,8 +434,9 @@ static int verify_trigger(struct sr_trigger *trigger)
 SR_API int sr_session_start(struct sr_session *session)
 {
        struct sr_dev_inst *sdi;
-       GSList *l;
-       int ret;
+       struct sr_channel *ch;
+       GSList *l, *c;
+       int enabled_channels, ret;
 
        if (!session) {
                sr_err("%s: session was NULL", __func__);
@@ -455,6 +457,21 @@ SR_API int sr_session_start(struct sr_session *session)
        ret = SR_OK;
        for (l = session->devs; l; l = l->next) {
                sdi = l->data;
+               enabled_channels = 0;
+               for (c = sdi->channels; c; c = c->next) {
+                       ch = c->data;
+                       if (ch->enabled) {
+                               enabled_channels++;
+                               break;
+                       }
+               }
+               if (enabled_channels == 0) {
+                       ret = SR_ERR;
+                       sr_err("%s instance %d has no enabled channels!",
+                                       sdi->driver->name, sdi->index);
+                       break;
+               }
+
                if ((ret = sr_config_commit(sdi)) != SR_OK) {
                        sr_err("Failed to commit device settings before "
                               "starting acquisition (%s)", sr_strerror(ret));