[Spice-devel] [RFC spice-vdagent 18/18] vdagentd: move code to do_agent_file_xfer_status()

Jakub Janků jjanku at redhat.com
Tue Aug 14 18:53:52 UTC 2018


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

Improve formatting a bit.
---
 src/vdagentd/vdagentd.c | 61 +++++++++++++++++++++++++----------------
 1 file changed, 37 insertions(+), 24 deletions(-)

diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
index e975abd..56c82b2 100644
--- a/src/vdagentd/vdagentd.c
+++ b/src/vdagentd/vdagentd.c
@@ -918,6 +918,41 @@ static void do_guest_xorg_resolution(struct udscs_connection    **connp,
     check_xorg_resolution();
 }
 
+static void do_agent_file_xfer_status(struct udscs_connection    **connp,
+                                      struct udscs_message_header *header,
+                                      guint8                      *data)
+{
+    gpointer task_id = GUINT_TO_POINTER(GUINT32_TO_LE(header->arg1));
+
+    /* header->arg1 = file xfer task id, header->arg2 = file xfer status */
+    switch (header->arg2) {
+        case VD_AGENT_FILE_XFER_STATUS_NOT_ENOUGH_SPACE: {
+            uint64_t free_space = GUINT64_TO_LE(*((uint64_t*)data));
+            send_file_xfer_status(virtio_port,
+                                  "Not enough free space. Cancelling file-xfer %u",
+                                  header->arg1, header->arg2,
+                                  (uint8_t*)&free_space, sizeof(uint64_t));
+            break;
+        }
+        case VD_AGENT_FILE_XFER_STATUS_DISABLED:
+            send_file_xfer_status(virtio_port,
+                                  "File-xfer is disabled. Cancelling file-xfer %u",
+                                  header->arg1, header->arg2,
+                                  NULL, 0);
+            break;
+        default:
+            send_file_xfer_status(virtio_port,
+                                  NULL,
+                                  header->arg1, header->arg2,
+                                  NULL, 0);
+    }
+
+    if (header->arg2 == VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA)
+        g_hash_table_insert(active_xfers, task_id, *connp);
+    else
+        g_hash_table_remove(active_xfers, task_id);
+}
+
 static void agent_read_complete(struct udscs_connection **connp,
     struct udscs_message_header *header, uint8_t *data)
 {
@@ -934,31 +969,9 @@ static void agent_read_complete(struct udscs_connection **connp,
             return;
         }
         break;
-    case VDAGENTD_FILE_XFER_STATUS:{
-        /* header->arg1 = file xfer task id, header->arg2 = file xfer status */
-        switch (header->arg2) {
-            case VD_AGENT_FILE_XFER_STATUS_NOT_ENOUGH_SPACE: {
-                uint64_t free_space = GUINT64_TO_LE(*((uint64_t*)data));
-                send_file_xfer_status(virtio_port, "Not enough free space. Cancelling file-xfer %u",
-                                      header->arg1, header->arg2,
-                                      (uint8_t*)&free_space, sizeof(uint64_t));
-                break;
-            }
-            case VD_AGENT_FILE_XFER_STATUS_DISABLED:
-                send_file_xfer_status(virtio_port, "File-xfer is disabled, cancelling",
-                                      header->arg1, header->arg2, NULL, 0);
-                break;
-            default:
-                send_file_xfer_status(virtio_port, NULL, header->arg1, header->arg2, NULL, 0);
-        }
-
-        if (header->arg2 == VD_AGENT_FILE_XFER_STATUS_CAN_SEND_DATA)
-            g_hash_table_insert(active_xfers, GUINT_TO_POINTER(GUINT32_TO_LE(header->arg1)),
-                                *connp);
-        else
-            g_hash_table_remove(active_xfers, GUINT_TO_POINTER(GUINT32_TO_LE(header->arg1)));
+    case VDAGENTD_FILE_XFER_STATUS:
+        do_agent_file_xfer_status(connp, header, data);
         break;
-    }
 
     default:
         syslog(LOG_ERR, "unknown message from vdagent: %u, ignoring",
-- 
2.17.1



More information about the Spice-devel mailing list