handle port renames. closes #32
This commit is contained in:
parent
0218ebda7e
commit
3bec987ea4
|
@ -1626,6 +1626,57 @@ ladish_graph_remove_port(
|
|||
return port_ptr->client_ptr->client;
|
||||
}
|
||||
|
||||
bool
|
||||
ladish_graph_rename_port(
|
||||
ladish_graph_handle graph_handle,
|
||||
ladish_port_handle port_handle,
|
||||
const char * new_port_name)
|
||||
{
|
||||
char * name;
|
||||
struct ladish_graph_port * port_ptr;
|
||||
char * old_name;
|
||||
|
||||
name = strdup(new_port_name);
|
||||
if (name == NULL)
|
||||
{
|
||||
log_error("strdup('%s') failed.", new_port_name);
|
||||
return false;
|
||||
}
|
||||
|
||||
port_ptr = ladish_graph_find_port(graph_ptr, port_handle);
|
||||
if (port_ptr == NULL)
|
||||
{
|
||||
ASSERT_NO_PASS;
|
||||
free(name);
|
||||
return false;
|
||||
}
|
||||
|
||||
old_name = port_ptr->name;
|
||||
port_ptr->name = name;
|
||||
|
||||
graph_ptr->graph_version++;
|
||||
|
||||
if (!port_ptr->hidden && graph_ptr->opath != NULL)
|
||||
{
|
||||
dbus_signal_emit(
|
||||
g_dbus_connection,
|
||||
graph_ptr->opath,
|
||||
JACKDBUS_IFACE_PATCHBAY,
|
||||
"PortRenamed",
|
||||
"ttstss",
|
||||
&graph_ptr->graph_version,
|
||||
&port_ptr->client_ptr->id,
|
||||
&port_ptr->client_ptr->name,
|
||||
&port_ptr->id,
|
||||
&old_name,
|
||||
&port_ptr->name);
|
||||
}
|
||||
|
||||
free(old_name);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const char * ladish_graph_get_client_name(ladish_graph_handle graph_handle, ladish_client_handle client_handle)
|
||||
{
|
||||
struct ladish_graph_client * client_ptr;
|
||||
|
|
|
@ -84,6 +84,12 @@ ladish_graph_remove_port(
|
|||
ladish_graph_handle graph_handle,
|
||||
ladish_port_handle port_handle);
|
||||
|
||||
bool
|
||||
ladish_graph_rename_port(
|
||||
ladish_graph_handle graph_handle,
|
||||
ladish_port_handle port_handle,
|
||||
const char * new_port_name);
|
||||
|
||||
uint64_t
|
||||
ladish_graph_add_connection(
|
||||
ladish_graph_handle graph_handle,
|
||||
|
|
|
@ -511,6 +511,38 @@ static void port_disappeared(void * context, uint64_t client_id, uint64_t port_i
|
|||
}
|
||||
}
|
||||
|
||||
static void port_renamed(void * context, uint64_t client_id, uint64_t port_id, const char * old_port_name, const char * new_port_name)
|
||||
{
|
||||
ladish_client_handle client;
|
||||
ladish_port_handle port;
|
||||
|
||||
log_info("port_renamed(%"PRIu64", '%s', '%s')", port_id, old_port_name, new_port_name);
|
||||
|
||||
client = ladish_graph_find_client_by_jack_id(virtualizer_ptr->jack_graph, client_id);
|
||||
if (client == NULL)
|
||||
{
|
||||
log_error("Port of unknown JACK client with id %"PRIu64" was renamed", client_id);
|
||||
return;
|
||||
}
|
||||
|
||||
port = ladish_graph_find_port_by_jack_id(virtualizer_ptr->jack_graph, port_id);
|
||||
if (port == NULL)
|
||||
{
|
||||
log_error("Unknown JACK port with id %"PRIu64" was renamed", port_id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ladish_graph_rename_port(virtualizer_ptr->jack_graph, port, new_port_name))
|
||||
{
|
||||
log_error("renaming of port in jack graph failed");
|
||||
}
|
||||
|
||||
if (!ladish_graph_rename_port(virtualizer_ptr->studio_graph, port, new_port_name))
|
||||
{
|
||||
log_error("renaming of port in jack studio failed");
|
||||
}
|
||||
}
|
||||
|
||||
static bool ports_connect_request(void * context, ladish_graph_handle graph_handle, ladish_port_handle port1, ladish_port_handle port2)
|
||||
{
|
||||
uint64_t port1_id;
|
||||
|
@ -661,6 +693,7 @@ ladish_virtualizer_create(
|
|||
client_appeared,
|
||||
client_disappeared,
|
||||
port_appeared,
|
||||
port_renamed,
|
||||
port_disappeared,
|
||||
ports_connected,
|
||||
ports_disconnected))
|
||||
|
|
|
@ -306,6 +306,14 @@ canvas_get_port_color(
|
|||
return port_ptr->get()->color();
|
||||
}
|
||||
|
||||
void
|
||||
canvas_set_port_name(
|
||||
canvas_port_handle port,
|
||||
const char * name)
|
||||
{
|
||||
port_ptr->get()->set_name(name);
|
||||
}
|
||||
|
||||
#undef port_ptr
|
||||
#define port1_ptr ((boost::shared_ptr<port_cls> *)port1)
|
||||
#define port2_ptr ((boost::shared_ptr<port_cls> *)port2)
|
||||
|
|
|
@ -119,6 +119,11 @@ int
|
|||
canvas_get_port_color(
|
||||
canvas_port_handle port);
|
||||
|
||||
void
|
||||
canvas_set_port_name(
|
||||
canvas_port_handle port,
|
||||
const char * name);
|
||||
|
||||
bool
|
||||
canvas_add_connection(
|
||||
canvas_handle canvas,
|
||||
|
|
|
@ -423,6 +423,37 @@ port_disappeared(
|
|||
free(port_ptr);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
port_renamed(
|
||||
void * graph_canvas,
|
||||
uint64_t client_id,
|
||||
uint64_t port_id,
|
||||
const char * old_port_name,
|
||||
const char * new_port_name)
|
||||
{
|
||||
struct client * client_ptr;
|
||||
struct port * port_ptr;
|
||||
|
||||
log_info("canvas::port_renamed(%"PRIu64", %"PRIu64", '%s', '%s')", client_id, port_id, old_port_name, new_port_name);
|
||||
|
||||
client_ptr = find_client(graph_canvas_ptr, client_id);
|
||||
if (client_ptr == NULL)
|
||||
{
|
||||
log_error("cannot find client %"PRIu64" of renamed port %"PRIu64"", client_id, port_id);
|
||||
return;
|
||||
}
|
||||
|
||||
port_ptr = find_port(client_ptr, port_id);
|
||||
if (client_ptr == NULL)
|
||||
{
|
||||
log_error("cannot find renamed port %"PRIu64" of client %"PRIu64"", port_id, client_id);
|
||||
return;
|
||||
}
|
||||
|
||||
canvas_set_port_name(port_ptr->canvas_port, new_port_name);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
ports_connected(
|
||||
|
@ -550,6 +581,7 @@ graph_canvas_attach(
|
|||
client_appeared,
|
||||
client_disappeared,
|
||||
port_appeared,
|
||||
port_renamed,
|
||||
port_disappeared,
|
||||
ports_connected,
|
||||
ports_disconnected))
|
||||
|
|
|
@ -34,6 +34,7 @@ struct monitor
|
|||
void (* client_appeared)(void * context, uint64_t id, const char * name);
|
||||
void (* client_disappeared)(void * context, uint64_t id);
|
||||
void (* port_appeared)(void * context, uint64_t client_id, uint64_t port_id, const char * port_name, bool is_input, bool is_terminal, bool is_midi);
|
||||
void (* port_renamed)(void * context, uint64_t client_id, uint64_t port_id, const char * old_port_name, const char * new_port_name);
|
||||
void (* port_disappeared)(void * context, uint64_t client_id, uint64_t port_id);
|
||||
void (* ports_connected)(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id);
|
||||
void (* ports_disconnected)(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id);
|
||||
|
@ -137,6 +138,25 @@ port_disappeared(
|
|||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
port_renamed(
|
||||
struct graph * graph_ptr,
|
||||
uint64_t client_id,
|
||||
uint64_t port_id,
|
||||
const char * old_port_name,
|
||||
const char * new_port_name)
|
||||
{
|
||||
struct list_head * node_ptr;
|
||||
struct monitor * monitor_ptr;
|
||||
|
||||
list_for_each(node_ptr, &graph_ptr->monitors)
|
||||
{
|
||||
monitor_ptr = list_entry(node_ptr, struct monitor, siblings);
|
||||
monitor_ptr->port_renamed(monitor_ptr->context, client_id, port_id, old_port_name, new_port_name);
|
||||
}
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
ports_connected(
|
||||
|
@ -465,6 +485,7 @@ graph_proxy_attach(
|
|||
void (* client_appeared)(void * context, uint64_t id, const char * name),
|
||||
void (* client_disappeared)(void * context, uint64_t id),
|
||||
void (* port_appeared)(void * context, uint64_t client_id, uint64_t port_id, const char * port_name, bool is_input, bool is_terminal, bool is_midi),
|
||||
void (* port_renamed)(void * context, uint64_t client_id, uint64_t port_id, const char * old_port_name, const char * new_port_name),
|
||||
void (* port_disappeared)(void * context, uint64_t client_id, uint64_t port_id),
|
||||
void (* ports_connected)(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id),
|
||||
void (* ports_disconnected)(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id))
|
||||
|
@ -488,6 +509,7 @@ graph_proxy_attach(
|
|||
monitor_ptr->client_appeared = client_appeared;
|
||||
monitor_ptr->client_disappeared = client_disappeared;
|
||||
monitor_ptr->port_appeared = port_appeared;
|
||||
monitor_ptr->port_renamed = port_renamed;
|
||||
monitor_ptr->port_disappeared = port_disappeared;
|
||||
monitor_ptr->ports_connected = ports_connected;
|
||||
monitor_ptr->ports_disconnected = ports_disconnected;
|
||||
|
@ -638,6 +660,39 @@ static void on_port_appeared(void * graph, DBusMessage * message_ptr)
|
|||
}
|
||||
}
|
||||
|
||||
static void on_port_renamed(void * graph, DBusMessage * message_ptr)
|
||||
{
|
||||
dbus_uint64_t new_graph_version;
|
||||
dbus_uint64_t client_id;
|
||||
const char * client_name;
|
||||
dbus_uint64_t port_id;
|
||||
const char * old_port_name;
|
||||
const char * new_port_name;
|
||||
|
||||
if (!dbus_message_get_args(
|
||||
message_ptr,
|
||||
&g_dbus_error,
|
||||
DBUS_TYPE_UINT64, &new_graph_version,
|
||||
DBUS_TYPE_UINT64, &client_id,
|
||||
DBUS_TYPE_STRING, &client_name,
|
||||
DBUS_TYPE_UINT64, &port_id,
|
||||
DBUS_TYPE_STRING, &old_port_name,
|
||||
DBUS_TYPE_STRING, &new_port_name,
|
||||
DBUS_TYPE_INVALID))
|
||||
{
|
||||
log_error("dbus_message_get_args() failed to extract PortRenamed signal arguments (%s)", g_dbus_error.message);
|
||||
dbus_error_free(&g_dbus_error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (new_graph_version > graph_ptr->version)
|
||||
{
|
||||
//log_info("got new graph version %llu", (unsigned long long)new_graph_version);
|
||||
graph_ptr->version = new_graph_version;
|
||||
port_renamed(graph_ptr, client_id, port_id, old_port_name, new_port_name);
|
||||
}
|
||||
}
|
||||
|
||||
static void on_port_disappeared(void * graph, DBusMessage * message_ptr)
|
||||
{
|
||||
dbus_uint64_t new_graph_version;
|
||||
|
@ -861,6 +916,7 @@ static struct dbus_signal_hook g_signal_hooks[] =
|
|||
{"ClientAppeared", on_client_appeared},
|
||||
{"ClientDisappeared", on_client_disappeared},
|
||||
{"PortAppeared", on_port_appeared},
|
||||
{"PortRenamed", on_port_renamed},
|
||||
{"PortDisappeared", on_port_disappeared},
|
||||
{"PortsConnected", on_ports_connected},
|
||||
{"PortsDisconnected", on_ports_disconnected},
|
||||
|
|
|
@ -64,6 +64,7 @@ graph_proxy_attach(
|
|||
void (* client_appeared)(void * context, uint64_t id, const char * name),
|
||||
void (* client_disappeared)(void * context, uint64_t id),
|
||||
void (* port_appeared)(void * context, uint64_t client_id, uint64_t port_id, const char * port_name, bool is_input, bool is_terminal, bool is_midi),
|
||||
void (* port_renamed)(void * context, uint64_t client_id, uint64_t port_id, const char * old_port_name, const char * new_port_name),
|
||||
void (* port_disappeared)(void * context, uint64_t client_id, uint64_t port_id),
|
||||
void (* ports_connected)(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id),
|
||||
void (* ports_disconnected)(void * context, uint64_t client1_id, uint64_t port1_id, uint64_t client2_id, uint64_t port2_id));
|
||||
|
|
Loading…
Reference in New Issue