]> sigrok.org Git - sigrok-test.git/blobdiff - decoder/runtc.c
runtc: avoid the 'class' identifier in C language application code
[sigrok-test.git] / decoder / runtc.c
index ec8c812f745b031985eb392ed62ee02fe47e3216..f095933df8697f1779a7da026d806013539f8c40 100644 (file)
@@ -17,6 +17,8 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <config.h>
+
 #include <Python.h>
 #include <libsigrokdecode/libsigrokdecode.h>
 #include <libsigrok/libsigrok.h>
@@ -68,7 +70,7 @@ struct output {
        const char *pd;
        const char *pd_id;
        int type;
-       const char *class;
+       const char *class_;
        int class_idx;
        const char *outfile;
        int outfd;
@@ -366,6 +368,9 @@ static void sr_cb(const struct sr_dev_inst *sdi,
                break;
        case SR_DF_END:
                DBG("Received SR_DF_END");
+#if defined HAVE_SRD_SESSION_SEND_EOF && HAVE_SRD_SESSION_SEND_EOF
+               (void)srd_session_send_eof(sess);
+#endif
                break;
        }
 
@@ -400,13 +405,17 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op)
                }
        }
 
-       if (sr_session_load(ctx, infile, &sr_sess) != SR_OK)
+       if (sr_session_load(ctx, infile, &sr_sess) != SR_OK){
+               ERR("sr_session_load() failed");
                return FALSE;
+       }
 
        sr_session_dev_list(sr_sess, &devices);
 
-       if (srd_session_new(&sess) != SRD_OK)
+       if (srd_session_new(&sess) != SRD_OK) {
+               ERR("srd_session_new() failed");
                return FALSE;
+       }
        sr_session_datafeed_callback_add(sr_sess, sr_cb, sess);
        switch (op->type) {
        case SRD_OUTPUT_ANN:
@@ -419,6 +428,7 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op)
                cb = srd_cb_py;
                break;
        default:
+               ERR("Invalid op->type");
                return FALSE;
        }
        srd_pd_output_callback_add(sess, op->type, cb, op);
@@ -427,8 +437,10 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op)
        pd = NULL;
        for (pdl = pdlist; pdl; pdl = pdl->next) {
                pd = pdl->data;
-               if (srd_decoder_load(pd->name) != SRD_OK)
+               if (srd_decoder_load(pd->name) != SRD_OK) {
+                       ERR("srd_decoder_load() failed");
                        return FALSE;
+               }
 
                /* Instantiate decoder and pass in options. */
                opts = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
@@ -452,8 +464,10 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op)
                                g_hash_table_insert(opts, option->key, option->value);
                        }
                }
-               if (!(di = srd_inst_new(sess, pd->name, opts)))
+               if (!(di = srd_inst_new(sess, pd->name, opts))) {
+                       ERR("srd_inst_new() failed");
                        return FALSE;
+               }
                g_hash_table_destroy(opts);
 
                /*
@@ -481,8 +495,10 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op)
                                g_hash_table_insert(channels, channel->name, gvar);
                        }
 
-                       if (srd_inst_channel_set_all(di, channels) != SRD_OK)
+                       if (srd_inst_channel_set_all(di, channels) != SRD_OK) {
+                               ERR("srd_inst_channel_set_all() failed");
                                return FALSE;
+                       }
                        g_hash_table_destroy(channels);
                }
 
@@ -503,8 +519,10 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op)
                                }
                        }
 
-                       if (srd_inst_initial_pins_set_all(di, initial_pins) != SRD_OK)
+                       if (srd_inst_initial_pins_set_all(di, initial_pins) != SRD_OK) {
+                               ERR("srd_inst_initial_pins_set_all() failed");
                                return FALSE;
+                       }
                        g_array_free(initial_pins, TRUE);
                }
 
@@ -524,23 +542,27 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op)
         * Bail out if we haven't created an instance of the selected
         * decoder type of which we shall grab output data from.
         */
-       if (!op->pd_id)
+       if (!op->pd_id) {
+               ERR("No / invalid decoder");
                return FALSE;
+       }
 
        /* Resolve selected decoder's class index, so we can match. */
        dec = srd_decoder_get_by_id(pd->name);
-       if (op->class) {
+       if (op->class_) {
                if (op->type == SRD_OUTPUT_ANN)
                        l = dec->annotations;
                else if (op->type == SRD_OUTPUT_BINARY)
                        l = dec->binary;
-               else
+               else {
                        /* Only annotations and binary can have a class. */
+                       ERR("Invalid decoder class");
                        return FALSE;
+               }
                idx = 0;
                while (l) {
                        decoder_class = l->data;
-                       if (!strcmp(decoder_class[0], op->class)) {
+                       if (!strcmp(decoder_class[0], op->class_)) {
                                op->class_idx = idx;
                                break;
                        }
@@ -549,10 +571,10 @@ static int run_testcase(const char *infile, GSList *pdlist, struct output *op)
                }
                if (op->class_idx == -1) {
                        ERR("Output class '%s' not found in decoder %s.",
-                                       op->class, pd->name);
+                                       op->class_, pd->name);
                        return FALSE;
                }
-               DBG("Class %s index is %d", op->class, op->class_idx);
+               DBG("Class %s index is %d", op->class_, op->class_idx);
        }
 
        sr_session_start(sr_sess);
@@ -805,7 +827,7 @@ int main(int argc, char **argv)
        op->pd = NULL;
        op->pd_id = NULL;
        op->type = -1;
-       op->class = NULL;
+       op->class_ = NULL;
        op->class_idx = -1;
        op->outfd = 1;
 
@@ -887,7 +909,7 @@ int main(int argc, char **argv)
                                usage(NULL);
                        }
                        if (opstr[2])
-                               op->class = g_strdup(opstr[2]);
+                               op->class_ = g_strdup(opstr[2]);
                        g_strfreev(opstr);
                        break;
                case 'f':