| | 198 | static |
| | 199 | bool |
| | 200 | ladish_graph_find_connection_ports_by_name_internal( |
| | 201 | struct ladish_graph * graph_ptr, |
| | 202 | const char * client1_name, |
| | 203 | const char * port1_name, |
| | 204 | const char * client2_name, |
| | 205 | const char * port2_name, |
| | 206 | struct ladish_graph_port ** port1_ptr_ptr, |
| | 207 | struct ladish_graph_port ** port2_ptr_ptr) |
| | 208 | { |
| | 209 | struct list_head * client1_node_ptr; |
| | 210 | struct ladish_graph_client * client1_ptr; |
| | 211 | struct list_head * port1_node_ptr; |
| | 212 | struct ladish_graph_port * port1_ptr; |
| | 213 | struct list_head * client2_node_ptr; |
| | 214 | struct ladish_graph_client * client2_ptr; |
| | 215 | struct list_head * port2_node_ptr; |
| | 216 | struct ladish_graph_port * port2_ptr; |
| | 217 | |
| | 218 | /* |
| | 219 | * Port names are not unique, so in order to find best match, |
| | 220 | * ports are searched with these assumptions: |
| | 221 | * |
| | 222 | * 1. port1 and port2 are of same type (midi or audio) |
| | 223 | * 2. port1 is a source (capture, output) port |
| | 224 | * 3. port2 is a destination (playback, input) port |
| | 225 | * |
| | 226 | * all these conditions have to be met for a port pair to match |
| | 227 | */ |
| | 228 | list_for_each(client1_node_ptr, &graph_ptr->clients) |
| | 229 | { |
| | 230 | client1_ptr = list_entry(client1_node_ptr, struct ladish_graph_client, siblings); |
| | 231 | if (strcmp(client1_ptr->name, client1_name) == 0) |
| | 232 | { |
| | 233 | list_for_each(port1_node_ptr, &client1_ptr->ports) |
| | 234 | { |
| | 235 | port1_ptr = list_entry(port1_node_ptr, struct ladish_graph_port, siblings_client); |
| | 236 | if (JACKDBUS_PORT_IS_OUTPUT(port1_ptr->flags) && |
| | 237 | strcmp(port1_ptr->name, port1_name) == 0) |
| | 238 | { |
| | 239 | list_for_each(client2_node_ptr, &graph_ptr->clients) |
| | 240 | { |
| | 241 | client2_ptr = list_entry(client2_node_ptr, struct ladish_graph_client, siblings); |
| | 242 | if (strcmp(client2_ptr->name, client2_name) == 0) |
| | 243 | { |
| | 244 | list_for_each(port2_node_ptr, &client2_ptr->ports) |
| | 245 | { |
| | 246 | port2_ptr = list_entry(port2_node_ptr, struct ladish_graph_port, siblings_client); |
| | 247 | if (port2_ptr->type == port1_ptr->type && |
| | 248 | JACKDBUS_PORT_IS_INPUT(port2_ptr->flags) && |
| | 249 | strcmp(port2_ptr->name, port2_name) == 0) |
| | 250 | { |
| | 251 | *port1_ptr_ptr = port1_ptr; |
| | 252 | *port2_ptr_ptr = port2_ptr; |
| | 253 | return true; |
| | 254 | } |
| | 255 | } |
| | 256 | } |
| | 257 | } |
| | 258 | } |
| | 259 | } |
| | 260 | } |
| | 261 | } |
| | 262 | |
| | 263 | return false; |
| | 264 | } |
| | 265 | |
| | 266 | static |
| | 267 | bool |
| | 268 | ladish_graph_find_connection_ports_by_name( |
| | 269 | struct ladish_graph * graph_ptr, |
| | 270 | const char * client1_name, |
| | 271 | const char * port1_name, |
| | 272 | const char * client2_name, |
| | 273 | const char * port2_name, |
| | 274 | struct ladish_graph_port ** port1_ptr_ptr, |
| | 275 | struct ladish_graph_port ** port2_ptr_ptr) |
| | 276 | { |
| | 277 | if (ladish_graph_find_connection_ports_by_name_internal( |
| | 278 | graph_ptr, |
| | 279 | client1_name, |
| | 280 | port1_name, |
| | 281 | client2_name, |
| | 282 | port2_name, |
| | 283 | port1_ptr_ptr, |
| | 284 | port2_ptr_ptr)) |
| | 285 | { |
| | 286 | return true; |
| | 287 | } |
| | 288 | |
| | 289 | if (ladish_graph_find_connection_ports_by_name_internal( |
| | 290 | graph_ptr, |
| | 291 | client2_name, |
| | 292 | port2_name, |
| | 293 | client1_name, |
| | 294 | port1_name, |
| | 295 | port1_ptr_ptr, |
| | 296 | port2_ptr_ptr)) |
| | 297 | { |
| | 298 | return true; |
| | 299 | } |
| | 300 | |
| | 301 | return false; |
| | 302 | } |
| | 303 | |
| 616 | | log_info("connect_ports_by_name() called."); |
| 617 | | lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "connect by name is not implemented yet"); |
| | 722 | const char * client1_name; |
| | 723 | const char * port1_name; |
| | 724 | const char * client2_name; |
| | 725 | const char * port2_name; |
| | 726 | struct ladish_graph_port * port1; |
| | 727 | struct ladish_graph_port * port2; |
| | 728 | |
| | 729 | if (!dbus_message_get_args( |
| | 730 | call_ptr->message, |
| | 731 | &g_dbus_error, |
| | 732 | DBUS_TYPE_STRING, &client1_name, |
| | 733 | DBUS_TYPE_STRING, &port1_name, |
| | 734 | DBUS_TYPE_STRING, &client2_name, |
| | 735 | DBUS_TYPE_STRING, &port2_name, |
| | 736 | DBUS_TYPE_INVALID)) |
| | 737 | { |
| | 738 | lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message); |
| | 739 | dbus_error_free(&g_dbus_error); |
| | 740 | return; |
| | 741 | } |
| | 742 | |
| | 743 | log_info("connect_ports_by_name(\"%s\", \"%s\", \"%s\", \"%s\") called.", client1_name, port1_name, client2_name, port2_name); |
| | 744 | |
| | 745 | if (!ladish_graph_find_connection_ports_by_name(graph_ptr, client1_name, port1_name, client2_name, port2_name, &port1, &port2)) |
| | 746 | { |
| | 747 | lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Cannot connect unknown ports"); |
| | 748 | return; |
| | 749 | } |
| | 750 | |
| | 751 | if (graph_ptr->connect_handler(graph_ptr->context, (ladish_graph_handle)graph_ptr, port1->port, port2->port)) |
| | 752 | { |
| | 753 | method_return_new_void(call_ptr); |
| | 754 | } |
| | 755 | else |
| | 756 | { |
| | 757 | lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "connect failed"); |
| | 758 | } |
| 691 | | log_info("disconnect_ports_by_name() called."); |
| 692 | | lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "disconnect by name is not implemented yet"); |
| | 832 | const char * client1_name; |
| | 833 | const char * port1_name; |
| | 834 | const char * client2_name; |
| | 835 | const char * port2_name; |
| | 836 | struct ladish_graph_port * port1; |
| | 837 | struct ladish_graph_port * port2; |
| | 838 | struct ladish_graph_connection * connection_ptr; |
| | 839 | |
| | 840 | if (!dbus_message_get_args( |
| | 841 | call_ptr->message, |
| | 842 | &g_dbus_error, |
| | 843 | DBUS_TYPE_STRING, &client1_name, |
| | 844 | DBUS_TYPE_STRING, &port1_name, |
| | 845 | DBUS_TYPE_STRING, &client2_name, |
| | 846 | DBUS_TYPE_STRING, &port2_name, |
| | 847 | DBUS_TYPE_INVALID)) |
| | 848 | { |
| | 849 | lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Invalid arguments to method \"%s\": %s", call_ptr->method_name, g_dbus_error.message); |
| | 850 | dbus_error_free(&g_dbus_error); |
| | 851 | return; |
| | 852 | } |
| | 853 | |
| | 854 | log_info("disconnect_ports_by_name(\"%s\", \"%s\", \"%s\", \"%s\") called.", client1_name, port1_name, client2_name, port2_name); |
| | 855 | |
| | 856 | if (!ladish_graph_find_connection_ports_by_name(graph_ptr, client1_name, port1_name, client2_name, port2_name, &port1, &port2)) |
| | 857 | { |
| | 858 | lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Cannot disconnect unknown ports"); |
| | 859 | return; |
| | 860 | } |
| | 861 | |
| | 862 | connection_ptr = ladish_graph_find_connection_by_ports(graph_ptr, port1, port2); |
| | 863 | if (connection_ptr == NULL) |
| | 864 | { |
| | 865 | lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Cannot disconnect not connected ports"); |
| | 866 | return; |
| | 867 | } |
| | 868 | |
| | 869 | disconnect_ports(call_ptr, connection_ptr); |