diff --git a/daemon/graph.c b/daemon/graph.c index ce603f3f..88e4efc6 100644 --- a/daemon/graph.c +++ b/daemon/graph.c @@ -1562,6 +1562,27 @@ ladish_graph_remove_client( } } +uint64_t +ladish_graph_get_client_id( + ladish_graph_handle graph_handle, + ladish_client_handle client_handle) +{ + struct ladish_graph_client * client_ptr; + + log_info("ladish_graph_get_client_id() called."); + + client_ptr = ladish_graph_find_client(graph_ptr, client_handle); + if (client_ptr != NULL) + { + return client_ptr->id; + } + else + { + ASSERT_NO_PASS; + return 0; + } +} + bool ladish_graph_add_port( ladish_graph_handle graph_handle, diff --git a/daemon/graph.h b/daemon/graph.h index 7013cbce..adf803c9 100644 --- a/daemon/graph.h +++ b/daemon/graph.h @@ -165,6 +165,7 @@ ladish_graph_set_link_port_override_uuid( const uuid_t override_uuid); ladish_client_handle ladish_graph_get_port_client(ladish_graph_handle graph_handle, ladish_port_handle port_handle); +uint64_t ladish_graph_get_client_id(ladish_graph_handle graph_handle, ladish_client_handle client_handle); const char * ladish_graph_get_client_name(ladish_graph_handle graph_handle, ladish_client_handle client_handle); const char * ladish_graph_get_port_name(ladish_graph_handle graph, ladish_port_handle port); bool ladish_graph_client_is_empty(ladish_graph_handle graph_handle, ladish_client_handle client_handle); diff --git a/daemon/graph_manager.c b/daemon/graph_manager.c index 605e835f..3d2f3667 100644 --- a/daemon/graph_manager.c +++ b/daemon/graph_manager.c @@ -170,6 +170,8 @@ static void ladish_graph_manager_dbus_move_port(struct dbus_method_call * call_p { uint64_t port_id; uint64_t client_id; + ladish_port_handle port; + ladish_client_handle client; if (!dbus_message_get_args( call_ptr->message, @@ -185,12 +187,30 @@ static void ladish_graph_manager_dbus_move_port(struct dbus_method_call * call_p log_info("move port request, graph '%s', port %"PRIu64", client %"PRIu64, ladish_graph_get_description(graph), port_id, client_id); + port = ladish_graph_find_port_by_id(graph, port_id); + if (port == NULL) + { + lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Cannot move unknown port"); + return; + } + + client = ladish_graph_find_client_by_id(graph, client_id); + if (client == NULL) + { + lash_dbus_error(call_ptr, LASH_DBUS_ERROR_INVALID_ARGS, "Cannot move port to unknown client"); + return; + } + + ladish_graph_move_port(graph, port, client); + method_return_new_void(call_ptr); } static void ladish_graph_manager_dbus_new_client(struct dbus_method_call * call_ptr) { const char * name; + ladish_client_handle client; + uint64_t client_id; if (!dbus_message_get_args( call_ptr->message, @@ -205,7 +225,22 @@ static void ladish_graph_manager_dbus_new_client(struct dbus_method_call * call_ log_info("new client request, graph '%s', name '%s'", ladish_graph_get_description(graph), name); - lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "method \"%s\" not implemented yet", call_ptr->method_name); + if (!ladish_client_create(NULL, &client)) + { + lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_client_create() failed."); + return; + } + + if (!ladish_graph_add_client(graph, client, name, false)) + { + lash_dbus_error(call_ptr, LASH_DBUS_ERROR_GENERIC, "ladish_graph_add_client() failed to add client '%s' to virtual graph", name); + ladish_client_destroy(client); + return; + } + + client_id = ladish_graph_get_client_id(graph, client); + + method_return_new_single(call_ptr, DBUS_TYPE_UINT64, &client_id); } #undef graph_ptr diff --git a/gui/canvas.cpp b/gui/canvas.cpp index 0c51f2f5..3c1b60a3 100644 --- a/gui/canvas.cpp +++ b/gui/canvas.cpp @@ -332,6 +332,46 @@ canvas_get_selected_modules_count( return canvas_ptr->get()->selected_items().size(); } +bool +canvas_get_one_selected_module( + canvas_handle canvas, + void ** module_context_ptr) +{ + int i; + + std::list > modules = canvas_ptr->get()->selected_items(); + if (modules.size() != 1) + { + return false; + } + + i = 0; + for (std::list >::iterator m = modules.begin(); m != modules.end(); ++m) + { + boost::shared_ptr module = boost::dynamic_pointer_cast(*m); + if (module == NULL) + { + ASSERT_NO_PASS; + return false; + } + + if (i == 0) + { + *module_context_ptr = module->m_context; + i++; + continue; + } + } + + if (i != 1) + { + ASSERT_NO_PASS; + return false; + } + + return true; +} + bool canvas_get_two_selected_modules( canvas_handle canvas, @@ -361,17 +401,20 @@ canvas_get_two_selected_modules( case 0: *module1_context_ptr = module->m_context; i++; - break; + continue; case 1: *module2_context_ptr = module->m_context; i++; - break; - default: - ASSERT_NO_PASS; - return false; + continue; } } + if (i != 2) + { + ASSERT_NO_PASS; + return false; + } + return true; } diff --git a/gui/canvas.h b/gui/canvas.h index aeeb833a..3a4d81cb 100644 --- a/gui/canvas.h +++ b/gui/canvas.h @@ -100,6 +100,11 @@ size_t canvas_get_selected_modules_count( canvas_handle canvas); +bool +canvas_get_one_selected_module( + canvas_handle canvas, + void ** module_context_ptr); + bool canvas_get_two_selected_modules( canvas_handle canvas, diff --git a/gui/graph_canvas.c b/gui/graph_canvas.c index c9b93118..34be12f1 100644 --- a/gui/graph_canvas.c +++ b/gui/graph_canvas.c @@ -237,6 +237,23 @@ static void on_popup_menu_action_port_rename(GtkWidget * menuitem, gpointer port } } +static void on_popup_menu_action_port_move(GtkWidget * menuitem, gpointer port_context) +{ + struct client * client_ptr; + + log_info("on_popup_menu_action_port_move %"PRIu64, port_ptr->id); + + if (!canvas_get_one_selected_module(port_ptr->graph_canvas->canvas, (void **)&client_ptr)) + { + return; + } + + if (!graph_proxy_move_port(port_ptr->graph_canvas->graph, port_ptr->id, client_ptr->id)) + { + error_message_box("Port move failed"); + } +} + static void fill_port_menu(GtkMenu * menu, void * port_context) { GtkWidget * menuitem; @@ -246,6 +263,13 @@ static void fill_port_menu(GtkMenu * menu, void * port_context) menuitem = gtk_menu_item_new_with_label(_("Rename")); g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_port_rename, port_ptr); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + + if (canvas_get_selected_modules_count(port_ptr->graph_canvas->canvas) == 1) + { + menuitem = gtk_menu_item_new_with_label(_("Move port")); + g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_port_move, port_ptr); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + } } #undef port_ptr @@ -268,12 +292,32 @@ static void on_popup_menu_action_join_clients(GtkWidget * menuitem, gpointer can } } +static void on_popup_menu_action_new_client(GtkWidget * menuitem, gpointer canvas_context) +{ + char * new_name; + uint64_t client_id; + + if (name_dialog(_("New client"), _("Client name"), "", &new_name)) + { + if (!graph_proxy_new_client(canvas_ptr->graph, new_name, &client_id)) + { + error_message_box("New client creation failed"); + } + + free(new_name); + } +} + static void fill_canvas_menu(GtkMenu * menu, void * canvas_context) { GtkWidget * menuitem; log_info("fill_canvas_menu"); + menuitem = gtk_menu_item_new_with_label(_("New client")); + g_signal_connect(menuitem, "activate", (GCallback)on_popup_menu_action_new_client, canvas_ptr); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + if (canvas_get_selected_modules_count(canvas_ptr->canvas) == 2) { menuitem = gtk_menu_item_new_with_label(_("Join clients"));