]> sigrok.org Git - libsigrok.git/commitdiff
Enable loading of session files without the capture file defined
authorSoeren Apel <redacted>
Thu, 24 Mar 2016 07:56:14 +0000 (08:56 +0100)
committerUwe Hermann <redacted>
Sun, 27 Mar 2016 23:06:28 +0000 (01:06 +0200)
src/libsigrok-internal.h
src/session_driver.c
src/session_file.c

index 3c18ffaf19c7d184d57b90f4e57198652a3cb6cd..0cf52884a93c6e3082b9f537630e7569c8236b8c 100644 (file)
@@ -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);
index 07ee10b04aee08d974daa55b62444df373e219ab..0793104b0ccc63683c5120a5279fbb1a7fa4ead7 100644 (file)
@@ -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. */
index f8746f60fa0ae9ae75ab5c1a8cab7c541399b743..fd0dbd07309f98f315726c3b0930020c9c8f9e93 100644 (file)
@@ -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,