diff --git a/daemon/graph.c b/daemon/graph.c index a823160a..3dbc81c2 100644 --- a/daemon/graph.c +++ b/daemon/graph.c @@ -2170,7 +2170,6 @@ bool ladish_graph_iterate_nodes( ladish_graph_handle graph_handle, bool skip_hidden, - void * vgraph_filter, void * callback_context, bool (* client_begin_callback)( @@ -2203,7 +2202,6 @@ ladish_graph_iterate_nodes( void * client_context; struct list_head * port_node_ptr; struct ladish_graph_port * port_ptr; - void * vgraph; list_for_each(client_node_ptr, &graph_ptr->clients) { @@ -2214,15 +2212,6 @@ ladish_graph_iterate_nodes( continue; } - if (vgraph_filter != NULL) - { - vgraph = ladish_client_get_vgraph(client_ptr->client); - if (vgraph != vgraph_filter) - { - continue; - } - } - if (client_begin_callback != NULL) { if (!client_begin_callback(callback_context, graph_handle, client_ptr->client, client_ptr->name, &client_context)) @@ -2589,7 +2578,6 @@ bool ladish_graph_copy(ladish_graph_handle src, ladish_graph_handle dest, bool s return ladish_graph_iterate_nodes( src, skip_hidden, - NULL, dest, ladish_graph_copy_client_begin_callback, ladish_graph_copy_port_callback, diff --git a/daemon/graph.h b/daemon/graph.h index c5092398..981c88c9 100644 --- a/daemon/graph.h +++ b/daemon/graph.h @@ -182,7 +182,6 @@ bool ladish_graph_iterate_nodes( ladish_graph_handle graph_handle, bool skip_hidden, - void * vgraph_filter, void * callback_context, bool (* client_begin_callback)( diff --git a/daemon/load.c b/daemon/load.c index 38c47da9..c7f8543a 100644 --- a/daemon/load.c +++ b/daemon/load.c @@ -358,5 +358,5 @@ void ladish_interlink_clients(ladish_graph_handle vgraph, ladish_app_supervisor_ ctx.vgraph = vgraph; ctx.app_supervisor = app_supervisor; - ladish_graph_iterate_nodes(ladish_studio_get_jack_graph(), false, NULL, &ctx, interlink_client, NULL, NULL); + ladish_graph_iterate_nodes(ladish_studio_get_jack_graph(), false, &ctx, interlink_client, NULL, NULL); } diff --git a/daemon/room.c b/daemon/room.c index ac633fd4..2e11f32c 100644 --- a/daemon/room.c +++ b/daemon/room.c @@ -537,7 +537,6 @@ ladish_room_iterate_link_ports( return ladish_graph_iterate_nodes( room_ptr->graph, false, - NULL, &context, ladish_room_iterate_link_ports_client_callback, ladish_room_iterate_link_ports_port_callback, @@ -574,7 +573,7 @@ void ladish_room_initiate_stop(ladish_room_handle room_handle, bool clear_persis ladish_graph_clear_persist(room_ptr->graph); } - ladish_graph_iterate_nodes(room_ptr->graph, false, NULL, room_ptr, NULL, destroy_port_link, NULL); + ladish_graph_iterate_nodes(room_ptr->graph, false, room_ptr, NULL, destroy_port_link, NULL); ladish_app_supervisor_stop(room_ptr->app_supervisor); } diff --git a/daemon/save.c b/daemon/save.c index 366cc565..a32b255f 100644 --- a/daemon/save.c +++ b/daemon/save.c @@ -609,127 +609,6 @@ ladish_write_room_port( return true; } -static -bool -ladish_save_jack_client_begin( - void * context, - ladish_graph_handle graph_handle, - ladish_client_handle client_handle, - const char * client_name, - void ** client_iteration_context_ptr_ptr) -{ - uuid_t uuid; - char str[37]; - - ladish_client_get_uuid(client_handle, uuid); - uuid_unparse(uuid, str); - - log_info("saving jack client '%s' (%s)", client_name, str); - - if (!ladish_write_indented_string(fd, indent, "\n")) - { - return false; - } - - if (!ladish_write_indented_string(fd, indent + 1, "\n")) - { - return false; - } - - return true; -} - -static -bool -ladish_save_jack_client_end( - void * context, - ladish_graph_handle graph_handle, - ladish_client_handle client_handle, - const char * client_name, - void * client_iteration_context_ptr) -{ - if (!ladish_write_indented_string(fd, indent + 1, "\n")) - { - return false; - } - - if (!ladish_write_indented_string(fd, indent, "\n")) - { - return false; - } - - return true; -} - -static -bool -ladish_save_jack_port( - void * context, - ladish_graph_handle graph_handle, - void * client_iteration_context_ptr, - ladish_client_handle client_handle, - const char * client_name, - ladish_port_handle port_handle, - const char * port_name, - uint32_t port_type, - uint32_t port_flags) -{ - uuid_t uuid; - char str[37]; - - ladish_port_get_uuid(port_handle, uuid); - uuid_unparse(uuid, str); - - log_info("saving jack port '%s':'%s' (%s)", client_name, port_name, str); - - if (!ladish_write_indented_string(fd, indent + 2, "\n")) - { - return false; - } - - return true; -} - #undef indent #undef fd @@ -778,7 +657,6 @@ bool ladish_write_vgraph(int fd, int indent, ladish_graph_handle vgraph, ladish_ if (!ladish_graph_iterate_nodes( vgraph, true, - NULL, &context, ladish_save_vgraph_client_begin, ladish_save_vgraph_port, @@ -843,9 +721,197 @@ bool ladish_write_room_link_ports(int fd, int indent, ladish_room_handle room) return true; } +/********************/ +/* write jack graph */ +/********************/ + +struct ladish_write_jack_context +{ + int fd; + int indent; + ladish_graph_handle vgraph_filter; + bool client_vgraph_match; + bool a2j; + bool client_visible; +}; + +static bool ladish_save_jack_client_write_prolog(int fd, int indent, ladish_client_handle client_handle, const char * client_name) +{ + uuid_t uuid; + char str[37]; + + ladish_client_get_uuid(client_handle, uuid); + uuid_unparse(uuid, str); + + log_info("saving jack client '%s' (%s)", client_name, str); + + if (!ladish_write_indented_string(fd, indent, "\n")) + { + return false; + } + + if (!ladish_write_indented_string(fd, indent + 1, "\n")) + { + return false; + } + + return true; +} + +#define fd (((struct ladish_write_jack_context *)context)->fd) +#define indent (((struct ladish_write_jack_context *)context)->indent) +#define ctx_ptr ((struct ladish_write_jack_context *)context) + +static +bool +ladish_save_jack_client_begin( + void * context, + ladish_graph_handle graph_handle, + ladish_client_handle client_handle, + const char * client_name, + void ** client_iteration_context_ptr_ptr) +{ + void * vgraph; + + vgraph = ladish_client_get_vgraph(client_handle); + ctx_ptr->client_vgraph_match = vgraph == ctx_ptr->vgraph_filter; + ctx_ptr->a2j = ladish_virtualizer_is_a2j_client(client_handle); + + /* for the a2j client vgraph is always the studio graph. + However if studio has no a2j ports, lets not write a2j client. + If there is a a2j port that matched the vgraph, the prolog will get written anyway */ + ctx_ptr->client_visible = ctx_ptr->client_vgraph_match && !ctx_ptr->a2j; + + if (!ctx_ptr->client_visible) + { + return true; + } + + return ladish_save_jack_client_write_prolog(fd, indent, client_handle, client_name); +} + +static +bool +ladish_save_jack_client_end( + void * context, + ladish_graph_handle graph_handle, + ladish_client_handle client_handle, + const char * client_name, + void * client_iteration_context_ptr) +{ + if (!ctx_ptr->client_visible) + { + return true; + } + + if (!ladish_write_indented_string(fd, indent + 1, "\n")) + { + return false; + } + + if (!ladish_write_indented_string(fd, indent, "\n")) + { + return false; + } + + return true; +} + +static +bool +ladish_save_jack_port( + void * context, + ladish_graph_handle graph_handle, + void * client_iteration_context_ptr, + ladish_client_handle client_handle, + const char * client_name, + ladish_port_handle port_handle, + const char * port_name, + uint32_t port_type, + uint32_t port_flags) +{ + uuid_t uuid; + char str[37]; + + /* check vgraph for a2j ports */ + if (ctx_ptr->a2j && ctx_ptr->vgraph_filter == ladish_port_get_vgraph(port_handle)) + { + if (!ctx_ptr->client_visible) + { + if (!ladish_save_jack_client_write_prolog(fd, indent, client_handle, client_name)) + { + return false; + } + + ctx_ptr->client_visible = true; + } + } + + if (!ctx_ptr->client_visible) + { + return true; + } + + ladish_port_get_uuid(port_handle, uuid); + uuid_unparse(uuid, str); + + log_info("saving jack port '%s':'%s' (%s)", client_name, port_name, str); + + if (!ladish_write_indented_string(fd, indent + 2, "\n")) + { + return false; + } + + return true; +} + +#undef ctx_ptr +#undef indent +#undef fd + bool ladish_write_jgraph(int fd, int indent, ladish_graph_handle vgraph) { - struct ladish_write_context context; + struct ladish_write_jack_context context; if (!ladish_write_indented_string(fd, indent, "\n")) { @@ -854,11 +920,11 @@ bool ladish_write_jgraph(int fd, int indent, ladish_graph_handle vgraph) context.fd = fd; context.indent = indent + 1; + context.vgraph_filter = vgraph; if (!ladish_graph_iterate_nodes( ladish_studio_get_jack_graph(), true, - vgraph, &context, ladish_save_jack_client_begin, ladish_save_jack_port, diff --git a/daemon/virtualizer.c b/daemon/virtualizer.c index 2ea78128..98c23521 100644 --- a/daemon/virtualizer.c +++ b/daemon/virtualizer.c @@ -442,7 +442,6 @@ port_appeared( const char * jack_client_name; const char * vclient_name; bool is_a2j; - uuid_t jclient_uuid; uuid_t vclient_uuid; pid_t pid; ladish_app_handle app; @@ -525,8 +524,7 @@ port_appeared( jack_client_name = ladish_graph_get_client_name(virtualizer_ptr->jack_graph, jack_client); - ladish_client_get_uuid(jack_client, jclient_uuid); - is_a2j = uuid_compare(jclient_uuid, g_a2j_uuid) == 0; + is_a2j = ladish_virtualizer_is_a2j_client(jack_client); if (is_a2j) { log_info("a2j port appeared"); @@ -1125,7 +1123,6 @@ ladish_virtualizer_is_hidden_app( ladish_graph_handle vgraph; uuid_t vclient_uuid; ladish_client_handle vclient; - uuid_t jclient_uuid; //ladish_graph_dump(g_studio.jack_graph); @@ -1142,8 +1139,7 @@ ladish_virtualizer_is_hidden_app( return true; } - ladish_client_get_uuid(jclient, jclient_uuid); - ASSERT(uuid_compare(jclient_uuid, g_a2j_uuid) != 0); /* a2j client has no app associated */ + ASSERT(!ladish_virtualizer_is_a2j_client(jclient)); /* a2j client has no app associated */ vgraph = ladish_client_get_vgraph(jclient); if (vgraph == NULL) @@ -1263,7 +1259,6 @@ ladish_virtualizer_remove_app( uuid_t vclient_uuid; ladish_client_handle vclient; bool is_empty; - uuid_t jclient_uuid; struct app_remove_context ctx; //ladish_graph_dump(g_studio.jack_graph); @@ -1271,7 +1266,7 @@ ladish_virtualizer_remove_app( uuid_copy(ctx.app_uuid, app_uuid); ctx.app_name = app_name; - ladish_graph_iterate_nodes(jack_graph, false, NULL, &ctx, NULL, remove_app_port, NULL); + ladish_graph_iterate_nodes(jack_graph, false, &ctx, NULL, remove_app_port, NULL); jclient = ladish_graph_find_client_by_app(jack_graph, app_uuid); if (jclient == NULL) @@ -1280,8 +1275,7 @@ ladish_virtualizer_remove_app( return; } - ladish_client_get_uuid(jclient, jclient_uuid); - ASSERT(uuid_compare(jclient_uuid, g_a2j_uuid) != 0); /* a2j client has no app associated */ + ASSERT(!ladish_virtualizer_is_a2j_client(jclient)); /* a2j client has no app associated */ vgraph = ladish_client_get_vgraph(jclient); if (vgraph == NULL) @@ -1378,3 +1372,11 @@ ladish_virtualizer_is_system_client( return false; } + +bool ladish_virtualizer_is_a2j_client(ladish_client_handle jclient) +{ + uuid_t jclient_uuid; + + ladish_client_get_uuid(jclient, jclient_uuid); + return uuid_compare(jclient_uuid, g_a2j_uuid) == 0; +} diff --git a/daemon/virtualizer.h b/daemon/virtualizer.h index c7e202b4..58a0ce38 100644 --- a/daemon/virtualizer.h +++ b/daemon/virtualizer.h @@ -71,6 +71,10 @@ bool ladish_virtualizer_is_system_client( uuid_t uuid); +bool +ladish_virtualizer_is_a2j_client( + ladish_client_handle jclient); + void ladish_virtualizer_destroy( ladish_virtualizer_handle handle);