| | 612 | #undef indent |
| | 613 | #undef fd |
| | 614 | |
| | 615 | bool ladish_write_dict(int fd, int indent, ladish_dict_handle dict) |
| | 616 | { |
| | 617 | struct ladish_write_context context; |
| | 618 | |
| | 619 | if (ladish_dict_is_empty(dict)) |
| | 620 | { |
| | 621 | return true; |
| | 622 | } |
| | 623 | |
| | 624 | context.fd = fd; |
| | 625 | context.indent = indent + 1; |
| | 626 | |
| | 627 | if (!ladish_write_indented_string(fd, indent, "<dict>\n")) |
| | 628 | { |
| | 629 | return false; |
| | 630 | } |
| | 631 | |
| | 632 | if (!ladish_dict_iterate(dict, &context, write_dict_entry)) |
| | 633 | { |
| | 634 | return false; |
| | 635 | } |
| | 636 | |
| | 637 | if (!ladish_write_indented_string(fd, indent, "</dict>\n")) |
| | 638 | { |
| | 639 | return false; |
| | 640 | } |
| | 641 | |
| | 642 | return true; |
| | 643 | } |
| | 644 | |
| | 645 | bool ladish_write_vgraph(int fd, int indent, ladish_graph_handle vgraph, ladish_app_supervisor_handle app_supervisor) |
| | 646 | { |
| | 647 | struct ladish_write_context context; |
| | 648 | |
| | 649 | context.fd = fd; |
| | 650 | context.indent = indent + 1; |
| | 651 | |
| | 652 | if (!ladish_write_indented_string(fd, indent, "<clients>\n")) |
| | 653 | { |
| | 654 | return false; |
| | 655 | } |
| | 656 | |
| | 657 | if (!ladish_graph_iterate_nodes( |
| | 658 | vgraph, |
| | 659 | true, |
| | 660 | &context, |
| | 661 | ladish_save_vgraph_client_begin, |
| | 662 | ladish_save_vgraph_port, |
| | 663 | ladish_save_vgraph_client_end)) |
| | 664 | { |
| | 665 | log_error("ladish_graph_iterate_nodes() failed"); |
| | 666 | return false; |
| | 667 | } |
| | 668 | |
| | 669 | if (!ladish_write_indented_string(fd, indent, "</clients>\n")) |
| | 670 | { |
| | 671 | return false; |
| | 672 | } |
| | 673 | |
| | 674 | if (!ladish_write_indented_string(fd, indent, "<connections>\n")) |
| | 675 | { |
| | 676 | return false; |
| | 677 | } |
| | 678 | |
| | 679 | if (!ladish_graph_iterate_connections(vgraph, true, &context, ladish_save_vgraph_connection)) |
| | 680 | { |
| | 681 | log_error("ladish_graph_iterate_connections() failed"); |
| | 682 | return false; |
| | 683 | } |
| | 684 | |
| | 685 | if (!ladish_write_indented_string(fd, indent, "</connections>\n")) |
| | 686 | { |
| | 687 | return false; |
| | 688 | } |
| | 689 | |
| | 690 | if (!ladish_write_indented_string(fd, indent, "<applications>\n")) |
| | 691 | { |
| | 692 | return false; |
| | 693 | } |
| | 694 | |
| | 695 | if (!ladish_app_supervisor_enum(app_supervisor, &context, ladish_save_app)) |
| | 696 | { |
| | 697 | return false; |
| | 698 | } |
| | 699 | |
| | 700 | if (!ladish_write_indented_string(fd, indent, "</applications>\n")) |
| | 701 | { |
| | 702 | return false; |
| | 703 | } |
| | 704 | |
| | 705 | return true; |
| | 706 | } |
| | 707 | |
| | 708 | bool ladish_write_room_link_ports(int fd, int indent, ladish_room_handle room) |
| | 709 | { |
| | 710 | struct ladish_write_context context; |
| | 711 | |
| | 712 | context.fd = fd; |
| | 713 | context.indent = indent; |
| | 714 | |
| | 715 | if (!ladish_room_iterate_link_ports(room, &context, ladish_write_room_port)) |
| | 716 | { |
| | 717 | log_error("ladish_room_iterate_link_ports() failed"); |
| | 718 | return false; |
| | 719 | } |
| | 720 | |
| | 721 | return true; |
| | 722 | } |
| | 723 | |
| | 724 | /********************/ |
| | 725 | /* write jack graph */ |
| | 726 | /********************/ |
| | 727 | |
| | 728 | struct ladish_write_jack_context |
| | 729 | { |
| | 730 | int fd; |
| | 731 | int indent; |
| | 732 | ladish_graph_handle vgraph_filter; |
| | 733 | bool client_vgraph_match; |
| | 734 | bool a2j; |
| | 735 | bool client_visible; |
| | 736 | }; |
| | 737 | |
| | 738 | static bool ladish_save_jack_client_write_prolog(int fd, int indent, ladish_client_handle client_handle, const char * client_name) |
| | 739 | { |
| | 740 | uuid_t uuid; |
| | 741 | char str[37]; |
| | 742 | |
| | 743 | ladish_client_get_uuid(client_handle, uuid); |
| | 744 | uuid_unparse(uuid, str); |
| | 745 | |
| | 746 | log_info("saving jack client '%s' (%s)", client_name, str); |
| | 747 | |
| | 748 | if (!ladish_write_indented_string(fd, indent, "<client name=\"")) |
| | 749 | { |
| | 750 | return false; |
| | 751 | } |
| | 752 | |
| | 753 | if (!ladish_write_string(fd, client_name)) |
| | 754 | { |
| | 755 | return false; |
| | 756 | } |
| | 757 | |
| | 758 | if (!ladish_write_string(fd, "\" uuid=\"")) |
| | 759 | { |
| | 760 | return false; |
| | 761 | } |
| | 762 | |
| | 763 | if (!ladish_write_string(fd, str)) |
| | 764 | { |
| | 765 | return false; |
| | 766 | } |
| | 767 | |
| | 768 | if (!ladish_write_string(fd, "\">\n")) |
| | 769 | { |
| | 770 | return false; |
| | 771 | } |
| | 772 | |
| | 773 | if (!ladish_write_indented_string(fd, indent + 1, "<ports>\n")) |
| | 774 | { |
| | 775 | return false; |
| | 776 | } |
| | 777 | |
| | 778 | return true; |
| | 779 | } |
| | 780 | |
| | 781 | #define fd (((struct ladish_write_jack_context *)context)->fd) |
| | 782 | #define indent (((struct ladish_write_jack_context *)context)->indent) |
| | 783 | #define ctx_ptr ((struct ladish_write_jack_context *)context) |
| | 784 | |
| 621 | | uuid_t uuid; |
| 622 | | char str[37]; |
| 623 | | |
| 624 | | ladish_client_get_uuid(client_handle, uuid); |
| 625 | | uuid_unparse(uuid, str); |
| 626 | | |
| 627 | | log_info("saving jack client '%s' (%s)", client_name, str); |
| 628 | | |
| 629 | | if (!ladish_write_indented_string(fd, indent, "<client name=\"")) |
| 630 | | { |
| 631 | | return false; |
| 632 | | } |
| 633 | | |
| 634 | | if (!ladish_write_string(fd, client_name)) |
| 635 | | { |
| 636 | | return false; |
| 637 | | } |
| 638 | | |
| 639 | | if (!ladish_write_string(fd, "\" uuid=\"")) |
| 640 | | { |
| 641 | | return false; |
| 642 | | } |
| 643 | | |
| 644 | | if (!ladish_write_string(fd, str)) |
| 645 | | { |
| 646 | | return false; |
| 647 | | } |
| 648 | | |
| 649 | | if (!ladish_write_string(fd, "\">\n")) |
| 650 | | { |
| 651 | | return false; |
| 652 | | } |
| 653 | | |
| 654 | | if (!ladish_write_indented_string(fd, indent + 1, "<ports>\n")) |
| 655 | | { |
| 656 | | return false; |
| 657 | | } |
| 658 | | |
| 659 | | return true; |
| | 794 | void * vgraph; |
| | 795 | |
| | 796 | vgraph = ladish_client_get_vgraph(client_handle); |
| | 797 | ctx_ptr->client_vgraph_match = vgraph == ctx_ptr->vgraph_filter; |
| | 798 | ctx_ptr->a2j = ladish_virtualizer_is_a2j_client(client_handle); |
| | 799 | |
| | 800 | /* for the a2j client vgraph is always the studio graph. |
| | 801 | However if studio has no a2j ports, lets not write a2j client. |
| | 802 | If there is a a2j port that matched the vgraph, the prolog will get written anyway */ |
| | 803 | ctx_ptr->client_visible = ctx_ptr->client_vgraph_match && !ctx_ptr->a2j; |
| | 804 | |
| | 805 | if (!ctx_ptr->client_visible) |
| | 806 | { |
| | 807 | return true; |
| | 808 | } |
| | 809 | |
| | 810 | return ladish_save_jack_client_write_prolog(fd, indent, client_handle, client_name); |
| 747 | | |
| 748 | | if (!ladish_write_indented_string(fd, indent, "<dict>\n")) |
| 749 | | { |
| 750 | | return false; |
| 751 | | } |
| 752 | | |
| 753 | | if (!ladish_dict_iterate(dict, &context, write_dict_entry)) |
| 754 | | { |
| 755 | | return false; |
| 756 | | } |
| 757 | | |
| 758 | | if (!ladish_write_indented_string(fd, indent, "</dict>\n")) |
| 759 | | { |
| 760 | | return false; |
| 761 | | } |
| 762 | | |
| 763 | | return true; |
| 764 | | } |
| 765 | | |
| 766 | | bool ladish_write_vgraph(int fd, int indent, ladish_graph_handle vgraph, ladish_app_supervisor_handle app_supervisor) |
| 767 | | { |
| 768 | | struct ladish_write_context context; |
| 769 | | |
| 770 | | context.fd = fd; |
| 771 | | context.indent = indent + 1; |
| 772 | | |
| 773 | | if (!ladish_write_indented_string(fd, indent, "<clients>\n")) |
| 774 | | { |
| 775 | | return false; |
| 776 | | } |
| 777 | | |
| 778 | | if (!ladish_graph_iterate_nodes( |
| 779 | | vgraph, |
| 780 | | true, |
| 781 | | NULL, |
| 782 | | &context, |
| 783 | | ladish_save_vgraph_client_begin, |
| 784 | | ladish_save_vgraph_port, |
| 785 | | ladish_save_vgraph_client_end)) |
| 786 | | { |
| 787 | | log_error("ladish_graph_iterate_nodes() failed"); |
| 788 | | return false; |
| 789 | | } |
| 790 | | |
| 791 | | if (!ladish_write_indented_string(fd, indent, "</clients>\n")) |
| 792 | | { |
| 793 | | return false; |
| 794 | | } |
| 795 | | |
| 796 | | if (!ladish_write_indented_string(fd, indent, "<connections>\n")) |
| 797 | | { |
| 798 | | return false; |
| 799 | | } |
| 800 | | |
| 801 | | if (!ladish_graph_iterate_connections(vgraph, true, &context, ladish_save_vgraph_connection)) |
| 802 | | { |
| 803 | | log_error("ladish_graph_iterate_connections() failed"); |
| 804 | | return false; |
| 805 | | } |
| 806 | | |
| 807 | | if (!ladish_write_indented_string(fd, indent, "</connections>\n")) |
| 808 | | { |
| 809 | | return false; |
| 810 | | } |
| 811 | | |
| 812 | | if (!ladish_write_indented_string(fd, indent, "<applications>\n")) |
| 813 | | { |
| 814 | | return false; |
| 815 | | } |
| 816 | | |
| 817 | | if (!ladish_app_supervisor_enum(app_supervisor, &context, ladish_save_app)) |
| 818 | | { |
| 819 | | return false; |
| 820 | | } |
| 821 | | |
| 822 | | if (!ladish_write_indented_string(fd, indent, "</applications>\n")) |
| 823 | | { |
| 824 | | return false; |
| 825 | | } |
| 826 | | |
| 827 | | return true; |
| 828 | | } |
| 829 | | |
| 830 | | bool ladish_write_room_link_ports(int fd, int indent, ladish_room_handle room) |
| 831 | | { |
| 832 | | struct ladish_write_context context; |
| 833 | | |
| 834 | | context.fd = fd; |
| 835 | | context.indent = indent; |
| 836 | | |
| 837 | | if (!ladish_room_iterate_link_ports(room, &context, ladish_write_room_port)) |
| 838 | | { |
| 839 | | log_error("ladish_room_iterate_link_ports() failed"); |
| 840 | | return false; |
| 841 | | } |
| 842 | | |
| 843 | | return true; |
| 844 | | } |
| 845 | | |
| 846 | | bool ladish_write_jgraph(int fd, int indent, ladish_graph_handle vgraph) |
| 847 | | { |
| 848 | | struct ladish_write_context context; |
| 849 | | |
| 850 | | if (!ladish_write_indented_string(fd, indent, "<clients>\n")) |
| 851 | | { |
| 852 | | return false; |
| 853 | | } |
| 854 | | |
| 855 | | context.fd = fd; |
| 856 | | context.indent = indent + 1; |
| | 923 | context.vgraph_filter = vgraph; |