[Spice-devel] [PATCH] Move InputsChannelClient to a separate file
Frediano Ziglio
fziglio at redhat.com
Mon May 23 20:06:24 UTC 2016
>
> I guess this is just my patch with the erroneous const changes removed? I
> guess
> it can be considered ACKed then.
>
Both yes!
>
> On Mon, 2016-05-23 at 11:46 +0100, Frediano Ziglio wrote:
> > From: Jonathon Jongsma <jjongsma at redhat.com>
> >
> > Preparation for converting to GObject
> >
> > Acked-by: Frediano Ziglio <fziglio at redhat.com>
> > ---
> > server/Makefile.am | 2 +
> > server/inputs-channel-client.c | 87
> > ++++++++++++++++++++++++++++++++++++++++++
> > server/inputs-channel-client.h | 48 +++++++++++++++++++++++
> > server/inputs-channel.c | 78 +++++++++++--------------------------
> > server/inputs-channel.h | 2 +
> > 5 files changed, 161 insertions(+), 56 deletions(-)
> > create mode 100644 server/inputs-channel-client.c
> > create mode 100644 server/inputs-channel-client.h
> >
> > diff --git a/server/Makefile.am b/server/Makefile.am
> > index 5a5c7e8..cca3b9b 100644
> > --- a/server/Makefile.am
> > +++ b/server/Makefile.am
> > @@ -80,6 +80,8 @@ libserver_la_SOURCES = \
> > glz-encoder-priv.h \
> > inputs-channel.c \
> > inputs-channel.h \
> > + inputs-channel-client.c \
> > + inputs-channel-client.h \
> > jpeg-encoder.c \
> > jpeg-encoder.h \
> > lz4-encoder.c \
> > diff --git a/server/inputs-channel-client.c
> > b/server/inputs-channel-client.c
> > new file mode 100644
> > index 0000000..f9dd6b2
> > --- /dev/null
> > +++ b/server/inputs-channel-client.c
> > @@ -0,0 +1,87 @@
> > +/*
> > + Copyright (C) 2009-2015 Red Hat, Inc.
> > +
> > + This library is free software; you can redistribute it and/or
> > + modify it under the terms of the GNU Lesser General Public
> > + License as published by the Free Software Foundation; either
> > + version 2.1 of the License, or (at your option) any later version.
> > +
> > + This library is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > + Lesser General Public License for more details.
> > +
> > + You should have received a copy of the GNU Lesser General Public
> > + License along with this library; if not, see
> > <http://www.gnu.org/licenses/
> > >.
> > +*/
> > +#ifdef HAVE_CONFIG_H
> > +#include <config.h>
> > +#endif
> > +
> > +#include "inputs-channel-client.h"
> > +#include "inputs-channel.h"
> > +#include "migration-protocol.h"
> > +
> > +struct InputsChannelClient {
> > + RedChannelClient base;
> > + uint16_t motion_count;
> > +};
> > +
> > +RedChannelClient* inputs_channel_client_create(RedChannel *channel,
> > + RedClient *client,
> > + RedsStream *stream,
> > + int monitor_latency,
> > + int num_common_caps,
> > + uint32_t *common_caps,
> > + int num_caps,
> > + uint32_t *caps)
> > +{
> > + InputsChannelClient* icc =
> > +
> > (InputsChannelClient*)red_channel_client_create(sizeof(InputsChannelClient),
> > + channel, client,
> > + stream,
> > + monitor_latency,
> > + num_common_caps,
> > + common_caps,
> > num_caps,
> > + caps);
> > + if (icc)
> > + icc->motion_count = 0;
> > + return &icc->base;
> > +}
> > +
> > +void inputs_channel_client_send_migrate_data(RedChannelClient *rcc,
> > + SpiceMarshaller *m,
> > + RedPipeItem *item)
> > +{
> > + InputsChannelClient *icc = SPICE_CONTAINEROF(rcc, InputsChannelClient,
> > base);
> > + InputsChannel *inputs = (InputsChannel*)rcc->channel;
> > +
> > + inputs_channel_set_src_during_migrate(inputs, FALSE);
> > + red_channel_client_init_send_data(rcc, SPICE_MSG_MIGRATE_DATA, item);
> > +
> > + spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_INPUTS_MAGIC);
> > + spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_INPUTS_VERSION);
> > + spice_marshaller_add_uint16(m, icc->motion_count);
> > +}
> > +
> > +void inputs_channel_client_handle_migrate_data(InputsChannelClient *icc,
> > + uint16_t motion_count)
> > +{
> > + icc->motion_count = motion_count;
> > +
> > + for (; icc->motion_count >= SPICE_INPUT_MOTION_ACK_BUNCH;
> > + icc->motion_count -= SPICE_INPUT_MOTION_ACK_BUNCH) {
> > + red_channel_client_pipe_add_type(&icc->base,
> > RED_PIPE_ITEM_MOUSE_MOTION_ACK);
> > + }
> > +}
> > +
> > +void inputs_channel_client_on_mouse_motion(InputsChannelClient *icc)
> > +{
> > + InputsChannel *inputs_channel = (InputsChannel *)icc->base.channel;
> > +
> > + if (++icc->motion_count % SPICE_INPUT_MOTION_ACK_BUNCH == 0 &&
> > + !inputs_channel_is_src_during_migrate(inputs_channel)) {
> > + red_channel_client_pipe_add_type(&icc->base,
> > RED_PIPE_ITEM_MOUSE_MOTION_ACK);
> > + icc->motion_count = 0;
> > + }
> > +}
> > diff --git a/server/inputs-channel-client.h
> > b/server/inputs-channel-client.h
> > new file mode 100644
> > index 0000000..e83cc29
> > --- /dev/null
> > +++ b/server/inputs-channel-client.h
> > @@ -0,0 +1,48 @@
> > +/*
> > + Copyright (C) 2009-2015 Red Hat, Inc.
> > +
> > + This library is free software; you can redistribute it and/or
> > + modify it under the terms of the GNU Lesser General Public
> > + License as published by the Free Software Foundation; either
> > + version 2.1 of the License, or (at your option) any later version.
> > +
> > + This library is distributed in the hope that it will be useful,
> > + but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> > + Lesser General Public License for more details.
> > +
> > + You should have received a copy of the GNU Lesser General Public
> > + License along with this library; if not, see
> > <http://www.gnu.org/licenses/
> > >.
> > +*/
> > +
> > +#ifndef _INPUTS_CHANNEL_CLIENT_H_
> > +#define _INPUTS_CHANNEL_CLIENT_H_
> > +
> > +#include "red-channel.h"
> > +
> > +typedef struct InputsChannelClient InputsChannelClient;
> > +
> > +RedChannelClient* inputs_channel_client_create(RedChannel *channel,
> > + RedClient *client,
> > + RedsStream *stream,
> > + int monitor_latency,
> > + int num_common_caps,
> > + uint32_t *common_caps,
> > + int num_caps,
> > + uint32_t *caps);
> > +
> > +void inputs_channel_client_send_migrate_data(RedChannelClient *rcc,
> > + SpiceMarshaller *m,
> > + RedPipeItem *item);
> > +void inputs_channel_client_handle_migrate_data(InputsChannelClient *icc,
> > + uint16_t motion_count);
> > +void inputs_channel_client_on_mouse_motion(InputsChannelClient *icc);
> > +
> > +enum {
> > + RED_PIPE_ITEM_INPUTS_INIT = RED_PIPE_ITEM_TYPE_CHANNEL_BASE,
> > + RED_PIPE_ITEM_MOUSE_MOTION_ACK,
> > + RED_PIPE_ITEM_KEY_MODIFIERS,
> > + RED_PIPE_ITEM_MIGRATE_DATA,
> > +};
> > +
> > +#endif /* _INPUTS_CHANNEL_CLIENT_H_ */
> > diff --git a/server/inputs-channel.c b/server/inputs-channel.c
> > index 197823d..a971bbb 100644
> > --- a/server/inputs-channel.c
> > +++ b/server/inputs-channel.c
> > @@ -39,6 +39,7 @@
> > #include "reds.h"
> > #include "reds-stream.h"
> > #include "red-channel.h"
> > +#include "inputs-channel-client.h"
> > #include "main-channel-client.h"
> > #include "inputs-channel.h"
> > #include "migration-protocol.h"
> > @@ -99,11 +100,6 @@ RedsState*
> > spice_tablet_state_get_server(SpiceTabletState
> > *st)
> > return st->reds;
> > }
> >
> > -typedef struct InputsChannelClient {
> > - RedChannelClient base;
> > - uint16_t motion_count;
> > -} InputsChannelClient;
> > -
> > struct InputsChannel {
> > RedChannel base;
> > uint8_t recv_buf[RECEIVE_BUF_SIZE];
> > @@ -115,13 +111,6 @@ struct InputsChannel {
> > SpiceTabletInstance *tablet;
> > };
> >
> > -enum {
> > - RED_PIPE_ITEM_INPUTS_INIT = RED_PIPE_ITEM_TYPE_CHANNEL_BASE,
> > - RED_PIPE_ITEM_MOUSE_MOTION_ACK,
> > - RED_PIPE_ITEM_KEY_MODIFIERS,
> > - RED_PIPE_ITEM_MIGRATE_DATA,
> > -};
> > -
> > typedef struct RedInputsPipeItem {
> > RedPipeItem base;
> > } RedInputsPipeItem;
> > @@ -239,21 +228,6 @@ static RedPipeItem *red_inputs_key_modifiers_item_new(
> > return &item->base;
> > }
> >
> > -static void inputs_channel_send_migrate_data(RedChannelClient *rcc,
> > - SpiceMarshaller *m,
> > - RedPipeItem *item)
> > -{
> > - InputsChannelClient *icc = SPICE_CONTAINEROF(rcc, InputsChannelClient,
> > base);
> > - InputsChannel *inputs = SPICE_CONTAINEROF(rcc->channel, InputsChannel,
> > base);
> > -
> > - inputs->src_during_migrate = FALSE;
> > - red_channel_client_init_send_data(rcc, SPICE_MSG_MIGRATE_DATA, item);
> > -
> > - spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_INPUTS_MAGIC);
> > - spice_marshaller_add_uint32(m, SPICE_MIGRATE_DATA_INPUTS_VERSION);
> > - spice_marshaller_add_uint16(m, icc->motion_count);
> > -}
> > -
> > static void inputs_channel_send_item(RedChannelClient *rcc, RedPipeItem
> > *base)
> > {
> > SpiceMarshaller *m = red_channel_client_get_marshaller(rcc);
> > @@ -283,7 +257,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:
> > - inputs_channel_send_migrate_data(rcc, m, base);
> > + inputs_channel_client_send_migrate_data(rcc, m, base);
> > break;
> > default:
> > spice_warning("invalid pipe iten %d", base->type);
> > @@ -331,11 +305,7 @@ static int
> > inputs_channel_handle_parsed(RedChannelClient
> > *rcc, uint32_t size, ui
> > SpiceMouseInstance *mouse =
> > inputs_channel_get_mouse(inputs_channel);
> > SpiceMsgcMouseMotion *mouse_motion = message;
> >
> > - if (++icc->motion_count % SPICE_INPUT_MOTION_ACK_BUNCH == 0 &&
> > - !inputs_channel->src_during_migrate) {
> > - red_channel_client_pipe_add_type(rcc,
> > RED_PIPE_ITEM_MOUSE_MOTION_ACK);
> > - icc->motion_count = 0;
> > - }
> > + inputs_channel_client_on_mouse_motion(icc);
> > if (mouse && reds_get_mouse_mode(reds) == SPICE_MOUSE_MODE_SERVER)
> > {
> > SpiceMouseInterface *sif;
> > sif = SPICE_CONTAINEROF(mouse->base.sif, SpiceMouseInterface,
> > base);
> > @@ -349,11 +319,7 @@ static int
> > inputs_channel_handle_parsed(RedChannelClient
> > *rcc, uint32_t size, ui
> > SpiceMsgcMousePosition *pos = message;
> > SpiceTabletInstance *tablet =
> > inputs_channel_get_tablet(inputs_channel);
> >
> > - if (++icc->motion_count % SPICE_INPUT_MOTION_ACK_BUNCH == 0 &&
> > - !inputs_channel->src_during_migrate) {
> > - red_channel_client_pipe_add_type(rcc,
> > RED_PIPE_ITEM_MOUSE_MOTION_ACK);
> > - icc->motion_count = 0;
> > - }
> > + inputs_channel_client_on_mouse_motion(icc);
> > if (reds_get_mouse_mode(reds) != SPICE_MOUSE_MODE_CLIENT) {
> > break;
> > }
> > @@ -523,7 +489,7 @@ static void inputs_connect(RedChannel *channel,
> > RedClient
> > *client,
> > int num_common_caps, uint32_t *common_caps,
> > int num_caps, uint32_t *caps)
> > {
> > - InputsChannelClient *icc;
> > + RedChannelClient *rcc;
> >
> > if (!reds_stream_is_ssl(stream) &&
> > !red_client_during_migrate_at_target(client)) {
> > main_channel_client_push_notify(red_client_get_main(client),
> > @@ -531,18 +497,13 @@ static void inputs_connect(RedChannel *channel,
> > RedClient *client,
> > }
> >
> > spice_printerr("inputs channel client create");
> > - icc =
> > (InputsChannelClient*)red_channel_client_create(sizeof(InputsChannelClient),
> > - channel,
> > - client,
> > - stream,
> > - FALSE,
> > - num_common_caps,
> > common_caps,
> > - num_caps, caps);
> > - if (!icc) {
> > + rcc = inputs_channel_client_create(channel, client, stream, FALSE,
> > + num_common_caps, common_caps,
> > + num_caps, caps);
> > + if (!rcc) {
> > return;
> > }
> > - icc->motion_count = 0;
> > - inputs_pipe_add_init(&icc->base);
> > + inputs_pipe_add_init(rcc);
> > }
> >
> > static void inputs_migrate(RedChannelClient *rcc)
> > @@ -583,7 +544,7 @@ static int
> > inputs_channel_handle_migrate_data(RedChannelClient *rcc,
> > uint32_t size,
> > void *message)
> > {
> > - InputsChannelClient *icc = SPICE_CONTAINEROF(rcc, InputsChannelClient,
> > base);
> > + InputsChannelClient *icc = (InputsChannelClient*)rcc;
> > InputsChannel *inputs = SPICE_CONTAINEROF(rcc->channel, InputsChannel,
> > base);
> > SpiceMigrateDataHeader *header;
> > SpiceMigrateDataInputs *mig_data;
> > @@ -598,12 +559,7 @@ static int
> > inputs_channel_handle_migrate_data(RedChannelClient *rcc,
> > return FALSE;
> > }
> > key_modifiers_sender(inputs);
> > - icc->motion_count = mig_data->motion_count;
> > -
> > - for (; icc->motion_count >= SPICE_INPUT_MOTION_ACK_BUNCH;
> > - icc->motion_count -= SPICE_INPUT_MOTION_ACK_BUNCH) {
> > - red_channel_client_pipe_add_type(rcc,
> > RED_PIPE_ITEM_MOUSE_MOTION_ACK);
> > - }
> > + inputs_channel_client_handle_migrate_data(icc,
> > mig_data->motion_count);
> > return TRUE;
> > }
> >
> > @@ -709,3 +665,13 @@ void inputs_channel_detach_tablet(InputsChannel
> > *inputs,
> > SpiceTabletInstance *ta
> > inputs->tablet = NULL;
> > }
> >
> > +gboolean inputs_channel_is_src_during_migrate(InputsChannel *inputs)
> > +{
> > + return inputs->src_during_migrate;
> > +}
> > +
> > +void inputs_channel_set_src_during_migrate(InputsChannel *inputs,
> > + gboolean value)
> > +{
> > + inputs->src_during_migrate = value;
> > +}
> > diff --git a/server/inputs-channel.h b/server/inputs-channel.h
> > index 9213aec..5b12fad 100644
> > --- a/server/inputs-channel.h
> > +++ b/server/inputs-channel.h
> > @@ -43,5 +43,7 @@ int inputs_channel_has_tablet(InputsChannel *inputs);
> > void inputs_channel_detach_tablet(InputsChannel *inputs,
> > SpiceTabletInstance
> > *tablet);
> > RedsState* spice_tablet_state_get_server(SpiceTabletState *dev);
> > RedsState* spice_kbd_state_get_server(SpiceKbdState *dev);
> > +gboolean inputs_channel_is_src_during_migrate(InputsChannel *inputs);
> > +void inputs_channel_set_src_during_migrate(InputsChannel *inputs, gboolean
> > value);
> >
> > #endif
>
More information about the Spice-devel
mailing list