]> sigrok.org Git - libsigrok.git/commitdiff
output: Modules can keep track of option resources without wrapper help.
authorBert Vermeulen <redacted>
Sat, 2 Aug 2014 17:20:00 +0000 (19:20 +0200)
committerBert Vermeulen <redacted>
Sat, 2 Aug 2014 17:20:00 +0000 (19:20 +0200)
src/libsigrok-internal.h
src/output/ascii.c
src/output/bits.c
src/output/hex.c
src/output/output.c
src/output/wav.c

index a18ccf6ae47787a7858d687f6ded1aadcdb0d080..63fcff919c93f8c2c8455f44d084533aae1a9bba 100644 (file)
@@ -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.
index 4d97479ce8c70c883f2434dc18be422e20c06c0e..45abb656447433a01e6ecc65d08ceeccb5971280 100644 (file)
@@ -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;
 }
index e9eace0793702f7b8d531426767e40403f540329..22212fd5cd205c088884ce396be49882ada6c4f2 100644 (file)
@@ -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;
 }
index 428dd58494f09592a0a1e567f83791dd5ed07402..ab4ce2d37cbc3a485652010f6e9cf53d28c6fc4c 100644 (file)
@@ -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;
 }
index c55334548ceaa90753a39f917029e4f0506bf2f0..e0bb2f1d7b1a1a3361fdd850fdfdcd2f359f46cf 100644 (file)
@@ -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;
index 61d184ccb5ce52333ce266605b7588022287f22c..9bf9843d18cd9333fbf01e26698a68c8f1b8da7d 100644 (file)
@@ -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;
 }