[Spice-devel] [PATCH 2/7] Use macros for casting Channel types
Frediano Ziglio
fziglio at redhat.com
Wed Oct 12 10:53:27 UTC 2016
>
> In preparation for converting RedChannel to GObject, switch to using
> RED_CHANNEL()-type macros for casting. For now they just do a regular
> cast, but it helps reduce the size of the GObject patch to make it
> easier to review.
> ---
> server/common-graphics-channel.c | 2 +-
> server/cursor-channel.c | 8 +++++---
> server/display-channel.c | 4 ++--
> server/display-channel.h | 2 ++
> server/inputs-channel-client.c | 2 +-
> server/inputs-channel.c | 18 +++++++++---------
> server/inputs-channel.h | 2 ++
> server/main-channel-client.c | 2 +-
> server/main-channel.c | 2 +-
> server/main-channel.h | 2 ++
> 10 files changed, 26 insertions(+), 18 deletions(-)
>
> diff --git a/server/common-graphics-channel.c
> b/server/common-graphics-channel.c
> index 625162c..bcf7279 100644
> --- a/server/common-graphics-channel.c
> +++ b/server/common-graphics-channel.c
> @@ -122,7 +122,7 @@ CommonGraphicsChannel*
> common_graphics_channel_new(RedsState *server,
> migration_flags);
> spice_return_val_if_fail(channel, NULL);
>
> - common = (CommonGraphicsChannel *)channel;
> + common = COMMON_GRAPHICS_CHANNEL(channel);
> common->qxl = qxl;
> return common;
> }
> diff --git a/server/cursor-channel.c b/server/cursor-channel.c
> index c73745f..e84b593 100644
> --- a/server/cursor-channel.c
> +++ b/server/cursor-channel.c
> @@ -27,6 +27,8 @@
> #include "cursor-channel-client.h"
> #include "reds.h"
>
> +#define CURSOR_CHANNEL(channel) ((CursorChannel*)(channel))
> +
> typedef struct CursorChannelClient CursorChannelClient;
>
> enum {
> @@ -171,7 +173,7 @@ static void cursor_fill(CursorChannelClient *ccc,
> SpiceCursor *red_cursor,
>
> void cursor_channel_disconnect(CursorChannel *cursor_channel)
> {
> - RedChannel *channel = (RedChannel *)cursor_channel;
> + RedChannel *channel = RED_CHANNEL(cursor_channel);
>
> if (!channel || !red_channel_is_connected(channel)) {
> return;
> @@ -199,7 +201,7 @@ static void red_marshall_cursor_init(CursorChannelClient
> *ccc, SpiceMarshaller *
> AddBufInfo info;
>
> spice_assert(rcc);
> - cursor_channel = (CursorChannel*)red_channel_client_get_channel(rcc);
> + cursor_channel = CURSOR_CHANNEL(red_channel_client_get_channel(rcc));
>
> red_channel_client_init_send_data(rcc, SPICE_MSG_CURSOR_INIT, NULL);
> msg.visible = cursor_channel->priv->cursor_visible;
> @@ -325,7 +327,7 @@ CursorChannel* cursor_channel_new(RedsState *server,
> QXLInstance *qxl,
> SPICE_CHANNEL_CURSOR, 0,
> &cbs,
> red_channel_client_handle_message);
>
> - cursor_channel = (CursorChannel *)channel;
> + cursor_channel = CURSOR_CHANNEL(channel);
> cursor_channel->priv->cursor_visible = TRUE;
> cursor_channel->priv->mouse_mode = SPICE_MOUSE_MODE_SERVER;
>
> diff --git a/server/display-channel.c b/server/display-channel.c
> index 93744a4..b9e2b93 100644
> --- a/server/display-channel.c
> +++ b/server/display-channel.c
> @@ -1924,10 +1924,10 @@ DisplayChannel* display_channel_new(RedsState *reds,
> };
>
> spice_info("create display channel");
> - display = (DisplayChannel *)common_graphics_channel_new(
> + display = DISPLAY_CHANNEL(common_graphics_channel_new(
> reds, qxl, core, sizeof(*display), SPICE_CHANNEL_DISPLAY,
> SPICE_MIGRATE_NEED_FLUSH | SPICE_MIGRATE_NEED_DATA_TRANSFER,
> - &cbs, dcc_handle_message);
> + &cbs, dcc_handle_message));
> spice_return_val_if_fail(display, NULL);
> display->priv->pub = display;
>
> diff --git a/server/display-channel.h b/server/display-channel.h
> index 936768e..3762e54 100644
> --- a/server/display-channel.h
> +++ b/server/display-channel.h
> @@ -45,6 +45,8 @@
> #include "image-encoders.h"
> #include "common-graphics-channel.h"
>
> +#define DISPLAY_CHANNEL(channel) ((DisplayChannel*)(channel))
> +
> typedef struct DependItem {
> Drawable *drawable;
> RingItem ring_item;
> diff --git a/server/inputs-channel-client.c b/server/inputs-channel-client.c
> index 76de382..4ab2457 100644
> --- a/server/inputs-channel-client.c
> +++ b/server/inputs-channel-client.c
> @@ -110,7 +110,7 @@ void
> inputs_channel_client_handle_migrate_data(InputsChannelClient *icc,
>
> void inputs_channel_client_on_mouse_motion(InputsChannelClient *icc)
> {
> - InputsChannel *inputs_channel = (InputsChannel
> *)red_channel_client_get_channel(RED_CHANNEL_CLIENT(icc));
> + InputsChannel *inputs_channel =
> INPUTS_CHANNEL(red_channel_client_get_channel(RED_CHANNEL_CLIENT(icc)));
>
> if (++icc->priv->motion_count % SPICE_INPUT_MOTION_ACK_BUNCH == 0 &&
> !inputs_channel_is_src_during_migrate(inputs_channel)) {
> diff --git a/server/inputs-channel.c b/server/inputs-channel.c
> index 840d5e9..85ca155 100644
> --- a/server/inputs-channel.c
> +++ b/server/inputs-channel.c
> @@ -151,7 +151,7 @@ static uint8_t
> *inputs_channel_alloc_msg_rcv_buf(RedChannelClient *rcc,
> uint16_t type,
> uint32_t size)
> {
> - InputsChannel *inputs_channel =
> (InputsChannel*)red_channel_client_get_channel(rcc);
> + InputsChannel *inputs_channel =
> INPUTS_CHANNEL(red_channel_client_get_channel(rcc));
>
> if (size > RECEIVE_BUF_SIZE) {
> spice_printerr("error: too large incoming message");
> @@ -259,7 +259,7 @@ static void inputs_channel_send_item(RedChannelClient
> *rcc, RedPipeItem *base)
> red_channel_client_init_send_data(rcc,
> SPICE_MSG_INPUTS_MOUSE_MOTION_ACK, base);
> break;
> case RED_PIPE_ITEM_MIGRATE_DATA:
> -
> ((InputsChannel*)red_channel_client_get_channel(rcc))->src_during_migrate
> = FALSE;
> +
> INPUTS_CHANNEL(red_channel_client_get_channel(rcc))->src_during_migrate
> = FALSE;
> inputs_channel_client_send_migrate_data(rcc, m, base);
> break;
> default:
> @@ -272,7 +272,7 @@ static void inputs_channel_send_item(RedChannelClient
> *rcc, RedPipeItem *base)
> static int inputs_channel_handle_parsed(RedChannelClient *rcc, uint32_t
> size, uint16_t type,
> void *message)
> {
> - InputsChannel *inputs_channel = (InputsChannel
> *)red_channel_client_get_channel(rcc);
> + InputsChannel *inputs_channel =
> INPUTS_CHANNEL(red_channel_client_get_channel(rcc));
> InputsChannelClient *icc = INPUTS_CHANNEL_CLIENT(rcc);
> uint32_t i;
> RedsState *reds = red_channel_get_server(&inputs_channel->base);
> @@ -458,13 +458,13 @@ static void
> inputs_channel_on_disconnect(RedChannelClient *rcc)
> if (!rcc) {
> return;
> }
> -
> inputs_release_keys((InputsChannel*)red_channel_client_get_channel(rcc));
> +
> inputs_release_keys(INPUTS_CHANNEL(red_channel_client_get_channel(rcc)));
> }
>
> static void inputs_pipe_add_init(RedChannelClient *rcc)
> {
> RedInputsInitPipeItem *item =
> spice_malloc(sizeof(RedInputsInitPipeItem));
> - InputsChannel *inputs =
> (InputsChannel*)red_channel_client_get_channel(rcc);
> + InputsChannel *inputs =
> INPUTS_CHANNEL(red_channel_client_get_channel(rcc));
>
> red_pipe_item_init(&item->base, RED_PIPE_ITEM_INPUTS_INIT);
> item->modifiers = kbd_get_leds(inputs_channel_get_keyboard(inputs));
> @@ -511,7 +511,7 @@ static void inputs_connect(RedChannel *channel, RedClient
> *client,
>
> static void inputs_migrate(RedChannelClient *rcc)
> {
> - InputsChannel *inputs =
> (InputsChannel*)red_channel_client_get_channel(rcc);
> + InputsChannel *inputs =
> INPUTS_CHANNEL(red_channel_client_get_channel(rcc));
> inputs->src_during_migrate = TRUE;
> red_channel_client_default_migrate(rcc);
> }
> @@ -548,7 +548,7 @@ static int
> inputs_channel_handle_migrate_data(RedChannelClient *rcc,
> void *message)
> {
> InputsChannelClient *icc = INPUTS_CHANNEL_CLIENT(rcc);
> - InputsChannel *inputs =
> (InputsChannel*)red_channel_client_get_channel(rcc);
> + InputsChannel *inputs =
> INPUTS_CHANNEL(red_channel_client_get_channel(rcc));
> SpiceMigrateDataHeader *header;
> SpiceMigrateDataInputs *mig_data;
>
> @@ -580,7 +580,7 @@ InputsChannel* inputs_channel_new(RedsState *reds)
> channel_cbs.handle_migrate_data = inputs_channel_handle_migrate_data;
> channel_cbs.handle_migrate_flush_mark =
> inputs_channel_handle_migrate_flush_mark;
>
> - inputs = (InputsChannel *)red_channel_create_parser(
> + inputs = INPUTS_CHANNEL(red_channel_create_parser(
> sizeof(InputsChannel),
> reds,
> reds_get_core_interface(reds),
> @@ -589,7 +589,7 @@ InputsChannel* inputs_channel_new(RedsState *reds)
> spice_get_client_channel_parser(SPICE_CHANNEL_INPUTS,
> NULL),
> inputs_channel_handle_parsed,
> &channel_cbs,
> - SPICE_MIGRATE_NEED_FLUSH |
> SPICE_MIGRATE_NEED_DATA_TRANSFER);
> + SPICE_MIGRATE_NEED_FLUSH |
> SPICE_MIGRATE_NEED_DATA_TRANSFER));
>
> if (!inputs) {
> spice_error("failed to allocate Inputs Channel");
> diff --git a/server/inputs-channel.h b/server/inputs-channel.h
> index e8f92cc..ae84eed 100644
> --- a/server/inputs-channel.h
> +++ b/server/inputs-channel.h
> @@ -26,6 +26,8 @@
>
> #include "red-channel.h"
>
> +#define INPUTS_CHANNEL(channel) ((InputsChannel*)(channel))
> +
> typedef struct InputsChannel InputsChannel;
>
> InputsChannel* inputs_channel_new(RedsState *reds);
> diff --git a/server/main-channel-client.c b/server/main-channel-client.c
> index 9966a38..b30083f 100644
> --- a/server/main-channel-client.c
> +++ b/server/main-channel-client.c
> @@ -704,7 +704,7 @@ void main_channel_client_migrate(RedChannelClient *rcc)
> gboolean main_channel_client_connect_semi_seamless(MainChannelClient *mcc)
> {
> RedChannelClient *rcc = RED_CHANNEL_CLIENT(mcc);
> - MainChannel* main_channel =
> (MainChannel*)red_channel_client_get_channel(rcc);
> + MainChannel* main_channel =
> MAIN_CHANNEL(red_channel_client_get_channel(rcc));
> if (red_channel_client_test_remote_cap(rcc,
> SPICE_MAIN_CAP_SEMI_SEAMLESS_MIGRATE))
> {
> RedClient *client = red_channel_client_get_client(rcc);
> diff --git a/server/main-channel.c b/server/main-channel.c
> index bf84694..a1b8e31 100644
> --- a/server/main-channel.c
> +++ b/server/main-channel.c
> @@ -329,7 +329,7 @@ MainChannel* main_channel_new(RedsState *reds)
> client_cbs.migrate = main_channel_client_migrate;
> red_channel_register_client_cbs(channel, &client_cbs, NULL);
>
> - return (MainChannel *)channel;
> + return MAIN_CHANNEL(channel);
> }
>
> static int main_channel_connect_semi_seamless(MainChannel *main_channel)
> diff --git a/server/main-channel.h b/server/main-channel.h
> index 868a14a..e0858d0 100644
> --- a/server/main-channel.h
> +++ b/server/main-channel.h
> @@ -25,6 +25,8 @@
> #include "red-channel.h"
> #include "main-channel-client.h"
>
> +#define MAIN_CHANNEL(channel) ((MainChannel*)(channel))
> +
> // TODO: Defines used to calculate receive buffer size, and also by reds.c
> // other options: is to make a reds_main_consts.h, to duplicate defines.
> #define REDS_AGENT_WINDOW_SIZE 10
Acked-by: Frediano Ziglio <fziglio at redhat.com>
Frediano
More information about the Spice-devel
mailing list