mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice
synced 2026-01-03 07:02:25 +00:00
inputs-channel-client: Improve encapsulation for InputsChannelClient
Move most inputs_channel_client_* functions inside the class. This also helps preparing handle_migrate_data to be virtual. Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
This commit is contained in:
parent
669df4fb38
commit
2ffa7d00c6
@ -20,8 +20,6 @@
|
||||
#include "migration-protocol.h"
|
||||
#include "red-channel-client.h"
|
||||
|
||||
XXX_CAST(RedChannelClient, InputsChannelClient, INPUTS_CHANNEL_CLIENT);
|
||||
|
||||
uint8_t *InputsChannelClient::alloc_recv_buf(uint16_t type, uint32_t size)
|
||||
{
|
||||
if (size > sizeof(recv_buf)) {
|
||||
@ -54,37 +52,32 @@ RedChannelClient* inputs_channel_client_create(RedChannel *channel,
|
||||
return rcc;
|
||||
}
|
||||
|
||||
void inputs_channel_client_send_migrate_data(RedChannelClient *rcc,
|
||||
SpiceMarshaller *m,
|
||||
RedPipeItem *item)
|
||||
void InputsChannelClient::send_migrate_data(SpiceMarshaller *m, RedPipeItem *item)
|
||||
{
|
||||
InputsChannelClient *icc = INPUTS_CHANNEL_CLIENT(rcc);
|
||||
|
||||
rcc->init_send_data(SPICE_MSG_MIGRATE_DATA);
|
||||
init_send_data(SPICE_MSG_MIGRATE_DATA);
|
||||
|
||||
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);
|
||||
spice_marshaller_add_uint16(m, motion_count);
|
||||
}
|
||||
|
||||
void inputs_channel_client_handle_migrate_data(InputsChannelClient *icc,
|
||||
uint16_t motion_count)
|
||||
void InputsChannelClient::handle_migrate_data(uint16_t motion_count)
|
||||
{
|
||||
icc->motion_count = motion_count;
|
||||
motion_count = motion_count;
|
||||
|
||||
for (; icc->motion_count >= SPICE_INPUT_MOTION_ACK_BUNCH;
|
||||
icc->motion_count -= SPICE_INPUT_MOTION_ACK_BUNCH) {
|
||||
icc->pipe_add_type(RED_PIPE_ITEM_MOUSE_MOTION_ACK);
|
||||
for (; motion_count >= SPICE_INPUT_MOTION_ACK_BUNCH;
|
||||
motion_count -= SPICE_INPUT_MOTION_ACK_BUNCH) {
|
||||
pipe_add_type(RED_PIPE_ITEM_MOUSE_MOTION_ACK);
|
||||
}
|
||||
}
|
||||
|
||||
void inputs_channel_client_on_mouse_motion(InputsChannelClient *icc)
|
||||
void InputsChannelClient::on_mouse_motion()
|
||||
{
|
||||
InputsChannel *inputs_channel = INPUTS_CHANNEL(icc->get_channel());
|
||||
InputsChannel *inputs_channel = INPUTS_CHANNEL(get_channel());
|
||||
|
||||
if (++icc->motion_count % SPICE_INPUT_MOTION_ACK_BUNCH == 0 &&
|
||||
if (++motion_count % SPICE_INPUT_MOTION_ACK_BUNCH == 0 &&
|
||||
!inputs_channel_is_src_during_migrate(inputs_channel)) {
|
||||
icc->pipe_add_type(RED_PIPE_ITEM_MOUSE_MOTION_ACK);
|
||||
icc->motion_count = 0;
|
||||
pipe_add_type(RED_PIPE_ITEM_MOUSE_MOTION_ACK);
|
||||
motion_count = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,26 +23,33 @@
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
// TODO: RECEIVE_BUF_SIZE used to be the same for inputs_channel and main_channel
|
||||
// since it was defined once in reds.c which contained both.
|
||||
// Now that they are split we can give a more fitting value for inputs - what
|
||||
// should it be?
|
||||
#define REDS_AGENT_WINDOW_SIZE 10
|
||||
#define REDS_NUM_INTERNAL_AGENT_MESSAGES 1
|
||||
|
||||
// approximate max receive message size
|
||||
#define RECEIVE_BUF_SIZE \
|
||||
(4096 + (REDS_AGENT_WINDOW_SIZE + REDS_NUM_INTERNAL_AGENT_MESSAGES) * SPICE_AGENT_MAX_DATA_SIZE)
|
||||
|
||||
class InputsChannelClient final: public RedChannelClient
|
||||
{
|
||||
uint8_t recv_buf[RECEIVE_BUF_SIZE];
|
||||
virtual bool handle_message(uint16_t type, uint32_t size, void *message) override;
|
||||
public:
|
||||
uint16_t motion_count; // XXX private
|
||||
// TODO: RECEIVE_BUF_SIZE used to be the same for inputs_channel and main_channel
|
||||
// since it was defined once in reds.c which contained both.
|
||||
// Now that they are split we can give a more fitting value for inputs - what
|
||||
// should it be?
|
||||
enum {
|
||||
AGENT_WINDOW_SIZE = 10,
|
||||
NUM_INTERNAL_AGENT_MESSAGES = 1,
|
||||
|
||||
// approximate max receive message size
|
||||
RECEIVE_BUF_SIZE =
|
||||
(4096 + (AGENT_WINDOW_SIZE + NUM_INTERNAL_AGENT_MESSAGES) *
|
||||
SPICE_AGENT_MAX_DATA_SIZE)
|
||||
};
|
||||
|
||||
using RedChannelClient::RedChannelClient;
|
||||
|
||||
uint8_t recv_buf[RECEIVE_BUF_SIZE];
|
||||
virtual bool handle_message(uint16_t type, uint32_t size, void *message) override;
|
||||
uint16_t motion_count;
|
||||
public:
|
||||
|
||||
void send_migrate_data(SpiceMarshaller *m, RedPipeItem *item);
|
||||
void on_mouse_motion();
|
||||
void handle_migrate_data(uint16_t motion_count);
|
||||
|
||||
protected:
|
||||
virtual uint8_t *alloc_recv_buf(uint16_t type, uint32_t size) override;
|
||||
virtual void release_recv_buf(uint16_t type, uint32_t size, uint8_t *msg) override;
|
||||
@ -55,11 +62,6 @@ RedChannelClient* inputs_channel_client_create(RedChannel *channel,
|
||||
RedStream *stream,
|
||||
RedChannelCapabilities *caps);
|
||||
|
||||
void inputs_channel_client_on_mouse_motion(InputsChannelClient* self);
|
||||
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);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
enum {
|
||||
|
||||
@ -262,7 +262,7 @@ void InputsChannelClient::send_item(RedPipeItem *base)
|
||||
break;
|
||||
case RED_PIPE_ITEM_MIGRATE_DATA:
|
||||
INPUTS_CHANNEL(get_channel())->src_during_migrate = FALSE;
|
||||
inputs_channel_client_send_migrate_data(this, m, base);
|
||||
send_migrate_data(m, base);
|
||||
break;
|
||||
default:
|
||||
spice_warning("invalid pipe iten %d", base->type);
|
||||
@ -307,7 +307,7 @@ bool InputsChannelClient::handle_message(uint16_t type, uint32_t size, void *mes
|
||||
SpiceMouseInstance *mouse = inputs_channel_get_mouse(inputs_channel);
|
||||
SpiceMsgcMouseMotion *mouse_motion = (SpiceMsgcMouseMotion *) message;
|
||||
|
||||
inputs_channel_client_on_mouse_motion(this);
|
||||
on_mouse_motion();
|
||||
if (mouse && reds_get_mouse_mode(reds) == SPICE_MOUSE_MODE_SERVER) {
|
||||
SpiceMouseInterface *sif;
|
||||
sif = SPICE_UPCAST(SpiceMouseInterface, mouse->base.sif);
|
||||
@ -321,7 +321,7 @@ bool InputsChannelClient::handle_message(uint16_t type, uint32_t size, void *mes
|
||||
SpiceMsgcMousePosition *pos = (SpiceMsgcMousePosition *) message;
|
||||
SpiceTabletInstance *tablet = inputs_channel_get_tablet(inputs_channel);
|
||||
|
||||
inputs_channel_client_on_mouse_motion(this);
|
||||
on_mouse_motion();
|
||||
if (reds_get_mouse_mode(reds) != SPICE_MOUSE_MODE_CLIENT) {
|
||||
break;
|
||||
}
|
||||
@ -552,7 +552,7 @@ static bool inputs_channel_handle_migrate_data(RedChannelClient *rcc,
|
||||
return FALSE;
|
||||
}
|
||||
key_modifiers_sender(inputs);
|
||||
inputs_channel_client_handle_migrate_data(icc, mig_data->motion_count);
|
||||
icc->handle_migrate_data(mig_data->motion_count);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user