]> sigrok.org Git - libsigrok.git/blobdiff - session_file.c
build: Portability fixes.
[libsigrok.git] / session_file.c
index e8ad2107e4793a28ad229844dd12ad3baf067c81..1c1cee5d68c9c9defe1521ef02a2b9a3f5d9260c 100644 (file)
@@ -107,7 +107,7 @@ SR_PRIV int sr_sessionfile_check(const char *filename)
  *         SR_ERR_MALLOC upon memory allocation errors, or SR_ERR upon
  *         other errors.
  */
-SR_API int sr_session_load(const char *filename)
+SR_API int sr_session_load(const char *filename, struct sr_session **session)
 {
        GKeyFile *kf;
        GPtrArray *capturefiles;
@@ -116,7 +116,7 @@ SR_API int sr_session_load(const char *filename)
        struct zip_stat zs;
        struct sr_dev_inst *sdi;
        struct sr_channel *ch;
-       int ret, channelnum, devcnt, i, j;
+       int devcnt, ret, i, j;
        uint64_t tmp_u64, total_channels, enabled_channels, p;
        char **sections, **keys, *metafile, *val;
        char channelname[SR_MAX_CHANNELNAME_LEN + 1];
@@ -145,7 +145,8 @@ SR_API int sr_session_load(const char *filename)
                return SR_ERR;
        }
 
-       sr_session_new();
+       if ((ret = sr_session_new(session)) != SR_OK)
+               return ret;
 
        devcnt = 0;
        capturefiles = g_ptr_array_new_with_free_func(g_free);
@@ -168,7 +169,7 @@ SR_API int sr_session_load(const char *filename)
                                                /* first device, init the driver */
                                                sdi->driver->init(NULL);
                                        sr_dev_open(sdi);
-                                       sr_session_dev_add(sdi);
+                                       sr_session_dev_add(*session, sdi);
                                        sdi->driver->config_set(SR_CONF_SESSIONFILE,
                                                        g_variant_new_string(filename), sdi, NULL);
                                        sdi->driver->config_set(SR_CONF_CAPTUREFILE,
@@ -200,9 +201,6 @@ SR_API int sr_session_load(const char *filename)
                                        tmp_u64 = strtoul(keys[j]+5, NULL, 10);
                                        /* sr_session_save() */
                                        sr_dev_channel_name_set(sdi, tmp_u64 - 1, val);
-                               } else if (!strncmp(keys[j], "trigger", 7)) {
-                                       channelnum = strtoul(keys[j]+7, NULL, 10);
-                                       sr_dev_trigger_set(sdi, channelnum, val);
                                }
                        }
                        g_strfreev(keys);
@@ -220,9 +218,9 @@ SR_API int sr_session_load(const char *filename)
 }
 
 /**
- * Save the current session to the specified file.
+ * Save a session to the specified file.
  *
- * @param filename The name of the filename to save the current session as.
+ * @param filename The name of the filename to save the session as.
  *                 Must not be NULL.
  * @param sdi The device instance from which the data was captured.
  * @param buf The data to be saved.
@@ -232,9 +230,12 @@ SR_API int sr_session_load(const char *filename)
  * @retval SR_OK Success
  * @retval SR_ERR_ARG Invalid arguments
  * @retval SR_ERR Other errors
+ *
+ * @since 0.2.0
  */
-SR_API int sr_session_save(const char *filename, const struct sr_dev_inst *sdi,
-               unsigned char *buf, int unitsize, int units)
+SR_API int sr_session_save(struct sr_session *session, const char *filename,
+               const struct sr_dev_inst *sdi, unsigned char *buf, int unitsize,
+               int units)
 {
        struct sr_channel *ch;
        GSList *l;
@@ -266,10 +267,11 @@ SR_API int sr_session_save(const char *filename, const struct sr_dev_inst *sdi,
                channel_names[cnt++] = ch->name;
        }
 
-       if ((ret = sr_session_save_init(filename, samplerate, channel_names)) != SR_OK)
+       if ((ret = sr_session_save_init(session, filename, samplerate,
+                       channel_names)) != SR_OK)
                return ret;
 
-       ret = sr_session_append(filename, buf, unitsize, units);
+       ret = sr_session_append(session, filename, buf, unitsize, units);
 
        return ret;
 }
@@ -277,7 +279,7 @@ SR_API int sr_session_save(const char *filename, const struct sr_dev_inst *sdi,
 /**
  * Initialize a saved session file.
  *
- * @param filename The name of the filename to save the current session as.
+ * @param filename The name of the filename to save the session as.
  *                 Must not be NULL.
  * @param samplerate The samplerate to store for this session.
  * @param channels A NULL-terminated array of strings containing the names
@@ -286,9 +288,11 @@ SR_API int sr_session_save(const char *filename, const struct sr_dev_inst *sdi,
  * @retval SR_OK Success
  * @retval SR_ERR_ARG Invalid arguments
  * @retval SR_ERR Other errors
+ *
+ * @since 0.3.0
  */
-SR_API int sr_session_save_init(const char *filename, uint64_t samplerate,
-               char **channels)
+SR_API int sr_session_save_init(struct sr_session *session,
+               const char *filename, uint64_t samplerate, char **channels)
 {
        FILE *meta;
        struct zip *zipfile;
@@ -296,6 +300,8 @@ SR_API int sr_session_save_init(const char *filename, uint64_t samplerate,
        int tmpfile, cnt, ret, i;
        char version[1], metafile[32], *s;
 
+       (void) session;
+
        if (!filename) {
                sr_err("%s: filename was NULL", __func__);
                return SR_ERR_ARG;
@@ -377,9 +383,11 @@ SR_API int sr_session_save_init(const char *filename, uint64_t samplerate,
  * @retval SR_OK Success
  * @retval SR_ERR_ARG Invalid arguments
  * @retval SR_ERR Other errors
+ *
+ * @since 0.3.0
  */
-SR_API int sr_session_append(const char *filename, unsigned char *buf,
-               int unitsize, int units)
+SR_API int sr_session_append(struct sr_session *session, const char *filename,
+               unsigned char *buf, int unitsize, int units)
 {
        struct zip *archive;
        struct zip_source *logicsrc;
@@ -394,6 +402,8 @@ SR_API int sr_session_append(const char *filename, unsigned char *buf,
        const char *entry_name;
        char *metafile, tmpname[32], chunkname[16];
 
+       (void) session;
+
        if ((ret = sr_sessionfile_check(filename)) != SR_OK)
                return ret;