X-Git-Url: http://sigrok.org/gitweb/?a=blobdiff_plain;f=session.c;h=210b73bad8c50e592ec3d65596d4b475f0f26eaf;hb=62c820258238485d3352f4a68a65d299b136b792;hp=0dc5142455b42a64e7a451cdc270b29d9c652214;hpb=1b452b8510922bac08db87f8ea769515c795e22f;p=libsigrok.git diff --git a/session.c b/session.c index 0dc51424..210b73ba 100644 --- a/session.c +++ b/session.c @@ -22,17 +22,16 @@ #include #include #include -#include "sigrok.h" +#include -/* there can only be one session at a time */ +/* There can only be one session at a time. */ struct session *session; - struct session *session_load(const char *filename) { struct session *session; - /* TODO: implement */ + /* TODO: Implement. */ session = NULL; /* QUICK HACK */ @@ -41,84 +40,66 @@ struct session *session_load(const char *filename) return session; } - struct session *session_new(void) { - session = calloc(1, sizeof(struct session)); return session; } - void session_destroy(void) { - g_slist_free(session->devices); - /* TODO: loop over protocols and free them */ + /* TODO: Loop over protocols and free them. */ g_free(session); - } - void session_device_clear(void) { - g_slist_free(session->devices); session->devices = NULL; - } - int session_device_add(struct device *device) { int ret; ret = device->plugin->open(device->plugin_index); - if(ret == SIGROK_OK) + if (ret == SIGROK_OK) session->devices = g_slist_append(session->devices, device); return ret; } - void session_pa_clear(void) { - - /* the protocols are pointers to the global set of PA plugins, so don't free them */ + /* + * The protocols are pointers to the global set of PA plugins, + * so don't free them. + */ g_slist_free(session->analyzers); session->analyzers = NULL; - } - void session_pa_add(struct analyzer *an) { - session->analyzers = g_slist_append(session->analyzers, an); - } - void session_datafeed_callback_clear(void) { - g_slist_free(session->datafeed_callbacks); session->datafeed_callbacks = NULL; - } - void session_datafeed_callback_add(datafeed_callback callback) { - - session->datafeed_callbacks = g_slist_append(session->datafeed_callbacks, callback); - + session->datafeed_callbacks = + g_slist_append(session->datafeed_callbacks, callback); } - int session_start(void) { struct device *device; @@ -126,50 +107,43 @@ int session_start(void) int ret; g_message("starting acquisition"); - for(l = session->devices; l; l = l->next) - { + for (l = session->devices; l; l = l->next) { device = l->data; - if( (ret = device->plugin->start_acquisition(device->plugin_index, device)) != SIGROK_OK) + if ((ret = device->plugin->start_acquisition( + device->plugin_index, device)) != SIGROK_OK) break; } return ret; } - void session_stop(void) { struct device *device; GSList *l; g_message("stopping acquisition"); - for(l = session->devices; l; l = l->next) - { + for (l = session->devices; l; l = l->next) { device = l->data; device->plugin->stop_acquisition(device->plugin_index, device); } - } - void session_bus(struct device *device, struct datafeed_packet *packet) { GSList *l; datafeed_callback cb; - /* TODO: send packet through PA pipe, and send the output of that to - * the callbacks as well + /* + * TODO: Send packet through PA pipe, and send the output of that to + * the callbacks as well. */ - - for(l = session->datafeed_callbacks; l; l = l->next) - { + for (l = session->datafeed_callbacks; l; l = l->next) { cb = l->data; cb(device, packet); } - } - void make_metadata(char *filename) { GSList *l, *p; @@ -180,38 +154,38 @@ void make_metadata(char *filename) f = fopen(filename, "wb"); - /* general */ + /* General */ - /* devices */ + /* Devices */ devcnt = 1; - for(l = session->devices; l; l = l->next) { + for (l = session->devices; l; l = l->next) { device = l->data; fprintf(f, "[device]\n"); fprintf(f, "driver = %s\n", device->plugin->name); - if(device->datastore) + + if (device->datastore) fprintf(f, "capturefile = raw-%d\n", devcnt); - for(p = device->probes; p; p = p->next) { + + for (p = device->probes; p; p = p->next) { probe = p->data; - if(probe->enabled) - { + if (probe->enabled) { fprintf(f, "probe %d", probe->index); - if(probe->name) + if (probe->name) fprintf(f, " name \"%s\"", probe->name); - if(probe->trigger) - fprintf(f, " trigger \"%s\"", probe->trigger); + if (probe->trigger) + fprintf(f, " trigger \"%s\"", + probe->trigger); fprintf(f, "\n"); } } devcnt++; } - /* TODO: protocol analyzers */ + /* TODO: Protocol analyzers */ fclose(f); - } - int session_save(char *filename) { GSList *l, *d; @@ -222,55 +196,59 @@ int session_save(char *filename) int bufcnt, devcnt, tmpfile, ret, error; char version[1], rawname[16], metafile[32], *buf; - /* quietly delete it first, libzip wants replace ops otherwise */ + /* Quietly delete it first, libzip wants replace ops otherwise. */ unlink(filename); - if( !(zipfile = zip_open(filename, ZIP_CREATE, &error)) ) + if (!(zipfile = zip_open(filename, ZIP_CREATE, &error))) return SIGROK_ERR; - /* version */ + /* Version */ version[0] = '1'; - if( !(src = zip_source_buffer(zipfile, version, 1, 0)) ) + if (!(src = zip_source_buffer(zipfile, version, 1, 0))) return SIGROK_ERR; - if(zip_add(zipfile, "version", src) == -1) { - g_message("error saving version into zipfile: %s", zip_strerror(zipfile)); + if (zip_add(zipfile, "version", src) == -1) { + g_message("error saving version into zipfile: %s", + zip_strerror(zipfile)); return SIGROK_ERR; } - /* metadata */ + /* Metadata */ strcpy(metafile, "sigrok-meta-XXXXXX"); - if( (tmpfile = g_mkstemp(metafile)) == -1) + if ((tmpfile = g_mkstemp(metafile)) == -1) return SIGROK_ERR; close(tmpfile); make_metadata(metafile); - if( !(src = zip_source_file(zipfile, metafile, 0, -1)) ) + if (!(src = zip_source_file(zipfile, metafile, 0, -1))) return SIGROK_ERR; - if(zip_add(zipfile, "metadata", src) == -1) + if (zip_add(zipfile, "metadata", src) == -1) return SIGROK_ERR; unlink(metafile); - /* raw */ + /* Raw */ devcnt = 1; - for(l = session->devices; l; l = l->next) { + for (l = session->devices; l; l = l->next) { device = l->data; ds = device->datastore; - if(ds) { - buf = malloc(ds->num_units * ds->ds_unitsize + DATASTORE_CHUNKSIZE); + if (ds) { + buf = malloc(ds->num_units * ds->ds_unitsize + + DATASTORE_CHUNKSIZE); bufcnt = 0; - for(d = ds->chunklist; d; d = d->next) { - memcpy(buf + bufcnt, d->data, DATASTORE_CHUNKSIZE); + for (d = ds->chunklist; d; d = d->next) { + memcpy(buf + bufcnt, d->data, + DATASTORE_CHUNKSIZE); bufcnt += DATASTORE_CHUNKSIZE; } - if( !(src = zip_source_buffer(zipfile, buf, ds->num_units * ds->ds_unitsize, TRUE)) ) + if (!(src = zip_source_buffer(zipfile, buf, + ds->num_units * ds->ds_unitsize, TRUE))) return SIGROK_ERR; snprintf(rawname, 15, "raw-%d", devcnt); - if(zip_add(zipfile, rawname, src) == -1) + if (zip_add(zipfile, rawname, src) == -1) return SIGROK_ERR; } devcnt++; } - if( (ret = zip_close(zipfile)) == -1) { + if ((ret = zip_close(zipfile)) == -1) { g_message("error saving zipfile: %s", zip_strerror(zipfile)); return SIGROK_ERR; }