[Spice-devel] [PATCH linux vdagent v2 2/9] Move handling of DeviceInfo to vdagent_x11

Jonathon Jongsma jjongsma at redhat.com
Thu Jan 3 22:45:41 UTC 2019


---
 src/vdagent/vdagent.c   | 68 +----------------------------------------
 src/vdagent/x11-priv.h  |  1 +
 src/vdagent/x11-randr.c | 58 +++++++++++++++++++++++++++++++++++
 src/vdagent/x11.c       | 13 ++++++++
 src/vdagent/x11.h       |  1 +
 5 files changed, 74 insertions(+), 67 deletions(-)

diff --git a/src/vdagent/vdagent.c b/src/vdagent/vdagent.c
index 5e265ca..739dcd6 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -53,7 +53,6 @@ typedef struct VDAgent {
     struct vdagent_file_xfers *xfers;
     struct udscs_connection *conn;
     GIOChannel *x11_channel;
-    GHashTable *graphics_display_infos;
 
     GMainLoop *loop;
 } VDAgent;
@@ -96,16 +95,6 @@ static GOptionEntry entries[] = {
     { NULL }
 };
 
-typedef struct GraphicsDisplayInfo {
-    char device_address[256];
-    uint32_t device_display_id;
-} GraphicsDisplayInfo;
-
-static void graphics_display_info_destroy(gpointer gdi)
-{
-    g_free(gdi);
-}
-
 /**
  * xfer_get_download_directory
  *
@@ -170,55 +159,6 @@ static gboolean vdagent_finalize_file_xfer(VDAgent *agent)
     return TRUE;
 }
 
-static void vdagent_handle_graphics_device_info(VDAgent *agent, uint8_t *data, size_t size)
-{
-    VDAgentGraphicsDeviceInfo *graphics_device_info = (VDAgentGraphicsDeviceInfo *)data;
-    VDAgentDeviceDisplayInfo *device_display_info = graphics_device_info->device_info;
-
-    void *buffer_end = data + size;
-
-    syslog(LOG_INFO, "Received Graphics Device Info:");
-
-    for (size_t i = 0; i < graphics_device_info->count; ++i) {
-        if ((void*) device_display_info > buffer_end ||
-                (void*) (&device_display_info->device_address +
-                    device_display_info->device_address_len) > buffer_end) {
-            syslog(LOG_ERR, "Malformed graphics_display_info message, "
-                   "extends beyond the end of the buffer");
-            break;
-        }
-
-        GraphicsDisplayInfo *value = g_malloc(sizeof(GraphicsDisplayInfo));
-
-        size_t device_address_len = device_display_info->device_address_len;
-        if (device_address_len > sizeof(value->device_address)) {
-            syslog(LOG_ERR, "Received a device address longer than %lu, "
-                   "will be truncated!", device_address_len);
-            device_address_len = sizeof(value->device_address);
-        }
-
-        strncpy(value->device_address,
-                (char*) device_display_info->device_address,
-                device_address_len);
-        value->device_address[device_address_len] = '\0';  // make sure the string is terminated
-        value->device_display_id = device_display_info->device_display_id;
-
-        syslog(LOG_INFO, "   channel_id: %u monitor_id: %u device_address: %s, "
-               "device_display_id: %u",
-               device_display_info->channel_id,
-               device_display_info->monitor_id,
-               value->device_address,
-               value->device_display_id);
-
-        g_hash_table_insert(agent->graphics_display_infos,
-                GUINT_TO_POINTER(device_display_info->channel_id + device_display_info->monitor_id),
-                value);
-
-        device_display_info = (VDAgentDeviceDisplayInfo*) ((char*) device_display_info +
-            sizeof(VDAgentDeviceDisplayInfo) + device_display_info->device_address_len);
-    }
-}
-
 static void vdagent_quit_loop(VDAgent *agent)
 {
     /* other GMainLoop(s) might be running, quit them before agent->loop */
@@ -304,7 +244,7 @@ static void daemon_read_complete(struct udscs_connection **connp,
         }
         break;
     case VDAGENTD_GRAPHICS_DEVICE_INFO:
-        vdagent_handle_graphics_device_info(agent, data, header->size);
+        vdagent_x11_handle_graphics_device_info(agent->x11, data, header->size);
         break;
     case VDAGENTD_CLIENT_DISCONNECTED:
         vdagent_clipboards_release_all(agent->clipboards);
@@ -412,11 +352,6 @@ static VDAgent *vdagent_new(void)
     g_unix_signal_add(SIGHUP, vdagent_signal_handler, agent);
     g_unix_signal_add(SIGTERM, vdagent_signal_handler, agent);
 
-    agent->graphics_display_infos = g_hash_table_new_full(&g_direct_hash,
-                                                          &g_direct_equal,
-                                                          NULL,
-                                                          &graphics_display_info_destroy);
-
     return agent;
 }
 
@@ -431,7 +366,6 @@ static void vdagent_destroy(VDAgent *agent)
 
     g_clear_pointer(&agent->x11_channel, g_io_channel_unref);
     g_clear_pointer(&agent->loop, g_main_loop_unref);
-    g_hash_table_destroy(agent->graphics_display_infos);
     g_free(agent);
 }
 
diff --git a/src/vdagent/x11-priv.h b/src/vdagent/x11-priv.h
index e7c64bd..5b1eff3 100644
--- a/src/vdagent/x11-priv.h
+++ b/src/vdagent/x11-priv.h
@@ -143,6 +143,7 @@ struct vdagent_x11 {
     int xrandr_minor;
     int has_xinerama;
     int dont_send_guest_xorg_res;
+    GHashTable *graphics_display_infos;
 };
 
 extern int (*vdagent_x11_prev_error_handler)(Display *, XErrorEvent *);
diff --git a/src/vdagent/x11-randr.c b/src/vdagent/x11-randr.c
index bd4bf4c..4a5c7e4 100644
--- a/src/vdagent/x11-randr.c
+++ b/src/vdagent/x11-randr.c
@@ -30,6 +30,7 @@
 
 #include <X11/extensions/Xinerama.h>
 
+#include "device-info.h"
 #include "vdagentd-proto.h"
 #include "x11.h"
 #include "x11-priv.h"
@@ -726,6 +727,63 @@ static void dump_monitors_config(struct vdagent_x11 *x11,
     }
 }
 
+typedef struct GraphicsDisplayInfo {
+    char device_address[256];
+    uint32_t device_display_id;
+} GraphicsDisplayInfo;
+
+// handle the device info message from the server. This will allow us to
+// maintain a mapping from spice display id to xrandr output
+void vdagent_x11_handle_graphics_device_info(struct vdagent_x11 *x11, uint8_t *data, size_t size)
+{
+    VDAgentGraphicsDeviceInfo *graphics_device_info = (VDAgentGraphicsDeviceInfo *)data;
+    VDAgentDeviceDisplayInfo *device_display_info = graphics_device_info->device_info;
+
+    void *buffer_end = data + size;
+
+    syslog(LOG_INFO, "Received Graphics Device Info:");
+
+    for (size_t i = 0; i < graphics_device_info->count; ++i) {
+        if ((void*) device_display_info > buffer_end ||
+                (void*) (&device_display_info->device_address +
+                    device_display_info->device_address_len) > buffer_end) {
+            syslog(LOG_ERR, "Malformed graphics_display_info message, "
+                   "extends beyond the end of the buffer");
+            break;
+        }
+
+        GraphicsDisplayInfo *value = g_malloc(sizeof(GraphicsDisplayInfo));
+
+        size_t device_address_len = device_display_info->device_address_len;
+        if (device_address_len > sizeof(value->device_address)) {
+            syslog(LOG_ERR, "Received a device address longer than %lu, "
+                   "will be truncated!", device_address_len);
+            device_address_len = sizeof(value->device_address);
+        }
+
+        strncpy(value->device_address,
+                (char*) device_display_info->device_address,
+                device_address_len);
+        value->device_address[device_address_len] = '\0';  // make sure the string is terminated
+        value->device_display_id = device_display_info->device_display_id;
+
+        syslog(LOG_INFO, "   channel_id: %u monitor_id: %u device_address: %s, "
+               "device_display_id: %u",
+               device_display_info->channel_id,
+               device_display_info->monitor_id,
+               value->device_address,
+               value->device_display_id);
+
+        g_hash_table_insert(x11->graphics_display_infos,
+                GUINT_TO_POINTER(device_display_info->channel_id + device_display_info->monitor_id),
+                value);
+
+        device_display_info = (VDAgentDeviceDisplayInfo*) ((char*) device_display_info +
+            sizeof(VDAgentDeviceDisplayInfo) + device_display_info->device_address_len);
+    }
+}
+
+
 /*
  * Set monitor configuration according to client request.
  *
diff --git a/src/vdagent/x11.c b/src/vdagent/x11.c
index c3c7a65..9d979fc 100644
--- a/src/vdagent/x11.c
+++ b/src/vdagent/x11.c
@@ -198,6 +198,12 @@ static gchar *vdagent_x11_get_wm_name(struct vdagent_x11 *x11)
 #endif
 }
 
+static void graphics_display_info_destroy(gpointer gdi)
+{
+    g_free(gdi);
+}
+
+
 struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
     int debug, int sync)
 {
@@ -318,6 +324,12 @@ struct vdagent_x11 *vdagent_x11_create(struct udscs_connection *vdagentd,
                __func__, net_wm_name, vdagent_x11_has_icons_on_desktop(x11));
     g_free(net_wm_name);
 
+    x11->graphics_display_infos = g_hash_table_new_full(&g_direct_hash,
+                                                  &g_direct_equal,
+                                                  NULL,
+                                                  &graphics_display_info_destroy);
+
+
     /* Flush output buffers and consume any pending events */
     vdagent_x11_do_read(x11);
 
@@ -339,6 +351,7 @@ void vdagent_x11_destroy(struct vdagent_x11 *x11, int vdagentd_disconnected)
     }
 #endif
 
+    g_hash_table_destroy(x11->graphics_display_infos);
     XCloseDisplay(x11->display);
     g_free(x11->randr.failed_conf);
     g_free(x11);
diff --git a/src/vdagent/x11.h b/src/vdagent/x11.h
index 1505f58..5f47859 100644
--- a/src/vdagent/x11.h
+++ b/src/vdagent/x11.h
@@ -55,5 +55,6 @@ void vdagent_x11_client_disconnected(struct vdagent_x11 *x11);
 #endif
 
 int vdagent_x11_has_icons_on_desktop(struct vdagent_x11 *x11);
+void vdagent_x11_handle_graphics_device_info(struct vdagent_x11 *x11, uint8_t *data, size_t size);
 
 #endif
-- 
2.17.2



More information about the Spice-devel mailing list