[RFC spice-vdagent 17/18] vdagentd: move code to do_guest_xorg_resolution()

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

 



Move code handling VDAGENTD_GUEST_XORG_RESOLUTION
from agent_read_complete() to a separate function
to make the switch statement less cluttered.

Remove unnecessary res variable.
---
 src/vdagentd/vdagentd.c | 61 +++++++++++++++++++++--------------------
 1 file changed, 31 insertions(+), 30 deletions(-)

diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
index b8f617c..e975abd 100644
--- a/src/vdagentd/vdagentd.c
+++ b/src/vdagentd/vdagentd.c
@@ -887,43 +887,44 @@ static void agent_disconnect(struct udscs_connection *conn)
     g_free(agent_data);
 }
 
-static void agent_read_complete(struct udscs_connection **connp,
-    struct udscs_message_header *header, uint8_t *data)
+static void do_guest_xorg_resolution(struct udscs_connection    **connp,
+                                     struct udscs_message_header *header,
+                                     guint8                      *data)
 {
     struct agent_data *agent_data = udscs_get_user_data(*connp);
+    guint n = header->size / sizeof(struct vdagentd_guest_xorg_resolution);
 
-    switch (header->type) {
-    case VDAGENTD_GUEST_XORG_RESOLUTION: {
-        struct vdagentd_guest_xorg_resolution *res;
-        int n = header->size / sizeof(*res);
-
-        /* Detect older version session agent, but don't disconnect, as
-           that stops it from getting the VDAGENTD_VERSION message, and then
-           it will never re-exec the new version... */
-        if (header->arg1 == 0 && header->arg2 == 0) {
-            syslog(LOG_INFO, "got old session agent xorg resolution message, "
-                             "ignoring");
-            return;
-        }
+    /* Detect older version session agent, but don't disconnect, as
+     * that stops it from getting the VDAGENTD_VERSION message, and then
+     * it will never re-exec the new version... */
+    if (header->arg1 == 0 && header->arg2 == 0) {
+        syslog(LOG_INFO, "got old session agent xorg resolution message, ignoring");
+        return;
+    }
 
-        if (header->size != n * sizeof(*res)) {
-            syslog(LOG_ERR, "guest xorg resolution message has wrong size, "
-                            "disconnecting agent");
-            udscs_destroy_connection(connp);
-            return;
-        }
+    if (header->size != n * sizeof(struct vdagentd_guest_xorg_resolution)) {
+        syslog(LOG_ERR, "guest xorg resolution message has wrong size, "
+                        "disconnecting agent");
+        udscs_destroy_connection(connp);
+        return;
+    }
+
+    g_free(agent_data->screen_info);
+    agent_data->screen_info = g_memdup(data, header->size);
+    agent_data->width  = header->arg1;
+    agent_data->height = header->arg2;
+    agent_data->screen_count = n;
 
-        g_free(agent_data->screen_info);
-        res = g_malloc(n * sizeof(*res));
-        memcpy(res, data, n * sizeof(*res));
-        agent_data->width  = header->arg1;
-        agent_data->height = header->arg2;
-        agent_data->screen_info  = res;
-        agent_data->screen_count = n;
+    check_xorg_resolution();
+}
 
-        check_xorg_resolution();
+static void agent_read_complete(struct udscs_connection **connp,
+    struct udscs_message_header *header, uint8_t *data)
+{
+    switch (header->type) {
+    case VDAGENTD_GUEST_XORG_RESOLUTION:
+        do_guest_xorg_resolution(connp, header, data);
         break;
-    }
     case VDAGENTD_CLIPBOARD_GRAB:
     case VDAGENTD_CLIPBOARD_REQUEST:
     case VDAGENTD_CLIPBOARD_DATA:
-- 
2.17.1

_______________________________________________
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]