ladishd: save&restore app associations of vclients. Fix for #149
This commit is contained in:
parent
918cecca74
commit
5288134676
|
@ -249,6 +249,7 @@ ladish_app_handle
|
|||
ladish_app_supervisor_add(
|
||||
ladish_app_supervisor_handle supervisor_handle,
|
||||
const char * name,
|
||||
uuid_t uuid,
|
||||
bool autorun,
|
||||
const char * command,
|
||||
bool terminal,
|
||||
|
@ -289,7 +290,15 @@ ladish_app_supervisor_add(
|
|||
app_ptr->firstborn_pgrp = 0;
|
||||
|
||||
app_ptr->id = supervisor_ptr->next_id++;
|
||||
uuid_generate(app_ptr->uuid);
|
||||
if (uuid == NULL || uuid_is_null(uuid))
|
||||
{
|
||||
uuid_generate(app_ptr->uuid);
|
||||
}
|
||||
else
|
||||
{
|
||||
uuid_copy(app_ptr->uuid, uuid);
|
||||
}
|
||||
|
||||
app_ptr->zombie = false;
|
||||
app_ptr->state = LADISH_APP_STATE_STOPPED;
|
||||
app_ptr->autorun = autorun;
|
||||
|
|
|
@ -190,6 +190,7 @@ ladish_app_supervisor_save_L1(
|
|||
*
|
||||
* @param[in] supervisor_handle supervisor object handle
|
||||
* @param[in] name Name of the app
|
||||
* @param[in] uuid Optional uuid of the app. If NULL, new uuid will be generated.
|
||||
* @param[in] autorun whether to start the app when ladish_app_supervisor_autorun() is called
|
||||
* @param[in] command Commandline that is used to start the app
|
||||
* @param[in] terminal Whether the app is started in terminal
|
||||
|
@ -201,6 +202,7 @@ ladish_app_handle
|
|||
ladish_app_supervisor_add(
|
||||
ladish_app_supervisor_handle supervisor_handle,
|
||||
const char * name,
|
||||
uuid_t uuid,
|
||||
bool autorun,
|
||||
const char * command,
|
||||
bool terminal,
|
||||
|
|
|
@ -271,6 +271,11 @@ static void callback_elstart(void * data, const char * el, const char ** attr)
|
|||
goto free;
|
||||
}
|
||||
|
||||
if (ladish_get_uuid_attribute(attr, "app", context_ptr->uuid, true))
|
||||
{
|
||||
ladish_client_set_app(context_ptr->client, context_ptr->uuid);
|
||||
}
|
||||
|
||||
if (!ladish_graph_add_client(g_studio.studio_graph, context_ptr->client, name_dup, true))
|
||||
{
|
||||
log_error("ladish_graph_add_client() failed to add client '%s' to studio graph", name_dup);
|
||||
|
@ -527,6 +532,11 @@ static void callback_elstart(void * data, const char * el, const char ** attr)
|
|||
goto free;
|
||||
}
|
||||
|
||||
if (!ladish_get_uuid_attribute(attr, "uuid", context_ptr->uuid, true))
|
||||
{
|
||||
uuid_clear(context_ptr->uuid);
|
||||
}
|
||||
|
||||
if (ladish_get_bool_attribute(attr, "terminal", &context_ptr->terminal) == NULL)
|
||||
{
|
||||
log_error("application \"terminal\" attribute is not available. name=\"%s\"", name);
|
||||
|
@ -827,7 +837,14 @@ static void callback_elend(void * data, const char * el)
|
|||
|
||||
log_info("application '%s' (%s, %s, level %u) with commandline '%s'", context_ptr->str, context_ptr->terminal ? "terminal" : "shell", context_ptr->autorun ? "autorun" : "stopped", (unsigned int)context_ptr->level, context_ptr->data);
|
||||
|
||||
if (ladish_app_supervisor_add(g_studio.app_supervisor, context_ptr->str, context_ptr->autorun, context_ptr->data, context_ptr->terminal, context_ptr->level) == NULL)
|
||||
if (ladish_app_supervisor_add(
|
||||
g_studio.app_supervisor,
|
||||
context_ptr->str,
|
||||
context_ptr->uuid,
|
||||
context_ptr->autorun,
|
||||
context_ptr->data,
|
||||
context_ptr->terminal,
|
||||
context_ptr->level) == NULL)
|
||||
{
|
||||
log_error("ladish_app_supervisor_add() failed.");
|
||||
context_ptr->error = XML_TRUE;
|
||||
|
@ -981,7 +998,7 @@ static bool run(void * command_context)
|
|||
return false;
|
||||
}
|
||||
|
||||
ladish_interlink_clients(ladish_studio_get_studio_graph(), ladish_studio_get_studio_app_supervisor());
|
||||
ladish_interlink(ladish_studio_get_studio_graph(), ladish_studio_get_studio_app_supervisor());
|
||||
|
||||
g_studio.persisted = true;
|
||||
log_info("Studio loaded. ('%s')", path);
|
||||
|
|
|
@ -124,7 +124,7 @@ static bool run(void * context)
|
|||
index++;
|
||||
}
|
||||
|
||||
app = ladish_app_supervisor_add(supervisor, name, true, cmd_ptr->commandline, cmd_ptr->terminal, cmd_ptr->level);
|
||||
app = ladish_app_supervisor_add(supervisor, name, NULL, true, cmd_ptr->commandline, cmd_ptr->terminal, cmd_ptr->level);
|
||||
|
||||
free(name_buffer);
|
||||
|
||||
|
|
|
@ -293,6 +293,7 @@ interlink_client(
|
|||
void ** client_iteration_context_ptr_ptr)
|
||||
{
|
||||
uuid_t app_uuid;
|
||||
uuid_t vclient_app_uuid;
|
||||
uuid_t vclient_uuid;
|
||||
ladish_client_handle vclient;
|
||||
pid_t pid;
|
||||
|
@ -330,13 +331,19 @@ interlink_client(
|
|||
}
|
||||
ASSERT(!interlinked);
|
||||
|
||||
/* XXX: why this is is here is a mystery. interlink is supposed to be called just after load so pid will always be 0 */
|
||||
pid = ladish_client_get_pid(jclient);
|
||||
jmcore = pid != 0 && pid != jmcore_proxy_get_pid_cached();
|
||||
jmcore = pid != 0 && pid == jmcore_proxy_get_pid_cached();
|
||||
if (jmcore)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ladish_virtualizer_is_a2j_client(jclient))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
app = ladish_app_supervisor_find_app_by_name(ctx_ptr->app_supervisor, name);
|
||||
if (app == NULL)
|
||||
{
|
||||
|
@ -355,15 +362,49 @@ interlink_client(
|
|||
ladish_client_interlink(jclient, vclient);
|
||||
|
||||
ladish_app_get_uuid(app, app_uuid);
|
||||
ladish_client_set_app(jclient, app_uuid);
|
||||
ladish_client_set_app(vclient, app_uuid);
|
||||
if (ladish_client_get_app(vclient, vclient_app_uuid))
|
||||
{
|
||||
if (uuid_compare(app_uuid, vclient_app_uuid) != 0)
|
||||
{
|
||||
log_error("vclient of app '%s' already has a different app uuid", name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log_info("associating vclient with app '%s'", name);
|
||||
ladish_client_set_app(vclient, app_uuid);
|
||||
}
|
||||
|
||||
ladish_client_set_app(jclient, app_uuid);
|
||||
ladish_client_set_vgraph(jclient, ctx_ptr->vgraph);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ladish_interlink_clients(ladish_graph_handle vgraph, ladish_app_supervisor_handle app_supervisor)
|
||||
bool
|
||||
interlink_port(
|
||||
void * context,
|
||||
ladish_graph_handle graph_handle,
|
||||
bool hidden,
|
||||
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 app_uuid;
|
||||
|
||||
if (ladish_client_get_app(client_handle, app_uuid))
|
||||
{
|
||||
ladish_port_set_app(port_handle, app_uuid);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ladish_interlink(ladish_graph_handle vgraph, ladish_app_supervisor_handle app_supervisor)
|
||||
{
|
||||
struct interlink_context ctx;
|
||||
|
||||
|
@ -371,4 +412,5 @@ void ladish_interlink_clients(ladish_graph_handle vgraph, ladish_app_supervisor_
|
|||
ctx.app_supervisor = app_supervisor;
|
||||
|
||||
ladish_graph_iterate_nodes(ladish_studio_get_jack_graph(), &ctx, interlink_client, NULL, NULL);
|
||||
ladish_graph_iterate_nodes(vgraph, &ctx, NULL, interlink_port, NULL);
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ struct ladish_parse_context
|
|||
char data[MAX_DATA_SIZE];
|
||||
int data_used;
|
||||
char * str;
|
||||
uuid_t uuid;
|
||||
ladish_client_handle client;
|
||||
ladish_port_handle port;
|
||||
ladish_dict_handle dict;
|
||||
|
@ -97,6 +98,6 @@ ladish_parse_port_type_and_direction_attributes(
|
|||
uint32_t * type_ptr,
|
||||
uint32_t * flags_ptr);
|
||||
|
||||
void ladish_interlink_clients(ladish_graph_handle vgraph, ladish_app_supervisor_handle app_supervisor);
|
||||
void ladish_interlink(ladish_graph_handle vgraph, ladish_app_supervisor_handle app_supervisor);
|
||||
|
||||
#endif /* #ifndef LOAD_H__43B1ECB8_247F_4868_AE95_563DD968D7B0__INCLUDED */
|
||||
|
|
|
@ -224,6 +224,11 @@ static void callback_elstart(void * data, const char * el, const char ** attr)
|
|||
goto free;
|
||||
}
|
||||
|
||||
if (ladish_get_uuid_attribute(attr, "app", context_ptr->uuid, true))
|
||||
{
|
||||
ladish_client_set_app(context_ptr->client, context_ptr->uuid);
|
||||
}
|
||||
|
||||
if (!ladish_graph_add_client(ladish_studio_get_jack_graph(), context_ptr->client, name_dup, true))
|
||||
{
|
||||
log_error("ladish_graph_add_client() failed to add client '%s' to JACK graph", name_dup);
|
||||
|
@ -527,6 +532,11 @@ static void callback_elstart(void * data, const char * el, const char ** attr)
|
|||
goto free;
|
||||
}
|
||||
|
||||
if (!ladish_get_uuid_attribute(attr, "uuid", context_ptr->uuid, true))
|
||||
{
|
||||
uuid_clear(context_ptr->uuid);
|
||||
}
|
||||
|
||||
if (ladish_get_bool_attribute(attr, "terminal", &context_ptr->terminal) == NULL)
|
||||
{
|
||||
log_error("application \"terminal\" attribute is not available. name=\"%s\"", name);
|
||||
|
@ -705,7 +715,14 @@ static void callback_elend(void * data, const char * el)
|
|||
|
||||
log_info("application '%s' (%s, %s, level %u) with commandline '%s'", context_ptr->str, context_ptr->terminal ? "terminal" : "shell", context_ptr->autorun ? "autorun" : "stopped", (unsigned int)context_ptr->level, context_ptr->data);
|
||||
|
||||
if (ladish_app_supervisor_add(room_ptr->app_supervisor, context_ptr->str, context_ptr->autorun, context_ptr->data, context_ptr->terminal, context_ptr->level) == NULL)
|
||||
if (ladish_app_supervisor_add(
|
||||
room_ptr->app_supervisor,
|
||||
context_ptr->str,
|
||||
context_ptr->uuid,
|
||||
context_ptr->autorun,
|
||||
context_ptr->data,
|
||||
context_ptr->terminal,
|
||||
context_ptr->level) == NULL)
|
||||
{
|
||||
log_error("ladish_app_supervisor_add() failed.");
|
||||
context_ptr->error = XML_TRUE;
|
||||
|
@ -853,7 +870,7 @@ bool ladish_room_load_project(ladish_room_handle room_handle, const char * proje
|
|||
goto free_parser;
|
||||
}
|
||||
|
||||
ladish_interlink_clients(room_ptr->graph, room_ptr->app_supervisor);
|
||||
ladish_interlink(room_ptr->graph, room_ptr->app_supervisor);
|
||||
/* ladish_graph_dump(ladish_studio_get_jack_graph()); */
|
||||
/* ladish_graph_dump(room_ptr->graph); */
|
||||
|
||||
|
|
|
@ -352,6 +352,8 @@ ladish_save_vgraph_client_begin(
|
|||
{
|
||||
uuid_t uuid;
|
||||
char str[37];
|
||||
uuid_t app_uuid;
|
||||
char app_str[37];
|
||||
|
||||
ctx_ptr->client_visible = !hidden;
|
||||
if (!ctx_ptr->client_visible)
|
||||
|
@ -407,6 +409,21 @@ ladish_save_vgraph_client_begin(
|
|||
return false;
|
||||
}
|
||||
|
||||
if (ladish_client_get_app(client_handle, app_uuid))
|
||||
{
|
||||
uuid_unparse(app_uuid, app_str);
|
||||
|
||||
if (!ladish_write_string(fd, "\" app=\""))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ladish_write_string(fd, str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ladish_write_string(fd, "\">\n"))
|
||||
{
|
||||
return false;
|
||||
|
@ -702,6 +719,9 @@ ladish_save_app(
|
|||
char * escaped_string;
|
||||
char * escaped_buffer;
|
||||
bool ret;
|
||||
char str[37];
|
||||
|
||||
uuid_unparse(uuid, str);
|
||||
|
||||
log_info("saving app: name='%s', %srunning, %s, level %u, commandline='%s'", name, running ? "" : "not ", terminal ? "terminal" : "shell", (unsigned int)level, command);
|
||||
|
||||
|
@ -728,6 +748,16 @@ ladish_save_app(
|
|||
goto free_buffer;
|
||||
}
|
||||
|
||||
if (!ladish_write_string(fd, "\" uuid=\""))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ladish_write_string(fd, str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!ladish_write_string(fd, "\" terminal=\""))
|
||||
{
|
||||
goto free_buffer;
|
||||
|
|
Loading…
Reference in New Issue