Properly handle normal clients

* create studio client when first port appears
 * destroy studio client when last port disappears
 * remove disappearing ports from jack graph
This commit is contained in:
Nedko Arnaudov 2009-09-20 17:33:07 +03:00
parent df6e35ccdf
commit 3159525589
7 changed files with 185 additions and 37 deletions

View File

@ -127,4 +127,14 @@ void ladish_client_get_uuid(ladish_client_handle client_handle, uuid_t uuid)
uuid_copy(uuid, client_ptr->uuid);
}
void ladish_client_set_jack_id(ladish_client_handle client_handle, uint64_t jack_id)
{
client_ptr->jack_id = jack_id;
}
uint64_t ladish_client_get_jack_id(ladish_client_handle client_handle)
{
return client_ptr->jack_id;
}
#undef client_ptr

View File

@ -47,4 +47,7 @@ ladish_dict_handle ladish_client_get_dict(ladish_client_handle client_handle);
void ladish_client_get_uuid(ladish_client_handle client_handle, uuid_t uuid);
void ladish_client_set_jack_id(ladish_client_handle client_handle, uint64_t jack_id);
uint64_t ladish_client_get_jack_id(ladish_client_handle client_handle);
#endif /* #ifndef CLIENT_H__2160B4BA_D6D1_464D_9DC5_ECA50B0958AD__INCLUDED */

View File

@ -459,7 +459,7 @@ ladish_graph_remove_port_internal(
list_del(&port_ptr->siblings_client);
list_del(&port_ptr->siblings_graph);
lash_info("removing port '%s':'%s' (%llu:%llu)", client_ptr->name, port_ptr->name, (unsigned long long)client_ptr->id, (unsigned long long)port_ptr->id);
lash_info("removing port '%s':'%s' (%"PRIu64":%"PRIu64") from graph %s", client_ptr->name, port_ptr->name, client_ptr->id, port_ptr->id, graph_ptr->opath != NULL ? graph_ptr->opath : "JACK");
if (graph_ptr->opath != NULL)
{
dbus_signal_emit(
@ -495,7 +495,7 @@ ladish_graph_remove_client_internal(
graph_ptr->graph_version++;
list_del(&client_ptr->siblings);
lash_info("removing client '%s' (%llu)", client_ptr->name, (unsigned long long)client_ptr->id);
lash_info("removing client '%s' (%"PRIu64") from graph %s", client_ptr->name, client_ptr->id, graph_ptr->opath != NULL ? graph_ptr->opath : "JACK");
if (graph_ptr->opath != NULL)
{
dbus_signal_emit(
@ -635,7 +635,7 @@ ladish_graph_add_port(
return false;
}
lash_info("adding port '%s':'%s' (%p)to graph %s", client_ptr->name, name, port_handle, graph_ptr->opath != NULL ? graph_ptr->opath : "JACK");
lash_info("adding port '%s':'%s' (%p) to graph %s", client_ptr->name, name, port_handle, graph_ptr->opath != NULL ? graph_ptr->opath : "JACK");
port_ptr = malloc(sizeof(struct ladish_graph_port));
if (port_ptr == NULL)
@ -717,7 +717,41 @@ ladish_port_handle ladish_graph_find_port_by_id(ladish_graph_handle graph_handle
return NULL;
}
void
ladish_client_handle ladish_graph_find_client_by_jack_id(ladish_graph_handle graph_handle, uint64_t client_id)
{
struct list_head * node_ptr;
struct ladish_graph_client * client_ptr;
list_for_each(node_ptr, &graph_ptr->clients)
{
client_ptr = list_entry(node_ptr, struct ladish_graph_client, siblings);
if (ladish_client_get_jack_id(client_ptr->client) == client_id)
{
return client_ptr->client;
}
}
return NULL;
}
ladish_port_handle ladish_graph_find_port_by_jack_id(ladish_graph_handle graph_handle, uint64_t port_id)
{
struct list_head * node_ptr;
struct ladish_graph_port * port_ptr;
list_for_each(node_ptr, &graph_ptr->ports)
{
port_ptr = list_entry(node_ptr, struct ladish_graph_port, siblings_graph);
if (ladish_port_get_jack_id(port_ptr->port) == port_id)
{
return port_ptr->port;
}
}
return NULL;
}
ladish_client_handle
ladish_graph_remove_port(
ladish_graph_handle graph_handle,
ladish_port_handle port)
@ -731,9 +765,39 @@ ladish_graph_remove_port(
if (port_ptr->port == port)
{
ladish_graph_remove_port_internal(graph_ptr, port_ptr->client_ptr, port_ptr, false);
return;
return port_ptr->client_ptr->client;
}
}
return NULL;
}
const char * ladish_graph_get_client_name(ladish_graph_handle graph_handle, ladish_client_handle client_handle)
{
struct ladish_graph_client * client_ptr;
client_ptr = ladish_graph_find_client(graph_ptr, client_handle);
if (client_ptr != NULL)
{
return client_ptr->name;
}
assert(false);
return NULL;
}
bool ladish_graph_is_client_empty(ladish_graph_handle graph_handle, ladish_client_handle client_handle)
{
struct ladish_graph_client * client_ptr;
client_ptr = ladish_graph_find_client(graph_ptr, client_handle);
if (client_ptr != NULL)
{
return list_empty(&client_ptr->ports);
}
assert(false);
return true;
}
bool

View File

@ -54,13 +54,18 @@ ladish_graph_add_port(
uint32_t type,
uint32_t flags);
void
ladish_client_handle
ladish_graph_remove_port(
ladish_graph_handle graph_handle,
ladish_port_handle port_handle);
ladish_client_handle ladish_graph_find_client_by_id(ladish_graph_handle graph_handle, uint64_t client_id);
ladish_port_handle ladish_graph_find_port_by_id(ladish_graph_handle graph_handle, uint64_t port_id);
ladish_client_handle ladish_graph_find_client_by_jack_id(ladish_graph_handle graph_handle, uint64_t client_id);
ladish_port_handle ladish_graph_find_port_by_jack_id(ladish_graph_handle graph_handle, uint64_t port_id);
const char * ladish_graph_get_client_name(ladish_graph_handle graph_handle, ladish_client_handle client_handle);
bool ladish_graph_is_client_empty(ladish_graph_handle graph_handle, ladish_client_handle client_handle);
bool
ladish_graph_iterate_nodes(

View File

@ -63,6 +63,8 @@ static void client_appeared(void * context, uint64_t id, const char * name)
return;
}
ladish_client_set_jack_id(client, id);
if (!ladish_graph_add_client(dispatcher_ptr->jack_graph, client, name))
{
lash_error("ladish_graph_add_client() failed to add client %"PRIu64" (%s) to JACK graph", id, name);
@ -74,15 +76,6 @@ static void client_appeared(void * context, uint64_t id, const char * name)
{
dispatcher_ptr->system_client_id = id;
}
else
{
if (!ladish_graph_add_client(dispatcher_ptr->studio_graph, client, name))
{
lash_error("ladish_graph_add_client() failed to add client %"PRIu64" (%s) to studio graph", id, name);
ladish_graph_remove_client(dispatcher_ptr->jack_graph, client, false);
ladish_client_destroy(client);
}
}
}
static void client_disappeared(void * context, uint64_t id)
@ -91,7 +84,7 @@ static void client_disappeared(void * context, uint64_t id)
lash_info("client_disappeared(%"PRIu64")", id);
client = ladish_graph_find_client_by_id(dispatcher_ptr->jack_graph, id);
client = ladish_graph_find_client_by_jack_id(dispatcher_ptr->jack_graph, id);
if (client == NULL)
{
lash_error("Unknown JACK client with id %"PRIu64" disappeared", id);
@ -102,10 +95,6 @@ static void client_disappeared(void * context, uint64_t id)
{
dispatcher_ptr->system_client_id = 0;
}
else
{
ladish_graph_remove_client(dispatcher_ptr->studio_graph, client, false);
}
ladish_graph_remove_client(dispatcher_ptr->jack_graph, client, false);
ladish_client_destroy(client);
@ -117,13 +106,45 @@ static void port_appeared(void * context, uint64_t client_id, uint64_t port_id,
ladish_port_handle port;
uint32_t type;
uint32_t flags;
const char * jack_client_name;
lash_info("port_appeared(%llu, %llu, %s (%s, %s))", (unsigned long long)client_id, (unsigned long long)port_id, port_name, is_input ? "in" : "out", is_midi ? "midi" : "audio");
lash_info("port_appeared(%"PRIu64", %"PRIu64", %s (%s, %s))", client_id, port_id, port_name, is_input ? "in" : "out", is_midi ? "midi" : "audio");
client = ladish_graph_find_client_by_jack_id(dispatcher_ptr->jack_graph, client_id);
if (client == NULL)
{
lash_error("Port of unknown JACK client with id %"PRIu64" appeared", client_id);
return;
}
jack_client_name = ladish_graph_get_client_name(dispatcher_ptr->jack_graph, client);
type = is_midi ? JACKDBUS_PORT_TYPE_MIDI : JACKDBUS_PORT_TYPE_AUDIO;
flags = is_input ? JACKDBUS_PORT_FLAG_INPUT : JACKDBUS_PORT_FLAG_OUTPUT;
if (is_terminal)
{
flags |= JACKDBUS_PORT_FLAG_TERMINAL;
}
if (!ladish_port_create(NULL, &port))
{
lash_error("ladish_port_create() failed.");
return;
}
ladish_port_set_jack_id(port, port_id);
if (!ladish_graph_add_port(dispatcher_ptr->jack_graph, client, port, port_name, type, flags))
{
lash_error("ladish_graph_add_port() failed.");
ladish_port_destroy(port);
return;
}
if (client_id == dispatcher_ptr->system_client_id)
{
if (!is_input)
{
{ /* output capture port */
if (dispatcher_ptr->system_capture_client == NULL)
{
if (!ladish_client_create(g_system_capture_guid, true, false, true, &dispatcher_ptr->system_capture_client))
@ -144,7 +165,7 @@ static void port_appeared(void * context, uint64_t client_id, uint64_t port_id,
client = dispatcher_ptr->system_capture_client;
}
else
{
{ /* input capture port */
if (dispatcher_ptr->system_playback_client == NULL)
{
if (!ladish_client_create(g_system_playback_guid, true, false, true, &dispatcher_ptr->system_playback_client))
@ -165,21 +186,25 @@ static void port_appeared(void * context, uint64_t client_id, uint64_t port_id,
}
}
else
{
return; /* TODO: find client by client_id */
}
{ /* non-system client */
client = ladish_graph_find_client_by_jack_id(dispatcher_ptr->studio_graph, client_id);
if (client == NULL)
{
if (!ladish_client_create(NULL, false, false, false, &client))
{
lash_error("ladish_client_create() failed.");
return;
}
type = is_midi ? JACKDBUS_PORT_TYPE_MIDI : JACKDBUS_PORT_TYPE_AUDIO;
flags = is_input ? JACKDBUS_PORT_FLAG_INPUT : JACKDBUS_PORT_FLAG_OUTPUT;
if (is_terminal)
{
flags |= JACKDBUS_PORT_FLAG_TERMINAL;
}
ladish_client_set_jack_id(client, client_id);
if (!ladish_port_create(NULL, &port))
{
lash_error("ladish_port_create() failed.");
return;
if (!ladish_graph_add_client(dispatcher_ptr->studio_graph, client, jack_client_name))
{
lash_error("ladish_graph_add_client() failed to add client '%s' to studio graph", jack_client_name);
ladish_client_destroy(client);
return;
}
}
}
if (!ladish_graph_add_port(dispatcher_ptr->studio_graph, client, port, port_name, type, flags))
@ -191,7 +216,35 @@ static void port_appeared(void * context, uint64_t client_id, uint64_t port_id,
static void port_disappeared(void * context, uint64_t client_id, uint64_t port_id)
{
lash_info("port_disappeared(%llu)", (unsigned long long)port_id);
ladish_client_handle client;
ladish_port_handle port;
lash_info("port_disappeared(%"PRIu64")", port_id);
client = ladish_graph_find_client_by_jack_id(dispatcher_ptr->jack_graph, client_id);
if (client == NULL)
{
lash_error("Port of unknown JACK client with id %"PRIu64" disappeared", client_id);
return;
}
port = ladish_graph_find_port_by_jack_id(dispatcher_ptr->jack_graph, port_id);
if (client == NULL)
{
lash_error("Unknown JACK port with id %"PRIu64" disappeared", port_id);
return;
}
ladish_graph_remove_port(dispatcher_ptr->jack_graph, port);
client = ladish_graph_remove_port(dispatcher_ptr->studio_graph, port);
if (client != NULL)
{
if (ladish_graph_is_client_empty(dispatcher_ptr->studio_graph, client))
{
ladish_graph_remove_client(dispatcher_ptr->studio_graph, client, false);
}
}
}
static void ports_connected(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id)

View File

@ -105,4 +105,14 @@ ladish_dict_handle ladish_port_get_dict(ladish_port_handle port_handle)
return port_ptr->dict;
}
void ladish_port_set_jack_id(ladish_port_handle port_handle, uint64_t jack_id)
{
port_ptr->jack_id = jack_id;
}
uint64_t ladish_port_get_jack_id(ladish_port_handle port_handle)
{
return port_ptr->jack_id;
}
#undef port_ptr

View File

@ -35,4 +35,7 @@ bool ladish_port_create(uuid_t uuid_ptr, ladish_port_handle * port_handle_ptr);
void ladish_port_destroy(ladish_port_handle port_handle);
ladish_dict_handle ladish_port_get_dict(ladish_port_handle port_handle);
void ladish_port_set_jack_id(ladish_port_handle port_handle, uint64_t jack_id);
uint64_t ladish_port_get_jack_id(ladish_port_handle port_handle);
#endif /* #ifndef PORT_H__62F81E7C_91FA_44AB_94A9_E0E2D226ED58__INCLUDED */