* Stack a decoder instance on top of another. * * @param sess The session holding the protocol decoder instances. * Must not be NULL. * @param di_bottom The instance on top of which di_top will be stacked. * @param di_top The instance to go on top. * * @return SRD_OK upon success, a (negative) error code otherwise. * * @since 0.3.0 */
| 534 | * @since 0.3.0 |
| 535 | */ |
| 536 | SRD_API int srd_inst_stack(struct srd_session *sess, |
| 537 | struct srd_decoder_inst *di_bottom, |
| 538 | struct srd_decoder_inst *di_top) |
| 539 | { |
| 540 | if (!sess) |
| 541 | return SRD_ERR_ARG; |
| 542 | |
| 543 | if (!di_bottom || !di_top) { |
| 544 | srd_err("Invalid from/to instance pair."); |
| 545 | return SRD_ERR_ARG; |
| 546 | } |
| 547 | |
| 548 | if (g_slist_find(sess->di_list, di_top)) { |
| 549 | /* Remove from the unstacked list. */ |
| 550 | sess->di_list = g_slist_remove(sess->di_list, di_top); |
| 551 | } |
| 552 | |
| 553 | /* |
| 554 | * Check if there's at least one matching input/output pair |
| 555 | * for the stacked PDs. We warn if that's not the case, but it's |
| 556 | * not a hard error for the time being. |
| 557 | */ |
| 558 | gboolean at_least_one_match = FALSE; |
| 559 | for (GSList *out = di_bottom->decoder->outputs; out; out = out->next) { |
| 560 | const char *o = out->data; |
| 561 | for (GSList *in = di_top->decoder->inputs; in; in = in->next) { |
| 562 | const char *i = in->data; |
| 563 | if (!strcmp(o, i)) { |
| 564 | at_least_one_match = TRUE; |
| 565 | break; |
| 566 | } |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | if (!at_least_one_match) |
| 571 | srd_warn("No matching in-/output when stacking %s onto %s.", |
| 572 | di_top->inst_id, di_bottom->inst_id); |
| 573 | |
| 574 | /* Stack on top of source di. */ |
| 575 | di_bottom->next_di = g_slist_append(di_bottom->next_di, di_top); |
| 576 | |
| 577 | srd_dbg("Stacking %s onto %s.", di_top->inst_id, di_bottom->inst_id); |
| 578 | |
| 579 | return SRD_OK; |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * Search a decoder instance and its stack for instance ID. |
no outgoing calls
no test coverage detected