]> sigrok.org Git - libsigrokdecode.git/commitdiff
srd_inst_stack(): Warn upon potentially incorrect stacking.
authorUwe Hermann <redacted>
Tue, 2 Apr 2019 19:35:32 +0000 (21:35 +0200)
committerUwe Hermann <redacted>
Tue, 2 Apr 2019 19:35:32 +0000 (21:35 +0200)
Currently there must be at least one match of inputs/outputs for
decoders that are stacked. If not, we emit an informational warning
(but this is not a hard error for the time being).

instance.c

index 99c5012886b48750f4bcd4f23ac2ffdfbf872666..23732ddb3ad1645825aa389c61d2dfa413055206 100644 (file)
@@ -529,6 +529,27 @@ SRD_API int srd_inst_stack(struct srd_session *sess,
                sess->di_list = g_slist_remove(sess->di_list, di_top);
        }
 
+       /*
+        * Check if there's at least one matching input/output pair
+        * for the stacked PDs. We warn if that's not the case, but it's
+        * not a hard error for the time being.
+        */
+       gboolean at_least_one_match = FALSE;
+       for (GSList *out = di_bottom->decoder->outputs; out; out = out->next) {
+               const char *o = out->data;
+               for (GSList *in = di_top->decoder->inputs; in; in = in->next) {
+                       const char *i = in->data;
+                       if (!strcmp(o, i)) {
+                               at_least_one_match = TRUE;
+                               break;
+                       }
+               }
+       }
+
+       if (!at_least_one_match)
+               srd_warn("No matching in-/output when stacking %s onto %s.",
+                       di_top->inst_id, di_bottom->inst_id);
+
        /* Stack on top of source di. */
        di_bottom->next_di = g_slist_append(di_bottom->next_di, di_top);