From: Soeren Apel Date: Thu, 24 Mar 2016 07:56:14 +0000 (+0100) Subject: Enable loading of session files without the capture file defined X-Git-Tag: libsigrok-0.5.0~540 X-Git-Url: http://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=7c69b528e4e216be213ff2a1bacaced6df3fe38f Enable loading of session files without the capture file defined --- diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index 3c18ffaf..0cf52884 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -817,6 +817,8 @@ SR_PRIV int sr_session_source_remove_channel(struct sr_session *session, SR_PRIV int sr_session_send(const struct sr_dev_inst *sdi, const struct sr_datafeed_packet *packet); SR_PRIV int sr_sessionfile_check(const char *filename); +SR_PRIV struct sr_dev_inst *sr_session_prepare_sdi(const char *filename, + struct sr_session **session); SR_PRIV int sr_packet_copy(const struct sr_datafeed_packet *packet, struct sr_datafeed_packet **copy); SR_PRIV void sr_packet_free(struct sr_datafeed_packet *packet); diff --git a/src/session_driver.c b/src/session_driver.c index 07ee10b0..0793104b 100644 --- a/src/session_driver.c +++ b/src/session_driver.c @@ -74,10 +74,11 @@ static gboolean stream_session_data(struct sr_dev_inst *sdi) got_data = FALSE; vdev = sdi->priv; + if (!vdev->capfile) { /* No capture file opened yet, or finished with the last * chunked one. */ - if (vdev->cur_chunk == 0) { + if (vdev->capturefile && (vdev->cur_chunk == 0)) { /* capturefile is always the unchunked base name. */ if (zip_stat(vdev->archive, vdev->capturefile, 0, &zs) != -1) { /* No chunks, just a single capture file. */ diff --git a/src/session_file.c b/src/session_file.c index f8746f60..fd0dbd07 100644 --- a/src/session_file.c +++ b/src/session_file.c @@ -163,6 +163,27 @@ SR_PRIV int sr_sessionfile_check(const char *filename) return SR_OK; } +SR_PRIV struct sr_dev_inst *sr_session_prepare_sdi(const char *filename, struct sr_session **session) +{ + struct sr_dev_inst *sdi = NULL; + + sdi = g_malloc0(sizeof(struct sr_dev_inst)); + sdi->driver = &session_driver; + sdi->status = SR_ST_ACTIVE; + if (!session_driver_initialized) { + /* first device, init the driver */ + session_driver_initialized = 1; + sdi->driver->init(sdi->driver, NULL); + } + sr_dev_open(sdi); + sr_session_dev_add(*session, sdi); + (*session)->owned_devs = g_slist_append((*session)->owned_devs, sdi); + sr_config_set(sdi, NULL, SR_CONF_SESSIONFILE, + g_variant_new_string(filename)); + + return sdi; +} + /** * Load the session from the specified filename. * @@ -223,32 +244,28 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, /* device section */ sdi = NULL; keys = g_key_file_get_keys(kf, sections[i], NULL, NULL); + + /* File contains analog data if there are analog channels. */ + total_analog = g_key_file_get_integer(kf, sections[i], + "total analog", &error); + if (total_analog > 0 && !error) + sdi = sr_session_prepare_sdi(filename, session); + g_clear_error(&error); + + /* File contains logic data if a capturefile is set. */ + val = g_key_file_get_string(kf, sections[i], + "capturefile", &error); + if (val && !error) { + if (!sdi) + sdi = sr_session_prepare_sdi(filename, session); + sr_config_set(sdi, NULL, SR_CONF_CAPTUREFILE, + g_variant_new_string(val)); + g_free(val); + } + g_clear_error(&error); + for (j = 0; keys[j]; j++) { - if (!strcmp(keys[j], "capturefile")) { - val = g_key_file_get_string(kf, sections[i], - keys[j], &error); - if (!val) { - ret = SR_ERR_DATA; - break; - } - sdi = g_malloc0(sizeof(struct sr_dev_inst)); - sdi->driver = &session_driver; - sdi->status = SR_ST_ACTIVE; - if (!session_driver_initialized) { - /* first device, init the driver */ - session_driver_initialized = 1; - sdi->driver->init(sdi->driver, NULL); - } - sr_dev_open(sdi); - sr_session_dev_add(*session, sdi); - (*session)->owned_devs = g_slist_append( - (*session)->owned_devs, sdi); - sr_config_set(sdi, NULL, SR_CONF_SESSIONFILE, - g_variant_new_string(filename)); - sr_config_set(sdi, NULL, SR_CONF_CAPTUREFILE, - g_variant_new_string(val)); - g_free(val); - } else if (!strcmp(keys[j], "samplerate")) { + if (!strcmp(keys[j], "samplerate")) { val = g_key_file_get_string(kf, sections[i], keys[j], &error); if (!sdi || !val || sr_parse_sizestring(val,