| 620 | } |
| 621 | |
| 622 | static struct plugin **plugin_hook_make_ordered(const tal_t *ctx, |
| 623 | struct logger *log, |
| 624 | struct plugin_hook *hook) |
| 625 | { |
| 626 | struct hook_node *graph, *n; |
| 627 | struct hook_instance **done; |
| 628 | |
| 629 | /* Populate graph nodes */ |
| 630 | graph = tal_arr(tmpctx, struct hook_node, 0); |
| 631 | for (size_t i = 0; i < tal_count(hook->hooks); i++) { |
| 632 | struct hook_node hn; |
| 633 | |
| 634 | if (!hook->hooks[i]) |
| 635 | continue; |
| 636 | hn.finished = false; |
| 637 | hn.hook = hook->hooks[i]; |
| 638 | hn.num_incoming = 0; |
| 639 | hn.outgoing = tal_arr(graph, struct hook_node *, 0); |
| 640 | tal_arr_expand(&graph, hn); |
| 641 | } |
| 642 | |
| 643 | if (tal_count(graph) == 0) |
| 644 | return NULL; |
| 645 | |
| 646 | /* Add edges. */ |
| 647 | for (size_t i = 0; i < tal_count(graph); i++) { |
| 648 | for (size_t j = 0; j < tal_count(graph[i].hook->before); j++) { |
| 649 | n = find_hook(graph, graph[i].hook->before[j]); |
| 650 | if (!n) { |
| 651 | /* This is useful for typos! */ |
| 652 | log_debug(graph[i].hook->plugin->log, |
| 653 | "hook %s before unknown plugin %s", |
| 654 | hook->name, |
| 655 | graph[i].hook->before[j]); |
| 656 | continue; |
| 657 | } |
| 658 | tal_arr_expand(&graph[i].outgoing, n); |
| 659 | n->num_incoming++; |
| 660 | } |
| 661 | for (size_t j = 0; j < tal_count(graph[i].hook->after); j++) { |
| 662 | n = find_hook(graph, graph[i].hook->after[j]); |
| 663 | if (!n) { |
| 664 | /* This is useful for typos! */ |
| 665 | log_debug(graph[i].hook->plugin->log, |
| 666 | "hook %s after unknown plugin %s", |
| 667 | hook->name, |
| 668 | graph[i].hook->after[j]); |
| 669 | continue; |
| 670 | } |
| 671 | tal_arr_expand(&n->outgoing, &graph[i]); |
| 672 | graph[i].num_incoming++; |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | done = tal_arr(tmpctx, struct hook_instance *, 0); |
| 677 | while ((n = get_best_candidate(graph)) != NULL) { |
| 678 | tal_arr_expand(&done, n->hook); |
| 679 | n->finished = true; |
no test coverage detected