struct context {
unsigned int num_enabled_channels;
- int samples_per_line;
+ int spl;
int bit_cnt;
int spl_cnt;
int trigger;
struct context *ctx;
struct sr_channel *ch;
GSList *l;
- GHashTableIter iter;
- gpointer key, value;
unsigned int i, j;
- uint32_t spl;
if (!o || !o->sdi)
return SR_ERR_ARG;
- spl = DEFAULT_SAMPLES_PER_LINE;
- if (options) {
- g_hash_table_iter_init(&iter, options);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- if (!strcmp(key, "width")) {
- if (!g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
- sr_err("Invalid type for 'width' option.");
- return SR_ERR_ARG;
- }
- if (!(spl = g_variant_get_uint32(value))) {
- sr_err("Invalid width.");
- return SR_ERR_ARG;
- }
- } else {
- sr_err("Unknown option '%s'.", key);
- }
- }
- }
-
ctx = g_malloc0(sizeof(struct context));
o->priv = ctx;
ctx->trigger = -1;
- ctx->samples_per_line = spl;
+ ctx->spl = g_variant_get_uint32(g_hash_table_lookup(options, "width"));
for (l = o->sdi->channels; l; l = l->next) {
ch = l->data;
}
g_string_append_c(ctx->lines[j], c);
- if (ctx->spl_cnt == ctx->samples_per_line) {
+ if (ctx->spl_cnt == ctx->spl) {
/* Flush line buffers. */
g_string_append_len(*out, ctx->lines[j]->str, ctx->lines[j]->len);
g_string_append_c(*out, '\n');
g_string_printf(ctx->lines[j], "%s:", ctx->channel_names[j]);
}
}
- if (ctx->spl_cnt == ctx->samples_per_line)
+ if (ctx->spl_cnt == ctx->spl)
/* Line buffers were already flushed. */
ctx->spl_cnt = 0;
memcpy(ctx->prev_sample, logic->data + i, logic->unitsize);
struct context {
unsigned int num_enabled_channels;
- int samples_per_line;
+ int spl;
int spl_cnt;
int trigger;
uint64_t samplerate;
struct context *ctx;
struct sr_channel *ch;
GSList *l;
- GHashTableIter iter;
- gpointer key, value;
unsigned int i, j;
- uint32_t spl;
if (!o || !o->sdi)
return SR_ERR_ARG;
- spl = DEFAULT_SAMPLES_PER_LINE;
- if (options) {
- g_hash_table_iter_init(&iter, options);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- if (!strcmp(key, "width")) {
- if (!g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
- sr_err("Invalid type for 'width' option.");
- return SR_ERR_ARG;
- }
- if (!(spl = g_variant_get_uint32(value))) {
- sr_err("Invalid width.");
- return SR_ERR_ARG;
- }
- } else {
- sr_err("Unknown option '%s'.", key);
- }
- }
- }
-
ctx = g_malloc0(sizeof(struct context));
o->priv = ctx;
ctx->trigger = -1;
- ctx->samples_per_line = spl;
+ ctx->spl = g_variant_get_uint32(g_hash_table_lookup(options, "width"));
for (l = o->sdi->channels; l; l = l->next) {
ch = l->data;
c = (*p & (1 << (idx % 8))) ? '1' : '0';
g_string_append_c(ctx->lines[j], c);
- if (ctx->spl_cnt == ctx->samples_per_line) {
+ if (ctx->spl_cnt == ctx->spl) {
/* Flush line buffers. */
g_string_append_len(*out, ctx->lines[j]->str, ctx->lines[j]->len);
g_string_append_c(*out, '\n');
g_string_append_c(ctx->lines[j], ' ');
}
}
- if (ctx->spl_cnt == ctx->samples_per_line)
+ if (ctx->spl_cnt == ctx->spl)
/* Line buffers were already flushed. */
ctx->spl_cnt = 0;
}
struct context {
unsigned int num_enabled_channels;
- int samples_per_line;
+ int spl;
int bit_cnt;
int spl_cnt;
int trigger;
struct context *ctx;
struct sr_channel *ch;
GSList *l;
- GHashTableIter iter;
- gpointer key, value;
unsigned int i, j;
- uint32_t spl;
if (!o || !o->sdi)
return SR_ERR_ARG;
- spl = DEFAULT_SAMPLES_PER_LINE;
- if (options) {
- g_hash_table_iter_init(&iter, options);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- if (!strcmp(key, "width")) {
- if (!g_variant_is_of_type(value, G_VARIANT_TYPE_UINT32)) {
- sr_err("Invalid type for 'width' option.");
- return SR_ERR_ARG;
- }
- if (!(spl = g_variant_get_uint32(value))) {
- sr_err("Invalid width.");
- return SR_ERR_ARG;
- }
- } else {
- sr_err("Unknown option '%s'.", key);
- return SR_ERR_ARG;
- }
- }
- }
-
ctx = g_malloc0(sizeof(struct context));
o->priv = ctx;
ctx->trigger = -1;
- ctx->samples_per_line = spl;
+ ctx->spl = g_variant_get_uint32(g_hash_table_lookup(options, "width"));
for (l = o->sdi->channels; l; l = l->next) {
ch = l->data;
ctx->sample_buf[j] = 0;
}
- if (ctx->spl_cnt == ctx->samples_per_line) {
+ if (ctx->spl_cnt == ctx->spl) {
/* Flush line buffers. */
g_string_append_len(*out, ctx->lines[j]->str, ctx->lines[j]->len);
g_string_append_c(*out, '\n');
g_string_printf(ctx->lines[j], "%s:", ctx->channel_names[j]);
}
}
- if (ctx->spl_cnt == ctx->samples_per_line)
+ if (ctx->spl_cnt == ctx->spl)
/* Line buffers were already flushed. */
ctx->spl_cnt = 0;
}
GHashTable *options, const struct sr_dev_inst *sdi)
{
struct sr_output *op;
+ struct sr_option *mod_opts;
+ const GVariantType *gvt;
+ GHashTable *new_opts;
+ GHashTableIter iter;
+ gpointer key, value;
+ int i;
op = g_malloc(sizeof(struct sr_output));
op->module = o;
op->sdi = sdi;
- if (op->module->init && op->module->init(op, options) != SR_OK) {
+ if (options) {
+ new_opts = g_hash_table_new_full(g_str_hash, g_str_equal, g_free,
+ (GDestroyNotify)g_variant_unref);
+ mod_opts = o->options();
+ for (i = 0; mod_opts[i].id; i++) {
+ if (g_hash_table_lookup_extended(options, mod_opts[i].id,
+ &key, &value)) {
+ /* Option not given: insert the default value. */
+ gvt = g_variant_get_type(mod_opts[i].def);
+ if (!g_variant_is_of_type(value, gvt)) {
+ sr_err("Invalid type for '%s' option.", key);
+ g_free(op);
+ return NULL;
+ }
+ g_hash_table_insert(new_opts, g_strdup(mod_opts[i].id),
+ g_variant_ref(value));
+ } else {
+ /* Pass option along. */
+ g_hash_table_insert(new_opts, g_strdup(mod_opts[i].id),
+ g_variant_ref(mod_opts[i].def));
+ }
+ }
+
+ /* Make sure no invalid options were given. */
+ g_hash_table_iter_init(&iter, options);
+ while (g_hash_table_iter_next(&iter, &key, &value)) {
+ if (!g_hash_table_lookup(new_opts, key)) {
+ sr_err("Output module '%s' has no option '%s'", o->id, key);
+ g_hash_table_destroy(new_opts);
+ g_free(op);
+ return NULL;
+ }
+ }
+ } else
+ new_opts = NULL;
+
+ if (op->module->init && op->module->init(op, new_opts) != SR_OK) {
+ g_hash_table_destroy(new_opts);
g_free(op);
op = NULL;
}
+ g_hash_table_destroy(new_opts);
return op;
}
struct out_context *outc;
struct sr_channel *ch;
GSList *l;
- GHashTableIter iter;
- gpointer key, value;
outc = g_malloc0(sizeof(struct out_context));
o->priv = outc;
-
- outc->scale = 0.0;
- if (options) {
- g_hash_table_iter_init(&iter, options);
- while (g_hash_table_iter_next(&iter, &key, &value)) {
- if (!strcmp(key, "scale")) {
- if (!g_variant_is_of_type(value, G_VARIANT_TYPE_DOUBLE)) {
- sr_err("Invalid type for 'scale' option.");
- return SR_ERR_ARG;
- }
- outc->scale = g_variant_get_double(value);
- } else {
- sr_err("Unknown option '%s'.", key);
- return SR_ERR_ARG;
- }
- }
- }
+ outc->scale = g_variant_get_double(g_hash_table_lookup(options, "scale"));
for (l = o->sdi->channels; l; l = l->next) {
ch = l->data;
static struct sr_option *get_options(void)
{
if (!options[0].def) {
- options[0].def = g_variant_new_double(0);
+ options[0].def = g_variant_new_double(0.0);
g_variant_ref_sink(options[0].def);
}