]> sigrok.org Git - libsigrok.git/commitdiff
When adding a device instance to a running session, start acquisition on it
authorBert Vermeulen <redacted>
Sat, 21 Sep 2013 15:44:49 +0000 (17:44 +0200)
committerBert Vermeulen <redacted>
Sat, 21 Sep 2013 15:44:49 +0000 (17:44 +0200)
libsigrok.h
session.c

index cfaec89bb1e027e64586f77bd9d747dcd54d280c..b686c6e5463c8a37680fda29a0566756489888a1 100644 (file)
@@ -830,6 +830,7 @@ struct sr_session {
        /** List of struct datafeed_callback pointers. */
        GSList *datafeed_callbacks;
        GTimeVal starttime;
+       gboolean running;
 
        unsigned int num_sources;
 
index b52c91a374540de5eadd41c2cf030666b08706eb..3ef7b0be9f5633a93da65396266448e1c50dc1d9 100644 (file)
--- a/session.c
+++ b/session.c
@@ -84,6 +84,7 @@ SR_API struct sr_session *sr_session_new(void)
        }
 
        session->source_timeout = -1;
+       session->running = FALSE;
        session->abort_session = FALSE;
        g_mutex_init(&session->stop_mutex);
 
@@ -148,6 +149,7 @@ 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__);
@@ -176,6 +178,15 @@ SR_API int sr_session_dev_add(const struct sr_dev_inst *sdi)
 
        session->devs = g_slist_append(session->devs, (gpointer)sdi);
 
+       if (session->running) {
+               /* Adding a device to a running session. Start acquisition
+                * on that device now. */
+               if ((ret = sdi->driver->dev_acquisition_start(sdi,
+                                               (void *)sdi)) != SR_OK)
+                       sr_err("Failed to start acquisition of device in "
+                                       "running session: %d", ret);
+       }
+
        return SR_OK;
 }
 
@@ -372,6 +383,7 @@ SR_API int sr_session_run(void)
                       "cannot be run without devices.", __func__);
                return SR_ERR_BUG;
        }
+       session->running = TRUE;
 
        sr_info("Running.");
 
@@ -419,6 +431,7 @@ SR_PRIV int sr_session_stop_sync(void)
                                sdi->driver->dev_acquisition_stop(sdi, sdi);
                }
        }
+       session->running = FALSE;
 
        return SR_OK;
 }