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

Submitted by Jakub Janku on Aug. 14, 2018, 6:53 p.m.

Details

Message ID 20180814185352.6080-19-jjanku@redhat.com
State New
Headers show
Series "GLib integration" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Jakub Janku Aug. 14, 2018, 6:53 p.m.
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(-)

Patch hide | download patch | download mbox

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",

Comments

Hi,

On Tue, Aug 14, 2018 at 08:53:52PM +0200, Jakub Janků wrote:
> 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.

If you send this outside of glib integration series, I'd be happy
to apply before the glib integration too

Reviewed-by: Victor Toso <victortoso@redhat.com>

Victor

> ---
>  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
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel