X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fsession_file.c;h=9def98d732efdcb1aef743345627bc6dfd9d4481;hb=2a8f2d41adcd0aa9e498c4eea2a5f82263039e5c;hp=e27ed85c0adf3f256b6a76cefbfab62f8922816a;hpb=5e23fcab889c62864b92aa3ad6902ce3e9f5be49;p=libsigrok.git diff --git a/src/session_file.c b/src/session_file.c index e27ed85c..9def98d7 100644 --- a/src/session_file.c +++ b/src/session_file.c @@ -17,6 +17,7 @@ * along with this program. If not, see . */ +#include #include #include #include @@ -26,8 +27,7 @@ #include #include #include -#include "config.h" /* Needed for PACKAGE_VERSION and others. */ -#include "libsigrok.h" +#include #include "libsigrok-internal.h" /** @cond PRIVATE */ @@ -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) { @@ -64,7 +63,7 @@ SR_PRIV int sr_sessionfile_check(const char *filename) return SR_ERR_ARG; if (stat(filename, &st) == -1) { - sr_err("Couldn't stat %s: %s", filename, strerror(errno)); + sr_err("Couldn't stat %s: %s", filename, g_strerror(errno)); return SR_ERR; } @@ -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; @@ -122,6 +123,7 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) struct zip_file *zf; struct zip_stat zs; struct sr_dev_inst *sdi; + struct sr_channel *ch; int ret, i, j; uint64_t tmp_u64, total_channels, p; char **sections, **keys, *metafile, *val; @@ -151,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; @@ -174,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); @@ -219,10 +221,11 @@ SR_API int sr_session_load(const char *filename, struct sr_session **session) 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); @@ -348,7 +351,7 @@ SR_API int sr_session_save_init(struct sr_session *session, close(tmpfile); meta = g_fopen(metafile, "wb"); fprintf(meta, "[global]\n"); - fprintf(meta, "sigrok version = %s\n", PACKAGE_VERSION); + fprintf(meta, "sigrok version = %s\n", SR_PACKAGE_VERSION_STRING); /* metadata */ fprintf(meta, "[device 1]\n"); @@ -462,7 +465,7 @@ SR_API int sr_session_append(struct sr_session *session, const char *filename, if ((tmpfile = g_mkstemp(tmpname)) == -1) return SR_ERR; if (write(tmpfile, metafile, len) < 0) { - sr_dbg("Failed to create new metadata: %s", strerror(errno)); + sr_dbg("Failed to create new metadata: %s", g_strerror(errno)); g_free(metafile); unlink(tmpname); return SR_ERR;