[PATCH linux vdagent v3 2/9] Move handling of DeviceInfo to vdagent_x11

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 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 e982a1f..aa52ee9 100644
--- a/src/vdagent/vdagent.c
+++ b/src/vdagent/vdagent.c
@@ -50,7 +50,6 @@ typedef struct VDAgent {
     struct vdagent_file_xfers *xfers;
     struct udscs_connection *conn;
     GIOChannel *x11_channel;
-    GHashTable *graphics_display_infos;
 
     GMainLoop *loop;
 } VDAgent;
@@ -93,16 +92,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
  *
@@ -167,55 +156,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 */
@@ -301,7 +241,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);
@@ -409,11 +349,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;
 }
 
@@ -428,7 +363,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 b31b0a5..0e954cf 100644
--- a/src/vdagent/x11-priv.h
+++ b/src/vdagent/x11-priv.h
@@ -139,6 +139,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 192b888..4fed458 100644
--- a/src/vdagent/x11-randr.c
+++ b/src/vdagent/x11-randr.c
@@ -31,6 +31,7 @@
 
 #include <X11/extensions/Xinerama.h>
 
+#include "device-info.h"
 #include "vdagentd-proto.h"
 #include "x11.h"
 #include "x11-priv.h"
@@ -727,6 +728,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 53d3c48..2473383 100644
--- a/src/vdagent/x11.c
+++ b/src/vdagent/x11.c
@@ -196,6 +196,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)
 {
@@ -316,6 +322,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);
 
@@ -337,6 +349,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 2117abf..bb2ac80 100644
--- a/src/vdagent/x11.h
+++ b/src/vdagent/x11.h
@@ -51,5 +51,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

_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux Virtualization]     [Linux Virtualization]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]