From: Bert Vermeulen Date: Sat, 2 Aug 2014 17:20:00 +0000 (+0200) Subject: output: Modules can keep track of option resources without wrapper help. X-Git-Tag: libsigrok-0.4.0~1175 X-Git-Url: https://sigrok.org/gitweb/?a=commitdiff_plain;h=950043c30ecd2a0d1d15a14f0d07f29b06157fc6;p=libsigrok.git output: Modules can keep track of option resources without wrapper help. --- diff --git a/src/libsigrok-internal.h b/src/libsigrok-internal.h index a18ccf6a..63fcff91 100644 --- a/src/libsigrok-internal.h +++ b/src/libsigrok-internal.h @@ -209,7 +209,7 @@ struct sr_output_module { * If cached is TRUE, no new GVariants are created for the def and * values fields; instead, the current values are returned. */ - struct sr_option *(*options) (gboolean cached); + struct sr_option *(*options) (void); /** * This function is called once, at the beginning of an output stream. diff --git a/src/output/ascii.c b/src/output/ascii.c index 4d97479c..45abb656 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -260,13 +260,12 @@ static struct sr_option options[] = { { 0 } }; -static struct sr_option *get_options(gboolean cached) +static struct sr_option *get_options(void) { - if (cached) - return options; - - options[0].def = g_variant_new_uint32(DEFAULT_SAMPLES_PER_LINE); - g_variant_ref_sink(options[0].def); + if (!options[0].def) { + options[0].def = g_variant_new_uint32(DEFAULT_SAMPLES_PER_LINE); + g_variant_ref_sink(options[0].def); + } return options; } diff --git a/src/output/bits.c b/src/output/bits.c index e9eace07..22212fd5 100644 --- a/src/output/bits.c +++ b/src/output/bits.c @@ -246,13 +246,12 @@ static struct sr_option options[] = { { 0 } }; -static struct sr_option *get_options(gboolean cached) +static struct sr_option *get_options(void) { - if (cached) - return options; - - options[0].def = g_variant_new_uint32(DEFAULT_SAMPLES_PER_LINE); - g_variant_ref_sink(options[0].def); + if (!options[0].def) { + options[0].def = g_variant_new_uint32(DEFAULT_SAMPLES_PER_LINE); + g_variant_ref_sink(options[0].def); + } return options; } diff --git a/src/output/hex.c b/src/output/hex.c index 428dd584..ab4ce2d3 100644 --- a/src/output/hex.c +++ b/src/output/hex.c @@ -261,13 +261,12 @@ static struct sr_option options[] = { { 0 } }; -static struct sr_option *get_options(gboolean cached) +static struct sr_option *get_options(void) { - if (cached) - return options; - - options[0].def = g_variant_new_uint32(DEFAULT_SAMPLES_PER_LINE); - g_variant_ref_sink(options[0].def); + if (!options[0].def) { + options[0].def = g_variant_new_uint32(DEFAULT_SAMPLES_PER_LINE); + g_variant_ref_sink(options[0].def); + } return options; } diff --git a/src/output/output.c b/src/output/output.c index c5533454..e0bb2f1d 100644 --- a/src/output/output.c +++ b/src/output/output.c @@ -166,7 +166,7 @@ SR_API const struct sr_option *sr_output_options_get(const struct sr_output_modu if (!o || !o->options) return NULL; - return o->options(FALSE); + return o->options(); } /** @@ -182,7 +182,7 @@ SR_API void sr_output_options_free(const struct sr_output_module *o) if (!o || !o->options) return; - for (opt = o->options(TRUE); opt->id; opt++) { + for (opt = o->options(); opt->id; opt++) { if (opt->def) { g_variant_unref(opt->def); opt->def = NULL; @@ -216,6 +216,7 @@ SR_API const struct sr_output *sr_output_new(const struct sr_output_module *o, op = g_malloc(sizeof(struct sr_output)); op->module = o; op->sdi = sdi; + if (op->module->init && op->module->init(op, options) != SR_OK) { g_free(op); op = NULL; diff --git a/src/output/wav.c b/src/output/wav.c index 61d184cc..9bf9843d 100644 --- a/src/output/wav.c +++ b/src/output/wav.c @@ -356,13 +356,12 @@ static struct sr_option options[] = { { 0 } }; -static struct sr_option *get_options(gboolean cached) +static struct sr_option *get_options(void) { - if (cached) - return options; - - options[0].def = g_variant_new_double(0); - g_variant_ref_sink(options[0].def); + if (!options[0].def) { + options[0].def = g_variant_new_double(0); + g_variant_ref_sink(options[0].def); + } return options; }