ladishd: implement ports connect

This commit is contained in:
Nedko Arnaudov 2009-11-28 19:46:43 +02:00
parent 5955c05ca0
commit 23b1a8fa1e
3 changed files with 118 additions and 19 deletions

View File

@ -53,12 +53,22 @@ struct ladish_graph_client
bool hidden;
};
struct ladish_graph_connection
{
struct list_head siblings;
uint64_t id;
bool hidden;
struct ladish_graph_port * port1_ptr;
struct ladish_graph_port * port2_ptr;
};
struct ladish_graph
{
char * opath;
ladish_dict_handle dict;
struct list_head clients;
struct list_head ports;
struct list_head connections;
uint64_t graph_version;
uint64_t next_client_id;
uint64_t next_port_id;
@ -134,7 +144,9 @@ static void get_graph(struct dbus_method_call * call_ptr)
struct list_head * port_node_ptr;
struct ladish_graph_port * port_ptr;
DBusMessageIter port_struct_iter;
//DBusMessageIter connection_struct_iter;
struct list_head * connection_node_ptr;
struct ladish_graph_connection * connection_ptr;
DBusMessageIter connection_struct_iter;
//log_info("get_graph() called");
@ -274,52 +286,51 @@ static void get_graph(struct dbus_method_call * call_ptr)
if (known_version < current_version)
{
#if 0
list_for_each(connection_node_ptr, &patchbay_ptr->graph.connections)
list_for_each(connection_node_ptr, &graph_ptr->connections)
{
connection_ptr = list_entry(connection_node_ptr, struct jack_graph_connection, siblings);
connection_ptr = list_entry(connection_node_ptr, struct ladish_graph_connection, siblings);
if (!dbus_message_iter_open_container(&connections_array_iter, DBUS_TYPE_STRUCT, NULL, &connection_struct_iter))
{
goto nomem_close_connections_array;
}
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port1->client->id))
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port1_ptr->client_ptr->id))
{
goto nomem_close_connection_struct;
}
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port1->client->name))
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port1_ptr->client_ptr->name))
{
goto nomem_close_connection_struct;
}
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port1->id))
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port1_ptr->id))
{
goto nomem_close_connection_struct;
}
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port1->name))
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port1_ptr->name))
{
goto nomem_close_connection_struct;
}
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port2->client->id))
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port2_ptr->client_ptr->id))
{
goto nomem_close_connection_struct;
}
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port2->client->name))
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port2_ptr->client_ptr->name))
{
goto nomem_close_connection_struct;
}
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port2->id))
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_UINT64, &connection_ptr->port2_ptr->id))
{
goto nomem_close_connection_struct;
}
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port2->name))
if (!dbus_message_iter_append_basic(&connection_struct_iter, DBUS_TYPE_STRING, &connection_ptr->port2_ptr->name))
{
goto nomem_close_connection_struct;
}
@ -334,7 +345,6 @@ static void get_graph(struct dbus_method_call * call_ptr)
goto nomem_close_connections_array;
}
}
#endif
}
if (!dbus_message_iter_close_container(&iter, &connections_array_iter))
@ -344,14 +354,12 @@ static void get_graph(struct dbus_method_call * call_ptr)
return;
#if 0
nomem_close_connection_struct:
dbus_message_iter_close_container(&connections_array_iter, &connection_struct_iter);
nomem_close_connections_array:
dbus_message_iter_close_container(&iter, &connections_array_iter);
goto nomem_unlock;
#endif
goto nomem;
nomem_close_port_struct:
dbus_message_iter_close_container(&ports_array_iter, &port_struct_iter);
@ -503,6 +511,7 @@ bool ladish_graph_create(ladish_graph_handle * graph_handle_ptr, const char * op
INIT_LIST_HEAD(&graph_ptr->clients);
INIT_LIST_HEAD(&graph_ptr->ports);
INIT_LIST_HEAD(&graph_ptr->connections);
graph_ptr->graph_version = 1;
graph_ptr->next_client_id = 1;
@ -1011,6 +1020,60 @@ ladish_graph_add_port(
return true;
}
bool
ladish_graph_add_connection(
ladish_graph_handle graph_handle,
ladish_port_handle port1_handle,
ladish_port_handle port2_handle,
bool hidden)
{
struct ladish_graph_port * port1_ptr;
struct ladish_graph_port * port2_ptr;
struct ladish_graph_connection * connection_ptr;
port1_ptr = ladish_graph_find_port(graph_ptr, port1_handle);
ASSERT(port1_ptr != NULL);
port2_ptr = ladish_graph_find_port(graph_ptr, port2_handle);
ASSERT(port2_ptr != NULL);
connection_ptr = malloc(sizeof(struct ladish_graph_connection));
if (connection_ptr == NULL)
{
log_error("malloc() failed for struct ladish_graph_connection");
return false;
}
connection_ptr->id = graph_ptr->next_connection_id++;
connection_ptr->port1_ptr = port1_ptr;
connection_ptr->port2_ptr = port2_ptr;
connection_ptr->hidden = hidden;
graph_ptr->graph_version++;
list_add_tail(&connection_ptr->siblings, &graph_ptr->connections);
if (!hidden && graph_ptr->opath != NULL)
{
dbus_signal_emit(
g_dbus_connection,
graph_ptr->opath,
JACKDBUS_IFACE_PATCHBAY,
"PortsConnected",
"ttstststst",
&graph_ptr->graph_version,
&port1_ptr->client_ptr->id,
&port1_ptr->client_ptr->name,
&port1_ptr->id,
&port1_ptr->name,
&port2_ptr->client_ptr->id,
&port2_ptr->client_ptr->name,
&port2_ptr->id,
&port2_ptr->name,
&connection_ptr->id);
}
return true;
}
ladish_client_handle ladish_graph_find_client_by_name(ladish_graph_handle graph_handle, const char * name)
{
struct list_head * node_ptr;

View File

@ -83,6 +83,13 @@ ladish_graph_remove_port(
ladish_graph_handle graph_handle,
ladish_port_handle port_handle);
bool
ladish_graph_add_connection(
ladish_graph_handle graph_handle,
ladish_port_handle port1_handle,
ladish_port_handle port2_handle,
bool hidden);
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);

View File

@ -272,7 +272,7 @@ static void port_disappeared(void * context, uint64_t client_id, uint64_t port_i
}
port = ladish_graph_find_port_by_jack_id(virtualizer_ptr->jack_graph, port_id);
if (client == NULL)
if (port == NULL)
{
log_error("Unknown JACK port with id %"PRIu64" disappeared", port_id);
return;
@ -314,9 +314,18 @@ static void port_disappeared(void * context, uint64_t client_id, uint64_t port_i
static bool ports_connect_request(void * context, ladish_graph_handle graph_handle, ladish_port_handle port1, ladish_port_handle port2)
{
uint64_t port1_id;
uint64_t port2_id;
ASSERT(graph_handle == virtualizer_ptr->studio_graph);
log_info("virtualizer: ports connect request");
return false;
port1_id = ladish_port_get_jack_id(port1);
port2_id = ladish_port_get_jack_id(port2);
graph_proxy_connect_ports(virtualizer_ptr->jack_graph_proxy, port1_id, port2_id);
return true;
}
static bool ports_disconnect_request(void * context, ladish_graph_handle graph_handle, uint64_t connection_id)
@ -328,7 +337,27 @@ static bool ports_disconnect_request(void * context, ladish_graph_handle graph_h
static void ports_connected(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id)
{
log_info("ports_connected");
ladish_port_handle port1;
ladish_port_handle port2;
log_info("ports_connected %"PRIu64":%"PRIu64" %"PRIu64":%"PRIu64"", client1_id, port1_id, client2_id, port2_id);
port1 = ladish_graph_find_port_by_jack_id(virtualizer_ptr->jack_graph, port1_id);
if (port1 == NULL)
{
log_error("Unknown JACK port with id %"PRIu64" connected", port1_id);
return;
}
port2 = ladish_graph_find_port_by_jack_id(virtualizer_ptr->jack_graph, port2_id);
if (port2 == NULL)
{
log_error("Unknown JACK port with id %"PRIu64" connected", port2_id);
return;
}
ladish_graph_add_connection(virtualizer_ptr->jack_graph, port1, port2, false);
ladish_graph_add_connection(virtualizer_ptr->studio_graph, port1, port2, false);
}
static void ports_disconnected(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id)