ladishd: save [only] relevant a2j ports for the vgraph being saved

For studio saves, save only studio vgraph a2j ports.
For room project saves, save only room vgraph a2j ports.
If there is not a2j ports for the vgraph being saved, an empty a2j client will not be saved anymore
This commit is contained in:
Nedko Arnaudov 2010-11-08 01:19:02 +02:00
parent 8aebce6821
commit 6c2201b933
7 changed files with 208 additions and 150 deletions

View File

@ -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,

View File

@ -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)(

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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, "<client name=\""))
{
return false;
}
if (!ladish_write_string(fd, client_name))
{
return false;
}
if (!ladish_write_string(fd, "\" uuid=\""))
{
return false;
}
if (!ladish_write_string(fd, str))
{
return false;
}
if (!ladish_write_string(fd, "\">\n"))
{
return false;
}
if (!ladish_write_indented_string(fd, indent + 1, "<ports>\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, "</ports>\n"))
{
return false;
}
if (!ladish_write_indented_string(fd, indent, "</client>\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, "<port name=\""))
{
return false;
}
if (!ladish_write_string(fd, port_name))
{
return false;
}
if (!ladish_write_string(fd, "\" uuid=\""))
{
return false;
}
if (!ladish_write_string(fd, str))
{
return false;
}
if (!ladish_write_string(fd, "\" />\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, "<client name=\""))
{
return false;
}
if (!ladish_write_string(fd, client_name))
{
return false;
}
if (!ladish_write_string(fd, "\" uuid=\""))
{
return false;
}
if (!ladish_write_string(fd, str))
{
return false;
}
if (!ladish_write_string(fd, "\">\n"))
{
return false;
}
if (!ladish_write_indented_string(fd, indent + 1, "<ports>\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, "</ports>\n"))
{
return false;
}
if (!ladish_write_indented_string(fd, indent, "</client>\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, "<port name=\""))
{
return false;
}
if (!ladish_write_string(fd, port_name))
{
return false;
}
if (!ladish_write_string(fd, "\" uuid=\""))
{
return false;
}
if (!ladish_write_string(fd, str))
{
return false;
}
if (!ladish_write_string(fd, "\" />\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, "<clients>\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,

View File

@ -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;
}

View File

@ -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);