[Spice-devel] [PATCH vdagent-linux 5/6] vdagentd: move code to do_agent_file_xfer_status()

Victor Toso victortoso at redhat.com
Fri Sep 7 07:56:19 UTC 2018


Hi,

On Tue, Sep 04, 2018 at 06:40:50PM +0200, Jakub Janků wrote:
> Move code handling VDAGENTD_FILE_XFER_STATUS messages
> from agent_read_complete() to a separate function
> to make the switch statement less cluttered.
> 
> Improve formatting a bit.
> 
> Signed-off-by: Jakub Janků <jjanku at redhat.com>
> ---
>  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 a1962be..5ead54c 100644
> --- a/src/vdagentd/vdagentd.c
> +++ b/src/vdagentd/vdagentd.c
> @@ -893,6 +893,41 @@ static void do_agent_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);
> +    }

Maybe moving send_file_xfer_status() out of the switch would make
it nicer too. That is, by defining:

    const char *err_msg = NULL;
    uint8_t *data = NULL;
    uint32_t data_size = 0;

    switch () {
    ... /* set things */
    }
    send_file_xfer_status(...);


> +
> +    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);
> +}

Up to you, current version is fine too.
Acked-by: Victor Toso <victortoso at redhat.com>

> +
>  static void agent_read_complete(struct udscs_connection **connp,
>      struct udscs_message_header *header, uint8_t *data)
>  {
> @@ -909,31 +944,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
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20180907/c191fe4e/attachment.sig>


More information about the Spice-devel mailing list