]> sigrok.org Git - sigrok-cli.git/commitdiff
Add struct sr_context to the sr_init() and sr_exit() calls
authorPeter Stuge <redacted>
Sun, 21 Oct 2012 18:43:32 +0000 (20:43 +0200)
committerPeter Stuge <redacted>
Sun, 21 Oct 2012 19:12:54 +0000 (21:12 +0200)
libsigrok.git commit b8072700c1bc7d13ba004fd897668b56cec4ac62 adds
struct sr_context to the public API, and changes sr_init() and sr_exit()
to take a struct sr_context ** and struct sr_context * parameter,
respectively.

struct sr_context is opaque, and all sr_init() and sr_exit() calls must
be balanced.

Thanks to the new struct sr_context * the error path code flow can also
be simplifed, and allow a single point in main() to clean up after any
possible program state.

sigrok-cli.c

index 2f6c59d80b26bb1eb016ea05fd27426f70943320..a626636dd137644f3b07ce5115ce074dcd5798ec 100644 (file)
@@ -1478,6 +1478,7 @@ int main(int argc, char **argv)
        int ret = 1;
        GOptionContext *context;
        GError *error;
        int ret = 1;
        GOptionContext *context;
        GError *error;
+       struct sr_context *sr_ctx = NULL;
 
        g_log_set_default_handler(logger, NULL);
 
 
        g_log_set_default_handler(logger, NULL);
 
@@ -1487,19 +1488,19 @@ int main(int argc, char **argv)
 
        if (!g_option_context_parse(context, &argc, &argv, &error)) {
                g_critical("%s", error->message);
 
        if (!g_option_context_parse(context, &argc, &argv, &error)) {
                g_critical("%s", error->message);
-               goto done_noexit;
+               goto done;
        }
 
        /* Set the loglevel (amount of messages to output) for libsigrok. */
        if (sr_log_loglevel_set(opt_loglevel) != SR_OK)
        }
 
        /* Set the loglevel (amount of messages to output) for libsigrok. */
        if (sr_log_loglevel_set(opt_loglevel) != SR_OK)
-               goto done_noexit;
+               goto done;
 
        /* Set the loglevel (amount of messages to output) for libsigrokdecode. */
        if (srd_log_loglevel_set(opt_loglevel) != SRD_OK)
 
        /* Set the loglevel (amount of messages to output) for libsigrokdecode. */
        if (srd_log_loglevel_set(opt_loglevel) != SRD_OK)
-               goto done_noexit;
+               goto done;
 
 
-       if (sr_init() != SR_OK)
-               goto done_noexit;
+       if (sr_init(&sr_ctx) != SR_OK)
+               goto done;
 
        if (opt_pds) {
                if (srd_init(NULL) != SRD_OK)
 
        if (opt_pds) {
                if (srd_init(NULL) != SRD_OK)
@@ -1539,9 +1540,9 @@ int main(int argc, char **argv)
        ret = 0;
 
 done:
        ret = 0;
 
 done:
-       sr_exit();
+       if (sr_ctx)
+               sr_exit(sr_ctx);
 
 
-done_noexit:
        g_option_context_free(context);
 
        return ret;
        g_option_context_free(context);
 
        return ret;