]> sigrok.org Git - libsigrok.git/blobdiff - src/session_file.c
yokogawa-dlm: Minor cosmetics, consistency fixes, typos.
[libsigrok.git] / src / session_file.c
index 26c0df7a3d88806b65e617f25815e86bbc0e66e7..9a1e316e8fd0411158215d011d9ed91b8d7fc00d 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)
 {
@@ -106,6 +105,7 @@ SR_PRIV int sr_sessionfile_check(const char *filename)
 /**
  * Load the session from the specified filename.
  *
+ * @param ctx The context in which to load the session.
  * @param filename The name of the session file to load.
  * @param session The session to load the file into.
  *
@@ -114,7 +114,8 @@ SR_PRIV int sr_sessionfile_check(const char *filename)
  * @retval SR_ERR_DATA Malformed session file
  * @retval SR_ERR This is not a session file
  */
-SR_API int sr_session_load(const char *filename, struct sr_session **session)
+SR_API int sr_session_load(struct sr_context *ctx, const char *filename,
+               struct sr_session **session)
 {
        GKeyFile *kf;
        GPtrArray *capturefiles;
@@ -152,7 +153,7 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session)
                return SR_ERR;
        }
 
-       if ((ret = sr_session_new(session)) != SR_OK)
+       if ((ret = sr_session_new(ctx, session)) != SR_OK)
                return ret;
 
        ret = SR_OK;
@@ -175,7 +176,7 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session)
                                        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);
@@ -212,19 +213,19 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session)
                                                        g_variant_new_uint64(total_channels), sdi, NULL);
                                        for (p = 0; p < total_channels; p++) {
                                                snprintf(channelname, SR_MAX_CHANNELNAME_LEN, "%" PRIu64, p);
-                                               ch = sr_channel_new(p, SR_CHANNEL_LOGIC, FALSE,
+                                               sr_channel_new(sdi, p, SR_CHANNEL_LOGIC, FALSE,
                                                                channelname);
-                                               sdi->channels = g_slist_append(sdi->channels, ch);
                                        }
                                } else if (!strncmp(keys[j], "probe", 5)) {
                                        if (!sdi) {
                                                ret = SR_ERR_DATA;
                                                break;
                                        }
-                                       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_enable(sdi, tmp_u64 - 1, TRUE);
+                                       sr_dev_channel_name_set(ch, val);
+                                       sr_dev_channel_enable(ch, TRUE);
                                }
                        }
                        g_strfreev(keys);