Re: [virt-tools-list] [PATCH virt-viewer 5/6] remote-viewer: add a --dbus-controller

2017-06-28 Thread Eduardo Lima (Etrunko)
On 23/06/17 12:30, marcandre.lur...@redhat.com wrote:
> From: Marc-André Lureau 
> 
> Allow to set connection details via DBus, and add a Connect method.
> This is intended to replace the Spice controller.
> 
> Sample usage:
> 
> DEST=`remote-viewer --dbus-controller`
> 
> gdbus call --session --dest $DEST --object-path 
> /org/virt_manager/remote_viewer \
>   --method org.freedesktop.DBus.Properties.Set 
> org.VirtManager.RemoteViewer.Controller \
>   host ''
> gdbus call --session --dest $DEST --object-path 
> /org/virt_manager/remote_viewer \
>   --method org.freedesktop.DBus.Properties.Set 
> org.VirtManager.RemoteViewer.Controller \
>   port ''
> gdbus call --session --dest $DEST --object-path 
> /org/virt_manager/remote_viewer \
>   --method org.freedesktop.DBus.Properties.Set 
> org.VirtManager.RemoteViewer.Controller \
>   type ''()
> gdbus call --session --dest $DEST --object-path 
> /org/virt_manager/remote_viewer \
>   --method org.VirtManager.RemoteViewer.Controller.Connect()
> 

Please consider spliting this patch, as I said on my comment on patch 3
of the series.

> Signed-off-by: Marc-André Lureau 
> ---
>  src/remote-viewer.c | 198 
> +++-
>  src/remote-viewer.h |   1 +
>  2 files changed, 196 insertions(+), 3 deletions(-)
> 
> diff --git a/src/remote-viewer.c b/src/remote-viewer.c
> index fb5376c..f0f9531 100644
> --- a/src/remote-viewer.c
> +++ b/src/remote-viewer.c
> @@ -57,6 +57,7 @@ struct _RemoteViewerPrivate {
>  OvirtForeignMenu *ovirt_foreign_menu;
>  #endif
>  gboolean open_recent_dialog;
> +VirtViewerFile *dbus_file;
>  };
>  
>  G_DEFINE_TYPE (RemoteViewer, remote_viewer, VIRT_VIEWER_TYPE_APP)
> @@ -137,6 +138,7 @@ remote_viewer_deactivated(VirtViewerApp *app, gboolean 
> connect_error)
>  static gchar **opt_args = NULL;
>  static char *opt_title = NULL;
>  static gboolean opt_controller = FALSE;
> +static gboolean opt_dbus_ctrl = FALSE;
>  
>  static void
>  remote_viewer_add_option_entries(VirtViewerApp *self, GOptionContext 
> *context, GOptionGroup *group)
> @@ -144,6 +146,8 @@ remote_viewer_add_option_entries(VirtViewerApp *self, 
> GOptionContext *context, G
>  static const GOptionEntry options[] = {
>  { "title", 't', 0, G_OPTION_ARG_STRING, &opt_title,
>N_("Set window title"), NULL },
> +{ "dbus-controller", '\0', 0, G_OPTION_ARG_NONE, &opt_dbus_ctrl,
> +  N_("Open connection using DBus controller"), NULL },
>  #ifdef HAVE_SPICE_GTK
>  { "spice-controller", '\0', 0, G_OPTION_ARG_NONE, &opt_controller,
>N_("Open connection using Spice controller communication"), NULL },
> @@ -175,7 +179,17 @@ remote_viewer_local_command_line (GApplication   *gapp,
>  if (ret)
>  goto end;
>  
> -if (!opt_args) {
> +if (opt_dbus_ctrl) {
> +if (opt_args || opt_controller) {
> +g_printerr(_("\nError: extra arguments given while using 
> --dbus\n\n"));
> +ret = TRUE;
> +*status = 1;
> +goto end;
> +}
> +self->priv->dbus_file = virt_viewer_file_new(NULL, NULL);
> +virt_viewer_app_set_dbus_ctrl(app, TRUE);
> +return FALSE;
> +} else if (!opt_args) {
>  self->priv->open_recent_dialog = TRUE;
>  } else {
>  if (g_strv_length(opt_args) > 1) {
> @@ -190,7 +204,7 @@ remote_viewer_local_command_line (GApplication   *gapp,
>  
>  #ifdef HAVE_SPICE_GTK
>  if (opt_controller) {
> -if (opt_args) {
> +if (opt_args || opt_dbus_ctrl) {
>  g_printerr(_("\nError: extra arguments given while using Spice 
> controller\n\n"));
>  ret = TRUE;
>  *status = 1;
> @@ -241,6 +255,180 @@ remote_viewer_get_property(GObject *object, guint 
> property_id,
>  }
>  }
>  
> +static void
> +handle_method_call (GDBusConnection   *connection G_GNUC_UNUSED,
> +const gchar   *sender G_GNUC_UNUSED,
> +const gchar   *object_path G_GNUC_UNUSED,
> +const gchar   *interface_name G_GNUC_UNUSED,
> +const gchar   *method_name,
> +GVariant  *parameters G_GNUC_UNUSED,
> +GDBusMethodInvocation *invocation,
> +gpointer   user_data)
> +{
> +RemoteViewer *self = REMOTE_VIEWER(user_data);
> +
> +if (g_str_equal(method_name, "Connect")) {
> +GError *error = NULL;
> +char *type = virt_viewer_file_get_file_type(self->priv->dbus_file);
> +g_debug("Connect! %s", type);
> +if (!remote_viewer_initial_connect(self, type, 
> self->priv->dbus_file, &error)) {
> +g_dbus_method_invocation_return_gerror(invocation, error);
> +g_clear_error(&error);
> +} else {
> +g_dbus_method_invocation_return_value (invocation, NULL);
> +}
> +}
> +}
> +
> +
> +static GVariant

[virt-tools-list] [PATCH virt-viewer 5/6] remote-viewer: add a --dbus-controller

2017-06-23 Thread marcandre . lureau
From: Marc-André Lureau 

Allow to set connection details via DBus, and add a Connect method.
This is intended to replace the Spice controller.

Sample usage:

DEST=`remote-viewer --dbus-controller`

gdbus call --session --dest $DEST --object-path /org/virt_manager/remote_viewer 
\
  --method org.freedesktop.DBus.Properties.Set 
org.VirtManager.RemoteViewer.Controller \
  host ''
gdbus call --session --dest $DEST --object-path /org/virt_manager/remote_viewer 
\
  --method org.freedesktop.DBus.Properties.Set 
org.VirtManager.RemoteViewer.Controller \
  port ''
gdbus call --session --dest $DEST --object-path /org/virt_manager/remote_viewer 
\
  --method org.freedesktop.DBus.Properties.Set 
org.VirtManager.RemoteViewer.Controller \
  type ''()
gdbus call --session --dest $DEST --object-path /org/virt_manager/remote_viewer 
\
  --method org.VirtManager.RemoteViewer.Controller.Connect()

Signed-off-by: Marc-André Lureau 
---
 src/remote-viewer.c | 198 +++-
 src/remote-viewer.h |   1 +
 2 files changed, 196 insertions(+), 3 deletions(-)

diff --git a/src/remote-viewer.c b/src/remote-viewer.c
index fb5376c..f0f9531 100644
--- a/src/remote-viewer.c
+++ b/src/remote-viewer.c
@@ -57,6 +57,7 @@ struct _RemoteViewerPrivate {
 OvirtForeignMenu *ovirt_foreign_menu;
 #endif
 gboolean open_recent_dialog;
+VirtViewerFile *dbus_file;
 };
 
 G_DEFINE_TYPE (RemoteViewer, remote_viewer, VIRT_VIEWER_TYPE_APP)
@@ -137,6 +138,7 @@ remote_viewer_deactivated(VirtViewerApp *app, gboolean 
connect_error)
 static gchar **opt_args = NULL;
 static char *opt_title = NULL;
 static gboolean opt_controller = FALSE;
+static gboolean opt_dbus_ctrl = FALSE;
 
 static void
 remote_viewer_add_option_entries(VirtViewerApp *self, GOptionContext *context, 
GOptionGroup *group)
@@ -144,6 +146,8 @@ remote_viewer_add_option_entries(VirtViewerApp *self, 
GOptionContext *context, G
 static const GOptionEntry options[] = {
 { "title", 't', 0, G_OPTION_ARG_STRING, &opt_title,
   N_("Set window title"), NULL },
+{ "dbus-controller", '\0', 0, G_OPTION_ARG_NONE, &opt_dbus_ctrl,
+  N_("Open connection using DBus controller"), NULL },
 #ifdef HAVE_SPICE_GTK
 { "spice-controller", '\0', 0, G_OPTION_ARG_NONE, &opt_controller,
   N_("Open connection using Spice controller communication"), NULL },
@@ -175,7 +179,17 @@ remote_viewer_local_command_line (GApplication   *gapp,
 if (ret)
 goto end;
 
-if (!opt_args) {
+if (opt_dbus_ctrl) {
+if (opt_args || opt_controller) {
+g_printerr(_("\nError: extra arguments given while using 
--dbus\n\n"));
+ret = TRUE;
+*status = 1;
+goto end;
+}
+self->priv->dbus_file = virt_viewer_file_new(NULL, NULL);
+virt_viewer_app_set_dbus_ctrl(app, TRUE);
+return FALSE;
+} else if (!opt_args) {
 self->priv->open_recent_dialog = TRUE;
 } else {
 if (g_strv_length(opt_args) > 1) {
@@ -190,7 +204,7 @@ remote_viewer_local_command_line (GApplication   *gapp,
 
 #ifdef HAVE_SPICE_GTK
 if (opt_controller) {
-if (opt_args) {
+if (opt_args || opt_dbus_ctrl) {
 g_printerr(_("\nError: extra arguments given while using Spice 
controller\n\n"));
 ret = TRUE;
 *status = 1;
@@ -241,6 +255,180 @@ remote_viewer_get_property(GObject *object, guint 
property_id,
 }
 }
 
+static void
+handle_method_call (GDBusConnection   *connection G_GNUC_UNUSED,
+const gchar   *sender G_GNUC_UNUSED,
+const gchar   *object_path G_GNUC_UNUSED,
+const gchar   *interface_name G_GNUC_UNUSED,
+const gchar   *method_name,
+GVariant  *parameters G_GNUC_UNUSED,
+GDBusMethodInvocation *invocation,
+gpointer   user_data)
+{
+RemoteViewer *self = REMOTE_VIEWER(user_data);
+
+if (g_str_equal(method_name, "Connect")) {
+GError *error = NULL;
+char *type = virt_viewer_file_get_file_type(self->priv->dbus_file);
+g_debug("Connect! %s", type);
+if (!remote_viewer_initial_connect(self, type, self->priv->dbus_file, 
&error)) {
+g_dbus_method_invocation_return_gerror(invocation, error);
+g_clear_error(&error);
+} else {
+g_dbus_method_invocation_return_value (invocation, NULL);
+}
+}
+}
+
+
+static GVariant *
+handle_get_property (GDBusConnection  *connection G_GNUC_UNUSED,
+ const gchar  *sender G_GNUC_UNUSED,
+ const gchar  *object_path G_GNUC_UNUSED,
+ const gchar  *interface_name G_GNUC_UNUSED,
+ const gchar  *property_name,
+ GError  **error G_GNUC_UNUSED,
+