X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fsession_file.c;h=9aa56601c8ab67a31818c5ef26e149d2067a50bc;hb=b317d1bbfb83f152f94959588336f4a07328d154;hp=294614a140095942a0b1ad1d6cd52cc3a1a01369;hpb=2c38a41a60b8ebb8137d3b5b14ae652c66af6034;p=libsigrok.git diff --git a/src/session_file.c b/src/session_file.c index 294614a1..9aa56601 100644 --- a/src/session_file.c +++ b/src/session_file.c @@ -46,6 +46,16 @@ extern SR_PRIV struct sr_dev_driver session_driver; static int session_driver_initialized = 0; +#if !HAVE_ZIP_DISCARD +/* Replacement for zip_discard() if it isn't available. + */ +SR_PRIV void sr_zip_discard(struct zip *archive) +{ + if (zip_unchange_all(archive) < 0 || zip_close(archive) < 0) + sr_err("Failed to discard ZIP archive: %s", zip_strerror(archive)); +} +#endif + /** Read metadata entries from a session archive. * @param[in] archive An open ZIP archive. * @param[in] entry Stat buffer filled in for the metadata archive member. @@ -176,7 +186,8 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, struct sr_channel *ch; int ret, i, j; uint64_t tmp_u64; - int total_channels, k; + int total_channels, total_analog, k; + GSList *l; int unitsize; char **sections, **keys, *val; char channelname[SR_MAX_CHANNELNAME_LEN + 1]; @@ -268,13 +279,28 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, sr_config_set(sdi, NULL, SR_CONF_NUM_LOGIC_CHANNELS, g_variant_new_int32(total_channels)); for (k = 0; k < total_channels; k++) { - g_snprintf(channelname, sizeof channelname, + g_snprintf(channelname, sizeof(channelname), "%d", k); sr_channel_new(sdi, k, SR_CHANNEL_LOGIC, FALSE, channelname); } + } else if (!strcmp(keys[j], "total analog")) { + total_analog = g_key_file_get_integer(kf, + sections[i], keys[j], &error); + if (!sdi || total_analog < 0 || error) { + ret = SR_ERR_DATA; + break; + } + sr_config_set(sdi, NULL, SR_CONF_NUM_ANALOG_CHANNELS, + g_variant_new_int32(total_analog)); + for (k = 0; k < total_analog; k++) { + g_snprintf(channelname, sizeof(channelname), + "%d", k); + sr_channel_new(sdi, k, SR_CHANNEL_ANALOG, + FALSE, channelname); + } } else if (!strncmp(keys[j], "probe", 5)) { - tmp_u64 = g_ascii_strtoull(keys[j]+5, NULL, 10); + tmp_u64 = g_ascii_strtoull(keys[j] + 5, NULL, 10); if (!sdi || tmp_u64 == 0 || tmp_u64 > G_MAXINT) { ret = SR_ERR_DATA; break; @@ -294,6 +320,34 @@ SR_API int sr_session_load(struct sr_context *ctx, const char *filename, sr_dev_channel_name_set(ch, val); g_free(val); sr_dev_channel_enable(ch, TRUE); + } else if (!strncmp(keys[j], "analog", 6)) { + tmp_u64 = g_ascii_strtoull(keys[j]+6, NULL, 10); + if (!sdi || tmp_u64 == 0 || tmp_u64 > G_MAXINT) { + ret = SR_ERR_DATA; + break; + } + ch = NULL; + for (l = sdi->channels; l; l = l->next) { + ch = l->data; + if ((guint64)ch->index == tmp_u64 - 1) + break; + else + ch = NULL; + } + if (!ch) { + ret = SR_ERR_DATA; + break; + } + val = g_key_file_get_string(kf, sections[i], + keys[j], &error); + if (!val) { + ret = SR_ERR_DATA; + break; + } + /* sr_session_save() */ + sr_dev_channel_name_set(ch, val); + g_free(val); + sr_dev_channel_enable(ch, TRUE); } } g_strfreev(keys);