[Spice-devel] [PATCH 2/4] Use macros for casting Channel types
Jonathon Jongsma
jjongsma at redhat.com
Fri Oct 7 22:01:35 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 | 6 +++---
server/cursor-channel.h | 1 +
server/display-channel.c | 4 ++--
server/display-channel.h | 2 ++
server/inputs-channel-client.c | 2 +-
server/inputs-channel.c | 2 +-
server/inputs-channel.h | 1 +
server/main-channel-client.c | 2 +-
server/main-channel.c | 2 +-
server/main-channel.h | 2 ++
11 files changed, 16 insertions(+), 10 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..85a7fe5 100644
--- a/server/cursor-channel.c
+++ b/server/cursor-channel.c
@@ -171,7 +171,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 +199,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 +325,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/cursor-channel.h b/server/cursor-channel.h
index a3ddaa3..0f2b43d 100644
--- a/server/cursor-channel.h
+++ b/server/cursor-channel.h
@@ -20,6 +20,7 @@
#include "common-graphics-channel.h"
+#define CURSOR_CHANNEL(channel) ((CursorChannel*)channel)
/**
* This type it's a RedChannel class which implement cursor (mouse)
* movements.
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..998970e 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..83c1360 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");
diff --git a/server/inputs-channel.h b/server/inputs-channel.h
index e8f92cc..7001094 100644
--- a/server/inputs-channel.h
+++ b/server/inputs-channel.h
@@ -26,6 +26,7 @@
#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..caea014 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
--
2.7.4
More information about the Spice-devel
mailing list