From: Bert Vermeulen Date: Sat, 21 Sep 2013 15:44:49 +0000 (+0200) Subject: When adding a device instance to a running session, start acquisition on it X-Git-Tag: libsigrok-0.2.2~58 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=5451816fd1676eab2942aba8cec6188451772760;p=libsigrok.git When adding a device instance to a running session, start acquisition on it --- diff --git a/libsigrok.h b/libsigrok.h index cfaec89b..b686c6e5 100644 --- a/libsigrok.h +++ b/libsigrok.h @@ -830,6 +830,7 @@ struct sr_session { /** List of struct datafeed_callback pointers. */ GSList *datafeed_callbacks; GTimeVal starttime; + gboolean running; unsigned int num_sources; diff --git a/session.c b/session.c index b52c91a3..3ef7b0be 100644 --- 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; }