]> sigrok.org Git - libsigrok.git/blobdiff - src/session_file.c
session_file.c: Use config_*() wrappers.
[libsigrok.git] / src / session_file.c
index 9f8ee75660556dc6cb4b34ca3a23746fed25a945..b8a1cb60d8e098d2986319767db2760a982ec461 100644 (file)
@@ -49,7 +49,6 @@
 extern SR_PRIV struct sr_dev_driver session_driver;
 static int session_driver_initialized = 0;
 
-
 /** @private */
 SR_PRIV int sr_sessionfile_check(const char *filename)
 {
@@ -124,7 +123,7 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session)
        struct sr_dev_inst *sdi;
        struct sr_channel *ch;
        int ret, i, j;
-       uint64_t tmp_u64, total_channels, enabled_channels, p;
+       uint64_t tmp_u64, total_channels, p;
        char **sections, **keys, *metafile, *val;
        char channelname[SR_MAX_CHANNELNAME_LEN + 1];
 
@@ -165,27 +164,27 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session)
                if (!strncmp(sections[i], "device ", 7)) {
                        /* device section */
                        sdi = NULL;
-                       enabled_channels = total_channels = 0;
                        keys = g_key_file_get_keys(kf, sections[i], NULL, NULL);
                        for (j = 0; keys[j]; j++) {
                                val = g_key_file_get_string(kf, sections[i], keys[j], NULL);
                                if (!strcmp(keys[j], "capturefile")) {
-                                       sdi = sr_dev_inst_new();
+                                       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(NULL);
+                                               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);
-                                       sdi->driver->config_set(SR_CONF_SESSIONFILE,
-                                                       g_variant_new_string(filename), sdi, NULL);
-                                       sdi->driver->config_set(SR_CONF_CAPTUREFILE,
-                                                       g_variant_new_string(val), sdi, NULL);
+
+                                       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_ptr_array_add(capturefiles, val);
                                } else if (!strcmp(keys[j], "samplerate")) {
                                        if (!sdi) {
@@ -193,47 +192,42 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session)
                                                break;
                                        }
                                        sr_parse_sizestring(val, &tmp_u64);
-                                       sdi->driver->config_set(SR_CONF_SAMPLERATE,
-                                                       g_variant_new_uint64(tmp_u64), sdi, NULL);
+                                       sr_config_set(sdi, NULL, SR_CONF_SAMPLERATE,
+                                                       g_variant_new_uint64(tmp_u64));
                                } else if (!strcmp(keys[j], "unitsize")) {
                                        if (!sdi) {
                                                ret = SR_ERR_DATA;
                                                break;
                                        }
                                        tmp_u64 = strtoull(val, NULL, 10);
-                                       sdi->driver->config_set(SR_CONF_CAPTURE_UNITSIZE,
-                                                       g_variant_new_uint64(tmp_u64), sdi, NULL);
+                                       sr_config_set(sdi, NULL, SR_CONF_CAPTURE_UNITSIZE,
+                                                       g_variant_new_uint64(tmp_u64));
                                } else if (!strcmp(keys[j], "total probes")) {
                                        if (!sdi) {
                                                ret = SR_ERR_DATA;
                                                break;
                                        }
                                        total_channels = strtoull(val, NULL, 10);
-                                       sdi->driver->config_set(SR_CONF_NUM_LOGIC_CHANNELS,
-                                                       g_variant_new_uint64(total_channels), sdi, NULL);
+                                       sr_config_set(sdi, NULL, SR_CONF_NUM_LOGIC_CHANNELS,
+                                                       g_variant_new_uint64(total_channels));
                                        for (p = 0; p < total_channels; p++) {
                                                snprintf(channelname, SR_MAX_CHANNELNAME_LEN, "%" PRIu64, p);
-                                               if (!(ch = sr_channel_new(p, SR_CHANNEL_LOGIC, TRUE,
-                                                               channelname)))
-                                                       return SR_ERR;
-                                               sdi->channels = g_slist_append(sdi->channels, ch);
+                                               sr_channel_new(sdi, p, SR_CHANNEL_LOGIC, FALSE,
+                                                               channelname);
                                        }
                                } else if (!strncmp(keys[j], "probe", 5)) {
                                        if (!sdi) {
                                                ret = SR_ERR_DATA;
                                                break;
                                        }
-                                       enabled_channels++;
-                                       tmp_u64 = strtoul(keys[j]+5, NULL, 10);
+                                       tmp_u64 = strtoul(keys[j]+5, NULL, 10) - 1;
+                                       ch = g_slist_nth_data(sdi->channels, tmp_u64);
                                        /* sr_session_save() */
-                                       sr_dev_channel_name_set(sdi, tmp_u64 - 1, val);
+                                       sr_dev_channel_name_set(ch, val);
+                                       sr_dev_channel_enable(ch, TRUE);
                                }
                        }
                        g_strfreev(keys);
-                       /* Disable channels not specifically listed. */
-                       if (total_channels)
-                               for (p = enabled_channels; p < total_channels; p++)
-                                       sr_dev_channel_enable(sdi, p, FALSE);
                }
        }
        g_strfreev(sections);