[Spice-devel] [PATCH 1/9] server/dispatcher: move worker enums to dispatcher header

Frediano Ziglio fziglio at redhat.com
Wed Oct 21 05:26:39 PDT 2015


> 
> From: Marc-André Lureau <marcandre.lureau at gmail.com>
> 
> Group enums with their respective struct location.
> ---
>  server/red_dispatcher.h | 97
>  ++++++++++++++++++++++++++++++++++++++++++++++++-
>  server/red_worker.h     | 93 +----------------------------------------------
>  2 files changed, 96 insertions(+), 94 deletions(-)
> 
> diff --git a/server/red_dispatcher.h b/server/red_dispatcher.h
> index 320b7e3..dbe65d1 100644
> --- a/server/red_dispatcher.h
> +++ b/server/red_dispatcher.h
> @@ -18,10 +18,13 @@
>  #ifndef _H_RED_DISPATCHER
>  #define _H_RED_DISPATCHER
>  
> +#include <errno.h>
> +#include "spice_server_utils.h"

Would be better to include unistd.h instead of spice_server_utils.h
Beside that I would ack it

Frediano


>  #include "red_channel.h"
>  
> -struct RedChannelClient;
> -struct RedDispatcher;
> +typedef struct RedDispatcher RedDispatcher;
> +typedef struct RedChannelClient RedChannelClient;
> +
>  typedef struct AsyncCommand AsyncCommand;
>  
>  void red_dispatcher_init(QXLInstance *qxl);
> @@ -41,6 +44,96 @@ struct Dispatcher *red_dispatcher_get_dispatcher(struct
> RedDispatcher *);
>  int red_dispatcher_use_client_monitors_config(void);
>  void red_dispatcher_client_monitors_config(VDAgentMonitorsConfig
>  *monitors_config);
>  
> +typedef uint32_t RedWorkerMessage;
> +
> +static inline void send_data(int fd, void *in_buf, int n)
> +{
> +    uint8_t *buf = in_buf;
> +    do {
> +        int now;
> +        if ((now = write(fd, buf, n)) == -1) {
> +            if (errno == EINTR) {
> +                continue;
> +            }
> +            spice_error("%s", strerror(errno));
> +        }
> +        buf += now;
> +        n -= now;
> +    } while (n);
> +}
> +
> +static inline void write_message(int fd, RedWorkerMessage *message)
> +{
> +    send_data(fd, message, sizeof(RedWorkerMessage));
> +}
> +
> +static inline void receive_data(int fd, void *in_buf, int n)
> +{
> +    uint8_t *buf = in_buf;
> +    do {
> +        int now;
> +        if ((now = read(fd, buf, n)) == -1) {
> +            if (errno == EINTR) {
> +                continue;
> +            }
> +            spice_error("%s", strerror(errno));
> +        }
> +        buf += now;
> +        n -= now;
> +    } while (n);
> +}
> +
> +static inline void read_message(int fd, RedWorkerMessage *message)
> +{
> +    receive_data(fd, message, sizeof(RedWorkerMessage));
> +}
> +
> +enum {
> +    RED_WORKER_MESSAGE_NOP,
> +    RED_WORKER_MESSAGE_UPDATE,
> +    RED_WORKER_MESSAGE_WAKEUP,
> +    RED_WORKER_MESSAGE_OOM,
> +    RED_WORKER_MESSAGE_READY,
> +    RED_WORKER_MESSAGE_DISPLAY_CONNECT,
> +    RED_WORKER_MESSAGE_DISPLAY_DISCONNECT,
> +    RED_WORKER_MESSAGE_DISPLAY_MIGRATE,
> +    RED_WORKER_MESSAGE_START,
> +    RED_WORKER_MESSAGE_STOP,
> +    RED_WORKER_MESSAGE_CURSOR_CONNECT,
> +    RED_WORKER_MESSAGE_CURSOR_DISCONNECT,
> +    RED_WORKER_MESSAGE_CURSOR_MIGRATE,
> +    RED_WORKER_MESSAGE_SET_COMPRESSION,
> +    RED_WORKER_MESSAGE_SET_STREAMING_VIDEO,
> +    RED_WORKER_MESSAGE_SET_MOUSE_MODE,
> +    RED_WORKER_MESSAGE_ADD_MEMSLOT,
> +    RED_WORKER_MESSAGE_DEL_MEMSLOT,
> +    RED_WORKER_MESSAGE_RESET_MEMSLOTS,
> +    RED_WORKER_MESSAGE_DESTROY_SURFACES,
> +    RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE,
> +    RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE,
> +    RED_WORKER_MESSAGE_RESET_CURSOR,
> +    RED_WORKER_MESSAGE_RESET_IMAGE_CACHE,
> +    RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT,
> +    RED_WORKER_MESSAGE_LOADVM_COMMANDS,
> +    /* async commands */
> +    RED_WORKER_MESSAGE_UPDATE_ASYNC,
> +    RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC,
> +    RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC,
> +    RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC,
> +    RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC,
> +    RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC,
> +    /* suspend/windows resolution change command */
> +    RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC,
> +
> +    RED_WORKER_MESSAGE_DISPLAY_CHANNEL_CREATE,
> +    RED_WORKER_MESSAGE_CURSOR_CHANNEL_CREATE,
> +
> +    RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC,
> +    RED_WORKER_MESSAGE_DRIVER_UNLOAD,
> +
> +    RED_WORKER_MESSAGE_COUNT // LAST
> +};
> +
>  typedef struct RedWorkerMessageDisplayConnect {
>      RedClient * client;
>      RedsStream * stream;
> diff --git a/server/red_worker.h b/server/red_worker.h
> index ca8aadb..c71e9c8 100644
> --- a/server/red_worker.h
> +++ b/server/red_worker.h
> @@ -21,6 +21,7 @@
>  #include <unistd.h>
>  #include <errno.h>
>  #include "red_common.h"
> +#include "red_dispatcher.h"
>  
>  enum {
>      RED_WORKER_PENDING_WAKEUP,
> @@ -28,54 +29,6 @@ enum {
>  };
>  
>  enum {
> -    RED_WORKER_MESSAGE_NOP,
> -    RED_WORKER_MESSAGE_UPDATE,
> -    RED_WORKER_MESSAGE_WAKEUP,
> -    RED_WORKER_MESSAGE_OOM,
> -    RED_WORKER_MESSAGE_READY,
> -    RED_WORKER_MESSAGE_DISPLAY_CONNECT,
> -    RED_WORKER_MESSAGE_DISPLAY_DISCONNECT,
> -    RED_WORKER_MESSAGE_DISPLAY_MIGRATE,
> -    RED_WORKER_MESSAGE_START,
> -    RED_WORKER_MESSAGE_STOP,
> -    RED_WORKER_MESSAGE_CURSOR_CONNECT,
> -    RED_WORKER_MESSAGE_CURSOR_DISCONNECT,
> -    RED_WORKER_MESSAGE_CURSOR_MIGRATE,
> -    RED_WORKER_MESSAGE_SET_COMPRESSION,
> -    RED_WORKER_MESSAGE_SET_STREAMING_VIDEO,
> -    RED_WORKER_MESSAGE_SET_MOUSE_MODE,
> -    RED_WORKER_MESSAGE_ADD_MEMSLOT,
> -    RED_WORKER_MESSAGE_DEL_MEMSLOT,
> -    RED_WORKER_MESSAGE_RESET_MEMSLOTS,
> -    RED_WORKER_MESSAGE_DESTROY_SURFACES,
> -    RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE,
> -    RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE,
> -    RED_WORKER_MESSAGE_RESET_CURSOR,
> -    RED_WORKER_MESSAGE_RESET_IMAGE_CACHE,
> -    RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT,
> -    RED_WORKER_MESSAGE_LOADVM_COMMANDS,
> -    /* async commands */
> -    RED_WORKER_MESSAGE_UPDATE_ASYNC,
> -    RED_WORKER_MESSAGE_ADD_MEMSLOT_ASYNC,
> -    RED_WORKER_MESSAGE_DESTROY_SURFACES_ASYNC,
> -    RED_WORKER_MESSAGE_CREATE_PRIMARY_SURFACE_ASYNC,
> -    RED_WORKER_MESSAGE_DESTROY_PRIMARY_SURFACE_ASYNC,
> -    RED_WORKER_MESSAGE_DESTROY_SURFACE_WAIT_ASYNC,
> -    /* suspend/windows resolution change command */
> -    RED_WORKER_MESSAGE_FLUSH_SURFACES_ASYNC,
> -
> -    RED_WORKER_MESSAGE_DISPLAY_CHANNEL_CREATE,
> -    RED_WORKER_MESSAGE_CURSOR_CHANNEL_CREATE,
> -
> -    RED_WORKER_MESSAGE_MONITORS_CONFIG_ASYNC,
> -    RED_WORKER_MESSAGE_DRIVER_UNLOAD,
> -
> -    RED_WORKER_MESSAGE_COUNT // LAST
> -};
> -
> -typedef uint32_t RedWorkerMessage;
> -
> -enum {
>      RED_RENDERER_INVALID,
>      RED_RENDERER_SW,
>      RED_RENDERER_OGL_PBUF,
> @@ -84,8 +37,6 @@ enum {
>      RED_RENDERER_LAST
>  };
>  
> -typedef struct RedDispatcher RedDispatcher;
> -
>  typedef struct WorkerInitData {
>      struct QXLInstance *qxl;
>      int id;
> @@ -107,46 +58,4 @@ typedef struct WorkerInitData {
>  
>  void *red_worker_main(void *arg);
>  
> -static inline void send_data(int fd, void *in_buf, int n)
> -{
> -    uint8_t *buf = in_buf;
> -    do {
> -        int now;
> -        if ((now = write(fd, buf, n)) == -1) {
> -            if (errno == EINTR) {
> -                continue;
> -            }
> -            spice_error("%s", strerror(errno));
> -        }
> -        buf += now;
> -        n -= now;
> -    } while (n);
> -}
> -
> -static inline void write_message(int fd, RedWorkerMessage *message)
> -{
> -    send_data(fd, message, sizeof(RedWorkerMessage));
> -}
> -
> -static inline void receive_data(int fd, void *in_buf, int n)
> -{
> -    uint8_t *buf = in_buf;
> -    do {
> -        int now;
> -        if ((now = read(fd, buf, n)) == -1) {
> -            if (errno == EINTR) {
> -                continue;
> -            }
> -            spice_error("%s", strerror(errno));
> -        }
> -        buf += now;
> -        n -= now;
> -    } while (n);
> -}
> -
> -static inline void read_message(int fd, RedWorkerMessage *message)
> -{
> -    receive_data(fd, message, sizeof(RedWorkerMessage));
> -}
> -
>  #endif


More information about the Spice-devel mailing list