-int setup_pd_stack(char *opt_pds, char *opt_pd_stack, char *opt_pd_annotations)
-{
- struct srd_decoder_inst *di_from, *di_to;
- int ret, i;
- char **pds, **ids;
-
- /* Set up the protocol decoder stack. */
- pds = g_strsplit(opt_pds, ",", 0);
- if (g_strv_length(pds) > 1) {
- if (opt_pd_stack) {
- /* A stack setup was specified, use that. */
- g_strfreev(pds);
- pds = g_strsplit(opt_pd_stack, ",", 0);
- if (g_strv_length(pds) < 2) {
- g_strfreev(pds);
- g_critical("Specify at least two protocol decoders to stack.");
- return 1;
- }
- }
-
- /* First PD goes at the bottom of the stack. */
- ids = g_strsplit(pds[0], ":", 0);
- if (!(di_from = srd_inst_find_by_id(srd_sess, ids[0]))) {
- g_strfreev(ids);
- g_critical("Cannot stack protocol decoder '%s': "
- "instance not found.", pds[0]);
- return 1;
- }
- g_strfreev(ids);
-
- /* Every subsequent PD goes on top. */
- for (i = 1; pds[i]; i++) {
- ids = g_strsplit(pds[i], ":", 0);
- if (!(di_to = srd_inst_find_by_id(srd_sess, ids[0]))) {
- g_strfreev(ids);
- g_critical("Cannot stack protocol decoder '%s': "
- "instance not found.", pds[i]);
- return 1;
- }
- g_strfreev(ids);
- if ((ret = srd_inst_stack(srd_sess, di_from, di_to)) != SRD_OK)
- return 1;
-
- /* Don't show annotation from this PD. Only the last PD in
- * the stack will be left on the annotation list (unless
- * the annotation list was specifically provided).
- */
- if (!opt_pd_annotations)
- g_hash_table_remove(pd_ann_visible, di_from->inst_id);
-
- di_from = di_to;
- }
- }
- g_strfreev(pds);
-
- return 0;
-}
-