Re: [PATCH 07/11] Move InputsChannelClient to a separate file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> Preparation for converting to GObject
> ---
>  server/Makefile.am             |  2 +
>  server/inputs-channel-client.c | 92
>  ++++++++++++++++++++++++++++++++++++++++++
>  server/inputs-channel-client.h | 44 ++++++++++++++++++++
>  server/inputs-channel.c        | 76 ++++++++++------------------------
>  server/inputs-channel.h        | 11 ++++-
>  5 files changed, 169 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..adcc5c6
> --- /dev/null
> +++ b/server/inputs-channel-client.c
> @@ -0,0 +1,92 @@
> +/*
> +   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;
> +};
> +
> +InputsChannelClient* 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;
> +}
> +
> +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;
> +    }
> +}
> +
> +RedChannelClient* inputs_channel_client_get_base(InputsChannelClient* icc)
> +{
> +    return &icc->base;
> +}

For most of inputs-channel.c there are conversion from RedChannelClient* to
InputsChannelClient* which are much less type unsafe, why a function for
such conversion?
This could be eliminated if inputs_channel_client_create returned
a RedChannelClient*.

Also in inputs-channel-client.c there is the RedChannel* -> InputsChannel*
conversion.

> diff --git a/server/inputs-channel-client.h b/server/inputs-channel-client.h
> new file mode 100644
> index 0000000..e655d9f
> --- /dev/null
> +++ b/server/inputs-channel-client.h
> @@ -0,0 +1,44 @@
> +/*
> +   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;
> +
> +InputsChannelClient* 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);
> +
> +/* FIXME: temporary until GObjectification */
> +RedChannelClient* inputs_channel_client_get_base(InputsChannelClient* icc);
> +
> +#endif /* _INPUTS_CHANNEL_CLIENT_H_ */
> diff --git a/server/inputs-channel.c b/server/inputs-channel.c
> index 584204f..2ae1d06 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;
> @@ -153,7 +142,7 @@ void inputs_channel_set_tablet_logical_size(InputsChannel
> *inputs, int x_res, in
>      sif->set_logical_size(inputs->tablet, x_res, y_res);
>  }
>  
> -const VDAgentMouseState *inputs_channel_get_mouse_state(InputsChannel
> *inputs)
> +VDAgentMouseState *inputs_channel_get_mouse_state(InputsChannel *inputs)
>  {
>      return &inputs->mouse_state;
>  }
> @@ -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_release_pipe_item(RedChannelClient *rcc,
>      RedPipeItem *base, int item_pushed)
>  {
> @@ -289,7 +263,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);
> @@ -337,11 +311,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);
> @@ -355,11 +325,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;
>          }
> @@ -541,18 +507,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);
> +    icc = inputs_channel_client_create(channel, client, stream, FALSE,
> +                                       num_common_caps, common_caps,
> +                                       num_caps, caps);
>      if (!icc) {
>          return;
>      }
> -    icc->motion_count = 0;
> -    inputs_pipe_add_init(&icc->base);
> +    inputs_pipe_add_init(inputs_channel_client_get_base(icc));
>  }
>  
>  static void inputs_migrate(RedChannelClient *rcc)
> @@ -593,7 +554,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;
> @@ -608,12 +569,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;
>  }
>  
> @@ -721,3 +677,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 fce757f..ce25ac7 100644
> --- a/server/inputs-channel.h
> +++ b/server/inputs-channel.h
> @@ -27,7 +27,7 @@
>  typedef struct InputsChannel InputsChannel;
>  
>  InputsChannel* inputs_channel_new(RedsState *reds);
> -const VDAgentMouseState *inputs_channel_get_mouse_state(InputsChannel
> *inputs);
> +VDAgentMouseState *inputs_channel_get_mouse_state(InputsChannel *inputs);
>  void inputs_channel_on_keyboard_leds_change(InputsChannel *inputs, uint8_t
>  leds);
>  void inputs_channel_set_tablet_logical_size(InputsChannel *inputs, int
>  x_res, int y_res);
>  
> @@ -41,5 +41,14 @@ 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);
> +
> +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,
> +};
>  

This enumeration can be moved to the client header.

>  #endif

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]