input/output modules: Adjust to GVariant-based sr_config_* functions

This commit is contained in:
Bert Vermeulen 2013-03-25 20:27:26 +01:00
parent 722db131a4
commit ec4063b83c
10 changed files with 50 additions and 35 deletions

View File

@ -121,9 +121,11 @@ static int loadfile(struct sr_input *in, const char *filename)
if (ctx->samplerate) {
packet.type = SR_DF_META;
packet.payload = &meta;
src = sr_config_new(SR_CONF_SAMPLERATE, (const void *)&ctx->samplerate);
src = sr_config_new(SR_CONF_SAMPLERATE,
g_variant_new_uint64(ctx->samplerate));
meta.config = g_slist_append(NULL, src);
sr_session_send(in->sdi, &packet);
sr_config_free(src);
}
/* Chop up the input file into chunks & send it to the session bus. */

View File

@ -172,9 +172,10 @@ static int loadfile(struct sr_input *in, const char *filename)
/* Send metadata about the SR_DF_LOGIC packets to come. */
packet.type = SR_DF_META;
packet.payload = &meta;
src = sr_config_new(SR_CONF_SAMPLERATE, (const void *)&samplerate);
src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate));
meta.config = g_slist_append(NULL, src);
sr_session_send(in->sdi, &packet);
sr_config_free(src);
/* TODO: Handle trigger point. */

View File

@ -571,9 +571,10 @@ static int loadfile(struct sr_input *in, const char *filename)
packet.type = SR_DF_META;
packet.payload = &meta;
samplerate = ctx->samplerate / ctx->downsample;
src = sr_config_new(SR_CONF_SAMPLERATE, (const void *)&samplerate);
src = sr_config_new(SR_CONF_SAMPLERATE, g_variant_new_uint64(samplerate));
meta.config = g_slist_append(NULL, src);
sr_session_send(in->sdi, &packet);
sr_config_free(src);
/* Parse the contents of the VCD file */
parse_contents(file, in->sdi, ctx);

View File

@ -148,9 +148,11 @@ static int loadfile(struct sr_input *in, const char *filename)
packet.type = SR_DF_META;
packet.payload = &meta;
src = sr_config_new(SR_CONF_SAMPLERATE, (const void *)&ctx->samplerate);
src = sr_config_new(SR_CONF_SAMPLERATE,
g_variant_new_uint64(ctx->samplerate));
meta.config = g_slist_append(NULL, src);
sr_session_send(in->sdi, &packet);
sr_config_free(src);
if ((fd = open(filename, O_RDONLY)) == -1)
return SR_ERR;

View File

@ -94,7 +94,7 @@ static int init(struct sr_output *o)
struct context *ctx;
struct sr_probe *probe;
GSList *l;
uint64_t *samplerate;
GVariant *gvar;
if (!o) {
sr_warn("%s: o was NULL", __func__);
@ -129,9 +129,9 @@ static int init(struct sr_output *o)
ctx->unitsize = (ctx->num_enabled_probes + 7) / 8;
if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
o->sdi->driver->config_get(SR_CONF_SAMPLERATE,
(const void **)&samplerate, o->sdi);
ctx->samplerate = *samplerate;
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi);
ctx->samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
} else
ctx->samplerate = 0;

View File

@ -60,8 +60,8 @@ static int init(struct sr_output *o)
struct context *ctx;
struct sr_probe *probe;
GSList *l;
GVariant *gvar;
int num_probes;
uint64_t *samplerate;
time_t t;
unsigned int i;
@ -100,9 +100,9 @@ static int init(struct sr_output *o)
num_probes = g_slist_length(o->sdi->probes);
if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
o->sdi->driver->config_get(SR_CONF_SAMPLERATE,
(const void **)&samplerate, o->sdi);
ctx->samplerate = *samplerate;
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi);
ctx->samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
} else
ctx->samplerate = 0;

View File

@ -63,7 +63,8 @@ static int init(struct sr_output *o)
struct context *ctx;
struct sr_probe *probe;
GSList *l;
uint64_t *samplerate;
GVariant *gvar;
uint64_t samplerate;
unsigned int i;
int b, num_probes;
char *c, *frequency_s;
@ -99,7 +100,7 @@ static int init(struct sr_output *o)
o->internal = ctx;
ctx->num_enabled_probes = 0;
for (l = o->sdi->probes; l; l = l->next) {
probe = l->data; /* TODO: Error checks. */
probe = l->data;
if (!probe->enabled)
continue;
ctx->probelist[ctx->num_enabled_probes++] = probe->name;
@ -109,18 +110,21 @@ static int init(struct sr_output *o)
num_probes = g_slist_length(o->sdi->probes);
comment[0] = '\0';
samplerate = 0;
if (sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
o->sdi->driver->config_get(SR_CONF_SAMPLERATE,
(const void **)&samplerate, o->sdi);
if (!(frequency_s = sr_samplerate_string(*samplerate))) {
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi);
samplerate = g_variant_get_uint64(gvar);
if (!(frequency_s = sr_samplerate_string(samplerate))) {
sr_err("%s: sr_samplerate_string failed", __func__);
g_free(ctx->header);
g_free(ctx);
g_variant_unref(gvar);
return SR_ERR;
}
snprintf(comment, 127, gnuplot_header_comment,
ctx->num_enabled_probes, num_probes, frequency_s);
g_free(frequency_s);
g_variant_unref(gvar);
}
/* Columns / channels */
@ -130,7 +134,7 @@ static int init(struct sr_output *o)
sprintf(c, "# %d\t\t%s\n", i + 1, ctx->probelist[i]);
}
if (!(frequency_s = sr_period_string(*samplerate))) {
if (!(frequency_s = sr_period_string(samplerate))) {
sr_err("%s: sr_period_string failed", __func__);
g_free(ctx->header);
g_free(ctx);

View File

@ -51,7 +51,8 @@ static int init(struct sr_output *o)
struct context *ctx;
struct sr_probe *probe;
GSList *l;
uint64_t *samplerate, tmp;
GVariant *gvar;
uint64_t samplerate;
int num_enabled_probes;
if (!(ctx = g_try_malloc(sizeof(struct context)))) {
@ -69,16 +70,16 @@ static int init(struct sr_output *o)
}
ctx->unitsize = (num_enabled_probes + 7) / 8;
if (o->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE))
o->sdi->driver->config_get(SR_CONF_SAMPLERATE,
(const void **)&samplerate, o->sdi);
else {
tmp = 0;
samplerate = &tmp;
if (o->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi);
samplerate = g_variant_get_uint64(gvar);
g_variant_unref(gvar);
} else {
samplerate = 0;
}
ctx->header = g_string_sized_new(512);
g_string_append_printf(ctx->header, ";Rate: %"PRIu64"\n", *samplerate);
g_string_append_printf(ctx->header, ";Rate: %"PRIu64"\n", samplerate);
g_string_append_printf(ctx->header, ";Channels: %d\n", num_enabled_probes);
g_string_append_printf(ctx->header, ";EnabledChannels: -1\n");
g_string_append_printf(ctx->header, ";Compressed: true\n");

View File

@ -79,7 +79,8 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
struct context *ctx;
struct sr_probe *probe;
GSList *l;
uint64_t *samplerate;
GVariant *gvar;
uint64_t samplerate;
int num_probes, ret;
char *samplerate_s;
@ -124,12 +125,13 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
snprintf(ctx->header, 511, "%s\n", PACKAGE_STRING);
num_probes = g_slist_length(o->sdi->probes);
if (o->sdi->driver || sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
ret = o->sdi->driver->config_get(SR_CONF_SAMPLERATE,
(const void **)&samplerate, o->sdi);
if (ret != SR_OK)
if ((ret = o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar,
o->sdi)) != SR_OK)
goto err;
if (!(samplerate_s = sr_samplerate_string(*samplerate))) {
samplerate = g_variant_get_uint64(gvar);
if (!(samplerate_s = sr_samplerate_string(samplerate))) {
ret = SR_ERR;
g_variant_unref(gvar);
goto err;
}
snprintf(ctx->header + strlen(ctx->header),
@ -137,6 +139,7 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode)
"Acquisition with %d/%d probes at %s\n",
ctx->num_enabled_probes, num_probes, samplerate_s);
g_free(samplerate_s);
g_variant_unref(gvar);
}
ctx->linebuf_len = ctx->samples_per_line * 2 + 4;

View File

@ -53,7 +53,7 @@ static int init(struct sr_output *o)
struct context *ctx;
struct sr_probe *probe;
GSList *l;
uint64_t *samplerate;
GVariant *gvar;
int num_probes, i;
char *samplerate_s, *frequency_s, *timestamp;
time_t t;
@ -93,17 +93,18 @@ static int init(struct sr_output *o)
PACKAGE, PACKAGE_VERSION);
if (o->sdi->driver && sr_dev_has_option(o->sdi, SR_CONF_SAMPLERATE)) {
o->sdi->driver->config_get(SR_CONF_SAMPLERATE,
(const void **)&samplerate, o->sdi);
ctx->samplerate = *samplerate;
o->sdi->driver->config_get(SR_CONF_SAMPLERATE, &gvar, o->sdi);
ctx->samplerate = g_variant_get_uint64(gvar);
if (!((samplerate_s = sr_samplerate_string(ctx->samplerate)))) {
g_string_free(ctx->header, TRUE);
g_free(ctx);
g_variant_unref(gvar);
return SR_ERR;
}
g_string_append_printf(ctx->header, vcd_header_comment,
ctx->num_enabled_probes, num_probes, samplerate_s);
g_free(samplerate_s);
g_variant_unref(gvar);
}
/* timescale */